Normals, planes - major probs!

I am attempting to construct a roller coaster simulator. Each track piece is defined by a right handed pair of vectors. A direction vector, and up vector and a normal vector. I can use the direction vector ok, but how do I calculate the up vector from the directional vector?

Once this is cracked I then want to rotate the up vector around directional vector to get track pieces to bank.


Copy and past the above links into a browser window, don’t click as they won’t work!

Is the ‘Up’ vector straight into the sky or 90 degrees off of the surface of the track?

At the moment is fixed at (0, 1, 0) however I need to calculate it according to the directional vector so it is always at a right angle to the directional vector. Reason for this is for lighting and also so the first person cam can take the up vector for each track piece.

If you look at that second picture it should explain what I need, copy and paste the link into a browser window to get it to work(damn angel fire).

To keep the Up vector perpendicular to the Front vector use the following. This should work so long as the front vector has not rotated so much that it is parallel to the CurrentUp vector.

Right = Front x CurrentUp
NewUp = Right x Front
Normalise NewUp

Rotating it around the Front vector by an angle A is given by the following. |CurrentUp| is the length of the CurrentUp vector. However, if you use this you will have to normalise / correct the length of the NewUp vector after a couple thousand rotations. The calculations give rounding errors after a while.

NewUp = CurrentUp * cos(A) + NormalisedRight * sin(A) * |CurrentUp|

There might be faster ways to do this. If anyone knows share it with us

Why cant you just use the surface normal?

I dont really understand what you want, but to get a vector perpendicular to 2 other vectors you need to Cross product those 2 vectors to get it.

Here’s my first suggestion: Rename your vectors! Use direction, left, and up (or normal). A “normal” vector is a specific vector which is not the same as your “normal” vector. You will save yourself (and everybody else) a lot of confusion.

If you have two vectors, you can get the third using the cross-product.