PDA

View Full Version : Calculating position in a 3d space



AE
08-01-2006, 05:22 PM
I'm making a 3D OpenGL screensaver. It will have an image that bounces off the edges of the screen. The trouble is, I can't figure out how to calculate when my image touches a side. Can anyone offer help in this area?

moebi
08-01-2006, 05:54 PM
Jesus Christ i'm drunk and maybe my account will be closed tomorrow but, well, your client area is of size x_client*y_client and your image is of size x_image*y_image, and maybe it's scaled, but, please, this is really not difficult, it's fu***ng 2-dimensional... okay, i'll help you tomorrow :D

Edit: I just have recognized that I've misunderstood you...

Jon723
08-02-2006, 09:01 AM
If im not mistaken what you need to do is take your image and do a simple check to see if your image x_position+x_width/2 and y_position+y_height/2 (that might not be right) is greater or less than the width and height of your screen. When it is you want to do whatever you have to to reverse your directions.

k_szczech
08-02-2006, 09:52 AM
You can try detecting if certain point is in view frustum. It was just discussed:
http://www.opengl.org/cgi-bin/ubb/ultimatebb.cgi?ubb=get_topic&f=6&t=000619#000008

Or you can use OpenGL's feedback mode - all you need to do is to search for minimum and maximum coordinates in the returned data.

AE
08-03-2006, 06:24 PM
I found that I can use gluProject to get the center of the object in screen coords, but that does not help me any unless I can get the outsides of the object in screen coords.

Does anyone know how to use gluProject to get the edges of an object in screen coords?

08-05-2006, 06:40 PM
I'm thinking a general way to deal with this is to collide your object's bounding-box against the planes of the view frustum. There are many resources online that deal with plane-AABB intersections and so forth. For a more accurate intersection, you may need to test triangles/points as opposed to their bounds.

For the orthogonal projection corner cases, it could be as simple as testing a 2D bounding rectangle's extents against the viewport, as was originally suggested.