Direction of flight

Okay then,

How do I go about normalizing this thingamajigger?

There are (I think) several ways of doing this, but the usual way is this:
Dig up that Greek mathematician, Pythagoras, and get him to tell you about his really cool way of calculating the hypotenuse of a triangle. If you can’t get to Greece in time, I’ll tell you. You need to find the length (or, more accurately the magnitude) of your vector, this is sqrt(xx + yy + z*z). Lets say that it equals 10. Now, you want your vector to have a magnitude of 1, so you divide the length of the vector by itself (n/n == 1). In other words, you divide each of your components (x, y & z) by the length of your vector.
Now this means you have 3 divides, 3 multiplies, 2 additions and a square root. Now that’s alot of maths! This can be trimmed a little, because dividing by a number n is the same as multiplying by 1/n so you can get it down to 1 divide, 6 multiplies, 2 additions and a square root, which is still an awful lot, but at least you’ve traded two divides for three mults, which should get you a bit more speed.
I’m convinced there are quicker ways that avoid using the sqrt, I’ll look it up tonight and post an update tomorrow.

He Who, At The Age Of 13, Wondered Who Would Use Trigonometry In The Real World.

-JohnD

[This message has been edited by JohnD (edited 05-22-2000).]

Err, okay.

Umm, I think someone confused me into using the wrong term earlier.

I meant, how do I re-orthogonalize my rotation matrix. Or is the the same?

– All I have to say is YIPES! –

Siwko

Ahhh! I see! Oh well, I’m sure someone will find my description useful.
This is what I did (although it may be wrong, I’m sure dmy will correct me).
I treated each column of the top-left 3x3 matrix as three vectors pointing in the local X, Y and Z. Where column one is the local X vector, column two as the local Y vector, and column three as the local Z. All I do is calculate columns one and two from my DOF vector and “up” (world positive Y), this makes sure they’re orthogonal (perpendicular to each other), then I normalise all three vectors (make them unit length). See my diagram in the very first post.
I calculate all three vectors every frame, because I go straight from my DOF vector. If, however, you’re using Euler angles, then the 3x3 matrix will be calculated as part of glRotate*(). Now, because of rounding errors, you need to make sure that your 3x3 matrix is orthogonal and normalised, so you need to perform the steps above every so often. Perhaps every 100 or so frames, if you never notice any dodgy rotations/scalings/shearings, then you don’t need to reorthogonalise so often. One thing you could do is keep track of the length of each vector, and if it gets bigger or smaller than 1, then it’s time to re-normalise. You only need to calculate xx + yy + z*z, because 1 squared is 1, so you don’t need the sqrt(), which makes it fairly cost efficient.
I hope that was clear enough, I havn’t had my first cup of tea yet.

He Who Was Up Till Some Ungodly Hour Playing Ultima Online.

-JohnD

Originally posted by JohnD:
He Who Was Up Till Some Ungodly Hour Playing Ultima Online.

Really? Which server?

Hmm, sounds like a plan. I however have another interesting bit here.

My vectors are nowhere near normal. In fact, I was under the impression that all vectors in OpenGL were required to have a magnitude or ±1.0. So I was attempting to keep them normal. However, when I did, then they exhibited strange ‘scaling/shearing/rotating’ phenominon so passionately described here.

Tell me what effect this would have :

My vectors generally have a magnitude of ±400. (More precisely, ± 1/2 Screen Height or ± 1/2 Screen Width).

I haven’t had any abnormal results so far in my testing.

Of course my boss just mentioned that if it ain’t broke…

Anyways, enough smiles for now. Any ideas?

Let me know.

Siwko