-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathConstraints.h
More file actions
110 lines (80 loc) · 2.24 KB
/
Constraints.h
File metadata and controls
110 lines (80 loc) · 2.24 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
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
#ifndef _CONSTRAINTS_H_
#define _CONSTRAINTS_H_
#include <vector>
#include <functional>
#include "Particle.h"
enum class CONSTRAINT_TYPE
{
CONSTRAINT_DISTANCE,
CONSTRAINT_BEND
};
class Constraint
{
public:
Constraint() = delete;
Constraint(size_t numOfRigidbodies);
~Constraint();
void InitLambda() { m_lambda = 0.0f; };
void ComputeCompliance(const float &dt);
virtual bool SolvePBDConstraint() = 0;
virtual bool SolveXPBDConstraint() = 0;
virtual float ConstraintFunction() = 0;
virtual std::vector<std::vector<float>> GradientFunction() = 0;
// setters
void setStiffness(float stiffness);
void setCompliance(float compliance);
// getter
virtual CONSTRAINT_TYPE getConstraintType() = 0;
/*
* Constraint caches particles but not owning it
* TODO: Rewrite this (Not generic solution)
*/
std::vector<Particle_Ptr> m_particles;
float m_lambda;
// stiffness is the value between 0-1
float m_stiffness;
// XPBD
float m_compliance;
// compliance_tmp = compliance / (dt * dt)
float m_compliance_tmp;
};
class DistanceConstraint final: public Constraint
{
public:
// Not allow to use C++ default constructor
DistanceConstraint() = delete;
/*
* @param p1 First particle
* @param p2 Second paritcle
* @param d Rest length of two particle
*/
DistanceConstraint(Particle_Ptr p0, Particle_Ptr p1, float rest_length);
~DistanceConstraint();
virtual bool SolvePBDConstraint();
virtual bool SolveXPBDConstraint();
virtual float ConstraintFunction();
virtual std::vector<std::vector<float>> GradientFunction();
// getters
CONSTRAINT_TYPE getConstraintType() { return CONSTRAINT_TYPE::CONSTRAINT_DISTANCE; };
private:
float m_rest_length;
};
class BendConstraint final: public Constraint
{
public:
// Not allow to use C++ default constructor
BendConstraint() = delete;
/*
* @param p1 First particle
* @param p2 Second paritcle
* @param d Initial distance of two particle
*/
BendConstraint(Particle* p1, Particle* p2, float d);
~BendConstraint();
virtual bool SolvePBDConstraint();
virtual bool SolveXPBDConstraint();
virtual float ConstraintFunction();
virtual std::vector<std::vector<float>> GradientFunction();
CONSTRAINT_TYPE getConstraintType() { return CONSTRAINT_TYPE::CONSTRAINT_BEND; };
};
#endif