   The FPS Camera Problems
  Hi, I am novice in the 3D Math. I have a problem about FPS camera when i try to implement it using the quaternion.hope someone can help me.(I use a quaternion to record the orientation of camera in world spacewhen the application need to update the camera, i actually orient the camera in world space. after update,i use the orientation to build the matrix that can transform the camera to desired orientaion and postion in world space, then i inverse this matrix to get the view matrix.pitch axis(1.0, 0.0, 0.0),yaw axis(0.0, 1.0, 0.0); there are two rotation orders to orient the FPS camera:    (1) yaw firstly,and pitch secondly    (2) pitch firstly, and yaw.(note: the axis are the unit axis as the above)according to my understand to the math,if i orient camera in world space using the the order(1), there is no roll in the scene. because after first rotation around the unit y axis, i will rotate around the new local x axis which deriveing from the prevoius yaw.  if i use the order (2) to transform camera, it will lead to roll of it. unfortunately, the actual effect is not the same as what i expect when i using the order(1), if i use the order(2), it works well. i dont known the reason , hope someone can give me a explanation about itThanks in advanced.[Edited by - kamimail on May 10, 2010 8:01:23 AM]
  How are you applying your camera quaternion? You know for view matrix you have to apply operations in inverse opposite order of how you would do a normal model transformation?Other than that you'll have to do better than "the effect is weird" to get a better answer.   ;  Hi,karwosts thank you for reply.i use a quaternion to record the orientation of camera in world spacewhen the application need to update the camera, i actually reorient the camera in world space. after update,i use the orientation to build the matrix that can transform the camera to desired orientaion and postion in world space, then i inverse this matrix to get the view matrix. is that correct? ;  You do sound like you have the right idea, you want the inverse of the camera's world space orientation matrix. Are you using D3D or OpenGL for this application? I believe pitch*yaw is correct for OpenGL, and yaw*pitch is correct for D3D. The matrix operations are transposed between the two API's which is why it is different.   ;  thanks for reply.there are two rotation orders to orient the FPS camera:(1) yaw firstly,and pitch secondly(2) pitch firstly, and yaw.(note: the axis are the following: pitch axis x_axis(1.0, 0.0, 0.0); yaw axis   y_axis(0.0, 1.0, 0.0);)according to my understand to the math,if i orient camera in world space using the the order(1), there is no roll in the scene. if i use the order (2) to transform camera, it will lead to roll of it. unfortunately, the actual effect is not the same as what i expect when i using the order(1), if i use the order(2), it works well. i dont known the reason , hope someone can give me a explanation about it   ;  Firstly, if you're new to 3-d math, I'd set aside quaternions for now; they're not needed for a simple FPS-style camera, and just tend to make things more complicated and confusing than they would be otherwise.For FPS-style motion using two Euler angles, the normal order of rotations would be pitch, then yaw (applying yaw first will, in general, not produce the expected effect, and may introduce roll as well, as you mentioned).In terms of matrix multiplication, with column vectors this would equate to yaw*pitch, and with row vectors it would equate to pitch*yaw (as alluded to previously), so make sure you have the order right when you assemble your transform.Here's an example of setting up a view matrix, using column-vector notation (typed into post, so no guarantee of correctness):matrix pitch = matrix_axis_angle(pitch, 1, 0, 0);matrix yaw = matrix_axis_angle(yaw, 0, 1, 0);matrix translation = matrix_translation(position);matrix transform = translation * yaw * pitch;matrix view = matrix_inverse(transform);For row vectors, you would simply reverse the order of the terms in the matrix multiplication.   ;  Hi,jyk, Thank you for your reply.you are so kind!I am still confused by the question: why the order(1) can not produce desired effect?  (i.e :Yaw*Pitch, if using matrix, and the row-vector notation (i.e,v' = v *mat0 * mat1...matN).)supposing that: (1)i use the matrix to represent the orientation of camera in world .(2)the camera is at the origin now.(3)all the local axis of camera align with the fixed axis of world.if i yaw camera firstly, it will rotate around the unit yaxis in world.after this transformation , the camera will have the new local x axis which is the axis of later pitch rotation. after finishing two rotations , why it will lead to the roll effect? i cant undestand it. is there someone can explan the reason for me? thanks!   ;Quote:after this transformation , the camera will have the new local x axis which is the axis of later pitch rotation.This is the part that you have wrong.The 'yaw' rotation doesn't change or modify the x axis in any way; even if yaw is applied first, the 'pitch' rotation still takes place around the world x axis, not the local x axis.When you apply an Euler-angle rotation to an object, each rotation takes place around the corresponding world (or parent) axis.Let's say that the order is y->x->z (as I believe is the case here). First the object is rotated by the 'y' angle about the world y axis. Then, the newly rotated object is rotated by the 'x' angle about the world x axis. Finally, the object is rotated by the 'z' angle about the world z axis.If you try this out with your hand or some object that you're holding, you should see how a 'y' rotation followed by an 'x' rotation (remember, about the world axes) can result in perceived roll.A possible point of confusion is that some Euler-angle rotations can *appear* to take place about a 'local' axis, but this is an illusion (more or less) caused by the fact that when the first rotation in the sequence is applied, the object's local axes are aligned with the world axes.[Edited by - jyk on May 11, 2010 12:45:17 AM];  jyk, thank you! according to your explanation ,i have understood that point. but is it possible to use the some thing like "yaw,pitch, roll" notation which is relative to the local axis to describle the orientation? thanks   ;Quote:but is it possible to use the some thing like "yaw,pitch, roll" notation which is relative to the local axis to describle the orientation? thanksIf you want *all* rotations to occur about the corresponding local axis, regardless of the current orientation of the object, then you'll have to abandon 'from scratch' Euler angles and store the object's orientation as (e.g.) a matrix or quaternion. (This would be if you want '6DOF' motion, where the object can rotate with complete freedom and all rotations occur about the local axes.)If you just want to change which rotations appear to occur about the 'local' axes and which appear to occur about the world axes, then you'll just need to change the order of rotations until you get the behavior you want. Keep in mind though that no order of rotation will give you the aforementioned 6DOF motion (as long as you're using 'from scratch' Euler angles, at least one of the rotations will appear to take place about a world axis).Now, since the topic of the thread is an FPS-style camera, I'm guessing it's not 6DOF motion that you're after. You could do what you're describing by applying the yaw rotation, then applying a pitch rotation about the (rotated) local x axis rather than the world x axis, but I'm not sure what the advantage of this would be. Applying two 'world axis' rotations in the order pitch->yaw will give you the same results, and is arguably a little simpler to implement.   