Matrix Stack Coords -> World Coords

Started by
5 comments, last by duckbob 21 years, 9 months ago
I''m rendering some points on top of a few matrix transformations, how do i get the world coordinates for these points? duckbob
Advertisement
If you are trying to do what I think you are (I'm a newcomer to OpenGL, and indeed 3d graphics programming) then you need glGetFloatv(GL_MODELVIEW, yourArray[16]); which stores the current modelview matrix in the second parameter array. There may well be other ways of doing this more efficiently (and i'll keep reading in case someone tells us) because someone on IRC #openGL mentioned glGetMatrix() which I couldn't fathom out, and isn't in any of my literature. Red herring?



[edited by - sdrhod on July 15, 2002 5:09:28 PM]
I''m not trying to return the actual matrix...Say I apply 5 sets of matrix transformations rendering a section of a limb type object, rotate, draw, translate, rotate, draw, translate, rotate, ect... I need to find the actual posistion of the end of that "limb" object...if someone knows how to dirive that from just the matrix returned with glGetFloatv(GL_MODELVIEW, yourArray[16]); that would work, (can anyone tell me?), but i''d prefer if openGL would simply return a point for me, say at the end of the transformations, such as

glTranslate(0,2,0);
glBegin(GL_LINES);
glVertex3f(0,0,0);
<--Command would go here, given 0,0,0 coords, would return 0,2,0
glEnd();

that would be the most useful...what i''m trying to do is adjust the trajectory of an object from the end of the limb being fired acording to where the end limb segment currently is.
(someone shooting while falling/getting shot, ect...)
I think this should work.

  float matrix[16];float x,y,z;glGetFloatv(GL_MODELVIEW_MATRIX,matrix);x=matrix[12];y=matrix[13];z=matrix[14];  

12,13,14 corespond to these positions on the 4x4 matrix:
|?,?,?,x||?,?,?,y||?,?,?,z||?,?,?,?| 

Although maybe I should be multiplying the 4x4 matrix by a 1x4 matrix?
(Someone who knows matrices better would know.
A quick test shows this works fine, IF you undo your camera transformation.

(Since it''s giving you coordinates already transformed by for camera, if you want world space you have to undo that.)
will glLookAt affect the camera transformation?

and thanks sdrhod & travis

Yes it will.


I''m trying to think of a simple way to undo the transformation, but I can''t think of a simple way.

This topic is closed to new replies.

Advertisement