File: Particle.h

package info (click to toggle)
jazz2-native 3.5.0-1
  • links: PTS, VCS
  • area: contrib
  • in suites:
  • size: 16,836 kB
  • sloc: cpp: 172,557; xml: 113; python: 36; makefile: 5; sh: 2
file content (59 lines) | stat: -rw-r--r-- 1,700 bytes parent folder | download | duplicates (3)
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
#pragma once

#include "Sprite.h"
#include "../Primitives/Vector2.h"
#include "../Primitives/Color.h"

namespace nCine
{
	class Texture;

	/// Renders a single particle
	class Particle : public Sprite
	{
		friend class ParticleSystem;

	public:
		/// Current particle remaining life in seconds
		float life_;
		/// Initial particle remaining life
		float startingLife; // for affectors
		/// Initial particle rotation
		float startingRotation; // for affectors
		/// Current particle velocity vector
		Vector2f velocity_;
		/// Flag indicating if particle transformations are in local space or not
		bool inLocalSpace_;

		/// Constructor for a particle with a parent and texture, positioned in the relative origin
		Particle(SceneNode* parent, Texture* texture);

		Particle& operator=(const Particle&) = delete;
		Particle(Particle&&) = default;
		Particle& operator=(Particle&&) = default;

		/// Returns true if the particle is still alive
		inline bool isAlive() const {
			return life_ > 0.0f;
		}

	protected:
		/// Returns a copy of this object
		/*! \note This method is protected as it should only be called by a `ParticleSystem` */
		inline Particle clone() const {
			return Particle(*this);
		}

		/// Protected copy constructor used to clone objects
		Particle(const Particle& other);

	private:
		/// Initializes a particle with initial life, position, velocity and rotation
		void init(float life, Vector2f pos, Vector2f vel, float rot, bool inLocalSpace);
		/// Updates particle data after the specified amount of seconds has passed
		void OnUpdate(float timeMult) override;
		/// Custom transform method to allow independent position from parent
		void transform() override;
	};

}