|
bkdougan
|
 |
« Reply #17 on: 2006/12/22 14:00:49 » |
|
I'm having the same problem as noted by others with translation+rotation causing an odd roll around the z-axis. While I didn't find the correct way to fix the problem, I did find a quick solution that gives a working FPS type camera.
1: Create a new method in HMCamera.cs that resets rotation, something like the following.
public void ResetRotation() { myRotation = new Quaternion(0, 0, 0, 1); Update(); }
2: Comment out the transform axis line in the Rotate() method of HMCamera.cs (you could also create a separate method if desired)
//axis = Vector3.Transform(axis,Matrix.CreateFromQuaternion(myRotation));
3: Create two global float variables in HMDemo.cs called yaw & pitch. Edit CameraControls() method of HMDemo.cs to add the following.
static float pitch=0,yaw=0;
public static void CameraControls() { //Existing code
pitch+=mouseMove.Y * -0.01f; yaw+=mouseMove.X * -0.01f;
HMCameraManager.ActiveCamera.ResetRotation(); HMCameraManager.ActiveCamera.Rotate( new Vector3(0, 1, 0), yaw); HMCameraManager.ActiveCamera.Rotate( new Vector3(1, 0, 0), pitch);
//Existing code }
This solution has at least one odd quirk...If you invert the camera by having pitch (rotation around x-axis) >90 or <-90, the yaw (rotation around the y-axis) becomes inverted. This isn't really an issue for me because I lock the pitch between these two points, but I thought I'd let you know.
PS, if you want to lock the height of the camera (so you don't get the noclip mode of travel), then this is a quick solution
-Create a new method in HMCamera.cs and call it from HMDemo.cs instead of Translate()
public void Translate_Lock_Y(Vector3 distance) { distance = Vector3.Transform(distance,Matrix.CreateFromQuaternion(myRotation)); distance.Y = myPosition.Y; myPosition += distance; Update(); }
Hope that helps anybody having issues with a FPS camera. Third-person should be able to use the same idea, but edit Revolve() instead of Rotate().
Brian
|