   Problem with First Person Camera
  Hi,I'm pretty new to DirectX and at the moment im trying to create a first person camera.  It works quite well when it rotates on each individual axis but when i combine the two it seems to tilt on the z axis as well (i only want it to rotate on the x and y axis)  Heres my code for the rotation matrices:Public Sub subCHANGE_VIEW()Dim matROTX As D3DMATRIXDim matROTY As D3DMATRIX    D3DXMatrixRotationX matROTX, -Vang    D3DXMatrixMultiply matVIEW, matVIEW, matROTX   D3DXMatrixRotationY matROTY, -Hang    D3DXMatrixMultiply matVIEW, matVIEW, matROTY   dx8_D3DDEVICE.SetTransform D3DTS_VIEW, matVIEWEnd SubmatVIEW is a view matrix.Heres the code for determing the angles: If KEYBOARD_STATE.Key(DIK_M) Then   Vang = Vang - pi / 180  End If   If KEYBOARD_STATE.Key(DIK_K) Then   Vang = Vang + pi / 180  End If   If KEYBOARD_STATE.Key(DIK_J) Then   Hang = Hang + pi / 180  End If   If KEYBOARD_STATE.Key(DIK_H) Then   Hang = Hang - pi / 180  End If   (I had it on the mouse before but i put it on the keyboard to help me visualise what was wrong)From what I've seen it rotates first on one axis and then on the other one after its been rotated which is what i think creates the tilt.  I have no idea how to fix this though.  Could anybody help please?[Edited by - Zephor on January 9, 2006 5:10:13 PM]
  Try switching the order you multiply the matricies. (That does matter)Public Sub subCHANGE_VIEW()Dim matROTX As D3DMATRIXDim matROTY As D3DMATRIXD3DXMatrixRotationY matROTY, -HangD3DXMatrixMultiply matVIEW, matVIEW, matROTYD3DXMatrixRotationX matROTX, -VangD3DXMatrixMultiply matVIEW, matVIEW, matROTXdx8_D3DDEVICE.SetTransform D3DTS_VIEW, matVIEW;  hmmm... thx, i tried it but it doesnt work, still seemingly tilts on the z-axis.  Thanks anyway, anymore ideas?   ;  Perhaps you're suffering from the "Gimbal Lock". The only way to solve this is to use Quaternions for rotation.http://www.gamasutra.com/features/19980703/quaternions_01.htmhttp://www.gamedev.net/reference/articles/article429.asphttp://www.gamedev.net/reference/articles/article1691.aspHope this helps,JVFF   ;Quote:Original post by jvffThe only way to solve [gimbal lock] is to use Quaternions for rotation.Just curious, what makes you think that is the case?   ;Quote:Original post by jykJust curious, what makes you think that is the case?I had a similiar problem with rotations, and since he mentioned it was a rotation problem, I thought I'd share my solution. Did I make a big mess? :S :(JVFF;Quote:Original post by jvffQuote:Original post by jykJust curious, what makes you think that is the case?I had a similiar problem with rotations, and since he mentioned it was a rotation problem, I thought I'd share my solution. Did I make a big mess? :S :(Nah, it's a common misunderstanding. I do think it's important that it be clarified whenever it comes up though, so that in the future people searching for 'gimbal lock matrix quaternion' aren't misled. So in short, gimbal lock is an artifact of Euler angles only, and doesn't have anything in particular to do with quaternions, matrices, or any other rotation representation. Using quaternions does not guarantee the absence of gimbal lock, and conversely, you can avoid gimbal lock just as easily with matrices or direction vectors as you can with quats.   ;Quote:Original post by jykNah, it's a common misunderstanding. I do think it's important that it be clarified whenever it comes up though, so that in the future people searching for 'gimbal lock matrix quaternion' aren't misled. So in short, gimbal lock is an artifact of Euler angles only, and doesn't have anything in particular to do with quaternions, matrices, or any other rotation representation. Using quaternions does not guarantee the absence of gimbal lock, and conversely, you can avoid gimbal lock just as easily with matrices or direction vectors as you can with quats.Sorry about the mistake. Well, learning new things everyday :) . Quaternions can show gimbal locks? How's that? I thought quaternions defined an angle of rotation? Guess I'm way too much a noob about this :( Thanks again,JVFFEdit: Fixed quotingEdit2: What triggered my memory to my error (which led to my response) and still bugs me is:Quote:Original post by ZephorFrom what I've seen it rotates first on one axis and then on the other one after its been rotated which is what i think creates the tilt. I have no idea how to fix this though. Could anybody help please?jyk: Do you think it has anything to do with the problem?[Edited by - jvff on January 7, 2006 8:31:41 PM];Quote:Quaternions can show gimbal locks? How's that? I thought quaternions defined an angle of rotation?Short answer: A quaternion (when used to represent a rotation) does represent an axis-angle pair, as you said. A rotation matrix does as well, so in this regard matrices and quaternions are the same. You can construct either a matrix or a quaternion from Euler angles, in which case the resulting matrix or quaternion may suffer from gimbal lock. Or, you can update a matrix or quaternion using incremental rotations, in which case gimbal lock won't be an issue. So again, whether or not you encounter gimbal lock isn't related to what representation you use (e.g. matrix or quaternion), but rather how you use it.   ;  Okay, thanks. That cleared my head :D . It appears I didn't see your new post before I edited my last one (edit2). So consider it as a follow up. Sorry :(JVFF   