Jump to content
  • Advertisement
Sign in to follow this  
Halsafar

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.

If you intended to correct an error in the post then please contact us.

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 this post


Link to post
Share on other sites
Advertisement
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.

Is this to advanced :)??? common show your stuff people.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!