Jump to content
  • Advertisement
Sign in to follow this  
RichardoX

OpenGL Quaternion camera look at

This topic is 4219 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! I am writing a small 3d application that has a quaternion based camera. The camera has a quaternion that represents it's orientation and a vector that is the camera's position. I can calculate the appropriate transformation matrix from the orientation and the vector. It works very nicely. I would like to implement a "look at" function for my camera, similar to gluLookAt in OpenGL. I can calculate the forward, upward and sideways (-z', x' and y', respcetively) vectors, but I don't know how to calculate a transformation from the base vectors x, y and z to x', y' and z'. The best I can think of is to build a transformation matrix from the vectors and then build a quaternion from that matrix. Is there a smarter way of doing it? thanks in advance, -Riku

Share this post


Link to post
Share on other sites
Advertisement
That's the best way I can think of doing it. Since the rotation matrix is really just the forward, up, and right vectors you're already calculated it's the most direct way of building the quaternion. The "poor mans rotation" would probably be to just take the cross product between the starting look direction and the ending look direction and calling that the rotation axis (from which it's even easier to build a quaternion), but that gives you absolutely no control over camera roll.

Share this post


Link to post
Share on other sites
The simplest (and I guess smartest) way is to create a matrix from the look-at parameters and compute the equivalent quaternion.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!