Jump to content
• ### What is your GameDev Story?

• Advertisement

# OpenGL Quaternion camera look at

This topic is 4375 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

##### 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

##### 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

##### Share on other sites

• Advertisement
• Advertisement
• ### What is your GameDev Story?

In 2019 we are celebrating 20 years of GameDev.net! Share your GameDev Story with us.

(You must login to your GameDev.net account.)

• ### Popular Now

• 10
• 11
• 13
• 9
• 9
• Advertisement
• ### Forum Statistics

• Total Topics
634082
• Total Posts
3015399
×

## Important Information

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

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!