Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

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.

share|improve this question
add comment

1 Answer 1

up vote 3 down vote accepted

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.

share|improve this answer
    
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. –  James andresakis Mar 6 '12 at 4:46
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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