• Announcements

Archived

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

OpenGL how can get XYZ coord in OopenGL

Recommended Posts

Dear all, after i use gltranslated(1,1,1) & glrotated(45, 0,1,0) to move the objects, how can i get XYZ corrd for this object.

Share on other sites
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 on other sites
if in world space, how can i do?

thx

Share on other sites
thx thx so much.
how about object space, how can i do?
thx

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

thx

• Partner Spotlight

• Forum Statistics

• Total Topics
627674
• Total Posts
2978558
• Similar Content

• Both functions are available since 3.0, and I'm currently using glMapBuffer(), which works fine.
But, I was wondering if anyone has experienced advantage in using glMapBufferRange(), which allows to specify the range of the mapped buffer. Could this be only a safety measure or does it improve performance?
Note: I'm not asking about glBufferSubData()/glBufferData. Those two are irrelevant in this case.
• By xhcao
Before using void glBindImageTexture(    GLuint unit, GLuint texture, GLint level, GLboolean layered, GLint layer, GLenum access, GLenum format), does need to make sure that texture is completeness.
• By cebugdev
hi guys,
are there any books, link online or any other resources that discusses on how to build special effects such as magic, lightning, etc. in OpenGL? i mean, yeah most of them are using particles but im looking for resources specifically on how to manipulate the particles to look like an effect that can be use for games,. i did fire particle before, and I want to learn how to do the other 'magic' as well.
Like are there one book or link(cant find in google) that atleast featured how to make different particle effects in OpenGL (or DirectX)? If there is no one stop shop for it, maybe ill just look for some tips on how to make a particle engine that is flexible enough to enable me to design different effects/magic
let me know if you guys have recommendations.
• By dud3
How do we rotate the camera around x axis 360 degrees, without having the strange effect as in my video below?
Mine behaves exactly the same way spherical coordinates would, I'm using euler angles.
Tried googling, but couldn't find a proper answer, guessing I don't know what exactly to google for, googled 'rotate 360 around x axis', got no proper answers.

References:
Code: https://pastebin.com/Hcshj3FQ
The video shows the difference between blender and my rotation:

• By Defend
I've had a Google around for this but haven't yet found some solid advice. There is a lot of "it depends", but I'm not sure on what.
My question is what's a good rule of thumb to follow when it comes to creating/using VBOs & VAOs? As in, when should I use multiple or when should I not? My understanding so far is that if I need a new VBO, then I need a new VAO. So when it comes to rendering multiple objects I can either:
* make lots of VAO/VBO pairs and flip through them to render different objects, or
* make one big VBO and jump around its memory to render different objects.
I also understand that if I need to render objects with different vertex attributes, then a new VAO is necessary in this case.
If that "it depends" really is quite variable, what's best for a beginner with OpenGL, assuming that better approaches can be learnt later with better understanding?

• 11
• 11
• 10
• 12
• 22