Brunot
Loading...
Searching...
No Matches
Particle.h
Go to the documentation of this file.
1
11// ____ __ __ __
12// /\__ _\/\ \ /\ \/\ \
13// \/_/\ \/\ \ \___ __ \ \ \_\ \ ___ __ __ ____ __
14// \ \ \ \ \ _ `\ /'__`\ \ \ _ \ / __`\/\ \/\ \ /',__\ /'__`\
15// \ \ \ \ \ \ \ \/\ __/ \ \ \ \ \/\ \L\ \ \ \_\ \/\__, `\/\ __/
16// \ \_\ \ \_\ \_\ \____\ \ \_\ \_\ \____/\ \____/\/\____/\ \____\
17// \/_/ \/_/\/_/\/____/ \/_/\/_/\/___/ \/___/ \/___/ \/____/
18
19
20#pragma once
21#include "Graphics/Texture.h"
22#include "Utility/Math/Bezier.h"
24
25
26namespace gfx
27{
28class Mesh;
29class Shader;
30class Texture;
31}
50{
51 Vector4D position = {0.f, 0.f, 0.f, 1.f};
52 Vector4D velocity = {0.f, 0.f, 0.f, 0.f};
53 Vector4D velocityBegin = {0.f, 0.f, 0.f, 0.f};
54 Vector4D velocityEnd = {0.f, 0.f, 0.f, 0.f};
55 Vector4D scale = {1.f, 1.f, 0.f, 0.f};
56 Vector4D scaleBegin = {1.f, 1.f, 0.f, 0.f};
57 Vector4D scaleEnd = {1.f, 1.f, 0.f, 0.f};
58 float rotation = 0.f;
59 float rotationalVelocity = 0.f;
61 Vector4D color = {1.f, 1.f, 1.f, 1.f};
62 Vector4D colorBegin = {1.f, 1.f, 1.f, 1.f};
63 Vector4D colorEnd = {1.f, 1.f, 1.f, 1.f};
65 unsigned frame = 0u;
67 float frameCountdown = 0.f;
69 float lifetime = 1.f;
71 float timeLeft = -1.f;
72
73 // @warning:
74 // All variable below this line are "special values" that aren't actually per particle
75 // but still are a property of the particle in a logical sense. in practice this means
76 // these are variables that are stored as a single value by the ParticleBlock , not in an
77 // array of values, per particle.
78
83 float fps = 0.f;
84
89 bool velocityChanges = false;
97
102 bool colorChanges = false;
108
113 bool scaleChanges = false;
119
120
125 bool loopingSprite = true;
135 gfx::Shader* shader = nullptr;
140 gfx::Mesh* mesh = nullptr;
141
142
143 friend auto to_json(json& j, const Particle& n) -> void
144 {
145 j = json{
146 {"position", n.position},
147 {"velocity", n.velocity},
148 {"velocityBegin", n.velocityBegin},
149 {"velocityEnd", n.velocityEnd},
150 {"scale", n.scale},
151 {"scaleBegin", n.scaleBegin},
152 {"scaleEnd", n.scaleEnd},
153 {"rotation", n.rotation},
154 {"rotationalVelocity", n.rotationalVelocity},
155 {"rotationalAcceleration", n.rotationalAcceleration},
156 {"color", n.color},
157 {"colorBegin", n.colorBegin},
158 {"colorEnd", n.colorEnd},
159 {"frame", n.frame},
160 {"frameCountdown", n.frameCountdown},
161 {"lifetime", n.lifetime},
162 {"timeLeft", n.timeLeft},
163
164 {"fps", n.fps},
165 {"velocityChanges", n.velocityChanges},
166 {"velocityCurve", n.velocityCurve},
167 {"colorChanges", n.colorChanges},
168 {"colorCurve", n.colorCurve},
169 {"scaleChanges", n.scaleChanges},
170 {"scaleCurve", n.scaleCurve},
171 {"loopingSprite", n.loopingSprite},
172 };
173 if (n.texture)
174 {
175 j["texture"] = n.texture->name();
176 }
177 if (n.mesh)
178 {
179 j["mesh"] = n.mesh->name();
180 }
181 if (n.shader)
182 {
183 j["shader"] = n.shader->name();
184 }
185 }
186
187 friend auto from_json(const json& j, Particle& n) -> void
188 {
189 j.at("position").get_to(n.position);
190 j.at("velocity").get_to(n.velocity);
191 j.at("velocityBegin").get_to(n.velocityBegin);
192 j.at("velocityEnd").get_to(n.velocityEnd);
193 j.at("scale").get_to(n.scale);
194 j.at("scaleBegin").get_to(n.scaleBegin);
195 j.at("scaleEnd").get_to(n.scaleEnd);
196 j.at("rotation").get_to(n.rotation);
197 j.at("rotationalVelocity").get_to(n.rotationalVelocity);
198 j.at("rotationalAcceleration").get_to(n.rotationalAcceleration);
199 j.at("color").get_to(n.color);
200 j.at("colorBegin").get_to(n.colorBegin);
201 j.at("colorEnd").get_to(n.colorEnd);
202 j.at("frame").get_to(n.frame);
203 j.at("frameCountdown").get_to(n.frameCountdown);
204 j.at("lifetime").get_to(n.lifetime);
205 j.at("timeLeft").get_to(n.timeLeft);
206 j.at("fps").get_to(n.fps);
207 j.at("velocityChanges").get_to(n.velocityChanges);
208 j.at("velocityCurve").get_to(n.velocityCurve);
209 j.at("colorChanges").get_to(n.colorChanges);
210 j.at("colorCurve").get_to(n.colorCurve);
211 j.at("scaleChanges").get_to(n.scaleChanges);
212 j.at("scaleCurve").get_to(n.scaleCurve);
213 j.at("loopingSprite").get_to(n.loopingSprite);
214
215 if (j.contains("mesh"))
216 {
217 n.mesh = th::Library::get<gfx::Mesh>("Mesh/" + j.at("mesh").get<std::string>());
218 }
219 if (j.contains("texture"))
220 {
221 n.texture = th::Library::get<gfx::Texture>("Texture/" + j.at("texture").get<std::string>());
222 }
223 if (j.contains("shader"))
224 {
225 n.shader = th::Library::get<gfx::Shader>("Shader/" + j.at("shader").get<std::string>());
226 }
227 }
228};
Wrapper for cubic bezier curve class.
nlohmann::json json
Definition Json.cpp:19
holds and manages textures for use with meshes in sprites
Definition Mesh.h:56
Definition Shader.h:25
holds and manages textures for use with meshes in sprites
Definition Texture.h:33
static auto get(const std::string &name) -> T *
get a pointer to an object in the library.
Definition Library.h:49
Definition Sprite.h:25
Struct for passing around all the data a particle has, before a particle is added to a Particle Block...
Definition Particle.h:50
gfx::Shader * shader
Shader for the particle.
Definition Particle.h:135
gfx::Mesh * mesh
Mesh for the particle.
Definition Particle.h:140
bool scaleChanges
whether the color should change for the particle.
Definition Particle.h:113
th::Bezier scaleCurve
if scaleChanges, then scaleCurve dictates how the particle should interpolate between the start and e...
Definition Particle.h:118
Vector4D velocityEnd
Definition Particle.h:54
friend auto to_json(json &j, const Particle &n) -> void
Definition Particle.h:143
Vector4D scale
Definition Particle.h:55
gfx::Texture * texture
Texture for the particle.
Definition Particle.h:130
float timeLeft
how long the particle has before death, if 0 or less, particle is inactive
Definition Particle.h:71
float frameCountdown
how many seconds until the next frame starts
Definition Particle.h:67
unsigned frame
the frame the particle is currently on
Definition Particle.h:65
float rotationalAcceleration
Definition Particle.h:60
Vector4D velocity
Definition Particle.h:52
bool colorChanges
whether the color should change for the particle.
Definition Particle.h:102
float fps
how many frames per second the animation on a particle should be.
Definition Particle.h:83
Vector4D position
Definition Particle.h:51
float lifetime
how long the particle will live for
Definition Particle.h:69
Vector4D color
Definition Particle.h:61
friend auto from_json(const json &j, Particle &n) -> void
Definition Particle.h:187
Vector4D colorBegin
Definition Particle.h:62
th::Bezier velocityCurve
if velocityChanges, then velocityCurve dictates how the particle should interpolate between the start...
Definition Particle.h:96
Vector4D scaleBegin
Definition Particle.h:56
bool loopingSprite
whether the sprite loops or not.
Definition Particle.h:125
th::Bezier colorCurve
if colorChanges, then colorCurve dictates how the particle should interpolate between the start and e...
Definition Particle.h:107
Vector4D scaleEnd
Definition Particle.h:57
bool velocityChanges
whether the velocity should change for the particle.
Definition Particle.h:89
Vector4D colorEnd
Definition Particle.h:63
float rotation
Definition Particle.h:58
Vector4D velocityBegin
Definition Particle.h:53
float rotationalVelocity
Definition Particle.h:59
Definition Vector4D.h:23
Definition Bezier.h:30