On a different question, the user that answered (Ricky) me also said the following (which I still find a little confusing):
When I say they must remain perpendicular, I only mean that if you rotate vectors independently by the same transformation over and over, floating point errors may creep in and they could diverge from being perpendicular. Dot(x,y), dot(y,z) and dot(x,z) should be very close to zero. If not, you need to do some cross products and re-perpendicularize them. It's as simple as overwriting z=cross(x,y), then y=cross(z,x).
There are 3 relevant vectors on my camera system, these vectors are floating point numbers and always normalized. Reference vector points in the direction the camera is looking at, UpVector and RightVector are self-explanatory.
Anyone knowing how to answer, should answer of course, but Ricky, if you're there, please help me out...
1) What exactly does it mean dot(x,y), dot(y,z) and dot(x,z)? Is this the dot product between these vectors? I suppose... But which ones (x, y, z) correspond to my Reference, UpVector and RightVector? I'm a little confused...
2) Then, these dot products should be very close to zero, how exactly should I check this? I've seen code like this to achieve the same thing in a similar context:
const float Math::EPSILON = 1e-6f;
Math::closeEnough(<floating_point_variable_to_check>, 0.0f);
static bool closeEnough(float f1, float f2) {
// Determines whether the two floating-point values f1 and f2 are
// close enough together that they can be considered equal.
return fabsf((f1 - f2) / ((f2 == 0.0f) ? 1.0f : f2)) < EPSILON;
}
I suppose it's good enough?
3) Where I exactly should I perform all these checks and re-perpendicularize the vectors? I have 3 functions that rotate the camera, Pitch, Yaw and Roll (the last one I don't use it that much), only these functions change those unit vectors. Should I perform the checks and fixes every time I call one of these rotate functions or would that be too much? Where and when then?
4) Last but not least, to fix them I need to overwrite the vectors with the cross product, makes sense as I want them perpendicular to each other. But isn't the quote above missing one cross product? And does the order i which I perform those fixes matter?