# Smooth camera movements/rotations (conversion between eye&up vector and quaternions)

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

## Recommended Posts

Hello all,

I am trying to move my camera smoothly. I use eye, up and side vectors and camera position to hold camera properties. Moving camera is OK, I am using a beizer curve and interpolate my camera position along with that curve.

However I am stuck with camera rotation. I have my initial and final eye up and side vectors but couldn't get far with this information. I google a bit and I suppose I should use quaternions but I couldn't find how I can convert between my structure and quaternions. There are answers for pitch roll and yaw but I couldn't even be able to calculate them (I only managed to find pitch & roll from eye vector).

So basically I want to be able to convert between

eye, up, side vectors <=> quaternions

or

eye, up, side vectors <=> pitch, yaw, roll

Also I can simply linear interpolate quaternions right?

On a side note, is there a way to rotate other two camera vectors using the first one. I mean lets say camera moves from v1 to v2. My new eye vector is normal(v2-v1) lets say it is e2 and old eye vector is e1. can I calculate new up vector using e2 and e1? (I can cross product to calculate side vector after that)

Thanks for all help!

##### Share on other sites

Hey taytay,

I'd recommend reading this tutorial: http://ogldev.atspace.co.uk/www/tutorial15/tutorial15.html

The site itself has OpenGL tutorials, but the concepts in this tutorial are universal and would easily work with whatever you're using.

Basically, quaternions allow you to rotate around any axis you want, as opposed to strictly the x, y, or z axes.

While the typical first-person camera rotates left and right around a fixed axis (the y-axis), vertical camera rotation happens around the cross product of the y-axis and the target vector, which is not fixed. So what you want isn't to convert between vectors and quaternions, but rather to use quaternions to rotate vectors.

The tutorial above doesn't go too deep into the math involved, but it shows how you would go about doing this in a practical sense.

And yes, quaternions can be interpolated (spherical linear interpolation, or slerp, is used often in 3D animation). However, slerping (any interpolation, really) only works when you have two points--a start and an end--and you want to move between the two. Slerping isn't used to figure out where the end point should be.

Hope this helps!

Edited by ratrace135

##### Share on other sites

It looks like what I really needed was simply spherical interpolation, I am now simply interpolating between end and beginning eye & up vectors using it and calculate side vec by cross product.

Check this out! (Click on stars to move them)

http://www.enginmercan.com/webgl/

##### Share on other sites

(I also need to calculate final up vector better, it can wait though)

• 13
• 18
• 29
• 11