Frustum Testing--bounds/point/occlusion

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.