   Local Rotation
  Probably yet another local rotation question, searched the forums, and the web, havnt found a huge amount on the subject. This is my current code, but once the values get beyond a certain ammount, the matrix seems to die.The code is also very temperamental about rotations, and once i call one rotation (i have similar functions for pitch, roll) they seem to cancel out. Or not work at all. Heres the example code.mm_MatrixR is my global rotation matrix for my meshTo me this seemed a really good idea, but maybe not. Any help would be greatly appreciated.void zObject::SetYaw(float Yaw){//Ok, what we are gonna do is, multiply the up vector (0,1,0) by the current rotation matrix//And then rotate around that axis and add it onto the current rotation matrix//So i can do local yaw rotation, make sense? good!D3DXVECTOR4 Vec;//Create a vector for the yaw axiszVector3D YawAxis = zVector3D( 0, 1.f, 0.f );//Transform that vectorD3DXVec3Transform( &Vec,&zVector3DToD3DXVec(&YawAxis), &mm_MatrixR);YawAxis.x = Vec.x;YawAxis.y = Vec.y;YawAxis.z = Vec.z;//Transform the current matrixD3DXMatrixRotationAxis(&mm_MatrixR, &zVector3DToD3DXVec(&YawAxis), Yaw );}
  Are you sure your not running into the old Gimbal Lock problem?  Some of what you mentioned seems to indicate that might be the problem.Also, one thing I've noticed (which may actually be your intention) is that you set the 'yaw axis' to the positive Y axis every time you 'yaw'.  what happens if you've rolled by 90 degrees and then try to yaw?  from the point of view of your model (for arguments sake, imagine a plane) it would be 'pitching', when you call SetYaw().I'm afraid thats all I have to offer at the moment.   ;  thats what//Transform that vectorD3DXVec3Transform( &Vec,&zVector3DToD3DXVec(&YawAxis), &mm_MatrixR);is for, its transforming the up vector by the current matrix rotation. So if it was rolled by 90 degrees, than it transforms it by that 90 degree roll, well, in theory.   ;  well in that case I can't really offer any more assistance.  is zVector3DToD3DXVec(...) a function you've written yourself?  If so maybe thats where the problem lies (I'm sure you've already thought of that though)   ;  Aren't you actually "saving" each Y/P/R rotation in the orientation matrix, -thus overwriting anything in it- without actually concatenating it with the previous orientation?Shouldn't you be saving the new rotation in a temp matrix, and then performmm_MatrixR = mm_MatrixR*temp?   ;  someusername ur a genious set of fresh eyes i needed.2 ticks...hmmph, its improved but it still isnt right. Seems to be caused by rounding errors, its calculating the new axis, sets the pitch, comes round does it again, the axis isnt quite on the same point, so rotates it, causing the mesh to rotate  in a ridiculous fashion, anyways, need to sleep on it.Thanks for the help so farvoid zObject::SetPitch(float Pitch){//Ok, what we are gonna do is, multiply the up vector (1,0,0) by the current rotation matrix//And then rotate around that axis and add it onto the current rotation matrix//So i can do local yaw rotation, make sense? good!D3DXMATRIX Temp;D3DXVECTOR4 Vec;//Create the pitch axisD3DXVECTOR3 PitchAxis = D3DXVECTOR3( 1.f, 0.f, 0.f );//Transform that vectorD3DXVec3Transform( &Vec,&PitchAxis, &mm_MatrixR);PitchAxis.x = Vec.x;PitchAxis.y = Vec.y;PitchAxis.z = Vec.z;//Transform the current matrixD3DXMatrixRotationAxis(&Temp, &PitchAxis, Pitch );D3DXMatrixMultiply(&mm_MatrixR, &Temp, &mm_MatrixR );};  Some times the only things you can't see are those under your nose! (happens to me all the time!)Some things I wanted to mention...1st) For clarity, use D3DXVec3TransformNormal instead of D3DXVec3Transform, to project the vector as a direction and not as a point. It will yield the same result since the matrix represents orientation, but it may help to avoid numericall error accumulating. (it projects the vector with w==0, not 1) Generally, orthogonalize the matrix every once in a while...2nd) Make sure that the all 3 axes around which you rotate are normal to each other (the dot product of any two of them is zero) Otherwise your implementation may be prone to gimbal lock. I find this hard to happen, given your specific implementation, but it doesn't hurt to check...3rd) The resulting orientation depends on the order that the rotations were performed. Are you sure this is what you want? It may not be that easy to uniquely decompose an orientation into the respective Y/P/R angles if you need to. Btw, why not use D3DXMatrixRotationYawPitchRoll()?   ;  thanks someusernamethis code works fine:void zObject::SetLocalRotation( float Pitch, float Yaw, float Roll ){D3DXMATRIX Temp;D3DXMatrixRotationYawPitchRoll(&Temp, Yaw, Pitch, Roll );D3DXMatrixMultiply(&mm_MatrixR, &Temp, &mm_MatrixR );}