aboutsummaryrefslogtreecommitdiff
path: root/src/crepe/Particle.h
diff options
context:
space:
mode:
authorheavydemon21 <nielsstunnebrink1@gmail.com>2024-11-11 19:48:18 +0100
committerheavydemon21 <nielsstunnebrink1@gmail.com>2024-11-11 19:48:18 +0100
commit141c4831be82654a692d03fdb0fbf87fa27dea88 (patch)
tree02bc3294cf44e3f962595d05bbdfcc0484d0d9f3 /src/crepe/Particle.h
parentca878336da5cdd120a929e6ce84f565ce5365248 (diff)
parente42d0877592aa1e88afbe0bc65822cd53a82205d (diff)
Merge branch 'jaro/particle-system-master' into niels/RenderingParticle
Diffstat (limited to 'src/crepe/Particle.h')
-rw-r--r--src/crepe/Particle.h65
1 files changed, 54 insertions, 11 deletions
diff --git a/src/crepe/Particle.h b/src/crepe/Particle.h
index 21e691d..06431bb 100644
--- a/src/crepe/Particle.h
+++ b/src/crepe/Particle.h
@@ -1,22 +1,65 @@
#pragma once
-#include "Position.h"
+#include <cstdint>
+
+#include "api/Vector2.h"
namespace crepe {
+/**
+ * \brief Represents a particle in the particle emitter.
+ *
+ * This class stores information about a single particle, including its position,
+ * velocity, lifespan, and other properties. Particles can be updated over time
+ * to simulate movement and can also be reset or stopped.
+ */
class Particle {
+ // TODO: add friend particleSsytem and rendersystem. Unit test will fail.
+
public:
- Position position;
- // FIXME: `Position` is an awkward name for a 2D vector. See FIXME comment in
- // api/Transform.h for fix proposal.
- Position velocity;
- float lifespan;
- bool active;
+ //! Position of the particle in 2D space.
+ Vector2 position;
+ //! Velocity vector indicating the speed and direction of the particle.
+ Vector2 velocity;
+ //! Accumulated force affecting the particle over time.
+ Vector2 force_over_time;
+ //! Total lifespan of the particle in milliseconds.
+ uint32_t lifespan;
+ //! Active state of the particle; true if it is in use, false otherwise.
+ bool active = false;
+ //! The time the particle has been alive, in milliseconds.
+ uint32_t time_in_life = 0;
+ //! The angle at which the particle is oriented or moving.
+ double angle;
- Particle();
- void reset(float lifespan, Position position, Position velocity);
- void update(float deltaTime);
- float time_in_life;
+ Particle() = default;
+ /**
+ * \brief Resets the particle with new properties.
+ *
+ * This method initializes the particle with a specific lifespan, position,
+ * velocity, and angle, marking it as active and resetting its life counter.
+ *
+ * \param lifespan The lifespan of the particle in amount of updates.
+ * \param position The starting position of the particle.
+ * \param velocity The initial velocity of the particle.
+ * \param angle The angle of the particle's trajectory or orientation.
+ */
+ void reset(uint32_t lifespan, Vector2 position, Vector2 velocity,
+ double angle);
+ /**
+ * \brief Updates the particle's state.
+ *
+ * Advances the particle's position based on its velocity and applies accumulated forces.
+ * Deactivates the particle if its lifespan has expired.
+ */
+ void update();
+ /**
+ * \brief Stops the particle's movement.
+ *
+ * Sets the particle's velocity to zero, effectively halting any further
+ * movement.
+ */
+ void stop_movement();
};
} // namespace crepe