-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPolygonForce.cpp
More file actions
62 lines (45 loc) · 2.01 KB
/
PolygonForce.cpp
File metadata and controls
62 lines (45 loc) · 2.01 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
#include "PolygonForce.hpp"
#include "LeapfrogSolver.hpp"
#include <iostream>
//#include "maths.hpp"
namespace imac3 {
void PolygonForce::apply(ParticleManager& pm) {
glm::vec2 intersection = glm::vec2(0,0);
glm::vec2 normal = glm::vec2(0,0);
if(m_fDt != 0) {
// Inner
if(m_Polygon->isInner() == true) {
// Pour chaque arrête du polygone
for(int i = 0; i < m_Polygon->getCount(); ++i) {
// Pour chaque particule
for(int j = 0; j < pm.getCount(); ++j) {
LeapfrogSolver::ParticleState nextState = m_Solver->getNextState(j, pm, m_fDt);
if(intersect(pm.getParticlePosition(j), nextState.position, m_Polygon->getPoint(i), m_Polygon->getPoint((i + 1) % m_Polygon->getCount()), &intersection, &normal)) {
glm::vec2 F = this->m_fElasticity * glm::dot(nextState.velocity, -normal) * (pm.getParticleMass(j)/m_fDt) * normal;
pm.addForceToParticle(j, F);
}
}
}
}
// Not inner
else {
// Pour chaque arrête du polygone
for(int i = m_Polygon->getCount() - 1; i >= 0; --i) {
// Pour chaque particule
for(int j = 0; j < pm.getCount(); ++j) {
LeapfrogSolver::ParticleState nextState = m_Solver->getNextState(j, pm, m_fDt);
if(intersect(pm.getParticlePosition(j), nextState.position, m_Polygon->getPoint((i + 1) % m_Polygon->getCount()), m_Polygon->getPoint(i), &intersection, &normal)) {
// std::cout << " #### Intersection #### " << std::endl;
// std::cout << "Position : " << nextState.position[0] << " - " << nextState.position[1] << std::endl;
// std::cout << "Velocity : " << nextState.velocity[0] << " - " << nextState.velocity[1] << std::endl;
//std::cout << "Normal : " << normal[0] << " - " << normal[1] << std::endl;
glm::vec2 F = this->m_fElasticity * glm::dot(nextState.velocity, -normal) * (pm.getParticleMass(j)/m_fDt) * normal;
//std::cout << "F : " << F[0] << " - " << F[1] << std::endl;
pm.addForceToParticle(j, F);
}
}
}
}
}
}
}