Game Development Reference
In-Depth Information
Frustum::Frustum()
{
m_Fov = D3DX_PI/4.0f; // default field of view is 90 degrees
m_Aspect = 1.0f;
// default aspect ratio is 1:1
m_Near = 1.0f;
// default near plane is 1m away from the camera
m_Far = 1000.0f;
// default near plane is 1000m away from the camera
}
bool Frustum::Inside(const Vec3 &point) const
{
for (int i=0; i<NumPlanes; ++i)
{
if (!m_Planes[i].Inside(point))
return false;
}
return true;
}
bool Frustum::Inside(const Vec3 &point, const float radius) const
{
for(int i = 0; i < NumPlanes; ++i)
{
if (!m_Planes[i].Inside(point, radius))
return false;
}
// otherwise we are fully in view
return true;
}
The next method, Init() , is a little heavy on the math. The algorithm is to find the
eight points in space made by corners of the view frustum and use those points to
define the six planes. If you remember your high school geometry, you ' ll remember
that the tangent of an angle is equal to the length of the opposite side divided by the
adjacent side. Since we know the length D from the camera to the near clipping
plane, we can find the length between the center point of the near clipping plane to
the right edge and also the top using the aspect ratio. The same operation is repeated
for the far clipping plane, and that gives us the 3D location of the corner points:
void Frustum::Init(const float fov, const float aspect, const float nearClip, const
float farClip)
{
m_Fov = fov;
m_Aspect = aspect;
Search WWH ::




Custom Search