Calculate Frustum Sphere
I got this method off of an article on flipcode. I do believe it is incorrect.
At a few angles the entire terrain gets culled.
It may be because of how I calculate the m_vForward vector...but...
I know all the planes I am using are correct because all other methods of culling have worked up until I turned the frustum into a sphere and checked that instead of checking all 6 planes.
m_Planes[0] = nearplane
m_Planes[1] = far plane
void Frustrum::CalculateFrustrumSphere(const Vector vCameraPosition, const Vector vCameraTarget)
{
// calculate the radius of the frustum sphere
float fViewLen = m_Planes[1].fDistance - m_Planes[0].fDistance;
// use some trig to find the height of the frustum at the far plane
float fHeight = fViewLen * TanFOV;
// with an aspect ratio of 1, the width will be the same
float fWidth = fHeight;
// halfway point between near/far planes starting at the origin and extending along the z axis
Vector P(0.0f, 0.0f, m_Planes[0].fDistance + fViewLen * 0.5f);
// the calculate far corner of the frustum
Vector Q(fWidth, fHeight, fViewLen);
// the vector between P and Q
Vector vDiff(P - Q);
m_vForward = vCameraPosition - vCameraTarget;
m_vForward.Normalize();
// the radius becomes the length of this vector
m_FrustrumSphere.SetRadius(vDiff.Magnitude());
// calculate the center of the sphere
m_FrustrumSphere.SetCenter(vCameraTarget + (m_vForward * (fViewLen * 0.5f) + m_Planes[0].fDistance));
}
This code here is used to determine a sphere to sphere collision.
I believe this is correct.
//---------------------
//Sphere to Sphere Collision -- Checkes to see if *this is colliding with s
//---------------------
bool Sphere::SphereToSphere(const Sphere s) const
{
Vector vSepAxis = m_vCenter - s.Center();
float fRadiiSum = m_fRadius + s.Radius();
// if the distance between the centers is less than the sum
// of the radii, then we have an intersection
if(vSepAxis.SquaredMagnitude() <= (fRadiiSum * fRadiiSum))
return true;
// otherwise they are separated
return false;
}
m_vForward is suppose to be the LookVector extred from the ViewMatrix...
Maybe that is the problem.
Maybe that is the problem.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement