PDA

View Full Version : My First post



Rohithzhere
05-30-2009, 07:56 AM
Hi all,

I started OpenGL recently. I managed to create a window and render a triangle inside it and also rotate it based on a timer.
I was trying to find a command that retrieves the current position and orientation of a given polygon.
Like i assign a ID to each polygon i create and then based on that ID i can query information about that polygon. Can any1 plz guide me how to do it?

Regards,
Rohith H N

Dark Photon
05-30-2009, 05:50 PM
I was trying to find a command that retrieves the current position and orientation of a given polygon.
Like i assign a ID to each polygon i create and then based on that ID i can query information about that polygon. Can any1 plz guide me how to do it?
One little tip for future posts: put a summary of your problem in the subject. You'll get more responses.

Well when you say "retrieve the current position and orientation of a given polygon" you need to state what coordinate space you want it in to have a properly defined question. I'll presume window-space for now.

I'm also presuming you're leaving the coordinates you provide to OpenGL (via glVertex, glVertexPointer, or whatever) the same and using glRotate to rotate the object.

In that case, the object-space position of your polygons (i.e. the coordinates you are providing OpenGL) are constant, but the window-space position of your polygons (i.e. those coordinates after being multiplied by the OpenGL MODELVIEW matrix, the PROJECTION matrix, and the VIEWING transform) are changing. And that you want to know what the window-space position of your polygon vertices are. Right?

If so, then the short answer is you "can" get the GPU to do what you ask (i.e. give you back where it transformed the vertices), but you're probably not ready for that yet. Get a little more familiar with basic GPU programming first. In simplest use, you send the GPU "draw commands", it draws your polygons, and then promptly tosses the details you gave it. So after it's done, it doesn't know anymore! :)

So for now what I suggest you do is, right after you render your polygons (i.e. right after glEnd or a glDraw* call, depending on how you're drawing), use gluProject (http://www.opengl.org/documentation/specs/man_pages/hardcopy/GL/html/glu/project.html) to transform some of your object-space vertices into window-space. This gives you what you want, but just does it on the CPU instead of the GPU.

To call this function, you're going to need the current MODELVIEW, PROJECTION and VIEWING transforms. Here's some code that shows you exactly how to do that. (http://www.gamedev.net/community/forums/topic.asp?topic_id=65558) Just call gluProject at the end instead of gluUnProject.