Advertisement
ChocoMan

Untitled

Oct 27th, 2012
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.43 KB | None | 0 0
  1.         //Right thumbstick (up and down) pitches the camera
  2.         Pitch = pController.ThumbSticks.Right.Y * -MathHelper.ToRadians(speedAnglePitch);
  3.  
  4.         // Orbit 360 (yaw) Camera around model no matter where model moves to
  5.         public void cameraYaw(float yaw)
  6.         {
  7.             Vector3 yawAngle = ModelLoad.CameraPos - ModelLoad.camTarget;
  8.             Vector3 axisYaw = Vector3.Up;
  9.        
  10.             ModelLoad.CameraPos = Vector3.Transform(yawAngle,
  11.                 Matrix.CreateFromAxisAngle(axisYaw, yaw)) + ModelLoad.camTarget;
  12.             ModelLoad.CameraPos.Normalize();
  13.         }
  14.  
  15.         // Pitch Camera around model
  16.         public void cameraPitch(float pitch)
  17.         {
  18.         // Which way is the camera facing?
  19.             cameraDirection = ModelLoad.CameraPos - ModelLoad.camTarget;
  20.             axisPitch = Vector3.Cross(Vector3.Up, cameraDirection);
  21.            
  22.             // pitch constrained to model's orientation
  23.             axisPitch.Normalize();
  24.  
  25.             ModelLoad.CameraPos = Vector3.Transform(cameraDirection,
  26.                 Matrix.CreateFromAxisAngle(axisPitch, pitch)) + ModelLoad.camTarget;
  27.         }
  28.  
  29.         // Called in update method
  30.         public void updateCamera()
  31.         {
  32.             cameraYaw(Yaw); // <-works perfectly (360 degrees around model's center)
  33.             cameraPitch(Pitch); // <-Not working as desired (cannot seem to limit pitch between two degrees)
  34.         }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement