camera.cs 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. #region File Description
  2. //-----------------------------------------------------------------------------
  3. // Camera.cs
  4. //
  5. // Microsoft XNA Community Game Platform
  6. // Copyright (C) Microsoft Corporation. All rights reserved.
  7. //-----------------------------------------------------------------------------
  8. #endregion
  9. #region Using Statements
  10. using System;
  11. using System.Collections.Generic;
  12. using Microsoft.Xna.Framework;
  13. using Microsoft.Xna.Framework.Graphics;
  14. #endregion
  15. namespace Spacewar
  16. {
  17. public class Camera
  18. {
  19. /// <summary>
  20. /// A global projection matrix since it never changes
  21. /// </summary>
  22. private Matrix projection;
  23. /// <summary>
  24. /// A global view matrix since it never changes
  25. /// </summary>
  26. private Matrix view;
  27. /// <summary>
  28. /// The Camera position which never changes
  29. /// </summary>
  30. private Vector3 viewPosition;
  31. #region Properties
  32. public Matrix Projection
  33. {
  34. get
  35. {
  36. return projection;
  37. }
  38. }
  39. public Matrix View
  40. {
  41. get
  42. {
  43. return view;
  44. }
  45. }
  46. public Vector3 ViewPosition
  47. {
  48. get
  49. {
  50. return viewPosition;
  51. }
  52. set
  53. {
  54. viewPosition = value;
  55. view = Matrix.CreateLookAt(viewPosition, Vector3.Zero, Vector3.Up);
  56. }
  57. }
  58. #endregion
  59. public Camera(float fov, float aspectRatio, float nearPlane, float farPlane)
  60. {
  61. projection = Matrix.CreatePerspectiveFieldOfView(fov, aspectRatio, nearPlane, farPlane);
  62. }
  63. }
  64. }