-
Notifications
You must be signed in to change notification settings - Fork 1
/
Particle.cpp
94 lines (70 loc) · 1.93 KB
/
Particle.cpp
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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
/*
* Particle.cpp
*
* Created on: 16/03/2016
* Author: Eduardo Gutiérrez
*
*/
#include "Particle.h"
namespace MyBilliards {
//-----------------------------------------------
particle::particle()
{
//Masa en kg de una bola de billar es 0.165
//mass=1.0;
//Diria que no hacia falta por defecto los vector3 se inicializan a 0
position.setVector3(0,0,0);
velocity.setVector3(0,0,0);
forceAccumulator.setVector3(0,0,0);
acceleration.setVector3(0,0,0);
}
//-----------------------------------------------
void particle::integrate(double t)
{
//Integrate con aceleracion
// acceleration = forceAccumulator/mass;
if (mass !=0 )
{
acceleration.setVector3( forceAccumulator.getVector3x()/mass,forceAccumulator.getVector3y()/mass, forceAccumulator.getVector3z()/mass);
velocity = velocity + acceleration*t;
if(velocity.getModulus() < 0.01)
{
velocity.setVector3(0.0,0.0,0.0);
//clearForceAccumulator();
//acceleration.setVector3(0.0,0.0,0.0);
}
//cout << "EL valor de position antes es :" << position << '\n';
position = position + t*velocity + 0.5*acceleration*(t*t);
//cout << "EL valor de position despues es :" << position << '\n';
}
else cerr << "No se pudo calcular la aceleración para masa =0." << '\n';
}
void particle::init_movement(int destination_x,int destination_y,int duration)
{
velocity.setVector3x( (destination_x - position.getVector3x())/duration);
velocity.setVector3y( (destination_y - position.getVector3y())/duration);
state=MOVE;
time_remaining=duration;
}
//-----------------------------------------------
void particle::setState(int state){
this->state = state;
}
//-----------------------------------------------
int particle::getState()
{
return state;
}
void particle::clearForceAccumulator()
{
forceAccumulator.setVector3(0,0,0);
}
void particle::addForce(vector3 force)
{
forceAccumulator = forceAccumulator + force;
}
particle::~particle()
{
// TODO Auto-generated destructor stub
}
}