# object to world space

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

## Recommended Posts

I am wondering what would be the best way to translate a vertice in object space to absolute world space. For example, imagine the following code: glLoadIdentity(); glTranslatef( 5, 0, 0 ); glTranslatef( 5, 0, 0 ); glBegin( GL_POINTS ); glVertex3f( 0,0,0 ); glEnd(); The object space coordinate of the point would be at 0,0,0, but the absolute worldspace coordinate would be 10,0,0. I believe I can just retrieve the modelview matrix and multiply it with the vertex, but I am not sure how to carry out the operation, for example the vertex needs to have 4 coordinates, should I make the 4th be 1?

##### Share on other sites
with a modelview transformation you can ignore anything that ends up in the 4th component, so you can either use a 3 component vector or make the 4th component 1.

##### Share on other sites
Ok, though it may not seem strikingly obvious, my experience with matrix operations is somewhat limited (sans the use of helper functions like glTranslatef, glRotatef, etc. )

However, I have done a little research, and I am wondering if the following would do what I want. Lets let x,y,z represent the values of a coordinate in object space which I want to translate in the following:

float m[16] = glGetFloatv( GL_MODELVIEW );
world_x = x*m[0] + y*m[4] + z*m[8] + 1*m[12];
world_y = x*m[1] + y*m[5] + z*m[9] + 1*m[13];
world_z = x*m[2] + y*m[6] + z*m[10]+ 1*m[14];

In other words, does this code effectively multiply the modelview matrix with my vertex ( I realize I am not computing the 4th component of the resultant vertex, but it will not be used )

that'll do it

##### Share on other sites
That is correct.

But I personally would manage the Modelview Transformations only for learning purposes to get more aquainted with Matrices, etc.
But when working with huge datasets performance is very important and so i would recommend to stick to the glTranslate*, glRotate* and glScale* Functions. They might seem to create overhead but they are much more efficient than a single call to glMultMatrix*.

##### Share on other sites
Quote:
 Original post by hoLogramm...glTranslate*, glRotate* and glScale* Functions. They might seem to create overhead but they are much more efficient than a single call to glMultMatrix*.

Really? Can you tell why?
I have never benchmarked these methods, by I would imagine multmatrix to the fastest, by far!

##### Share on other sites
Ok I have experienced a problem. At the beginning of each scene, I call the function gluLookAt and so when I multiply my vertex by the modelview matrix I get a position that doesn't take into account by view transformation....

Would this be solved by using my code from before and then furthur multiplying that by the matrix used from my gluLookAt function?

##### Share on other sites
Quote:
 Original post by hoLogrammThey might seem to create overhead but they are much more efficient than a single call to glMultMatrix*.

##### Share on other sites

glTranslate and glRotate each are twice as fast than a call to glMultMatrix.
However glRotate is slower and need nearly twice as much time than glMultMatrix.

1. 1
2. 2
Rutin
19
3. 3
khawk
18
4. 4
A4L
14
5. 5

• 12
• 16
• 26
• 10
• 44
• ### Forum Statistics

• Total Topics
633767
• Total Posts
3013737
×