# Rotate camera with quaternion around axis going through the origin

I am trying to implement my own third person camera using quaternions in DirectX. I first wanted to check that the camera rotates as expected so I started to rotate it 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 can put some code if someone asks but I first wanted to check there is no mistake in my approach. Thanks.

• I've just tried putting the up vector colinear to the rotation axis which is maybe more realistic but I still get a similir strange result. Commented Dec 4, 2015 at 20:40
• I suspect the camera is being rotated (that is, its Up no longer matches the global Up) rather than being orbited around the axis in question and maintaining its facing. Commented Dec 4, 2015 at 22:20
• When you say "global up" I think you mean the y-axis of the world frame. I do rotate it too. I also rotate the camera position vector ( which is the camera position point - lookAt, but since lookAt is always the world origin, the vector position has the same coordinate as the position point of the camera). All the coordinates are related to the world frame. Commented Dec 4, 2015 at 22:56
• Yes, the y-axis. I had a brain fart over what to call it. Commented Dec 5, 2015 at 2:35
• This is the kind of question where a video or animated gif of what you're seeing would be invaluable for diagnosing the issue. Code helps too, of course. Commented Dec 5, 2015 at 6:08