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.

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);

Published Jan 14 2008, 11:44 AM by leaf
Filed under: , ,

Comments

No Comments

Leave a Comment

(required)  
(optional)
(required)  
Add