Test whether a particular rendered object is in a specific camera frustum:
1 // returns True if renderer is within frustum 2 Public Static BOOL isredererinfrustum (Renderer renderer,camera Cam) 3 {4 plane[] planes = geometryutility.calculatefrustumplanes (CAM); 5 return Geometryutility.testplanesaabb (Planes, renderer.bounds); 6 }
Geometryutility.calculatefrustumplanes got six planes of the camera cones (up, down, around, and back and forth) I drew their respective normals:
It's not hard to understand the six planes here.
The result of a test render is true whether it is partially or wholly in the frustum.
To test whether a particular point is in the camera frustum:
1 //returns True is the point in the frustum2 Public Static BOOLIspointinfrustum (Vector3 point,camera Cam, outVector3 viewportlocation)3 {4Bounds B =NewBounds ();5B.center =Point ;6B.size =Vector3.zero;7 8 //construct frustum planes from camera9Plane[] Planes =geometryutility.calculatefrustumplanes (CAM);Ten One BOOLIsVisible =Geometryutility.testplanesaabb (Planes, B); A -Viewportlocation =Vector3.zero; - the if(isVisible) - { -Viewportlocation =Cam. Worldtoviewportpoint (point); - } + returnisVisible; -}
Consider the point as a special case of the last rendered object with a boundary size of 0
Consider the object in the camera and test without occlusion:
1 Public Static BOOLIsVisible (Renderer renderer,camera Cam)2 {3 4 //whether is in camera frustum5 if(Isredererinfrustum (renderer, Cam))6 return! Physics.linecast (Renderer.transform.position, cam.transform.position);//whether there ' s no objects between the other objs.7 8 9 return false;Ten}
Determine the condition except the object in the camera frustum, and there is no other object between the camera block
Through the physical ray detection between the two to achieve
For: third-person role-play the role of the detection control to where the scene is obscured
--Added separately--
Frustum Testing--bounds/point/occlusion