   Quaternion Camera
  Hey guys.  I would like to create a camera that uses quaternions (D3DXQUATERNION) to hold its orientation.  I found a few bits of information on GameDev, but it's more code and less explanation.How should a camera class be set up for this?  Here's how I imagine it, but something seems to be missing and I can't get my implementation quite right:- Camera has D3DXVECTOR3 for position and D3DXQUATERNION for orientation- To rotate the camera, say around Y-axis, I build a quaternion with D3DXRotationAxis using D3DXVECTOR3(0.0f, 1.0f, 0.0f) as the axis parameter.- I combine this newly create rotation quaternion with my camera orientation quaternion- I convert the orientation quaternion + position vector into a view matrixThis just doesn't seem to work though.  My orientation slowly starts to roll around the z-axis, even though I only have X and Y rotation code.  I am also normalizing my quaternions after every operation.Can anyone explain how a quaternion camera should work?  Thanks for your help!   
  Rotating the camera is different than rotating an object (like a mesh).  You use the camera to set the view matrix with D3DXMatrixLookAtLH(), and you need to maintain the up,left, and look vectors (that are orthogonal and represent the camera's 3D space, or "camera space") and the point it is looking at.  So, when you rotate, how you do it depends on what you are rotating around.  If you want to rotate it in an orbit fashion around the point it is looking at, what you are really going to do is rotate one of the vectors around another.  So, if you want to rotate the camera to the left or right, you will actually want to calculate a rotation matrix around the up vector, and then rotate the look vector with that matrix.If you want to rotate up or down, you want to calculate a rotation matrix around the left vector and then apply it to the look vector.Then after rotating one of the vectors you make sure they are all orthogonal again before doing the D3DXMatrixLookAtLH() call, but using the cross product.  For example, you rotate to the left, and have rotated the look vector around the up vector, so you now use the cross product to recalculate the left vector.You don't have to use quaternions to do this.  You can also just use matrices and use the D3DXMatrixRotationAxis() function to create the rotation matrix around the chosen vector with the desired rotation amount.   ;  Your description looks good, so maybe it is just a bug in your code somewhere. However, you left out some details that might be the source of the problem:Quote:Original post by GaryNas- I combine this newly create rotation quaternion with my camera orientation quaternion How do you combine the new rotation? It should be a simple quaternion multiply.Quote:Original post by GaryNas- I convert the orientation quaternion + position vector into a view matrixHow do you do the conversion? Generally, you convert the quaternion to a rotation matrix and invert it (along with transforming the position). See this thread: camera transformation.Quote:Original post by DXNut... You use the camera to set the view matrix with D3DXMatrixLookAtLH(), and you need to maintain the up,left, and look vectors (that are orthogonal and represent the camera's 3D space, or "camera space") and the point it is looking at. ... That is one way, but not the only way.For a camera, I prefer using a matrix over a quaternion because you end up converting to a matrix anyway, and a matrix is usually more convenient because you frequently need to know the up, forward and left/right vectors.   