Profile.cs 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  1. // Copyright (c) Craftwork Games. All rights reserved.
  2. // Licensed under the MIT license.
  3. // See LICENSE file in the project root for full license information.
  4. using Microsoft.Xna.Framework;
  5. using Microsoft.Xna.Framework.Graphics;
  6. namespace MonoGame.Extended.Particles.Profiles;
  7. /// <summary>
  8. /// Provides an abstract base class for particle emission profiles.
  9. /// </summary>
  10. /// <remarks>
  11. /// A profile determines how particles are initially positioned and directed when they are emitted. Different profiles
  12. /// create different distribution patterns, such as points, lines, circles, or boxes.
  13. /// </remarks>
  14. public abstract class Profile
  15. {
  16. /// <summary>
  17. /// Computes the offset and heading for a new particle.
  18. /// </summary>
  19. /// <param name="offset">A pointer to the Vector2 where the offset from the emitter position will be stored.</param>
  20. /// <param name="heading">A pointer to the Vector2 where the unit direction vector will be stored.</param>
  21. public abstract unsafe void GetOffsetAndHeading(Vector2* offset, Vector2* heading);
  22. /// <summary>
  23. /// Creates a <see cref="PointProfile"/> that emits particles from a single point.
  24. /// </summary>
  25. /// <returns>A new <see cref="PointProfile"/> instance.</returns>
  26. public static Profile Point()
  27. {
  28. return new PointProfile();
  29. }
  30. /// <summary>
  31. /// Creates a <see cref="LineProfile"/> that emits particles along a line segment.
  32. /// </summary>
  33. /// <param name="axis">The direction vector of the line.</param>
  34. /// <param name="length">The length of the line segment.</param>
  35. /// <returns>A new <see cref="LineProfile"/> instance.</returns>
  36. public static Profile Line(Vector2 axis, float length)
  37. {
  38. return new LineProfile { Axis = axis, Length = length };
  39. }
  40. /// <summary>
  41. /// Creates a <see cref="LineProfile"/> that emits particles along a line segment.
  42. /// </summary>
  43. /// <param name="axis">The direction vector of the line.</param>
  44. /// <param name="length">The length of the line segment.</param>
  45. /// <param name="radiate">The radiation mode that determines how particle headings are calculated.</param>
  46. /// <returns>A new <see cref="LineProfile"/> instance.</returns>
  47. public static Profile Line(Vector2 axis, float length, LineRadiation radiate)
  48. {
  49. return new LineProfile { Axis = axis, Length = length, Radiate = radiate, Direction = Vector2.Zero };
  50. }
  51. /// <summary>
  52. /// Creates a <see cref="LineProfile"/> that emits particles along a line segment.
  53. /// </summary>
  54. /// <param name="axis">The direction vector of the line.</param>
  55. /// <param name="length">The length of the line segment.</param>
  56. /// <param name="radiate">The radiation mode that determines how particle headings are calculated.</param>
  57. /// <param name="direction">
  58. /// The emission direction vector used when <paramref name="radiate"/> is <see cref="LineRadiation.Directional"/>
  59. /// or as a scale factor when <paramref name="radiate"/> is <see cref="LineRadiation.NormalUp"/> or
  60. /// <see cref="LineRadiation.NormalDown"/>.
  61. /// </param>
  62. /// <returns>A new <see cref="LineProfile"/> instance.</returns>
  63. public static Profile Line(Vector2 axis, float length, LineRadiation radiate, Vector2 direction)
  64. {
  65. return new LineProfile { Axis = axis, Length = length, Radiate = radiate, Direction = direction };
  66. }
  67. /// <summary>
  68. /// Creates a <see cref="RingProfile"/> that emits particles from the perimeter of a circle.
  69. /// </summary>
  70. /// <param name="radius">The radius of the ring.</param>
  71. /// <param name="radiate">The radiation pattern for particle headings.</param>
  72. /// <returns>A new <see cref="RingProfile"/> instance.</returns>
  73. public static Profile Ring(float radius, CircleRadiation radiate)
  74. {
  75. return new RingProfile { Radius = radius, Radiate = radiate };
  76. }
  77. /// <summary>
  78. /// Creates a <see cref="BoxProfile"/> that emits particles from the perimeter of a rectangle.
  79. /// </summary>
  80. /// <param name="width">The width of the rectangle.</param>
  81. /// <param name="height">The height of the rectangle.</param>
  82. /// <returns>A new <see cref="BoxProfile"/> instance.</returns>
  83. public static Profile Box(float width, float height)
  84. {
  85. return new BoxProfile { Width = width, Height = height };
  86. }
  87. /// <summary>
  88. /// Creates a <see cref="BoxFillProfile"/> that emits particles from within a rectangular area.
  89. /// </summary>
  90. /// <param name="width">The width of the rectangle.</param>
  91. /// <param name="height">The height of the rectangle.</param>
  92. /// <returns>A new <see cref="BoxFillProfile"/> instance.</returns>
  93. public static Profile BoxFill(float width, float height)
  94. {
  95. return new BoxFillProfile { Width = width, Height = height };
  96. }
  97. /// <summary>
  98. /// Creates a <see cref="BoxUniformProfile"/> that emits particles from the perimeter of a rectangle with uniform density.
  99. /// </summary>
  100. /// <param name="width">The width of the rectangle.</param>
  101. /// <param name="height">The height of the rectangle.</param>
  102. /// <returns>A new <see cref="BoxUniformProfile"/> instance.</returns>
  103. public static Profile BoxUniform(float width, float height)
  104. {
  105. return new BoxUniformProfile { Width = width, Height = height };
  106. }
  107. /// <summary>
  108. /// Creates a <see cref="CircleProfile"/> that emits particles from within a circular area.
  109. /// </summary>
  110. /// <param name="radius">The radius of the circle.</param>
  111. /// <param name="radiate">The radiation pattern for particle headings.</param>
  112. /// <returns>A new <see cref="CircleProfile"/> instance.</returns>
  113. public static Profile Circle(float radius, CircleRadiation radiate)
  114. {
  115. return new CircleProfile { Radius = radius, Radiate = radiate };
  116. }
  117. /// <summary>
  118. /// Creates a <see cref="SprayProfile"/> that emits particles in a directional cone.
  119. /// </summary>
  120. /// <param name="direction">The central direction of the spray.</param>
  121. /// <param name="spread">The angular spread of the spray, in radians.</param>
  122. /// <returns>A new <see cref="SprayProfile"/> instance.</returns>
  123. public static Profile Spray(Vector2 direction, float spread)
  124. {
  125. return new SprayProfile { Direction = direction, Spread = spread };
  126. }
  127. /// <inheritdoc />
  128. public override string ToString()
  129. {
  130. return GetType().Name;
  131. }
  132. }