Sign in to follow this  
Antrim

Axis of rotation at 180

Recommended Posts

Antrim    122
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 this post


Link to post
Share on other sites
jyk    2094
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.

Share this post


Link to post
Share on other sites
JohnBolton    1372
As jyk wrote, your forward, right, and up vectors combine to form a matrix which describes the orientation the ship. Treating the vectors together as a matrix, you don't need to reconstruct them -- you simply multiply the orientation by a rotation matrix. For example, if you are going to rotate the ship 180 degrees around the Y axis, you would multiply the current orientation matrix by this matrix:
    cos(180)  0  sin(180)
0 1 0
-sin(180) 0 cos(180)

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this