-
Notifications
You must be signed in to change notification settings - Fork 0
/
particle.cpp
51 lines (45 loc) · 1.34 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
// SAMPLE_SOLUTION
#include "particle.h"
/***************
* Constructors
***************/
Particle::Particle(void)
:t(0.0),
numberOfParticles(0)
{
// positionOfParticles = new float[numberOfParticles * 3];
}
Particle::Particle(float new_t, int new_numOfParticles)
:t(new_t),
numberOfParticles(new_numOfParticles)
{
// positionOfParticles = new float[numberOfParticles * 3];
}
Particle::~Particle(void) {
/*
if (positionOfParticles != NULL) {
delete[] positionOfParticles;
}
*/
}
void Particle::copyPosition(const vector<float>& state) {
// positionOfParticles = new float[numberOfParticles * 3];
for (int i = 0; i < numberOfParticles; i++) {
if (i >= 0 && ((i * 6 + 5) < state.size())) {
float temp_x = state[i * 6];
float temp_y = state[i * 6 + 1];
float temp_z = state[i * 6 + 2];
positionOfParticles.push_back(temp_x);
positionOfParticles.push_back(temp_y);
positionOfParticles.push_back(temp_z);
}
// cout << "save particle at position of " << state[i * 6] << " " << state[i * 6 + 1] << " " << state[i * 6 + 2] << endl;
}
}
Vec3f Particle::getPositionOf(const int& index, bool& flag) {
if (index >= 0 && ((index * 3 + 2) < positionOfParticles.size())) {
flag = true;
return Vec3f(positionOfParticles[index * 3], positionOfParticles[index * 3 + 1], positionOfParticles[index * 3 + 2]);
}
return Vec3f(0.0, 0.0, 0.0);
}