Bubba-3D  0.9.0
Awesome game engine!
Particle.cpp
1 /*
2  * This file is part of Bubba-3D.
3  *
4  * Bubba-3D is free software: you can redistribute it and/or modify
5  * it under the terms of the GNU Lesser General Public License as published by
6  * the Free Software Foundation, either version 3 of the License, or
7  * (at your option) any later version.
8  *
9  * Bubba-3D is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU Lesser General Public License for more details.
13  *
14  * You should have received a copy of the GNU Lesser General Public License
15  * along with Bubba-3D. If not, see http://www.gnu.org/licenses/.
16  */
17 #include "particle/Particle.h"
18 #include "ParticleConf.h"
19 
20 Particle::Particle(ParticleConf *conf, chag::float4x4 modelMatrix) {
21  reset(conf, modelMatrix);
22 };
23 
24 void Particle::reset(ParticleConf *conf, chag::float4x4 modelMatrix) {
25  position = conf->initialPosition();
26  chag::float4 vec = chag::make_vector(position.x, position.y, position.z, 1.0f);
27  chag::float4 mat = modelMatrix * vec;
28  position.x = mat.x;
29  position.y = mat.y;
30  position.z = mat.z;
31  velocity = conf->initialVelocity();
32  life = conf->calcLifetime();
33 }
34 
35 void Particle::update(float deltaTime, float distanceToCam, ParticleConf *conf) {
36  velocity = conf->accelerate(velocity);
37  position += velocity * deltaTime / 1000;
38  life -= deltaTime + (distanceToCam * 2);
39 }
40 
42  return life > 0.0f;
43 }
44 
45 chag::float3 Particle::getPosition() {
46  return position;
47 }
virtual chag::float3 initialPosition()=0
void reset(ParticleConf *conf, chag::float4x4 modelMatrix)
Definition: Particle.cpp:24
virtual chag::float3 accelerate(chag::float3 velocity)=0
bool isAlive()
Definition: Particle.cpp:41
virtual float calcLifetime()=0
virtual chag::float3 initialVelocity()=0
void update(float deltaTime, float distanceToCam, ParticleConf *conf)
Definition: Particle.cpp:35