Skip to content

Commit ebece0d

Browse files
authored
Merge pull request #32 from Im-Rises/staging
Staging
2 parents de8bea3 + 1a8488d commit ebece0d

59 files changed

Lines changed: 760 additions & 276 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
#ifndef PARTICULECONTACTGENERATOR
2+
#define PARTICULECONTACTGENERATOR
3+
4+
#include "../ParticleContact.h"
5+
6+
class ParticleContactGenerator {
7+
8+
public:
9+
virtual int addContact(ParticleContact *particuleContact, unsigned int limit, unsigned int current) = 0;
10+
};
11+
12+
#endif // !PARTICULECONTACTGENERATOR
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
#include "ParticleCable.h"
2+
3+
ParticleCable::ParticleCable(Particle *particle1, Particle *particle2, float max_length, float restitution)
4+
: ParticleLink(particle1, particle2) {
5+
m_maxLength = max_length;
6+
m_restitution = restitution;
7+
}
8+
9+
int ParticleCable::addContact(ParticleContact *particleContact, unsigned int limit, unsigned int current) {
10+
float distance = m_particles[0]->getPosition().distance(m_particles[1]->getPosition());
11+
Vector3d normalParticle = m_particles[0]->getPosition() - m_particles[1]->getPosition();
12+
if (distance <= m_maxLength) {
13+
return current;
14+
} else {
15+
particleContact[current].SetParticles(m_particles);
16+
particleContact[current].setContactNormal(Vector3d(0, 0, 0) - normalParticle);
17+
particleContact[current].setPenetration(distance - m_maxLength);
18+
particleContact[current].setElasticity(0);
19+
return current + 1;
20+
}
21+
22+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
#ifndef PARTICLECABLE_H
2+
#define PARTICLECABLE_H
3+
4+
#include "ParticleLink.h"
5+
6+
class ParticleCable : public ParticleLink {
7+
8+
private:
9+
float m_maxLength;
10+
float m_restitution;
11+
12+
public:
13+
14+
ParticleCable(Particle *particle1, Particle *particle2, float max_length, float restitution);
15+
16+
int addContact(ParticleContact *particleContact, unsigned int limit, unsigned int current) override;
17+
};
18+
19+
#endif // !PARTICLECABLE
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
#include "ParticleCollide.h"
2+
3+
void ParticleCollide::addCollider(ParticleCollider particleCollider) {
4+
5+
}
6+
7+
int ParticleCollide::addContact(ParticleContact *particleContact, unsigned int limit, unsigned int current) {
8+
for (int i = 0; i < m_colliders.size(); i++) {
9+
for (int j = i + 1; j < m_colliders.size(); j++) {
10+
if (current < limit) {
11+
Particle *particle0 = m_colliders[i].getParticle();
12+
Particle *particle1 = m_colliders[j].getParticle();
13+
float distance = particle0->getPosition().distance(particle1->getPosition());
14+
float sumRadius = m_colliders[i].getRadius() + m_colliders[j].getRadius();
15+
if (distance < sumRadius) {
16+
particleContact[current].setPenetration(sumRadius - distance);
17+
particleContact[current].setElasticity(elasticity);
18+
Vector3d normalParticle = particle0->getPosition() - particle1->getPosition();
19+
particleContact[current].setContactNormal(normalParticle);
20+
current += 1;
21+
}
22+
} else {
23+
return current;
24+
}
25+
26+
}
27+
}
28+
return current;
29+
}
30+
31+
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
#ifndef PARTICLECOLLIDE_H
2+
#define PARTICLECOLLIDE_H
3+
4+
#include "../ParticleContactGenerator.h"
5+
6+
#include "../../ParticleCollider/ParticleCollider.h"
7+
8+
#include <vector>
9+
10+
class ParticleCollide : public ParticleContactGenerator {
11+
12+
private:
13+
14+
std::vector<ParticleCollider> m_colliders;
15+
16+
float elasticity;
17+
18+
public:
19+
20+
void addCollider(ParticleCollider particleCollider);
21+
22+
int addContact(ParticleContact *particleContact, unsigned int limit, unsigned int current) override;
23+
24+
25+
};
26+
27+
#endif // !PARTICLECOLLIDE_H
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#include "ParticleLink.h"
2+
3+
float ParticleLink::currentLength() const {
4+
return m_particles[0]->getPosition().distance(m_particles[1]->getPosition());
5+
6+
}
7+
8+
ParticleLink::ParticleLink(Particle *particle1, Particle *particle2) {
9+
m_particles[0] = particle1;
10+
m_particles[1] = particle2;
11+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
#ifndef PARTICLELINK_H
2+
#define PARTICLELINK_H
3+
4+
#include "../ParticleContactGenerator.h"
5+
6+
class ParticleLink : public ParticleContactGenerator {
7+
8+
protected:
9+
Particle *m_particles[2];
10+
11+
public:
12+
float currentLength() const;
13+
14+
ParticleLink(Particle *particle1, Particle *particle2);
15+
16+
// virtual int addContact(ParticleContact *particleContact, unsigned int limit, unsigned int current) = 0;
17+
18+
19+
};
20+
21+
#endif // !ParticleLink_H
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
#include "ParticleRode.h"
2+
3+
ParticleRode::ParticleRode(Particle *particle1, Particle *particle2, float length) : ParticleLink(particle1,
4+
particle2) {
5+
m_length = length;
6+
}
7+
8+
int ParticleRode::addContact(ParticleContact *particleContact, unsigned int limit, unsigned int current) {
9+
10+
float distance = m_particles[0]->getPosition().distance(m_particles[1]->getPosition());
11+
if (distance == m_length) {
12+
return current;
13+
}
14+
Vector3d normalParticle = m_particles[0]->getPosition() - m_particles[1]->getPosition();
15+
particleContact[current].SetParticles(m_particles);
16+
if (distance > m_length) {
17+
particleContact->setContactNormal(Vector3d(0, 0, 0) - normalParticle);
18+
particleContact->setPenetration(distance - m_length);
19+
} else {
20+
particleContact->setContactNormal(normalParticle);
21+
particleContact->setPenetration(m_length - distance);
22+
}
23+
particleContact->setElasticity(0);
24+
return current + 1;
25+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
#ifndef PARTICLERODE_H
2+
#define PARTICLERODE_H
3+
4+
#include "ParticleLink.h"
5+
6+
class ParticleRode : public ParticleLink {
7+
8+
private:
9+
float m_length;
10+
11+
public:
12+
13+
ParticleRode(Particle *particle1, Particle *particle2, float length);
14+
15+
int addContact(ParticleContact *particleContact, unsigned int limit, unsigned int current) override;
16+
};
17+
18+
#endif // !PARTICLELINK_H
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
#include "ParticleCollider.h"
2+
3+
4+
ParticleCollider::ParticleCollider(Particle *particle, float radius) {
5+
m_radius = radius;
6+
m_particule = particle;
7+
}
8+
9+
float ParticleCollider::getRadius() const {
10+
return m_radius;
11+
}
12+
13+
Particle *ParticleCollider::getParticle() {
14+
return m_particule;
15+
}

0 commit comments

Comments
 (0)