Jump to content
  • Advertisement


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

Mark Tanner

How to calculate a quaternion orientation?

This topic is 5559 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 everyone, In my 3d engine, suppose I have an object at D3DXVECTOR3 position, and with orientation D3DXQUATERNION orientation. Now, I want this object to look at/or have an orientation towards another object, let''s say at D3DXVECTOR3 target. (I am keeping my position, orientation, etc. seperate and build them into a 4x4matrix) How do get the orientation quaternion? I can do it axis by axis through getting the angle object<->target Vec3Dot but this doesn''t seem to be the right way to do it. Any advice appreciated, Mark

Share this post

Link to post
Share on other sites
calculate a 3x3 matrix and convert to quaternion.

for a "look at" matrix, it's quite simple

Vector Dir = (target - pos).UnitVector(); // direction of the camera

Vector Up = Vector(0, 1, 0); // you should specify this vector yourself

Vector Side = Up.Cross(Dir).UnitVector(); // calculate the vector that goes across the camera

Up = Dir.Cross(Side); // re-normalise the camera's up vector

if you don't know what the Up vector should be, you can use the Up direction of the previous frame for the camera and plug it into the algo.

then you load the three vectors into a 3x3 matrix (side/up/dir vectors corresponds to the rows or columns of the matrix, depends if your matrix system is row major or column major) and convert to quaternion (should be a D3D support routine for that).

you may have a quaternion conversion function already, which takes two vectors and build a quaternion. Supplying the direction of the camera is not enough, you also need another reference vector to define the roll of the camera (like the up vector).

[edited by - oliii on September 21, 2003 2:53:49 PM]

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.

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!