   UP vector
  I have a 'free-floating' camera (descent style).  Everything works fine moving forward, backwards, and turning (yaw).  When I rotate up and down (pitch), I get odd results.  Am I supposed to be recalculating the UP vector after I pitch?  Here is the code that rotates my camera: bool cCamera::RotateView(float angle, float x, float y, float z){   // Get the vector from position to targetD3DXVECTOR3 vViewDir = m_vAt - m_vPos;D3DXVECTOR3 vNewView;// Calculate the sin/cos of angle oncefloat sinTheta = sin(angle);float cosTheta = cos(angle);// Find the new x positionvNewView.x  = (cosTheta + (1 - cosTheta) * x * x)    * vViewDir.x;vNewView.x += ((1 - cosTheta) * x * y - z * sinTheta)* vViewDir.y;vNewView.x += ((1 - cosTheta) * x * z + y * sinTheta)* vViewDir.z;// Find the new y positionvNewView.y  = ((1 - cosTheta) * x * y + z * sinTheta)* vViewDir.x;vNewView.y += (cosTheta + (1 - cosTheta) * y * y)* vViewDir.y;vNewView.y += ((1 - cosTheta) * y * z - x * sinTheta)* vViewDir.z;// Find the new z positionvNewView.z  = ((1 - cosTheta) * x * z - y * sinTheta)* vViewDir.x;vNewView.z += ((1 - cosTheta) * y * z + x * sinTheta)* vViewDir.y;vNewView.z += (cosTheta + (1 - cosTheta) * z * z)* vViewDir.z;// Now add the newly rotated vector to our positionm_vAt = m_vPos + vNewView;return true;}I am using the keys R and F to pitch up and down respectively.  On R, I am sending in m_Camera.RotateView(-0.1f, 1.0f, 0.0f, 0.0f);and on F,m_Camera.RotateView(0.1f, 1.0f, 0.0f, 0.0f);You can download a test program at this link:http://www.thewildhome.com/camtest.zipThanks for any help [edited by - TWild on February 12, 2004 8:57:26 PM]
  You shouldn''t have to recalculate the up vector on pitch (I believe that would defeat the purpose) but I know that D3D has some problems when the LookAtVector is exactly (0, 1, 0) so when your pitch is straight up change the up vector to (0, 1.0001, 0) or something along those lines and it should be fine. ;  Thanks for replying ms291052 OK, I tried this if(m_vAt.y == 1)m_vUp.y = 1.0001;at the end of the RotateView method.  This didn''t seem to do anything (if that is what you meant to do)   Any other ideas? ;  Well, the only reason you have an up vector is that it is used to calculate the right vector (using a cross product). If the up vector and the forward vector are ''close enough'' that floating point numbers cannot differentiate them, D3D cannot produce a definitive right vector, and things go mathematically crazy.  In other words, you should clamp your forward vector to maybe 89.5 degrees up or down from the horizon which leaves plenty of room for D3D to calculate the correct vectors.   Chris PergrossiMy Realm | "Good Morning, Dave" ;quote:Well, the only reason you have an up vector is that it is used to calculate the right vector (using a cross product).Ah, I see.  But there still must a way to  get my camera to be able to rotate all the way around.  :/ ;  you CAN re-calculate your up vector - makes a little more sense semantically that way anyway. ;  I just downloaded and ran your program, and I think I see your problem.  When you pass the vertical point for your camera, the view suddenly flips around 180 degrees.  Recalculating your up vector WILL fix that.  It''s happening because of the nature of cross products - look up the "right hand rule" if you''re interested in the math behind it.  Anyway, yeah, recalculate your up vector. ;  Still playing with your program, and I realized the "weird result" you were talking about is probably the circular motion you get instead of the up/down motion you get after you rotate the camera, not what I was talking about.  The circular effect is called "Gimbal Lock," and there are several places on the internet that explain it and how to fix it. ;  I''ve read up on gimbal lock but never really saw it in action.  Is the only way to get rid of it is by using quaternions? ;  Also, on re-calculating the UP vector... Not sure how to do it but am I close?  I could calculate the right vector by getting the cross product of the view and the up.  Next adjust my camera angle then take the cross product of the right and the view to get the new UP? 