XNA Creators Club Online
Page 1 of 1 (2 items)
Sort Posts: Previous Next

Calculation a projection matrix

Last post 10/04/2009 0:37 by PhilTaylor. 1 replies.
  • 08/04/2009 17:54

    Calculation a projection matrix

    MSDN says:
    http://msdn.microsoft.com/en-us/library/bb147302(VS.85).aspx
    "For your application, using field-of-view angles to define the x- and y-scaling coefficients might not be as convenient as using the viewport's horizontal and vertical dimensions (in camera space). As the math works out, the following two formulas for w and h use the viewport's dimensions, and are equivalent to the preceding formulas."
    Math fomula
    Let we have following data:
    eye = (0, 0, 0);
    at = (0, 0, -1000);
    up = (0, 1, 0);
    znearPlane = 0.0001;
    zfarPlane = 1000.0;
    Device.Vieport: size=(400,400)
    aspectRatio=1.0;

    In that case we must to get:
    w = h = 2*0.0001/400 = 0.0000005
    If we will use Matrix.PerspectiveFovRH method then we will get following results from device.Transform.Projection:
    w = h = 3.732051

    What am I doing incorrectly?

    Thanks
  • 10/04/2009 0:37 In reply to

    Re: Calculation a projection matrix

    RH functions use slightly different equations, from the API doc:

    This function computes the returned matrix as shown.

    xScale     0          0              0
    0        yScale       0              0
    0        0        zf/(zn-zf)        -1
    0        0        zn*zf/(zn-zf)      0
    


    where: yScale = cot(fovY/2) xScale = yScale / aspect ratio
    so you'd have to work out from that what the corresponding w,h values would be


    http://www.futuregpu.net ex-Aces Lead PM/ex DX SDK PM/ex D3D Evangelist now LRB Launch Native Title Wrangler
Page 1 of 1 (2 items) Previous Next