Sign in to follow this  
Khaos Dragon

object to world space

Recommended Posts

Khaos Dragon    196
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
Khaos Dragon    196
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
hoLogramm    170
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
stein    164
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
Khaos Dragon    196
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
hoLogramm    170
@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

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this