• 12
• 10
• 10
• 13
• 10

# Axis of rotation at 180

This topic is 4514 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

So after a bit of digging, I decided on the following method for displaying a ship (in 3rd person view). I keep track of the front, right, and up vectors which are updated any time that the player roll/pitch/yaws. I also keep track of the initial front, right, up, values for the model (how the model looks when it is just drawn without transforms). When orienting the ship to be drawn to the screen, I first calculate the rotation from the initial forward to the current forward direction. Then I calculate the new up direction, and calculate the rotation from this new up to the current up. It seems like this should work, since after orienting the forward vector, I can only be off by the up (or roll) of the ship. However, this runs into problems if the forward rotation puts the new up vector at exactly opposite of the current up. For example, if my ship initially has front = (0, -1, 0) and up (0, 0, 1), and the current front = (0, 0, -1) and current up = (0, 1, 0). First, I get the axis of rotation from the cross product of init_front and current front, get the angle or rotation from the dot product, which ends up being a 90 degree rotation about x. So the ship is facing (0, 0, -1), but it is upside down. Here is where the problem comes in...this up vector is (0, -1, 0) and current up is (0, 1, 0). So the cross product will be (0, 0, 0)...I'm not sure how exactly to work around this and get the 180 rotation about the z axis like I want. I mean, I could just put a conditional in for this occurence to rotate 180 around the forward vector, but it seems like that is just a brute force solution for something that surely has a more elegant way. So anyone know of a good method for getting around this? or even a better method from performing this set of transformations than I am thinking of? Thanks for any help.

##### Share on other sites
Just a quick note. If you already have the front, right, and up vectors for your ship, you already have its rotation matrix - there's no need to reconstruct it. The direction vectors go in the rows or columns of the 3x3 rotation matrix. With 4x4 transformation matrices, the rotation matrix is the upper-left 3x3 portion.

    cos(180)  0  sin(180)       0      1     0   -sin(180)  0  cos(180)