Calculating position in a 3d space

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?

Jesus Christ i’m drunk and maybe my account will be closed tomorrow but, well, your client area is of size x_clienty_client and your image is of size x_imagey_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 :smiley:

Edit: I just have recognized that I’ve misunderstood you…

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.

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.

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?

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.