I have a system where we load objects into the scene. The following operations are allowed. All inputs are given using mouse.
- rotate individual objs
- translate individual objs
- rotate the entire system about the origin
- translate the entire system
To do this, I keep the following data
- A quaternion (Q) for rotations on the entire system (opr.3)
- A quaternion (qi) for each object (opr. 1)
- Translation parameters (Tx,Ty,Tz) (opr.2 + opr. 4)
- Center of each obj Cix,Ciy,Ciz
And I do the following in the display function
foreach object i
- apply rotation using quaternion Q
- translate using parameters Tx,Ty,Tz
- rotate using quaternion qi
- translate to center using Cix,Ciy,Ciz
this seems to work fine for some transformations, but after certain amount of rotation, I find that the objects move in opposite direction. Can some one tell me what is wrong with my method? I would be glad to an alternative method.
depending on you're applying your transformations [i.e. keeping the rotated matrix] you could be applying what you may think is a controlled angle but REALISTICALLY you're applying a rotation on an already rotated "world".
if you could be a bit more descriptive on how you're applying the rotations, that might help.
I found my mistake. I was unprojecting screen (window) co-ordinates to object co-ordinates to find the axis of rotation for individial objects. But this axis has to be mapped to the global co-ordinate system by appling the inverse rotation matrix. This new axis should be used to compute the quaternion for individual objects. Same theory applies to any translations done to the objects.
good job! and thanks for reporting your findings - it'll serve as a reminder to pay attention to the stuff we may overlook by mistake.