• Create Account

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

Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

3 replies to this topic

### #1taytay  Members   -  Reputation: 117

Like
0Likes
Like

Posted 02 September 2013 - 01:11 PM

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!

### #2ratrace135  Members   -  Reputation: 318

Like
0Likes
Like

Posted 02 September 2013 - 06:34 PM

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, 02 September 2013 - 06:35 PM.

### #3taytay  Members   -  Reputation: 117

Like
0Likes
Like

Posted 08 September 2013 - 08:02 AM

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/

### #4taytay  Members   -  Reputation: 117

Like
0Likes
Like

Posted 08 September 2013 - 08:07 AM

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

Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

PARTNERS