Rotating other two euler angles using difference between two

1k Views Asked by At

I am trying to a camera that moves using a spline. Camera position works nice however I want my camera eye to the turn itself while moving.

For example camera moves from x0 y0 z0 to x1 y1 z1. Now my eye vector is normal(x1-x0, y1-y0, z1-z0). How do I rotate other two vectors (side and up vector) to match eye vector and not destroying 90 degree angles between them?

If it is easier in yaw/pitch form it is fine too, I can convert between two. Or a different approach to what I want to achieve?

For example I think I can do it by calculating normal of the spline (it is a 3 point beizer curve) and each step I can calculate how much camera will rotate around that normal. But I would prefer an easier and a more general method, if it exists.

You can see what I am doing here. (click on a planet) In this one I convert my old and new eye vector to pitch/yaw and find the difference and rotate other vectors using this but this is obviously wrong since in some cases, other vectors may not change at all (if eye is rotating perpendicular to one)

1

There are 1 best solutions below

0
On

This is called key frame animation. The best way to do it is to take the Euler angles at the positions you are interested in and put them in quaternion form. You can then interpolate the key frame quaternions using a spline to get the interpolating frames.

Why do this? The main reason is that you don't have issues maintaining the orthonormality of transformation matrices of the interpolating frames, nor do you have to come up with a heuristic to choose Euler angles. Read more on Wikipedia, especially the section Comparison with other representations of rotations.

Don't let quaternion form scare you off, it's actually pretty easy. All you need are recipes to go from euler angles (or transformation matrices) to quaternions and the reverse. You don't have to know much about quaternions themselves, other than that they can be interpolated with a spline nicely.