Jump to content
  • Advertisement
Sign in to follow this  
Khaos Dragon

object to world space

This topic is 4970 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

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 this post


Link to post
Share on other sites
Advertisement
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 this post


Link to post
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 )

Share this post


Link to post
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 this post


Link to post
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 this post


Link to post
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 this post


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

Wrong. Read here.

Share this post


Link to post
Share on other sites
@all readers. follow link from above post

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.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

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

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!