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_;
}
}
}
|