Archived

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

jmschust

modelmatrix 'vertex' after rotation / translation

Recommended Posts

I''m using this to get an ''orbit'' around an object at the origin. I''ll use a sphere here as a placeholder. glPushMatrix(); glRotatef( rotg, 1.0f, 0.0f, 0.0f ); glTranslatef( 0.0, 10.1f, 0.0f ); GLUquadricObj *pObj = gluNewQuadric(); gluQuadricDrawStyle(pObj, GLU_FILL); gluSphere(pObj, 0.05f, 10, 10); gluDeleteQuadric(pObj); glPopMatrix(); How do I get the actual location (x,y,z) of the new origin in relation to the origin before the pushmatrix?

Share this post


Link to post
Share on other sites
Just to clarify...

If the angle is 0, the x,y,z should be (5, 0, 0)

if the angle is 90, the x,y,z should be (0,5,0)

if the angle is 180, the x,y,z should be (-5,0,0)

if the angle is 270, the x,y,z should be (-5,0,0)

I know that I could just do this case by just calculating a circle. But I just simplified this example. I still would like to figure out after a bunch of rotations/ translations what the ''current'' origin is.

- Joel

Share this post


Link to post
Share on other sites
oops, sorry. The above would be if the code would look like this:

glPushMatrix();

glRotatef( angle, 0.0f, 0.0f, 1.0f);
glTranslatef( 5.0f, 0.0f, 0.0f);

GLUquadricObj *pObj = gluNewQuadric();
gluQuadricDrawStyle(pObj, GLU_FILL);
gluSphere(pObj, 0.05f, 10, 10);
gluDeleteQuadric(pObj);

glPopMatrix();

Share this post


Link to post
Share on other sites
I''m a little confused:

1) are you new''ing the quadric only because you wanted to post the code, or are you doing this each frame which is very bad?

2) are you trying to get the offset between two points in a third space that ecapsulates the original and the modified coordinate systems. In other words - do you want to know the offset from point A to point B if B is a translated + rotated version of point A.

3) If so, you have to do the math separately (you know - a little bit of trig here, addition there etc etc) - calculate B from A and find the distance

4) if not, then what do you mean by "relation between A and B"?

Crispy

Share this post


Link to post
Share on other sites
Sorry if I wasn''t very clear.

I just posted the code as an example.

I wanted to get the offset between the two coordinate systems. What is the matrix to convert between the two.

result = Origin * matrix ( or whatever)

where origin is 0,0,0 in second coordinate system and result is a location in the first coordinate system. when all i know is the code sample given. ie rotations and translations.

Share this post


Link to post
Share on other sites
quote:
Original post by jmschust
I wanted to get the offset between the two coordinate systems. What is the matrix to convert between the two.



Look into matrix division. Knowing that you get matrix |B| by multiplying matrix |A| with matrix |X|, you can reverse the process. Google it. I''m not too sure, but I think you have to |X| = |B|x|A-1|. That is, multiply the resultant matrix with the inverse original matrix.

Crispy

Share this post


Link to post
Share on other sites
Look in the red book to see what matrices glTranslatef and glRotatef give you. Then simply multiply these together.

http://users.ox.ac.uk/~univ1234

Share this post


Link to post
Share on other sites