Profile.cs 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  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="RingProfile"/> that emits particles from the perimeter of a circle.
  42. /// </summary>
  43. /// <param name="radius">The radius of the ring.</param>
  44. /// <param name="radiate">The radiation pattern for particle headings.</param>
  45. /// <returns>A new <see cref="RingProfile"/> instance.</returns>
  46. public static Profile Ring(float radius, CircleRadiation radiate)
  47. {
  48. return new RingProfile { Radius = radius, Radiate = radiate };
  49. }
  50. /// <summary>
  51. /// Creates a <see cref="BoxProfile"/> that emits particles from the perimeter of a rectangle.
  52. /// </summary>
  53. /// <param name="width">The width of the rectangle.</param>
  54. /// <param name="height">The height of the rectangle.</param>
  55. /// <returns>A new <see cref="BoxProfile"/> instance.</returns>
  56. public static Profile Box(float width, float height)
  57. {
  58. return new BoxProfile { Width = width, Height = height };
  59. }
  60. /// <summary>
  61. /// Creates a <see cref="BoxFillProfile"/> that emits particles from within a rectangular area.
  62. /// </summary>
  63. /// <param name="width">The width of the rectangle.</param>
  64. /// <param name="height">The height of the rectangle.</param>
  65. /// <returns>A new <see cref="BoxFillProfile"/> instance.</returns>
  66. public static Profile BoxFill(float width, float height)
  67. {
  68. return new BoxFillProfile { Width = width, Height = height };
  69. }
  70. /// <summary>
  71. /// Creates a <see cref="BoxUniformProfile"/> that emits particles from the perimeter of a rectangle with uniform density.
  72. /// </summary>
  73. /// <param name="width">The width of the rectangle.</param>
  74. /// <param name="height">The height of the rectangle.</param>
  75. /// <returns>A new <see cref="BoxUniformProfile"/> instance.</returns>
  76. public static Profile BoxUniform(float width, float height)
  77. {
  78. return new BoxUniformProfile { Width = width, Height = height };
  79. }
  80. /// <summary>
  81. /// Creates a <see cref="CircleProfile"/> that emits particles from within a circular area.
  82. /// </summary>
  83. /// <param name="radius">The radius of the circle.</param>
  84. /// <param name="radiate">The radiation pattern for particle headings.</param>
  85. /// <returns>A new <see cref="CircleProfile"/> instance.</returns>
  86. public static Profile Circle(float radius, CircleRadiation radiate)
  87. {
  88. return new CircleProfile { Radius = radius, Radiate = radiate };
  89. }
  90. /// <summary>
  91. /// Creates a <see cref="SprayProfile"/> that emits particles in a directional cone.
  92. /// </summary>
  93. /// <param name="direction">The central direction of the spray.</param>
  94. /// <param name="spread">The angular spread of the spray, in radians.</param>
  95. /// <returns>A new <see cref="SprayProfile"/> instance.</returns>
  96. public static Profile Spray(Vector2 direction, float spread)
  97. {
  98. return new SprayProfile { Direction = direction, Spread = spread };
  99. }
  100. /// <inheritdoc />
  101. public override string ToString()
  102. {
  103. return GetType().Name;
  104. }
  105. }