forked from ruudandriessen/2imv15-assignment2
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathParticle.cpp
71 lines (63 loc) · 2.17 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
#include "Particle.h"
#if defined(_WIN32) || defined(WIN32)
#include <GL/glut.h>
#else
#include <GLUT/glut.h>
#endif
Particle::Particle(const Vector3f &startPosition, float mass, int index, bool movable, bool rigid, bool cloth) :
startPos(startPosition), density(0), position(Vector3f(0.0, 0.0, 0.0)),
velocity(Vector3f(0.0, 0.0, 0.0)), force(Vector3f(0.0, 0.0, 0.0)), mass(mass), index(index),
movable(movable), rigid(rigid), cloth(cloth) {
position = startPos;
}
Particle::~Particle(void) {
}
void Particle::reset()
{
position = startPos;
velocity = Vector3f(0.0, 0.0, 0.0);
force = Vector3f(0.0, 0.0, 0.0);
}
void Particle::draw(bool drawVelocity, bool drawForce) {
glPushMatrix();
float sphereSize = 0.01f;
if (movable) {
glColor3f(.2f, 1.f, 1.f);
} else {
sphereSize = 0.01f;
glColor4f(1.f, 1.f, 1.f, 0.1f);
}
if (rigid) {
glColor3f(0.f, 0.f, 1.f);
}
if (cloth) {
sphereSize = 0.005f;
glColor3f(1.f, .3f, .7f);
}
glTranslated(position[0], position[1], position[2]);
glutSolidSphere(sphereSize, 10, 10);
glPopMatrix();
float fMult = 0.00001f;
if (drawVelocity && movable) {
glColor3f(0.0, 0.6, 0.0);
glBegin(GL_LINES);
glVertex3f(position[0], position[1], position[2]);
glVertex3f(position[0] + velocity[0] * 0.2f, position[1] + velocity[1] * 0.2f,
position[2] + velocity[2] * 0.2f);
glEnd();
}
if (drawForce && movable) {
glColor3f(0.0, 1.f, 1.f);
glBegin(GL_LINES);
glVertex3f(position[0], position[1], position[2]);
glVertex3f(position[0] + force[0] * fMult, position[1] + force[1] * fMult,
position[2] + force[2] * fMult);
glEnd();
}
}
void Particle::handleSweep(bool isStart, vector<RigidBody *> *activeRigidBodies,
vector<pair<RigidBody *, Particle *>> *range) {
for (RigidBody *r:(*activeRigidBodies)) {
(*range).push_back(make_pair(r, this));
}
}