Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

Kin Wong

Quaternion Look at

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

Hey guys, If I use a vector and a quaternion and to store the position and the orientation of my camera object, what is the quickly and best way to calculates a look-at matrix to be used as the view transform in Direct3D? Should I calculate the amount of angle change and rotate the quaternion? Should I convert the quaternion into something else, such as Euler angles or Axis angle, and work from there? Many thanks in advance. Kinny Wong

Share this post


Link to post
Share on other sites
Advertisement
This is a bit of a hack and prolly not the best way to do things but. . .

Take a starting point that is defined in terms relative to your camera. This starting point represents the look direction of the camera, assuming that an identity quarternion is used.

For example, if the camera is at (9,0,0) and you want it to look down the x-axis, the absolute look at would be (10,0,0) while the relative would be (1,0,0)

In other words, this pt, the look at pt, represents what you are looking at before the camera is rotated. This pt defines what happens if you don''t rotate the camera.

Then, apply the quaternion to the relative pt to rotate the camera. You will actually have to have 2 of these pts -- one that is the up vector, the other that is the look at vector.

Then, apply D3DXMatrixLookAtLH to your camera, the up vector and the look at vector. (you will have to convert the relative look at point to absolute values.)

This is of course assuming that the quarternion is defined relative to the camera, not the world origin.

Hope that makes some kind of sense.

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

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

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!