Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- namespace UmbraGame.Camera
- {
- using Microsoft.Xna.Framework;
- using Microsoft.Xna.Framework.Graphics;
- public class FpsCamera : ICamera
- {
- #region Fields
- private readonly MainGame _game;
- private Matrix view;
- #endregion
- #region Properties
- public Matrix View
- {
- get { return view; }
- }
- public Matrix Projection { get; set; }
- #endregion
- public FpsCamera(MainGame game, Viewport viewport)
- {
- _game = game;
- float aspectRatio = viewport.AspectRatio;
- Projection = Matrix.CreatePerspectiveFieldOfView(MathHelper.ToRadians(55), aspectRatio, 0.05f, 500f);
- }
- /// <summary>
- /// Updates all information regarding the current camera.
- /// </summary>
- /// <param name="gameTime">Time elapsed since last update.</param>
- /// <param name="position">Vector 3 position of which to draw the camera from.</param>
- /// <param name="yaw">The yaw of the cameres rotation.</param>
- /// <param name="pitch">The pitch of the cameres rotation.</param>
- /// <param name="roll">The roll of the cameres rotation.</param>
- public void Update(GameTime gameTime, Vector3 position, float yaw, float pitch, float roll)
- {
- Matrix rotationMatrix = Matrix.CreateFromYawPitchRoll(pitch, yaw, roll);
- Vector3 transformedReference = Vector3.Transform(Vector3.Forward, rotationMatrix);
- Vector3 target = transformedReference + position;
- view = Matrix.CreateLookAt(position, target, rotationMatrix.Up);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement