Crazy Camera Happenings When Pointing Straight Down

Started by
10 comments, last by Roof Top Pew Wee 18 years, 10 months ago
yes it is. They must be orthogonal or the orientation matrix will be skewed and everything will look quite trippy. If you pass the vectors to D3D (and maybe opengl), then there is a good chance D3D will re-orthogonalise the vectors itself just to make sure. This is where the weird camera behaviour happens if the vectors are parallel, because it's imposible to make two parallel vectors orthogonal. D3D will probably do a fail-safe procedure and set the Up vector from (0, 1, 0) to something like (1, 0, 0).

this is some code to make the vectors orthogonal again and generate a valid orientation matrix.

// right-handed orthogonal system// vector basis// ------------------------------// Z = X x Y// Y = Z x X// X = Y x Z// Camera equivalent// -----------------// Up <=> Y// Dir <=> Z// Side <=> XVector& Y = Up;Vector& Z = Dir;Vector  X;Matrix3x3 Orientation;// make sure vectors are not parallel// Or the orientation matrix will be completely shagged// -----------------------------------------------------if (fabs(Y * Z) > 0.999999f) // '*' <=> vector dot product{    Assert(false, "Camera Up and dir are parallel!"); // assert    // Set Up to an arbitrary vector    // -----------------------------    if (fabs(Y.y) < 0.99f)    {         Y = Vector(0, 1, 0);     }    else    {         Y = Vector(1, 0, 0);     }}// re-orthogonalise the vector basis// ---------------------------------// Dir and Up have to be of length one beforehand// If not, normalise them.// ---------------------------------X  = Y ^ Z; // '^' <=> vector cross productX.Normalise(); // re-normalise (should always be valid thanks to the parallel checks)Y = Z ^ X; // (should always be of length 1).Assert(ApproxEqual(X.LengthSquared(), 1.0f), "Error in Camera re-orthogonalisation");Assert(ApproxEqual(Y.LengthSquared(), 1.0f), "Error in Camera re-orthogonalisation");Assert(ApproxEqual(Z.LengthSquared(), 1.0f), "Error in Camera re-orthogonalisation");// Set the orietnation to the// vector basis (for a row-major matrix system).// --------------------------Orientation.SetRow(0, X);Orientation.SetRow(1, Y);Orientation.SetRow(2, Z);

Everything is better with Metal.

Advertisement
Ok, yeah, that must be it. D3D must automatically do it becasuse I've been just using the same vector for the up angle no matter which way I'm looking. I've just never looked stragiht up or down. Interesting to know.

--Vic--

This topic is closed to new replies.

Advertisement