NcEngine
ParticleEmitter.h
Go to the documentation of this file.
1
5#pragma once
6
10
11#include "ncmath/Color.h"
12#include "ncmath/Vector.h"
13
14namespace nc
15{
16namespace graphics
17{
18class ParticleSubsystem;
19} // namespace graphics
20
23{
24 unsigned maxParticleCount = 100u;
25 unsigned initialEmissionCount = 0u;
26 unsigned periodicEmissionCount = 0u;
27 float periodicEmissionFrequency = 0.0f;
28};
29
32{
33 float lifetime = 5.0f;
34 Vector3 positionMin = Vector3::Zero();
35 Vector3 positionMax = Vector3::Zero();
36 float rotationMin = 0.0f;
37 float rotationMax = 0.0f;
38 float scaleMin = 1.0f;
39 float scaleMax = 1.0f;
40};
41
44{
45 Vector3 velocityMin = Vector3::Zero();
46 Vector3 velocityMax = Vector3::Zero();
47 float velocityOverTimeFactor = 0.0f;
48 float rotationMin = 0.0f;
49 float rotationMax = 0.0f;
50 float rotationOverTimeFactor = 0.0f;
51 float scaleOverTimeFactor = 0.0f;
52};
53
56{
57 Gradient start = Gradient{Color::White()};
58 Gradient end = Gradient{Color::White()};
59 CurveType colorCurve = CurveType::Linear;
60 CurveType alphaCurve = CurveType::Linear;
61};
62
65{
70};
71
74{
75 public:
77 const asset::TextureView& texture,
78 const ParticleInfo& info = {});
79
80 ParticleEmitter(ParticleEmitter&& other) noexcept
81 : m_self{std::exchange(other.m_self, Entity::Null())},
82 m_texture{other.m_texture},
83 m_info{other.m_info}
84 {
85 }
86
87 ParticleEmitter& operator=(ParticleEmitter&& other) noexcept
88 {
89 if (this != &other)
90 {
91 Release();
92 m_self = std::exchange(other.m_self, Entity::Null());
93 m_texture = other.m_texture;
94 m_info = other.m_info;
95 }
96
97 return *this;
98 }
99
100 ~ParticleEmitter() noexcept
101 {
102 Release();
103 }
104
106 auto GetEntity() const -> Entity { return m_self; }
107
109 auto GetTexture() const noexcept -> const asset::TextureView& { return m_texture; }
110 void SetTexture(const asset::TextureView& texture);
111
113 auto GetInfo() const noexcept -> const ParticleInfo& { return m_info; }
114 void SetInfo(const ParticleInfo& info);
115
117 void Emit(size_t count);
118
120 static void RegisterSubsystem(graphics::ParticleSubsystem* subsystem)
121 {
122 s_subsystem = subsystem;
123 }
126 private:
127 static inline graphics::ParticleSubsystem* s_subsystem = nullptr;
128
129 Entity m_self;
130 asset::TextureView m_texture;
131 ParticleInfo m_info;
132
133 void Release() noexcept;
134};
135} // namespace nc
CurveType
Common types of curves.
Definition: Curve.h:13
Identifies an object in the registry.
Definition: Entity.h:18
static constexpr auto Null() noexcept
Construct a null Entity.
Definition: Entity.h:61
Component for creating particle effects.
Definition: ParticleEmitter.h:74
auto GetInfo() const noexcept -> const ParticleInfo &
Definition: ParticleEmitter.h:113
void SetInfo(const ParticleInfo &info)
void Emit(size_t count)
Emit count number of particles, saturating at maxParticleCount.
Gradient between two Colors.
Definition: Color.h:45
Describes particle color properties.
Definition: ParticleEmitter.h:56
CurveType alphaCurve
‍curve describing how RGB values change over time
Definition: ParticleEmitter.h:60
Gradient end
‍gradient initial color is randomly selected from
Definition: ParticleEmitter.h:58
CurveType colorCurve
‍gradient final color is randomly selected from
Definition: ParticleEmitter.h:59
Describes particle emission behavior for a ParticleEmitter.
Definition: ParticleEmitter.h:23
Settings for a ParticleEmitter.
Definition: ParticleEmitter.h:65
Describes initial particle properties.
Definition: ParticleEmitter.h:32
Describes particle motion over time.
Definition: ParticleEmitter.h:44
A three component vector.
Definition: Vector.h:29
Definition: AssetViews.h:66