Sign in to follow this  

Camera Path Movement with Quaternions

This topic is 4840 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
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]

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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)

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
IIRC more continuous interpolation are usually done by interpolating parameters for "linear" spherical interpolation.

That is,if you have path
A B C D
to move along BC ,if you have function "Slerp(Start,End,t)" that interpolates between start and end, you can use something like
Slerp(B, Slerp(2*B*(B Dot A)-A,C,t) , t)
(all vectors/quaternions must be normalized before that)
Main idea is to interpolate second endvector to make it be continuous. 2*B*(B Dot A)-A continues path AB it had before passing point B .

It have continuous speed but not continuous acceleration,that is, it's "quadratic" interpolation.
You can similarly make cubic interpolation .

I don't know if more efficients accurate interpolation methods is avaliable.

It can be used both for 4D and 3D, that is , for quaternions and vectors.
Also it's not hard to extend it for better interpolation.

and note: if you interpolate quaternions, you need to check if "dot product" of quaternions is negative, and if it's so, negate all components of one of quaternions.

Share this post


Link to post
Share on other sites

This topic is 4840 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this