#### Archived

This topic is now archived and is closed to further replies.

# Matrix Stack Coords -> World Coords

This topic is 5942 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

I''m rendering some points on top of a few matrix transformations, how do i get the world coordinates for these points? duckbob

##### Share on other sites
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]

##### Share on other sites
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...)

##### Share on other sites
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.

##### Share on other sites
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.)

##### Share on other sites
will glLookAt affect the camera transformation?

and thanks sdrhod & travis

##### Share on other sites
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.

1. 1
Rutin
46
2. 2
3. 3
4. 4
5. 5

• 11
• 9
• 12
• 10
• 13
• ### Forum Statistics

• Total Topics
632989
• Total Posts
3009740
• ### Who's Online (See full list)

There are no registered users currently online

×