# Calculate Frustum Sphere

This topic is 5090 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

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

##### Share on other sites
m_vForward is suppose to be the LookVector extred from the ViewMatrix...
Maybe that is the problem.

##### Share on other sites
I got a cone test ready....
But I prefer the speed test.

##### Share on other sites
You know I've been suggested to go here by tons of people...saying Gamedev is the forum for questions.

I have maybe only asked 4 questions on these forums.
Not one has EVER gotten even a reply.

1. 1
2. 2
3. 3
Rutin
15
4. 4
5. 5

• 10
• 9
• 9
• 11
• 11
• ### Forum Statistics

• Total Topics
633686
• Total Posts
3013323
×