Hi people!
I’m making a 3D game engine, and I have a problem.
I want to map objects coordinates to world coordinates, it is, get the position of each informed vertex.
For example:
glLoadIdentity();
glTranslatef(3.0f, 0.0f, 0.0f);
glRotatef(30.0f, 0.0f, 1.0f, 0.0f);
glBegin(GL_QUADS);
/* Here! I want to get the position where all the 4 points will be drawn (in X, Y, and Z). I can’t preknown this because I informed a rotation before. */
glVertex3f(0.0f, 1.0f, 0.0f);
glVertex3f(1.0f, 1.0f, 0.0f);
glVertex3f(1.0f, 0.0f, 0.0f);
glVertex3f(0.0f, 0.0f, 0.0f);
glEnd();
In this example, If i didn’t have informed the glRotatef(30.0f, 0.0f, 1.0f, 0.0f), It would be easy to discover the four points. All we should do is subtract each vertice informed in glVertex3f with the actual translation:
For example:
glLoadIdentity();
glTranslatef(1.0f, 0.0f, 0.0f);
glBegin(GL_QUADS);
glVertex3f(0.0f, 1.0f, 0.0f);
glVertex3f(1.0f, 1.0f, 0.0f);
glVertex3f(1.0f, 0.0f, 0.0f);
glVertex3f(0.0f, 0.0f, 0.0f);
glEnd();
In this case, we know that the first glVertex3f will be draw at X = 1.0f, Y = 1.0f and Z = 0.0f in relation to the WORLD.
We arrived to this, by adding the values passed to glTranslatef and glVertex3f.
So, this is my problem!! I would like to know how to get the objects coordinates in World coordinates, but I don’t know a way to do this.
Sorry for the long text guys, I hope someone knows how to do this!
If you didn’t understand what I asked, please, post a message telling this! Because I don’t know if I explained correctly what I want to do, and my english is not very good too…
If you don’t want to post the code here, send it to my e-mail: fernandohu@bol.com.br
I’ll be very greatefull!
Thank you a lot!
Fernando