Jump to content
• Advertisement

# How can i calculate world coordinates?

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

If you intended to correct an error in the post then please contact us.

## Recommended Posts

hi all, i want to draw an object with the following transformations
glTranslatef(1,2,3);
DrawObject();


Now if i do this instead
float Matrix[16];
float *vect1 = new float[3];

glTranslatef(1,2,3);
glGetFloatv(GL_MODELVIEW_MATRIX,Matrix);
vect[0] = Matrix[12];
vect[1] = Matrix[13];
vect[2] = Matrix[14];
DrawObject();


Would this "vect" be not the World Coordinates of Object i am drawing? In this case the vect should be (1,2,3); if Not.. then i how would i calculate its world coordinates. Thanks in advance.

#### Share this post

##### Share on other sites
Advertisement
As the name GL_MODELVIEW_MATRIX implies, the resulting matrix is the product of the VIEW matrix and the MODEL matrix. Hence it defines the transformation from local space (across the world space) to view space.

Look at this thread. Therein I've described a method that does something similar like you want.

#### Share this post

##### Share on other sites
Quote:
 Original post by haegarrAs the name GL_MODELVIEW_MATRIX implies, the resulting matrix is the product of the VIEW matrix and the MODEL matrix. Hence it defines the transformation from local space (across the world space) to view space.Look at this thread. Therein I've described a method that does something similar like you want.

i have read that thread many times. and i read it again today as well.

can't exactly find where i can calculate world coordinates in it.

I just wanna know. when i am drawing anything in a scene who's position is not knows to me. what i know is that i have a camera and i am doing some transformations and after that i am drawing that object. can i find his position in terms of a vector (x,y,z) from the transformation matrices given?

#### Share this post

##### Share on other sites
As explained in the cited thread, you've to break OpenGL's computation of the MODELVIEW matrix, intermediately perform the computation of the world matrix, and then continue the MODELVIEW matrix by multiplying with the world matrix.

An outline looks like this:
glLoadIdentity();// do here all transformations of the camera as usual// at this point, the MODELVIEW matrix consists of nothing but the VIEW portionglPushMatrix(); // create a (temporary) matrix that can be overwritten nextglLoadIdentity(); // initialize temporary matrix as identity matrix// do here all transformation of the model as usual// at this point, MODELVIEW has an identity VIEW portion and the wanted MODEL portion, ...// ... so it shows a pure local-to-global transformationGLfloat model[16];glGetFloatv(GL_MODELVIEW_MATRIX, model); // read the model's world matrix// at this point the "model" variable contains the wanted world matrixglPopMatrix(); // remove the temporary matrixglMultMatrix(model); // complete the MODELVIEW matrix// at this point the MODELVIEW matrix is the product of the original VIEW portion ...// ... and the model's world matrix// do here the rendering of the model

The shown method is not meant to be optimal. E.g. it may be better to isolate the world matrix computation and perform it (for each model) before entering the rendering loop.

#### Share this post

##### Share on other sites
Yea i get it now.. thanx a bunch..

i feel a little dumb though :)

[Edited by - waZim on June 5, 2009 12:16:35 PM]

#### Share this post

##### Share on other sites

• Advertisement
• Advertisement

• ### Popular Contributors

1. 1
2. 2
Rutin
22
3. 3
4. 4
frob
18
5. 5
• Advertisement

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

• Total Topics
632566
• Total Posts
3007107

×

## Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!