Camera.cs 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192
  1. using System;
  2. using Microsoft.Xna.Framework;
  3. namespace MonoGame.Extended
  4. {
  5. /// <summary>
  6. /// Represents an abstract camera.
  7. /// </summary>
  8. /// <typeparam name="T">
  9. /// The position type for the camera.
  10. /// Typically <see cref="Vector2"/> for 2D cameras or <see cref="Vector3"/> for 3D cameras
  11. /// </typeparam>
  12. public abstract class Camera<T> where T : struct
  13. {
  14. /// <summary>
  15. /// Gets or sets the position fo the camera in world coordinates.
  16. /// </summary>
  17. public abstract T Position { get; set; }
  18. /// <summary>
  19. /// Gets or sets the rotation of the camera in radians.
  20. /// </summary>
  21. public abstract float Rotation { get; set; }
  22. /// <summary>
  23. /// Gets or sets the zoom level of the camera.
  24. /// </summary>
  25. /// <value>
  26. /// The zoom factor where <c>1.0</c> represents the default zoom level.
  27. /// Values greater than <c>1.0</c> in and values less than <c>1.0</c> zoom out.
  28. /// </value>
  29. public abstract float Zoom { get; set; }
  30. /// <summary>
  31. /// Gets or sets the minimum allowed zoom level.
  32. /// </summary>
  33. public abstract float MinimumZoom { get; set; }
  34. /// <summary>
  35. /// Gets or sets the maximum allowed zoom level.
  36. /// </summary>
  37. public abstract float MaximumZoom { get; set; }
  38. /// <summary>
  39. /// Gets or sets the vertical scale multiplier applied to the camera's zoom.
  40. /// </summary>
  41. /// <remarks>
  42. /// This property is deprecated and will be removed in the next major version.
  43. /// </remarks>
  44. [Obsolete("Pitch will be removed in the next major version")]
  45. public abstract float Pitch { get; set; }
  46. /// <summary>
  47. /// Gets or sets the minimum allowed pitch value.
  48. /// </summary>
  49. /// <remarks>
  50. /// This property is deprecated and will be removed in the next major version.
  51. /// </remarks>
  52. [Obsolete("Pitch will be removed in the next major version")]
  53. public abstract float MinimumPitch { get; set; }
  54. /// <summary>
  55. /// Gets or Sets the maximum allowed pitch value.
  56. /// </summary>
  57. /// <remarks>
  58. /// This property is deprecated and will be removed in the next major version.
  59. /// </remarks>
  60. [Obsolete("Pitch will be removed in the next major version")]
  61. public abstract float MaximumPitch { get; set; }
  62. /// <summary>
  63. /// Gets the axis-aligned bounding rectangle of the camera's view in world coordinates.
  64. /// </summary>
  65. public abstract RectangleF BoundingRectangle { get; }
  66. /// <summary>
  67. /// Gets or sets the origin point for rotation and zoom transformations.
  68. /// </summary>
  69. /// <remarks>
  70. /// The origin defines the center point around which rotation and zoom are applied.
  71. /// Typically set to the center of the viewport.
  72. /// </remarks>
  73. public abstract T Origin { get; set; }
  74. /// <summary>
  75. /// Gets the center position of the camera's view in world coordinates.
  76. /// </summary>
  77. public abstract T Center { get; }
  78. /// <summary>
  79. /// Moves the camera by the specified direction vector.
  80. /// </summary>
  81. /// <param name="direction">The direction and distance to move the camera.</param>
  82. public abstract void Move(T direction);
  83. /// <summary>
  84. /// Rotates the camera by the specified amount
  85. /// </summary>
  86. /// <param name="deltaRadians">The rotation amount in radians to apply.</param>
  87. public abstract void Rotate(float deltaRadians);
  88. /// <summary>
  89. /// Increases the camera's zoom level by the specified amount.
  90. /// </summary>
  91. /// <param name="deltaZoom">The amount to increase the zoom by.</param>
  92. public abstract void ZoomIn(float deltaZoom);
  93. /// <summary>
  94. /// Decreases the camera's zoom level by the specified amount.
  95. /// </summary>
  96. /// <param name="deltaZoom">The amount to decrease the zoom by.</param>
  97. public abstract void ZoomOut(float deltaZoom);
  98. /// <summary>
  99. /// Increases the pitch value by the specified amount.
  100. /// </summary>
  101. /// <param name="deltaZoom">The amount to increase the pitch by.</param>
  102. /// <remarks>
  103. /// This method is deprecated and will be removed in the next major version.
  104. /// </remarks>
  105. [Obsolete("Pitch will be removed in the next major version")]
  106. public abstract void PitchUp(float deltaZoom);
  107. /// <summary>
  108. /// Decreases the pitch value by the specified amount.
  109. /// </summary>
  110. /// <param name="deltaZoom">The amount to decrease the pitch by.</param>
  111. /// <remarks>
  112. /// This method is deprecated and will be removed in the next major version.
  113. /// </remarks>
  114. [Obsolete("Pitch will be removed in the next major version")]
  115. public abstract void PitchDown(float deltaZoom);
  116. /// <summary>
  117. /// Positions the camera to look at the specified position.
  118. /// </summary>
  119. /// <param name="position">The world position to center the camera on.</param>
  120. public abstract void LookAt(T position);
  121. /// <summary>
  122. /// Converts a position from world coordinates to screen coordinates.
  123. /// </summary>
  124. /// <param name="worldPosition">The position in world coordinates.</param>
  125. /// <returns>The corresponding position in screen coordinates.</returns>
  126. public abstract T WorldToScreen(T worldPosition);
  127. /// <summary>
  128. /// Converts a position from screen coordinates to world coordinates.
  129. /// </summary>
  130. /// <param name="screenPosition">The position in screen coordinates.</param>
  131. /// <returns>The corresponding position in world coordinates.</returns>
  132. public abstract T ScreenToWorld(T screenPosition);
  133. /// <summary>
  134. /// Gets the view transformation matrix for the camera.
  135. /// </summary>
  136. /// <returns>A <see cref="Matrix"/> representing the camera's view transformation.</returns>
  137. public abstract Matrix GetViewMatrix();
  138. /// <summary>
  139. /// Gets the inverse of the view transformation matrix for the camera.
  140. /// </summary>
  141. /// <returns>A <see cref="Matrix"/> representing the inverse of the camera's view transformation.</returns>
  142. public abstract Matrix GetInverseViewMatrix();
  143. /// <summary>
  144. /// Gets the bounding frustum for the camera's view volume.
  145. /// </summary>
  146. /// <returns>A <see cref="BoundingFrustum"/> representing the camera's view volume.</returns>
  147. public abstract BoundingFrustum GetBoundingFrustum();
  148. /// <summary>
  149. /// Determines whether the camera's view contains the specified point.
  150. /// </summary>
  151. /// <param name="vector2">The point to test, in world coordinates.</param>
  152. /// <returns>
  153. /// A <see cref="ContainmentType"/> indicating whether the point is inside, outside, or
  154. /// intersects the camera's view.
  155. /// </returns>
  156. public abstract ContainmentType Contains(Vector2 vector2);
  157. /// <summary>
  158. /// Determines whether the camera's view contains the specified rectangle.
  159. /// </summary>
  160. /// <param name="rectangle">The rectangle to test, in world coordinates.</param>
  161. /// /// <returns>
  162. /// A <see cref="ContainmentType"/> indicating whether the rectangle is inside, outside, or
  163. /// intersects the camera's view.
  164. /// </returns>
  165. public abstract ContainmentType Contains(Rectangle rectangle);
  166. }
  167. }