PDA

View Full Version : get new vertex's value with/without glRotatef



Elqno
04-26-2010, 03:46 PM
Hi all,

I have posted the same question on gamedev, but I didn't get a straight away answer so far, so I will give it a try here too, coz if I remember good, the most popular forums are GD and this one :) so my qst is (hopefully in the right forum->beginner), is a way for getting the vertex value after a rotation was done using the glRotatef (I guess same case can be applied with glTranslatef), if it can't, does anybody have an idea of how to do it, I want to get this values, because I want them to apply for Collision Detection purposes (when the lowest vertex is touching or not the floor so it get's aligned with it), I read on .net about glGetFloatv but I don't know if that is useful, and I tried with glMultMatrixf with unsatisfactory results :p I don't know what I'm missing that I can't have it done, I tried using some cos/sin for every vertex but I think that is just a performance waste!, so I hope anybody will know how to help me, and hope to hear any answer to it soon :)

strattonbrazil
04-26-2010, 05:05 PM
Let me make sure I understand the problem. You have an object in object space and you want to know it's coordinates after it's transformed by the modelview matrix?

The glMultMatrixf is only useful for multiplying another matrix. Here's an example of what you might be looking for.

glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glTranslatef(5,6,7);
glRotatef(45,0,1,0);

Where does the vertex go after the translation and rotation?

Call glGet once on the GL_MODELVIEW_MATRIX, and multiply this by every vertex you want to get it's new position. Use a matrix API, hack it up yourself, you grab some code that multiplies matrices.

Another option that's a little harder and newer, but faster is transform feedback, where you can send vertex arrays to the GPU and can read back how they were transformed.

Rosario Leonardi
04-26-2010, 05:15 PM
Once you send your vertexes to openGL for drawing you can retrieve them with transform feedback, but this is not probably what you want.
glRotate (and glTranslate) modify the model view matrix, then the vertexes are postmultiplied by this matrix.

Probably you need this matrix (you can get it with glGetFloatv or you can compute it by yourself) to compute the collision detection. Probably you should compute the collision some bounding volume first, and then use convex mesh and Minkowsky addiction to simplify the computation.

There is a lot of literature on collision detection and the argument is really broad, can you be more specific on what you wanna do?

Elqno
04-30-2010, 01:32 PM
thxs strattonbrazil big up yourself! that was a massive answer, all the information that i needed i got thxs to you :) i will look about multiplying the 4x4 matrix with the 3d vector, i mean checking what i need to multiply hehe1 ;)

thxs :)