aboutsummaryrefslogtreecommitdiff
path: root/src/crepe/Particle.h
blob: 570c9be1d26cee0cbf358c2176909da460b793a9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#pragma once

#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 of the particle in 2D space.
	Vector2<double> position;
	//! Velocity vector indicating the speed and direction of the particle.
	Vector2<double> velocity;
	//! Accumulated force affecting the particle over time.
	Vector2<double> 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 = 0;

	/**
	 * \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, const Vector2<double> & position,
			   const Vector2<double> & 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