Game Development Reference
In-Depth Information
m_Near = nearClip;
m_Far = farClip;
double tanFovOver2 = tan(m_Fov/2.0f);
Vec3 nearRight = (m_Near * tanFovOver2) * m_Aspect * g_Right;
Vec3 farRight = (m_Far * tanFovOver2) * m_Aspect * g_Right;
Vec3 nearUp = (m_Near * tanFovOver2 ) * g_Up;
Vec3 farUp = (m_Far * tanFovOver2) * g_Up;
// points start in the upper right and go around clockwise
m_NearClip[0] = (m_Near * g_Forward) - nearRight + nearUp;
m_NearClip[1] = (m_Near * g_Forward) + nearRight + nearUp;
m_NearClip[2] = (m_Near * g_Forward) + nearRight - nearUp;
m_NearClip[3] = (m_Near * g_Forward) - nearRight - nearUp;
m_FarClip[0] = (m_Far * g_Forward) - farRight + farUp;
m_FarClip[1] = (m_Far * g_Forward) + farRight + farUp;
m_FarClip[2] = (m_Far * g_Forward) + farRight - farUp;
m_FarClip[3] = (m_Far * g_Forward) - farRight - farUp;
// now we have all eight points. Time to construct six planes.
// the normals point away from you if you use counter clockwise verts.
Vec3 origin(0.0f, 0.0f, 0.0f);
m_Planes[Near].Init(m_NearClip[2], m_NearClip[1], m_NearClip[0]);
m_Planes[Far].Init(m_FarClip[0], m_FarClip[1], m_FarClip[2]);
m_Planes[Right].Init(m_FarClip[2], m_FarClip[1], origin);
m_Planes[Top].Init(m_FarClip[1], m_FarClip[0], origin);
m_Planes[Left].Init(m_FarClip[0], m_FarClip[3], origin);
m_Planes[Bottom].Init(m_FarClip[3], m_FarClip[2], origin);
}
With the location of the corner points correctly nabbed, the planes of the view frus-
tum can be created with three known points for each one. Don
'
t forget that the order
in which the points are sent into the plane equation is important. The order deter-
mines the direction of the plane
'
s normal and therefore which side of the plane is the
inside versus the outside.
Transformations
One of the processes in a 3D graphics pipeline transforms arbitrary points in the 3D
game universe into 2D points on a display. There are three things to consider: an
object
s position and orientation in the 3D world, the position and orientation of
the camera or viewpoint, and the physical dimensions of the display and field of
view. Each one requires the definition of a transform, which is stored in a Mat4 x 4
'
 
 
Search WWH ::




Custom Search