• Advertisement

#### Archived

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

# Translation after cummulative rotations

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

Hi I know this is quite a long post, but please read. Thanks. I have a class representing an object in 3D space. It holds internally 2 matrices, a translation matrix, and a rotation matrix. The class provides functions to adjust the pitch, yaw and roll – all of these functions multiply the internal Rotation matrix by the appropriate axis-rotation matrix. The class also has functions to move the object. There are three functions, one to move Up/Down, another to move Left/Right and the third to move In/Out. These all work by extracting the appropriate direction vector from the internal Rotation matrix and using that to update the translation matrix. This works fine until an object rotates through two axes. For example, if the object’s yaw angle is 90 and then the object’s pitch angle is updated to 90 also, the movement functions no longer move the object as I want. Below is the sequence that the Rotation matrix goes through. It’s plain to see from the matrices why the object moves as it does, but can see why it doesn’t work, but how can I fix the problem? The rotation initially starts of as the identity matrix.
  | 1.00 0.00 0.00 0.00 | | 0.00 1.00 0.00 0.00 | | 0.00 0.00 1.00 0.00 | | 0.00 0.00 0.00 1.00 | 
The “Out” ("Forwards") vector (row 3) is as expected and will result in translating the object along the world Z-Axis. After the Yaw angle adjustment of 90 degrees, the rotation matrix looks like this.
  | -0.00 0.00 1.00 0.00 | | 0.00 1.00 0.00 0.00 | | -1.00 0.00 -0.00 0.00 | | 0.00 0.00 0.00 1.00 | 
The “Out” vector is still as expected and will now result in translating the object along the world X-Axis. However, after adjusting the Pitch angle by 90 degrees, the rotation matrix becomes.
  | -0.00 1.00 -0.00 0.00 | | 0.00 -0.00 -1.00 0.00 | | -1.00 -0.00 0.00 0.00 | | 0.00 0.00 0.00 1.00 | 
The “Out” vector is not as I want. It was unchanged and still results in a translation along the World X-Axis. I want the object to move along the world Y-Axis. I hope the problem is clear from all that. I’m sure there’s a solution to this, perhaps in the way I’m multiplying the matrices or something, but can’t for the life of me fathom this out! Thanks for reading, any help you can offer much appreciated. Boony.

#### Share this post

##### Share on other sites
Advertisement
I am not quite sure, but maybe you use maths that use the columns as the direction vectors rather than the rows (if you know what I mean...) Maybe you need to transpose your axis rotation matrices, and maybe you (also) need to multiply them from the other side (A*B instead of B*A).. or you take the 3rd column as the out vector. I have no clue really, but sometimes you need to use the transpose or the inverse (or both) of the matrices, and things suddenly work... Hope this helped.
Btw, the transpose of a matrix is just mirroring at the topleft-bottomright line of the matrix, i.e. exchanging rows and colums, just in case you didn´t know...

#### Share this post

##### Share on other sites
I''m not sure why you''re keeping two matrices. A 4x4 matrix will hold rotation and translation information.

My first guess is that you''re rotating first. Which rotates the objects local coordinate space. Any translations after the rotation will take place relative to the newly rotated coordinate space.

For example, if moving an object "up" means translating on the Y axis, then it should move straight up correct? But if you rotate the object 45 degrees on the z axis, THEN translate, it will move diagonally. It''s still translating just on the Y axis. But the y axis is rotated.

If you''re drawing these objects with a 3D API, I would suggest using it''s code for handling object orientations in space.

#### Share this post

##### Share on other sites

• Advertisement
• Advertisement
• ### Popular Tags

• Advertisement
• ### Popular Now

• 10
• 14
• 9
• 9
• 11
• Advertisement