-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathParticle.cpp
260 lines (219 loc) · 6.67 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
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
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
#include <iostream>
#include <cstdlib>
#include "Particle.h"
#define MAX_X .2
#define MAX_Y .2
#define MAX_Z .2
// Constructor for a water particle in random locations
Particle::Particle(void) {
this->mass = 0.02f;
this->pressure = 0.0;
this->stiffness = 3.0;
this->restDensity = 998.29;
this->density = 0;
this->viscosity = 3.5;
float x = MAX_X*((2*(static_cast <float> (rand()) / static_cast <float> (RAND_MAX)))-1);
float y = MAX_Y*((2*(static_cast <float> (rand()) / static_cast <float> (RAND_MAX)))-1)-.5;
float z = MAX_Z*((2*(static_cast <float> (rand()) / static_cast <float> (RAND_MAX)))-1);
this->position = Point3D(x, y, z);
this->oldPosition = position;
this->supportRadius = 0.0457f;
this->velocity = Vector(0, 0, 0);
this->color = Vector(0, 0, .8f);
this->opacity = 0.8f;
this->threshold = 7.065f;
this->surfTension = 0.0728f;
}
Water::Water(void) {
this->mass = 0.02f;
this->pressure = 0.0f;
this->stiffness = 3.0f;
this->restDensity = 998.29f;
this->density = 0.0f;
this->viscosity = 3.5f;
float x = MAX_X*((2*(static_cast <float> (rand()) / static_cast <float> (RAND_MAX)))-1);
float y = MAX_Y*((2*(static_cast <float> (rand()) / static_cast <float> (RAND_MAX)))-1)-.5;
float z = MAX_Z*((2*(static_cast <float> (rand()) / static_cast <float> (RAND_MAX)))-1);
this->position = Point3D(x, y, z);
this->oldPosition = position;
this->supportRadius = 0.0457f;
this->velocity = Vector(0,0,0);
this->color = Vector(0, 0, .8f);
this->opacity = 0.5f;
this->restCoeff = 0.9;
this->threshold = 7.065f;
this->surfTension = 0.0728f;
}
Water::Water(Point3D position) {
this->mass = 0.02f;
this->pressure = 0.0f;
this->stiffness = 3.0f;
this->restDensity = 998.29f;
this->density = 0.0f;
this->viscosity = 3.5f;
this->position = position;
this->oldPosition = position;
this->supportRadius = 0.0457f;
this->velocity = Vector(0,0,0);
this->color = Vector(0, 0, .8f);
this->opacity = 0.5f;
this->restCoeff = 0.9;
this->threshold = 7.065f;
this->surfTension = 0.0728f;
}
Mucus::Mucus(void) {
this->mass = 0.04f;
this->pressure = 0.0f;
this->stiffness = 5.0f;
this->restDensity = 1000.0f;
this->density = 0.0f;
this->viscosity = 36.0f;
float x = MAX_X*((2*(static_cast <float> (rand()) / static_cast <float> (RAND_MAX)))-1);
float y = MAX_Y*((2*(static_cast <float> (rand()) / static_cast <float> (RAND_MAX)))-1)-.5;
float z = MAX_Z*((2*(static_cast <float> (rand()) / static_cast <float> (RAND_MAX)))-1);
this->position = Point3D(x, y, z);
this->oldPosition = position;
this->supportRadius = 0.0726f;
this->velocity = Vector(0, 0, 0);
this->color = Vector(0, .8f, 0);
this->opacity = 0.5f;
this->restCoeff = 0.8;
this->threshold = 5.0f;
this->surfTension = 6.0f;
}
Mucus::Mucus(Point3D position) {
this->mass = 0.04f;
this->pressure = 0.0f;
this->stiffness = 5.0f;
this->restDensity = 1000.0f;
this->density = 0.0f;
this->viscosity = 36.0f;
this->position = position;
this->oldPosition = position;
this->supportRadius = 0.0726f;
this->velocity = Vector(0, 0, 0);
this->color = Vector(0, .8f, 0);
this->opacity = 0.5f;
this->restCoeff = 0.8;
this->threshold = 5.0f;
this->surfTension = 6.0f;
}
Particle::Particle(float mass, float pressure, float stiffness, float restDensity, float density, float viscosity, float restCoeff, float threshold, float surfTension, Point3D position, Vector velocity, Vector color, float opacity) {
this->mass = mass;
this->pressure = pressure;
this->stiffness = stiffness;
this->restDensity = restDensity;
this->density = density;
this->viscosity = viscosity;
this->position = position;
this->oldPosition = position;
this->velocity = velocity;
this->color = Vector(.2,0,1);
}
float Particle::getMass() const {
return this->mass;
}
float Particle::getVolume() const {
return (this->mass)/(this->density);
}
float Particle::getPressure() const {
return this->pressure;
}
float Particle::getStiffness() const {
return this->stiffness;
}
float Particle::getRestDensity() const {
return this->restDensity;
}
float Particle::getDensity() const {
return this->density;
}
float Particle::getViscosity() const {
return this->viscosity;
}
Point3D Particle::getPosition() const {
return this->position;
}
Point3D Particle::getOldPosition() const {
return this->oldPosition;
}
Vector Particle::getVelocity() const {
return this->velocity;
}
Vector Particle::getVelocityHalf() const {
return this->velocityHalf;
}
Vector Particle::getAcceleration() const {
return this->acceleration;
}
float Particle::getRestCoeff() const {
return this->restCoeff;
}
float Particle::getSupportRadius() const {
return this->supportRadius;
}
float Particle::getThreshold() const {
return this->threshold;
}
float Particle::getSurfTension() const {
return this->surfTension;
}
Vector Particle::getColor() const {
return this->color;
}
float Particle::getOpacity() const {
return this->opacity;
}
int Particle::getHashID() const {
return this->hashID;
}
void Particle::setMass(const float mass) {
this->mass = mass;
}
void Particle::setDensity(const float density) {
this->density = density;
}
void Particle::setViscosity(const float viscosity) {
this->density = viscosity;
}
void Particle::setPressure(const float pressure) {
this->pressure = pressure;
}
void Particle::setPosition(Point3D position) {
this->position = position;
}
void Particle::setOldPosition(Point3D oldPosition) {
this->oldPosition = oldPosition;
}
void Particle::setVelocity(Vector velocity) {
this->velocity = velocity;
}
void Particle::setVelocityHalf(Vector velocityHalf) {
this->velocityHalf = velocityHalf;
}
void Particle::setAcceleration(Vector acceleration) {
this->acceleration = acceleration;
}
void Particle::setColor(const Vector color) {
this->color = color;
}
void Particle::setOpacity(const float opacity) {
this->opacity = opacity;
}
void Particle::setHashID(const int i){
this->hashID = i;
}
std::ostream& operator <<(ostream& outs, const Particle& particle) {
outs << "//===========================================//" << endl
<< "// Mass: " << particle.getMass() << endl
<< "// Volume: " << particle.getVolume() << endl
<< "// Density: " << particle.getDensity() << endl
<< "// Pressure: " << particle.getPressure() << endl
<< "// Velocity: " << particle.getVelocity() << endl
<< "// Velocity Half: " << particle.getVelocityHalf() << endl
<< "// Acceleration: " << particle.getAcceleration() << endl
<< "// Position: " << particle.getPosition() << endl
<< "// Old Position: " << particle.getOldPosition() << endl
<< "//===========================================//" << endl;
return outs;
}