1
\$\begingroup\$

In a small game Im working on I was able to implement ray picking with an opensource 3d engine called min3d but I cant figure how to keep track of what object is onscreen. I will some times have upwards of 120 objects to render within my scene and the raypicking is off occasionally. What id like to do is keep track of how many screen objects are within the camera and being rendered onscreen and set a boolean value based on that to add or remove objects from my arraylist I iterate through when the screen touch is registered and the ray picking method goes off.

So how can I check for which objects are onscreen and offscreen in opengl es on android.

\$\endgroup\$
3
\$\begingroup\$

Your task is just get a polyhedron representing the view area, and check if your objects bounding boxes are inside it.

n1 description

The blue are the near and far plane, the red and blue, together are a convex POLYHEDRON. Some engines give you helping methods to get this polyhedron. It's usually a pyramid(from camera to far plane), a trapezium(from near plane to far plane) or simply, a box for a orthographic projection. There are a lot of formulas about how to calculate if one box is inside a convex polyhedron on the web, This link is an awesome example.

I thought a little more, and other way, maybe cheaper to try this, is to calculate the angle between the object and the camera, see if it's withing fovy angle, farther than near plane, and nearer than far plane. Depending on how you do it, this could be cheaper but i'm not sure. Trig functions usually gets a great CPU time.

Some links to help you:

http://www.flipcode.com/archives/Frustum_Culling.shtml - Frustum culling is the technique that makes you don't draw what's outside the camera range. This link has how you can build a frustum bounding sphere, that may be very useful to you.
http://www.yaldex.com/game-programming/0131020099_ch22lev1sec1.html - Point inclusion, AABB tests and Point-in-Convex Polygon. To check if the object is inside the camera range.

| improve this answer | |
\$\endgroup\$
  • \$\begingroup\$ Awesome :) its so easy to get lost in all the info. Thanks for the link. Ill post back when I get it to work better using what I get from the link. \$\endgroup\$ – James andresakis Mar 6 '12 at 4:46

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.