The eternally jerky camera movement.

Started by
4 comments, last by paulcoz 23 years, 7 months ago
I must have asked this question heaps (do a search for paulcoz, quaternions and keyframes, I can prove it!!! ) but I still can't find an easy solution: SITUATION: Camera movement very smooth, camera rotations jerky as hell. Not good. Will quaternions smooth these rotations? (I am currently using the UVN vector method for camera orientation - rotation of these is done with a 3x3 matrix), or should I believe what I have read - quaternions are no good for cameras (I think this is stated either in the Gamasutra article or a column in Game Developer magazine), and try to use keyframes instead? Either way, I need a very easy to understand tutorial on quaternions or keyframes. I am having trouble visualising the quaternions and I haven't found a detailed enough description of keyframes to implement them. &$#% $#! Paulcoz. Edited by - paulcoz on 9/4/00 2:40:28 AM
Advertisement

paulcoz,

I have recently used quaternions via a keyframe system and have had nothing but success with them. I do not understand the theories behind quaternions, although I''ve never tried. I have found that you do not need to understand them at all in order to use them.

Try experimenting. I implemented a few functions. I think they were,

1, Euler angles to quaterinon conversion.
2, Quaternion To Matrix conversion.
3, Quaternion multiply.
4, Spherical linear interpolation (SLERP).

All of these functions can be found in the DirectX SDK, and they allowed me to create a fully featured keyframe app, with smoothly orientated interpolation without understanding quaternions.

Try it. I think you''ll find them easier than you''d expect.

Jon.



D3D Retained Mode already has a lot of quaternion functions, and a lot of interpolation interfaces. Quite nice, although I have yet to use interpolation yet (quaternions work so well).

=======================================
A man with no head is still a man.
A head with no man is plain freaky.
jon3z,

I accept your statement about not needing to understand quaternions to use them.

Can you answer these two questions for me?

Is a quaternion a representation of an angle (say a Euler), or is it a representation of an axis rotated by an angle?

Is this process correct?

I convert my Euler angles (or rotated X axis, Y axis, and Z Axis, which are presumably unit vectors) to quaternions. I multiply these quaternions in uh.....quaternion-land . I then convert the combined quaternion to a matrix. And finally, I transform all of my world objects to camera space using this matrix.

Thanks,
Paulcoz.

paulcoz,

I store an objects quaternion in it''s data structure. The first one can be created by a call to...
''QuaternionFromEuler(&Object.Quat, fRoll, fPitch, fYaw)''
...for example. To create the world transformation matrix, then you can convert this straight to a matrix with...
''QuaternionToMatrix(&Object.WorldMatrix, &Object.Quat)''

It''s as simple as that. Now if you wan''t to rotate the object, let''s say roll the object by some angle fDeltaRoll, you would create a new temporary quaternion like...
''QuaternionFromEuler(&TempQuat, fDeltaRoll, 0.0f, 0.0f)''
... and the resulting quaternion that represents the new orientation would be simply the old quaternion multiplied by the temporary quaternion. * This can then be converted straight to a world matrix as we did before.

Jon.


*(I think. Quaternions do not commute, so it may be the other way around!)

Well, a quaternion isn''t exactly a representation of an angle (of a single angle, anyway) and it''s not a representation of an axis rotated by an angle either (that would just be a vector). It''s almost best to think of quaternions just as abstract things; all they represent is rotations. (So what''s a rotation? Just a transform from one coordinate system to another that keeps the origin the same and keeps distances the same.) If you make one rotation of your coordinate system and then make another rotation (about the same point) it''s not hard to see that the result is a rotation too; this operation of ''composition of rotations'' is represented by multiplying two quaternions together.

The process you described is close to right, but it''s missing the most important step, the interpolation step! The way you describe it, the quaternions don''t do anything but act as a go-between from Euler angles to matrices. What you''ll more likely want to do is something like this:

1) Convert the rotation portion of your first camera position (represented by Euler angles) into a rotation (represented by quaternions). What I''m really talking about here is the camera''s ''lookat'', its camera coordinate system.

2) Do the same thing for the rotation portion of your second camera position. Now you''ve got two quaternions -- q0 and q1 -- that represent the two orientations of your camera.

3) For each frame of your interpolation, Slerp the appropriate amount between your two quaternions. Let''s say that you want to compute the quaternion qt that''s at point t between q0 (t=0) and q1(t=1); the formula for this is

qt = (q1*sin((1-t)*theta) + q2*sin(t*theta))/sin(theta)

Where cos(theta) = q1.q2 (the dot product of the two, computed exactly like you compute dot products of vectors).

4) Turn this interpolated quaternion qt into a rotation matrix Rt and then transform your world objects to camera space using the matrix Rt (again, this has to be done every frame).

Hope this helps!

This topic is closed to new replies.

Advertisement