5.1.1.2.3 : Implementation Particle.cpp
Implementation of Particle.cpp file : First, we have to include the appropriate files :

1
#include "Particle.h"


The constructor and copy constructor :

1
2
3
4
5
6
7
8
9
10
11
///Default constructeur of Particle
Particle::Particle(){
	initialisationParticle();
}

///Copy constructor of Particle
/**	@param other : class to copy
*/
Particle::Particle(const Particle & other){
	copyParticle(other);
}


The destructor :

1
2
3
4
///Destructeur of Particle
Particle::~Particle(){
	
}


The equal operator :

1
2
3
4
5
6
7
8
///Definition of equal operator of Particle
/**	@param other : class to copy
 * 	@return copied class
*/
Particle & Particle::operator = (const Particle & other){
	copyParticle(other);
	return *this;
}


Random initialisation :

1
2
3
4
5
6
7
///Initialise randomly the Particle
void Particle::randomInit(){
	float boxHalfSize(1.0f), velocity(0.005f);
	p_position.setComposante(randfloat(-boxHalfSize, boxHalfSize), randfloat(-boxHalfSize, boxHalfSize), randfloat(-boxHalfSize, boxHalfSize));
	p_velocity.setComposante(randfloat(-velocity, velocity), randfloat(-velocity, velocity), randfloat(-velocity, velocity));
	p_acceleration.setComposante(0.0f, 0.0f, -9.81f);
}


Moving the Particle :

1
2
3
4
5
6
7
///Move the current Particle
/**	@param dt : ellapsed time
*/
void Particle::move(float dt){
	p_velocity += p_acceleration*dt;
	p_position += p_velocity*dt;
}


The setters :

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
///Set the position of the Particle
/**	@param position : position of the Particle
*/
void Particle::setPosition(const Vec3f & position){
	p_position = position;
}

///Set the position of the Particle
/**	@param velocity : velocity of the Particle
*/
void Particle::setVelocity(const Vec3f & velocity){
	p_velocity = velocity;
}

///Set the position of the Particle
/**	@param acceleration : acceleration of the Particle
*/
void Particle::setAcceleration(const Vec3f & acceleration){
	p_acceleration = acceleration;
}


The getters :

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
///Get the position of the Particle
/**	@return position of the Particle
*/
const Vec3f & Particle::getPosition() const{return p_position;}

///Get the position of the Particle
/**	@return position of the Particle
*/
Vec3f & Particle::getPosition(){return p_position;}

///Get the velocity of the Particle
/**	@return velocity of the Particle
*/
const Vec3f & Particle::getVelocity() const{return p_velocity;}

///Get the velocity of the Particle
/**	@return velocity of the Particle
*/
Vec3f & Particle::getVelocity(){return p_velocity;}

///Get the acceleration of the Particle
/**	@return acceleration of the Particle
*/
const Vec3f & Particle::getAcceleration() const{return p_acceleration;}

///Get the acceleration of the Particle
/**	@return acceleration of the Particle
*/
Vec3f & Particle::getAcceleration(){return p_acceleration;}


Copy and initialisation functions :

1
2
3
4
5
6
7
8
9
10
11
12
13
///Copy function of Particle
/**	@param other : class to copy
*/
void Particle::copyParticle(const Particle & other){
	p_position = other.p_position;
	p_velocity = other.p_velocity;
	p_acceleration = other.p_acceleration;
}

///Initialisation function of the class Particle
void Particle::initialisationParticle(){
	
}