UiParticle.h 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. /*
  2. * Copyright (c) Contributors to the Open 3D Engine Project.
  3. * For complete copyright and license terms please see the LICENSE at the root of this distribution.
  4. *
  5. * SPDX-License-Identifier: Apache-2.0 OR MIT
  6. *
  7. */
  8. #pragma once
  9. #include <AzCore/Math/Color.h>
  10. #include <AzCore/Math/Matrix4x4.h>
  11. #include <AzCore/Math/Vector2.h>
  12. #include <LmbrCentral/Rendering/TextureAsset.h>
  13. #include <Animation/AnimSplineTrack.h>
  14. #include <Animation/CompoundSplineTrack.h>
  15. #include <LyShine/UiRenderFormats.h>
  16. class UiParticle
  17. {
  18. public: //types
  19. struct UiParticleInitialParameters
  20. {
  21. float lifetime;
  22. AZ::Vector2 position;
  23. AZ::Vector2 initialEmitterOffset;
  24. AZ::Vector2 initialVelocity;
  25. AZ::Vector2 acceleration;
  26. float rotation;
  27. float angularVelocity;
  28. AZ::Vector2 pivot;
  29. AZ::Vector2 size;
  30. AZ::Color color;
  31. int spriteSheetCellIndex;
  32. };
  33. struct UiParticleUpdateParameters
  34. {
  35. bool isParticleInfinite;
  36. bool isVelocityCartesian;
  37. bool isAccelerationCartesian;
  38. bool isSpeedMultiplierUsed;
  39. C2DSplineTrack* speedMultiplier;
  40. };
  41. struct UiParticleRenderParameters
  42. {
  43. ISprite* sprite;
  44. AZ::Vector2* particleOffset;
  45. bool isVelocityCartesian;
  46. bool isRelativeToEmitter;
  47. bool isParticleInfinite;
  48. bool isAspectRatioLocked;
  49. bool isRotationVelocityBased;
  50. bool isWidthMultiplierUsed;
  51. bool isHeightMultiplierUsed;
  52. bool isColorMultiplierUsed;
  53. bool isAlphaMultiplierUsed;
  54. bool isColorOverrideUsed;
  55. bool isAlphaOverrideUsed;
  56. AZ::Color colorOverride;
  57. float alphaOverride;
  58. float alphaFadeMultiplier;
  59. C2DSplineTrack* sizeWidthMultiplier;
  60. C2DSplineTrack* sizeHeightMultiplier;
  61. UiCompoundSplineTrack* colorMultiplier;
  62. C2DSplineTrack* alphaMultiplier;
  63. int spritesheetStartFrame;
  64. int spritesheetFrameRange;
  65. float spritesheetFrameDelay;
  66. bool spritesheetCellIndexAnimated;
  67. bool spritesheetCellIndexAnimationLooped;
  68. };
  69. public:
  70. void Init(UiParticle::UiParticleInitialParameters* emitter);
  71. void Update(float timeStep, const UiParticleUpdateParameters& updateParameters);
  72. //! Fill out the four vertices for the particle.
  73. //! Returns false if the vertex was not added because it was fully transparent.
  74. bool FillVertices(LyShine::UiPrimitiveVertex* outputVertices, const UiParticleRenderParameters& renderParameters, const AZ::Matrix4x4& transform);
  75. bool IsActive(bool infiniteLifetime) const;
  76. private:
  77. float m_particleAge;
  78. float m_particleLifetime;
  79. AZ::Vector2 m_emitterInitialOffset;
  80. AZ::Vector2 m_position;
  81. AZ::Vector2 m_pivot;
  82. float m_rotation;
  83. int m_spriteCellIndex;
  84. AZ::Vector2 m_size;
  85. AZ::Vector2 m_positionDifference;
  86. AZ::Vector2 m_velocity;
  87. AZ::Vector2 m_accelerationBasedVelocity;
  88. AZ::Vector2 m_acceleration;
  89. float m_angularVelocity;
  90. AZ::Color m_color;
  91. };