Brunot
Loading...
Searching...
No Matches
ParticleEmitter.h
Go to the documentation of this file.
1
12// ____ __ __ __
13// /\__ _\/\ \ /\ \/\ \
14// \/_/\ \/\ \ \___ __ \ \ \_\ \ ___ __ __ ____ __
15// \ \ \ \ \ _ `\ /'__`\ \ \ _ \ / __`\/\ \/\ \ /',__\ /'__`\
16// \ \ \ \ \ \ \ \/\ __/ \ \ \ \ \/\ \L\ \ \ \_\ \/\__, `\/\ __/
17// \ \_\ \ \_\ \_\ \____\ \ \_\ \_\ \____/\ \____/\/\____/\ \____\
18// \/_/ \/_/\/_/\/____/ \/_/\/_/\/___/ \/___/ \/___/ \/____/
19
20
21#pragma once
25
26
31class ParticleEmitter final
32{
33public:
36 ParticleEmitter(const ParticleEmitter& other);
37 ParticleEmitter(ParticleEmitter&& other) noexcept;
38 auto operator=(const ParticleEmitter& other) -> ParticleEmitter&;
39 auto operator=(ParticleEmitter&& other) noexcept -> ParticleEmitter&;
40
47 auto setParentTransform(const AffineMatrix& affineMatrix, Vector4D scale, float rot) -> void;
48
50 auto registerWithParticles() const -> void;
51
56 auto update(float dt) -> void;
57
61 auto showMenu() -> void;
62
66 auto reset() -> void;
67
68 [[nodiscard]] auto getName() const -> std::string;
69
70 friend auto to_json(json& j, const ParticleEmitter& n) -> void;
71 friend auto from_json(const json& j, ParticleEmitter& n) -> void;
72
73private:
75 std::string name = "Emitter";
77 std::shared_ptr<ParticleBlock> block;
79 std::unique_ptr<ParticleSpawner> spawner;
80
86 float parentRot = 0;
88 float spawnsPerSecond = 1.f;
90 float timeToNextSpawn = 0.f;
91
93 auto getTimeBetweenSpawns() const -> float;
94
95};
nlohmann::json json
Definition Json.cpp:19
A container for holding and updating particles that are all the same type.
Creates Particles, based on initial conditions set in the editor, with potential randomness.
auto operator=(const ParticleEmitter &other) -> ParticleEmitter &
Definition ParticleEmitter.cpp:66
std::shared_ptr< ParticleBlock > block
where the particles generated by the emitter are stored. this block is also referenced by sys::Partic...
Definition ParticleEmitter.h:77
auto setParentTransform(const AffineMatrix &affineMatrix, Vector4D scale, float rot) -> void
set the transforms for the parent Entity, so that Particles will be generated at the right scale and ...
Definition ParticleEmitter.cpp:98
ParticleEmitter()
Definition ParticleEmitter.cpp:32
friend auto to_json(json &j, const ParticleEmitter &n) -> void
Definition ParticleEmitter.cpp:170
float parentRot
parent rotation, as last set by setParentTransform
Definition ParticleEmitter.h:86
std::unique_ptr< ParticleSpawner > spawner
the ParticleSpawner is what actually creates the particles
Definition ParticleEmitter.h:79
auto reset() -> void
resets the timer on the emitter, so that particles will be emitted next time it updates
Definition ParticleEmitter.cpp:150
~ParticleEmitter()
Definition ParticleEmitter.cpp:38
friend auto from_json(const json &j, ParticleEmitter &n) -> void
Definition ParticleEmitter.cpp:179
AffineMatrix parentTransform
parent transform, as last set by setParentTransform
Definition ParticleEmitter.h:82
float timeToNextSpawn
how long until particles will spawn next
Definition ParticleEmitter.h:90
float spawnsPerSecond
how often particles should spawn
Definition ParticleEmitter.h:88
Vector4D parentScale
parent scale, as last set by setParentTransform
Definition ParticleEmitter.h:84
std::string name
The name of the emitter, for ease of reference in editor.
Definition ParticleEmitter.h:75
auto registerWithParticles() const -> void
registers the ParticleEmitter with sys::ParticleManager, so that the particles can be updated
Definition ParticleEmitter.cpp:27
auto getTimeBetweenSpawns() const -> float
helper function for calculating time between spawns, based on how many spawnsPerSecond
Definition ParticleEmitter.cpp:160
auto update(float dt) -> void
runs update for the emitter, the emitter will automatically count down to decide when to emit particl...
Definition ParticleEmitter.cpp:106
auto showMenu() -> void
Draw the ImGui menu for the Emitter, has controls for what types of particles are emitted,...
Definition ParticleEmitter.cpp:124
auto getName() const -> std::string
Definition ParticleEmitter.cpp:155
Definition AffineMatrix.h:30
Definition Vector4D.h:23