PDA

View Full Version : Updating array of vertex coordinates



S4pphire
09-06-2004, 04:58 PM
I have an array of vertex coordinates and I'm using it in conjunction with glVertexPointer to draw a 2d shape. What I'm trying to figure out is, after applying a transformation such as reposition or rotate, how to either 1) update that array to reflect the new coordinates of each vertex, or 2) somehow retrieve the coordinate info.

09-06-2004, 05:54 PM
When you say you apply a transformation, are you referring to an OpenGL transformation through glTranslate, glMultMatrixd, etc. or manually changing vertex positions?

If you're talking about OpenGL transformations, you could use the feedback buffer, you could extract the modelview matrix and transform them yourself in software (...) or some other ways; what exactly is your goal?

As for replacing the data, you should be able to just overwrite the vertex array in main memory (assuming you're not using any vertex array extensions that lock or upload the data) and reinitialize your vertex pointers.

S4pphire
09-06-2004, 06:48 PM
Yes, I would be using the built-in transform functions like glTranslate, glRotate, and glScale. The reason I need to know the updated coords of the vertices is that I will be doing things based on user input, specifically mouse clicks on certain parts of the 2D shape, so it'd be useful to know where the vertices are located. So I guess I'll try looking into the glFeedbackBuffer. Thanks for the tip.

-NiCo-
09-07-2004, 12:41 AM
Originally posted by S4pphire:
The reason I need to know the updated coords of the vertices is that I will be doing things based on user input, specifically mouse clicks on certain parts of the 2D shape, so it'd be useful to know where the vertices are locatedYou could use gluUnproject for this, it converts window space coordinates back to 3D space coordinates.

Greetz,

Nico

09-08-2004, 04:47 PM
When I need to know world-space coordinates for everything I just use a spare matrix (for example, GL_MODELVIEW1_ARB if GL_ARB_vertex_blend is supported, or one of the program matrices if you have vertex/fragment programs) to which all modelling transformations are also applied as they are applied to the modelview matrix. For viewing transformations, i.e. gluLookAt or putting the camera somewhere, I just apply it to the modelview matrix. This way, the modelview matrix still correctly goes to eye coordinates from object space while the "modelling" matrix goes from object space to world space.

Useful for getting relative positions of hierarchial stuff and proper vectors for other effects.