Basic transformation problem

Started by
3 comments, last by level10boy 20 years, 10 months ago
I have a problem where my model is defined at the coordinate origin and I want to translate it then rotate it about the coordinate origin. If I rotate then translate then obviously all rotations will have the affect of rotating the model about its centre wherever it is in the world. So naturally I reverse the order so I am translating then rotating the model. All is well apart from when I go to translate the model again after having it rotated, only to find the model moving in the wrong direction. For example, if I keep translating along the x axis then rotate 90 degress about the Y axis the model will move backwards instead of left. I know why this is happening but I can''t find a fix. I''m sure countless people have come up against this basic transformation problem. Any thoughts.
Advertisement
To shed some light on my question, I should probably being asking how do I rotate an object about an arbitrary point that is defined in modelling coordinates at the world origin (its centre is being at the world origin), and have translations appear as expected. There is a D3D function called
D3DXMatrixTransformation() that might to the trick.
i dont know anything about direct x but in opengl i would translate to where i wanted to draw it, rotate to the approppriate angle, draw it, then rotate back to where i was and continue with my transformations. the opengl code if this helps:

glMatrixMode(GL_MODELVIEW); //select the matrix to do with rotations and transformations
glLoadIdentity(); //move to the origin, looking in the negative z direction

glTranslatef(obj_x, obj_y, obj_z); //move to the object position
glPushMatrix() //remember my current transformations
glRotatef(axis_x, axis_y, axis_z, angle); //rotate however much you want

//draw the object, it will be rotated by angle about axis

//restore transformation matrix to what it was before the rotation and continue drawing
glPopMatrix();

HTH
Just to state the obvious...
Instead of doing
    T1, R1, T2, R2   


do this...
    T1, T2, R1, R2   


or this (ugly)...
    T1, R1, -R1, T2, R1, R2   


It sounds to me like the problem is that all your transformations are in world space. If you "nest" your transformations (i.e. local vs global), you don't have to worry about reordering or undoing previous rotations.

[edited by - Jambolo on June 20, 2003 1:54:39 PM]
John BoltonLocomotive Games (THQ)Current Project: Destroy All Humans (Wii). IN STORES NOW!
I'll give that a try, thanks.

[edited by - level10boy on June 21, 2003 11:19:49 AM]

This topic is closed to new replies.

Advertisement