-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathparticle.cpp
55 lines (49 loc) · 1.12 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
#include "headers/particle.h"
Particle::Particle() :
position(0,0),
velocity(0,0),
acceleration(0,0),
height(0),
massDensity(0.0),
pressure(0.0),
mass(0.02),
radius(0.025)
{}
Particle::Particle(vec2 &position) :
position(position),
velocity(0,0),
acceleration(0,0),
height(0),
massDensity(0.0),
pressure(0.0),
mass(0.02),
radius(0.025)
{}
Particle::Particle(float x, float y) :
position(x,y),
velocity(0,0),
acceleration(0,0),
height(0),
massDensity(0.0),
pressure(0.0),
mass(0.02),
radius(0.025)
{}
Particle::~Particle() {}
void Particle::render() {
glColor3f(0,0,1);
glPointSize(5);
glBegin(GL_POINTS);
glVertex3f(position.x, position.y, height);
glEnd();
}
void Particle::updateWalls(vec2 (&walls)[4], vec2 (&wallsNormal)[4], float rebound){
for (int j = 0; j < 4; j++){
float penetration = dot((position - walls[j]), wallsNormal[j]);
if (penetration < 0) {
float vPen = dot(velocity, wallsNormal[j]);
position += -penetration * wallsNormal[j];
velocity += -(1 + rebound) * vPen * wallsNormal[j];
}
}
}