Game Development Reference
In-Depth Information
Straight Up and Straight Down Are Tricky!
This
t completely perfect because there are two degenerate
orientations. Given the definition of up as (X=0, Y=1, Z=0) in world space, the
two places you can
system isn
'
t easily look are straight up and straight down. You can
construct the view transform for this degenerate case quite easily by creating a
view transform looking straight forward in the normal way and then using a
90-degree rotation about the Y-axis to transform the matrix to look straight up.
'
'
Remember that the camera
s view transform is a matrix, just like any other. You
don ' t have to use the look-at function to calculate it, but it tends to be the most effec-
tive camera positioning function there is.
Projection Transform
Using the world transform and the view transform, vertices from object space can be
transformed into vertices from world space and then transformed into camera space.
Now we need to take all those 3D vertices sitting in camera space and figure out
where they belong on your computer screen and which objects sit in front of other
objects. The view frustum will help determine what gets drawn and what gets culled.
Every object inside the view frustum will be drawn on your screen. The projection
transform takes the camera space (X,Y,Z) of every vertex and transforms it into a
new vector that holds the screen pixel (X,Y) location and a measure of the vertices
'
distance into the scene.
Here ' s the code to create the projection transform using the settings of the viewing
frustum and the screen dimensions:
Mat4x4 matProj;
m_Frustum.SetAspect(DXUTGetWindowWidth() / (FLOAT) DXUTGetWindowHeight());
D3DXMatrixPerspectiveFovLH(
&m_Projection,
m_Frustum.m_Fov,
m_Frustum.m_Aspect,
m_Frustum.m_Near, m_Frustum.m_Far );
The DirectX function that helps you calculate a projection matrix
something you
don ' t want to do by yourself accepts four parameters after the address of the
matrix:
n Field of view: Expressed in radians, this is the width of the view angle.
/4 is a
π
pretty standard angle. Wider angles such as 3
/4 make for some weird results.
π
Try it and see what happens.
n Aspect ratio: This is the aspect ratio of your screen. If this ratio were 1.0, the
projection transform would assume you had a square screen. A 1280 × 960
screen has a 1.333 aspect ratio.
Search WWH ::




Custom Search