-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathParticle.cpp
More file actions
170 lines (150 loc) · 4.61 KB
/
Particle.cpp
File metadata and controls
170 lines (150 loc) · 4.61 KB
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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
#include "Particle.h"
/*---------------OP OVERLOADS---------------------------*/
void Particle::operator = (const Particle &other)
{
this->ptnum = other.ptnum ;
this->position = other.position ;
this->velocity = other.velocity ;
this->forces = other.forces ;
this->mass = other.mass ;
this->radius = other.radius ;
this->color = other.color ;
//Life should be initialised to 0 as the particle is Born
// this->life = 0 ;
// this->maxLife = other.maxLife ;
// this->lifeVariance = other.lifeVariance ;
}
//Also need to copy particles attributes (maybe a flag for it)
//Will Implement it later after setting up a functional system
//////////////////////////////////////////////////////////
Particle::Particle() : ptnum(0), position(ofVec3f::zero()), mass(1.f), radius(1.f), color(ofColor::white)
{
// cout << "Initializing default Settings" << endl ;
// cout << "position( " << position.x << "," << position.y << "," << position.z << " )" << endl ;
}
Particle::~Particle() {}
//TO DO copy attributes of the input Particle
Particle::Particle(const Particle &other) :
ptnum(other.ptnum),
position(other.position),
velocity(other.velocity),
forces(other.forces),
color(other.color)
{
cout << "Created Particle(ptnum: " << ptnum << ")"
<< " from input Particle(ptnum: " << other.ptnum << ")" << endl ;
}
Particle::Particle(int _ptnum, const ofVec3f &pos, const ofVec3f &initialVel, float xvelVar, float yvelVar, float zvelVar, float _mass, float massVar) :
ptnum(_ptnum),
position(pos),
color(ofColor::white)
{
ofVec3f jitterVel(Utility::of_Randomuf(ptnum) * xvelVar, Utility::of_Randomuf(ptnum*2) * yvelVar, Utility::of_Randomuf(ptnum*3) * zvelVar) ;
velocity = initialVel + jitterVel;
mass = abs( _mass + Utility::of_Randomuf(ptnum) ) ;
radius = mass ;
//init forces to zero
forces.set(0,0,0) ;
}
Particle::Particle(int _ptnum, float xpos, float ypos, float zpos, float xvel, float yvel, float zvel, float xvelVar, float yvelVar, float zvelVar, float _mass, float massVar) :
ptnum(_ptnum),
position(ofVec3f(xpos, ypos, zpos)) ,
color(ofColor::white)
{
// position.set(xpos, ypos, zpos) ;
// velocity.set(xvel, yvel, zvel) ;
ofVec3f jitterVel(Utility::of_Randomuf(ptnum) * xvelVar, Utility::of_Randomuf(ptnum*2) * yvelVar, Utility::of_Randomuf(ptnum*3) * zvelVar) ;
velocity = ofVec3f(xvel, yvel, zvel) + jitterVel;
mass = abs( _mass + Utility::of_Randomuf(ptnum) ) ;
radius = mass ;
//init forces to zero
forces.set(0.f, 0.f, 0.f) ;
}
/*-------------PTNUM--------------------------------*/
int Particle::getPtnum() const
{
return ptnum ;
}
void Particle::setPtnum(int _ptnum)
{
ptnum = _ptnum ;
}
/*-------POSITION------------------------------------*/
ofVec3f& Particle::getPosition()
{
return position ;
}
void Particle::setPosition(const ofVec3f &pos)
{
position = pos ;
}
void Particle::setPosition(float x, float y, float z)
{
position.set(x,y,z) ;
}
///////////////////////////////////////////////////////
/*------VELOCITY--------------------------------------*/
ofVec3f& Particle::getVelocity()
{
return velocity ;
}
void Particle::setVelocity(const ofVec3f &vel)
{
velocity = vel ;
}
void Particle::setVelocity(float x, float y, float z)
{
velocity.set(x,y,z) ;
}
///////////////////////////////////////////////////////
/*------FORCES---------------------------------------*/
void Particle::addForce(const ofVec3f &force)
{
forces += force ;
}
void Particle::addForce(float x, float y, float z)
{
forces += ofVec3f(x,y,z) ;
}
//////////////////////////////////////////////////////
/*--------COLOR--------------------------------------*/
void Particle::setColor(const ofColor &_color)
{
color = _color ;
}
void Particle::setColor(const ofVec3f &_color)
{
color.set(_color.x, _color.y, _color.z) ;
}
void Particle::setColor(float r, float g, float b)
{
color.set(r, g, b) ;
}
ofColor& Particle::getColor()
{
return color ;
}
//////////////////////////////////////////////////////
/*---------------------------UPDATE-----------------------------*/
void Particle::update(float timeStep)
{
velocity += forces/max(mass,0.0001f) ;
position += velocity * timeStep ;
forces.set(0,0,0) ;
}
void Particle::update(float timeStep, float maxSpeed)
{
velocity += forces/max(mass,0.0001f) ;
velocity.limit(maxSpeed) ;
position += velocity * timeStep ;
forces.set(0,0,0) ;
}
//////////////////////////////////////////////////////////////////
/*---------------------------DRAW-------------------------------*/
void Particle::draw()
{
//draw as points
ofSetColor(color) ;
glVertex3f(position.x, position.y, position.z) ;
}
//////////////////////////////////////////////////////////////////