XNA UK User Group

A helping hand for bedroom coders throughout the land.
in

XNAGoodies

Articles and thoughts on working with the Microsoft XNA Framework.

January 2008 - Posts

  • Using Matrix.CreatePerspectiveOffCenter()

    I wanted to use Matrix.CreatePerspectiveOffCenter() recently but had a little trouble converting from my usage of Matrix.CreatePerspective(). The latter method requires field of view, aspect ratio and near far distances, the former requires the boundaries of the near plane in view space. Fortunately, calculating the near plane size is just a little simple trigonometry.

    // tan(angle) = opposite / adjacent
    // opposite = adjacent * tan(angle)
    float nearPlaneHSize = nearClip * (float)Math.Tan(fov*0.5f);
    projection = Matrix.CreatePerspectiveOffCenter(
        -nearPlaneHSize * aspectRatio,
        nearPlaneHSize * aspectRatio,
        -nearPlaneHSize, nearPlaneHSize,
        nearClip, farClip);
    

    Posted Jan 14 2008, 11:44 AM by leaf with no comments
    Filed under: , ,