• Advertisement
Sign in to follow this  

Rotating the camera with quaternions

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

Hello,

 

I am trying to implement my own third person camera using quaternions in DirectX. I first wanted to check the rotations are fine so I started to rotate around the world y-axis (0,1,0) and then x-axis (1,0,0) and it worked fine. But when rotating around the axis (1,1,0) the effect is not what I expected. Here is a description of what I do.

 

The scene is composed by a cube of side 2, centered at the world origin. The camera is originally placed at (0,0,-10), looking at the origin (0,0,0) and has the up vector (0,1,0). To test the rotation, at each frame I increase the angle of rotation theta by a constant amount dTheta. I build my quaternion from the axis of rotation (1,1,0) and the angle theta, transform the quaternion to its 3-by-3 matrix form and multiply both the position vector and up vector. I call the D3DXMatrixLookAtLH function to build the view matrix with the new position, the lookAt point (the origin of the world frame) and the new up vector.

 

What I get is my cube rotating in a very strange way (well, I know it is the camera that is rotating, but you know what I mean, everything is relative). Moreover it seems the distance between the cube and the camera changing because, as the cube rotates, its size oscillates.

 

I have also tried to use a vector colinear to the axis of rotation for the up vector of the camera but the result is similar: the rotation is not conform to what one can expect et there is still the zoom in / zoom out effect.

 

I can put some code if someone asks but I first wanted to check there is no mistake in my approach. Thanks.

Edited by Itsbananas

Share this post


Link to post
Share on other sites
Advertisement

Hello swiftcoder and thank you for your response.

 

Well, after five days of research, I feel dumb... It turns out that my function that normalizes the quaternion only normalizes [w,x,y,z] but does not recompute the rotation matrix. I feel very.... dumb. It works fine now.

 

If it can helps other people for their own implementation, I can put my code here. Just ask if you want.

Share this post


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

  • Advertisement