Reputation: 12024
In my Android application I am using GLSurfaceView to draw 3d object like a box object. I animate this object by translating it using OpenGL ES apis. At some point during animation, the object would have gone out of the visible viewport window. At this point I must remove this object from the collection of other objects that are being drawn. How can I detect that the object has gone out of the view? Short code sample would be appreciated.
Upvotes: 1
Views: 2192
Reputation: 3009
Here is a frustum class for android, a port of the code from here. It allows you to extract the frustum parameters from OpenGL, and then test various geometric primitives (points, spheres, axis-aligned cuboids) for inclusion in the view volume.
Two things to look out for:
Upvotes: 1
Reputation: 10106
What you you're looking from is called viewing frustum culling.
The viewing frustum is a geometric representation of the volume visible to the virtual camera. Naturally, objects outside this volume will not be visible in the final image, so they are discarded. Often, objects lie on the boundary of the viewing frustum. These objects are cut into pieces along this boundary in a process called clipping, and the pieces that lie outside the frustum are discarded as there is no place to draw them.
Several tutorials on the topic:
http://www.lighthouse3d.com/opengl/viewfrustum/
http://www.crownandcutlass.com/features/technicaldetails/frustum.html
Upvotes: 1