-
Notifications
You must be signed in to change notification settings - Fork 0
/
Solver.h
73 lines (66 loc) · 2.15 KB
/
Solver.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
#include "Joints.h"
#include <assert.h>
#include <vector>
float CheckSolveImpulse(ContactJoint &joint);
float CheckSolveDisplacingImpulse(ContactJoint &joint);
void FastSolveJoints(ContactJoint *joints, int nJoints, int nIter, int nDisp);
struct Solver
{
Solver()
{
}
void RefreshJoints()
{
for (size_t jointIndex = 0; jointIndex < contactJoints.size();)
{
if (!contactJoints[jointIndex].valid)
{
contactJoints[jointIndex] = contactJoints[contactJoints.size() - 1];
contactJoints.pop_back();
}
else
{
contactJoints[jointIndex++].Refresh();
}
}
for (size_t jointIndex = 0; jointIndex < contactJoints.size(); jointIndex++)
{
contactJoints[jointIndex].PreStep();
}
}
void SolveJoints(int contactIterationsCount, int penetrationIterationsCount)
{
FastSolveJoints(contactJoints.data(), contactJoints.size(), contactIterationsCount, penetrationIterationsCount); return;
for (int iterationIndex = 0; iterationIndex < contactIterationsCount; iterationIndex++)
{
for (size_t jointIndex = 0; jointIndex < contactJoints.size(); jointIndex++)
{
contactJoints[jointIndex].SolveImpulse();
//CheckSolveImpulse(contactJoints[jointIndex]);
}
}
for (int iterationIndex = 0; iterationIndex < penetrationIterationsCount; iterationIndex++)
{
for (size_t jointIndex = 0; jointIndex < contactJoints.size(); jointIndex++)
{
contactJoints[jointIndex].SolveDisplacement();
//CheckSolveDisplacingImpulse(contactJoints[jointIndex]);
}
}
}
void RefreshContactJoint(ContactJoint::Descriptor desc)
{
ContactJoint *joint = (ContactJoint*)(desc.collision->userInfo);
joint->valid = 1;
joint->collision = desc.collision;
assert(joint->body1 == desc.body1);
assert(joint->body2 == desc.body2);
if ((joint->body1->coords.pos - joint->body2->coords.pos) * desc.collision->normal < 0.0f)
{
int pp = 1;
}
joint->valid = 1;
joint->collision = desc.collision;
}
std::vector<ContactJoint> contactJoints;
};