Advertisement
Guest User

FpsCamera.cs

a guest
Oct 14th, 2013
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.68 KB | None | 0 0
  1. namespace UmbraGame.Camera
  2. {
  3.     using Microsoft.Xna.Framework;
  4.     using Microsoft.Xna.Framework.Graphics;
  5.  
  6.     public class FpsCamera : ICamera
  7.     {
  8.         #region Fields
  9.  
  10.         private readonly MainGame _game;
  11.         private Matrix view;
  12.  
  13.         #endregion
  14.  
  15.         #region Properties
  16.  
  17.         public Matrix View
  18.         {
  19.             get { return view; }
  20.         }
  21.  
  22.         public Matrix Projection { get; set; }
  23.  
  24.         #endregion
  25.  
  26.         public FpsCamera(MainGame game, Viewport viewport)
  27.         {
  28.             _game = game;
  29.  
  30.             float aspectRatio = viewport.AspectRatio;
  31.             Projection = Matrix.CreatePerspectiveFieldOfView(MathHelper.ToRadians(55), aspectRatio, 0.05f, 500f);
  32.         }
  33.  
  34.         /// <summary>
  35.         ///     Updates all information regarding the current camera.
  36.         /// </summary>
  37.         /// <param name="gameTime">Time elapsed since last update.</param>
  38.         /// <param name="position">Vector 3 position of which to draw the camera from.</param>
  39.         /// <param name="yaw">The yaw of the cameres rotation.</param>
  40.         /// <param name="pitch">The pitch of the cameres rotation.</param>
  41.         /// <param name="roll">The roll of the cameres rotation.</param>
  42.         public void Update(GameTime gameTime, Vector3 position, float yaw, float pitch, float roll)
  43.         {
  44.             Matrix rotationMatrix = Matrix.CreateFromYawPitchRoll(pitch, yaw, roll);
  45.             Vector3 transformedReference = Vector3.Transform(Vector3.Forward, rotationMatrix);
  46.  
  47.             Vector3 target = transformedReference + position;
  48.  
  49.             view = Matrix.CreateLookAt(position, target, rotationMatrix.Up);
  50.         }
  51.     }
  52. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement