If I have three vectors which are initially perpendicular to eachother, how can I re-orthogonalise them when I rotate them to make sure they're still perpendicular? I guess it has something to do with checking that the dot product is zero, but I'm not sure beyond that. Thanks!
How to re-orthogonalise vectors
If they were ok before you rotated them, then they should be ok after you rotate them, except for really small numerical errors. These errors are only a problem if you keep applying rotations to a matrix frame after frame, instead of rebuilding it from scratch each time, so most of the time this isn't required.
If it is required, you can use the cross product to find a vector that's perpendicular to two others. Pick 2 of your vectors and cross them to regenerate the 3rd. Then use the 1st and the 3rd to regenerate the 2nd. Each time you regenerate one, you can check it's dot product with the original version; it should be very close to 1.0 or -1.0. If it's negative, then flip the regenerated vector so it matches the direction/handedness of the original.
If you rotate all three vectors by the same rotation matrix (or any other method), they should preserve their orthogonality.
If you're interested in just verifying that they're still orthogonal, it is as simple as checking the three dot products to see if they're equal to 0.
If you want to re-orthogonalize them, you have to do a bit more work. First, you can't arbitrarily re-orthogonalize them.
here's two general cases, given the three potentiall non-orthogonal vectors A, B and C. (these are the vectors after rotation here)
First if A and B are perpendicular ( or A and C, or B and C - these are all equivalent cases), you can calculate the third vector by doing
C = A cross B or B cross A - depending on handedness. Same goes for the case if A and C are perpendicular, or if B and C are perpendicular.
Second general case is if no two vectors are perpendicular to each other. If that's the case, you have to pick one vector which you want to remain unchanged - usually this is one vector who's orientation you know is correct.
Let's say you pick vector A as the 'correct' one.
You can then obtain a new orthogonal vector B' by doing
B' = A cross C
even though C is not perpendicular to A, A cross C will yield a vector that IS perpendicular to A (as well as to C)
Then you can obtain the new C' by doing
C' = A cross B'
In that case your three new vectors are A, B' and C' - which are now orthogonal. You'll also have to keep track of handedness of the system, because otherwise you might end up with a B' or C' that is oriented in the opposite direction of the originals.
Same goes if you pick B and C, just substitute the proper letters above.
Mind that you might have to re-normalize the vectors if you want to keep them unit and if there's a chance that the rotated vectors are no longer of unit length.
My setup at the moment is that I have an 'orientation' matrix which I update every frame by an incremental amount. I am using it to control the yaw, pitch and roll of an object about its local axes, each of which are defined by a vector (i.e. I have an up, forward and right vector set to define the orientation of the axes). It's these axes that I'm trying to ensure remain perpendicular to eachother. I have to rotate each vector by a different matrix because they are each rotating around eachother (i.e. to pitch forward, I have to rotate around my 'right' vector, then to roll left I have to rotate about my new 'forward' vector, so they all depend on eachother). It's pretty awkward, but it seems to work.
I'll take my 'up' axis as always being correct and regenerate each axis around that one. I checked and the deviations are very small (a tiny fraction of a degree which gradually increases over time), but I'd rather do it properly and re-orthogonalise them each time.
From another thread here
http://www.gamedev.net/topic/640889-pixel-perfect-local-rotations-and-quats-vs-mats/
i've learned that quats also have precision errors, but they do not accumulate as quickly.
it looks like fixed point is the way to do it, then convert to mat for drawing.
that would mean rolling your own fixed point versions of mat mul or whatever method used to turn.
error would eventually creep in most likely.
looks like re-ortho normalize is still required.
Everything has precision errors.
All that's required if you store orientation as a quaternion is renormalising once per frame. When you construct a matrix from the quat it will be orthonormal (within accuracy limits).
Error only "creeps in" if you never renormalise or reorthonormalise.
Using fixed point won't solve anything, don't roll your own fixed point functions just to get rounding issues and worse performance.