Camera Path Movement with Quaternions

Started by
10 comments, last by Dmytry 19 years, 7 months ago
Hi there, I'm trying to move a camera along a couple of control points which form a spline. The camera has an up vector, a position and a center of interest. (just like you define it with gluLookAt()) Actually, to create the quaternion for each control point, I use gluLookAt for that point and get the matrix from the matrix stack. With this matrix I'm creating the quaternion. Now, I'm not quite sure if that's the matrix I want to interpolate, cause I'm not getting correct results when extracting the matrix out of the interpolated quaternion. So, can anyone tell me how to do that right or point me to a site with the information i need. Thanks alot! ALex
Advertisement
How are you getting the up vector from the spline? A spline would only define position and view direction. Also, why exactly do you need the quaternions? It seems to me that you're passing in a matrix, and then taking the matrix straight back out again.
As far as I can tell, you are doing two separate things:

1) using a spline to interpolate between camera positions
2) using quaternions to interpolate between camera orientations

right?

Unless you tell us why you're "not getting correct results when extracting the matrix", it is hard to indicate what is wrong.
Sorry about not beeing precise enough, here is the thing i wanna do.
I have a couple of control points containing camera position, center of interrest and an up vector. I now like to create a camera movement which performs a smooth animation through all of them. The scene consist of a model of the earth, the points lie more or less on the surface (height varries). So in order to move the camera from let's say australia to america, I need to move the camera on an arc instead of a straight line. If I understood it correctly (not totally sure :-P) quaternions are the right choice to do that.
Question is, how exactly...

Hope this clearifies some things, any help appreciated :-)

- ALex
Well. Sounds like you're seriously mixed something.
What you want is 2 different things that should be done separately.
1: Interpolate camera path well,so it moves along arc.
2: interpolate camera orientation.

1: You definitely need some kind of 3D spherical interpolation(search for it in google), to interpolate between points on sphere. It's somewhat related to quaternions, but not too much.

And you need different method to interpolate height(i mean, distance from center of planet). If you don't want camera speed to have discontinuity at control points, you need both interpolations to be better than linear, say to be quadratic or cubic.

2: To interpolate between camera's orientations, the most sane method is to
1: store camera orientation in quaternion.(you can get that quaternion from your lookat and up vectors,if you want)
2: use 4D spherical interpolation with that quaternion.

Is it what you want?
Try google for spherical interpolation and quaternion interpolation.
[edit:typos]
Yes, that really helped. I got it working now :-)
Thanks alot!
If all you're doing is interpolating between two points on a sphere, why are you using quaternions at all? Just find the vectors for each position, determine the rotation axis and angle from v0 to v1, and linearly interpolate the angle.
You are suggesting that he should move his camera along a geodesic on the 2-sphere. This is analogus to moving along straight lines eucledian space.

This is a method that certainly will take you from one point to another, but the problem arises when you want to combine to such paths. The directional derivates of the position will in almost all cases be discontinuous. Thats why one uses splines, as you certainly know.

Also, he proposes to use quarternions only for interpolating camera orientations.
Sneftel :
Yes,it's one of methods of 3D spherical interpolation...

there are more general/simplified methods avaliable (but a bit harder to understand):
http://www.cg.tuwien.ac.at/studentwork/CESCG/CESCG-2002/GSchroecker/node13.html
With quaternions(for camera orientation) it's exactly the same, like if it's just 4D vectors.
edit: and i must note - their notation is bit misleading for programmer. They mean U1* sin((1-t)*a)/sin(a) + U2* sin(t*a)/sin(a)
,note the sin((1-t)*a)

to get sin from cos you can use
sin(a)=sqrt(1-cos(a)2)

Quote:Original post by sverre
the problem arises when you want to combine to such paths. The directional derivates of the position will in almost all cases be discontinuous. Thats why one uses splines, as you certainly know.
Yes.... my brain skipped over the word "spline" in the original post. My bad.

This topic is closed to new replies.

Advertisement