- Home /
CalculateFrustumPlanes not working
I tried the code on the Unity Scripting Reference to see how CalculateFrustumPlanes() works, yet it gave me these really weird planes that were not representative of the view frustum at all!
What's going on here?
http://docs.unity3d.com/ScriptReference/GeometryUtility.CalculateFrustumPlanes.html
Do I need to add the position of the camera as offset to each of the planes' transforms?
Answer by Bunny83 · Jul 09, 2016 at 09:47 PM
They do work, but you interpreted the result wrong. The returned planes are infinite mathematical planes, not polygons. The example in the docs is actually misleading. Drawing a quad mesh for each plane makes no sense this way. There have been a lot questions about that topic. See this question for how to create a mesh that represents the camera frustum.
Wow, thank you! It appears you did a lot of work on this topic. I actually was able to get the results I needed by just making each plane a child of the camera before calculating their rotation and position. In this way, I was able to get 6 quads that represented the frustum of the camera, and would rotate and translate with the camera (because they were childed). However, when I tried to use GeometryUtility.TestPlanesAABB() to tell if a particular collider was within the bounds of the planes, it would always return null. Is this because of what you are talking about?
cam = Camera.main;
planes = GeometryUtility.CalculateFrustumPlanes(cam);
int k = 0;
while (k < planes.Length)
{
GameObject p = GameObject.CreatePrimitive(PrimitiveType.Plane);
p.name = "Plane " + k.ToString();
p.transform.parent = cam.gameObject.transform;
p.transform.position = (-planes[k].normal * planes[k].distance);
p.transform.rotation = Quaternion.FromToRotation(Vector3.up, planes[k].normal);
k++;
}
I just retested TestPlanesAABB and it works like expected. As soon as the AABB of a collider enters the viewing frustum TestPlanesAABB returns true, otherwise it returns false.
Your original question doesn't even mention TestPlanesAABB and seems to be more about visualizing the view frustum. Your original question is a hypothesis that states CalculateFrustumPlanes doesn't work. At no point you state what you actually want to do. When you ask a question it should be based on the problem you want to solve and not about speculations what might be wrong because the answer to such question is usually either "yes" or "no".
The planes returned by CalculateFrustumPlanes are oriented in worldspace. So the plane normal is a world space direction and the distance is the distance of the plane from the world origin.
Do you have any actual code you're using that doesn't work? If so you might ask a seperate question, stating what you actually want to do, what doesn't work and what you would have expected.
Your answer
Follow this Question
Related Questions
How do I trigger the visibility of an object through OnBecame(In)visible? 0 Answers
Which plane is which with CalculateFrustumPlanes 3 Answers
How to change camera visibility after certain distance? 0 Answers
Why is part of object outside camera frustum visible? 1 Answer
Can't see a flare from above? 0 Answers