View Full Version : Extracting Roll from matrix
Nickolei
2003.09.28, 12:54 PM
I'm using matricies and quaternions to represent rotations for a spaceship. I want to be able to extract the roll component so that I can create a rotation in the yaw direction relative to the current roll of the ship.
(Basically when the ship leans to the left it should turn that direction as well)
Is there a simple way to extract the roll angle (relative to the pilot and not the world) from the matrix?
ummm, err, can you re-formulate that? wait...I saw that thing in the parenthesis.
If the ship gets upright again by itself, and given the Y vector is the one pointing up, you could extract it from the rotation matrix (which contains the x,y,z unit vectors), and measure its angle compared to the normal of (0,1,0), most easily done by the scalar vector product.
codemattic
2003.09.28, 05:10 PM
The first question is wether a spaceship in zero-g would actually roll the way a plane does when making a turn. Im guessing no.
(Basically when the ship leans to the left it should turn that direction as well)
an airplane - yes, but a spaceship... ?
anyway, the 3x3 rotational part of your 4x4 matrix contains 3 vectors which represent the right, up, and forward vectors. Compare your ships 'up' vector to the universe's 'up' vector (this is normally just the opposite of the gravity vector - but again we are in space, no?). Assuming you are only using rigid transforms, take the acos() of the dot product of those two vectors and bobs your uncle.
this link <http://sjbaker.org/steve/omniv/matrices_can_be_your_friends.html> may help you visualize it better.
If you are continually accumulating your transformation matrix - you *may* experience drift. Thus you may need to also Orthonormalize your matrix occasionally.
Also check out the WildMagic2 <http://wild-magic.com/> library. If you use the library directly you should buy Eberly's book. However I think its cool to just study the code if you want. His Matrix3 class has methods for getting the Euler angles as well as an Orthonormalize method.
Originally posted by codemattic
The first question is wether a spaceship in zero-g would actually roll the way a plane does when making a turn. Im guessing no.
...
Actually, the turn is made that way because of the G-forces involved. You turn a spaceship just the same, if you have to pull a high-g turn. Being pressed into your seat is just more endurable than being squished sideways.
Nickolei
2003.09.28, 06:46 PM
Thanks much for the replies - this forum rocks.
Spaceship/airplane...they both have to land sometime, right? Just think of it as airplane under the conditions of gravity, lift...
Correct me if I'm wrong (wont be the first time today) but if I take the dot product of my ships up vector and the world up vector wont that also be affected by pitch?
Obviously if a ship was flying along and when you started a dive it veered off to the left it would be incorrect.
MattDiamond
2003.09.28, 11:02 PM
Realism, schmealism. X-Wing and Tie Fighter both bank the spacecraft as you turn, and I'm convinced it's just for the "feel" of it. Also, there is a roar from enemy ships that pass too close. These touches lends a physical, intuitive feel to the game which is a lot of fun, and bears almost no resemblance to reality. The movies were the same (the space dogfights were inspired by airplane dogfights from old WW2 movies.) Carry on!
(Ironically, I just picked up a cheap copy of Terminus and I've been planning to play it as a reward after uDG is done. Newtonian physics in that one, which increases the game's learning curve and may have contributed to it's lack of popularity.)
Originally posted by Nickolei
...
Correct me if I'm wrong (wont be the first time today) but if I take the dot product of my ships up vector and the world up vector wont that also be affected by pitch?
Obviously if a ship was flying along and when you started a dive it veered off to the left it would be incorrect.
Hmm, yes, in that case, it is a little more complicated. Assuming the Z direction is forward, X is right, and Y is up, you would have to project your ship's up vector onto the XY plane, which is simply accomplished by removing the Z component. Then normalize the vector, and do the dot product. Should do, unless you are in a full 90 degree dive, in which case it would not work.
I feel something is wrong with the approach you are taking, though. In a real plane, you bank it first, then you pull on the stick like you would to raise the nose, which leads to turning because the nose points sideways. Just banking the plane practically doesn't turn it.
Is what you are planning full 3D or just a top-down view?
Nickolei
2003.09.30, 02:37 AM
Fully 3D with flying follow camera
I'm thinking it's probably simpler at this point to preserve the euler angles and convert to a matrix instead of preserving a matrix. I'm just understanding the conversion back from matrix to euler's is an approximation so I think it makes sense not to do it.
vBulletin® v3.6.8, Copyright ©2000-2008, Jelsoft Enterprises Ltd.