-
Notifications
You must be signed in to change notification settings - Fork 0
/
cloth.h
143 lines (106 loc) · 2.45 KB
/
cloth.h
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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
#ifndef __Simulation__cloth__
#define __Simulation__cloth__
#include "particle.h"
class Spring;
class Gel;
class Particle {
public:
Particle(const Vec3& p, double r, Gel* c);
inline void addSpring(Spring* s) {
springs.push_back(s);
}
inline void setIndex(int i, int j, int k) {
this->i = i;
this->j = j;
this->k = k;
}
inline void resetForce() {
force.x = 0;
force.y = 0;
force.z = 0;
}
inline void addForce(const Vec3& f) {
force += f;
}
void updateForce();
void updatePos(double deltaT);
Vec3 pos;
Vec3 speed;
Vec3 force;
double radius;
double mass;
int i, j, k;
Gel* parent;
vector<Spring*> springs; // springs connected to this particle
bool atBottom;
private:
static const Vec3 gravity;
};
class Spring {
public:
Spring(Particle* p1, Particle* p2);
~Spring();
void update();
double k;
bool broken;
private:
Particle* p1;
Particle* p2;
double origLength;
};
class IndexTri {
public:
IndexTri(int i, int j, int k) {
this->i = i;
this->j = j;
this->k = k;
}
friend bool operator<(const IndexTri& t1, const IndexTri& t2) {
if (t1.i == t2.i) {
if (t1.j == t2.j) {
if (t1.k == t2.k) {
return 0;
}
return t1.k - t2.k;
}
return t1.j - t2.j;
}
return t1.i - t2.i;
}
int i;
int j;
int k;
};
class GelFace {
public:
inline void addParticle(Particle* p) {
vertices.push_back(p);
}
vector<Particle*> vertices;
};
class Gel {
public:
Gel(int s, double sc = 10, double l = 1, const Vec3& c = Vec3(0, 0, 0));
~Gel();
void simulate();
void clearState();
void draw();
int size;
double springCoeff;
double length;
Vec3 center;
Vec3*** vertices;
Vec3*** forces;
Vec3*** speeds;
bool still;
vector<Particle*> particles;
vector<Spring*> springs;
vector<GelFace*> faces;
// map<IndexTri, Particle*> indexParticleMap;
static vector<Particle*> allParticles;
Particle**** displayParticles;
private:
vector<IndexTri> getNeighbors(int i, int j, int k);
double gridLength;
};
#endif /* defined(__Simulation__cloth__) */