Archived

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

grassgrass

OpenGL how can get XYZ coord in OopenGL

Recommended Posts

Depends if you need the coordinate in object-space, world-space etc.?

Just multiply your coordinate with your final tranformation-matrix and you'll have the coordinate.

Best regards
Roquqkie

[edited by - Roquqkie on March 23, 2004 5:09:11 AM]

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
if in world space, how can i do?

thx

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
thx thx so much.
how about object space, how can i do?
thx

Share this post


Link to post
Share on other sites
I use D3D where you would simply multiply your scaling-matrix with the rotation-matrix and the translation-matrix to form the world-matrix. In ogl you use immediate calls like glRotate3f(...) etc. so if you don''t explicitly create your own world-matrix, you can retrieve the current world-matrix using:

glGetFloatv(GL_MODELVIEW_MATRIX, mm);

where mm is float mm[16];

Now you have your world-matrix stored in the mm array. Now you just need to matrix-multiply this with your xyzw-coordinate.

Best regards
Roquqkie

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
thx...
but i ....

for example
glTranslatef(10, 0, 0);
glutWireSphere(10.5, 10, 8);
float mm[16];
glGetFloatv(GL_MODELVIEW_MATRIX, mm);

mm[12..14] should be XYZ coord, isn''t it?

Share this post


Link to post
Share on other sites
Ignore my last post if you saw it. You'll need your camera matrix in order to convert to world coordinates.

Currently your modelview is your camera matrix * any object transformations :

Mv = Cm * Om

You need Om in order to go from object to world space. To get Om, you can do this:

Mv = Om * CmT

So
Om = Mv * CmT-1

That should be right anyway, it's been a while since I last had to do it, but it should work. Then, to go from obj space to world space, just post multiply the position vector in object space by Om, ie

Pw = Om*Po

[edited by - benjamin bunny on March 23, 2004 5:58:04 AM]

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
thx for teaching

for example
glLookAt(20,10,0, 10,0,0, 0,1,0);
glTranslatef(10, 0, 0);
glutWireSphere(10.5, 10, 8);
float mm[16];
glGetFloatv(GL_MODELVIEW_MATRIX, mm);

i get obj matrix XYZ from mm[12..14], then how can i get camera matrix?

Share this post


Link to post
Share on other sites
The camera matrix is your modelview matrix just after the camera transformation, so I guess you should put a glGetFloatv after gluLookAt to get the camera matrix, unless the glTranslate is supposed to be part of your camera transform, in which case you'd put it after that.

By the way, the solution I've given you is a general purpose one that works if you've got only the camera matrix and the modelview matrix. You can probably shortcut it if you already know the object transformation.

[edited by - benjamin bunny on March 23, 2004 7:22:33 AM]

Share this post


Link to post
Share on other sites