File: Particle.cpp

package info (click to toggle)
jazz2-native 3.5.0-2
  • links: PTS, VCS
  • area: contrib
  • in suites: forky, sid
  • size: 16,912 kB
  • sloc: cpp: 172,557; xml: 113; python: 36; makefile: 5; sh: 2
file content (57 lines) | stat: -rw-r--r-- 1,361 bytes parent folder | download
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
#include "Particle.h"
#include "RenderCommand.h"

namespace nCine
{
	Particle::Particle(SceneNode* parent, Texture* texture)
		: Sprite(parent, texture), life_(0.0f), startingLife(0.0f), startingRotation(0.0f), inLocalSpace_(false)
	{
		_type = ObjectType::Particle;
		renderCommand_.SetType(RenderCommand::Type::Particle);
		setEnabled(false);
	}

	Particle::Particle(const Particle& other)
		: Sprite(other), life_(other.life_), startingLife(other.startingLife), startingRotation(other.startingRotation), inLocalSpace_(other.inLocalSpace_)
	{
		_type = ObjectType::Particle;
		renderCommand_.SetType(RenderCommand::Type::Particle);
	}

	void Particle::init(float life, Vector2f pos, Vector2f vel, float rot, bool inLocalSpace)
	{
		life_ = life;
		startingLife = life;
		startingRotation = rot;
		setPosition(pos);
		velocity_ = vel;
		setRotation(rot);
		inLocalSpace_ = inLocalSpace;
		setEnabled(true);
	}

	void Particle::OnUpdate(float timeMult)
	{
		if (timeMult >= life_) {
			life_ = 0.0f; // dead particle
			setEnabled(false);
		} else {
			life_ -= timeMult;
			move(velocity_ * timeMult);
		}
	}

	void Particle::transform()
	{
		SceneNode::transform();

		if (!inLocalSpace_) {
			worldMatrix_ = localMatrix_;

			// Always independent movement
			absScaleFactor_ = scaleFactor_;
			absRotation_ = rotation_;
			absPosition_ = position_;
		}
	}
}