b2_rope.h
Go to the documentation of this file.
1 // MIT License
2 
3 // Copyright (c) 2019 Erin Catto
4 
5 // Permission is hereby granted, free of charge, to any person obtaining a copy
6 // of this software and associated documentation files (the "Software"), to deal
7 // in the Software without restriction, including without limitation the rights
8 // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 // copies of the Software, and to permit persons to whom the Software is
10 // furnished to do so, subject to the following conditions:
11 
12 // The above copyright notice and this permission notice shall be included in all
13 // copies or substantial portions of the Software.
14 
15 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 // SOFTWARE.
22 
23 #ifndef B2_ROPE_H
24 #define B2_ROPE_H
25 
26 #include "b2_api.h"
27 #include "b2_math.h"
28 
29 class b2Draw;
30 struct b2RopeStretch;
31 struct b2RopeBend;
32 
34 {
37 };
38 
40 {
47 };
48 
51 {
53  {
54  stretchingModel = b2_pbdStretchingModel;
55  bendingModel = b2_pbdAngleBendingModel;
56  damping = 0.0f;
57  stretchStiffness = 1.0f;
58  bendStiffness = 0.5f;
59  bendHertz = 1.0f;
60  bendDamping = 0.0f;
61  isometric = false;
62  fixedEffectiveMass = false;
63  warmStart = false;
64  }
65 
68  float damping;
70  float stretchHertz;
73  float bendHertz;
74  float bendDamping;
75  bool isometric;
77  bool warmStart;
78 };
79 
82 {
84  {
85  position.SetZero();
86  vertices = nullptr;
87  count = 0;
88  masses = nullptr;
89  gravity.SetZero();
90  }
91 
95  float* masses;
98 };
99 
102 {
103 public:
104  b2Rope();
105  ~b2Rope();
106 
108  void Create(const b2RopeDef& def);
109 
111  void SetTuning(const b2RopeTuning& tuning);
112 
114  void Step(float timeStep, int32 iterations, const b2Vec2& position);
115 
117  void Reset(const b2Vec2& position);
118 
120  void Draw(b2Draw* draw) const;
121 
122 private:
123 
124  void SolveStretch_PBD();
125  void SolveStretch_XPBD(float dt);
126  void SolveBend_PBD_Angle();
127  void SolveBend_XPBD_Angle(float dt);
128  void SolveBend_PBD_Distance();
129  void SolveBend_PBD_Height();
130  void SolveBend_PBD_Triangle();
131  void ApplyBendForces(float dt);
132 
134 
138 
141 
146 
147  float* m_invMasses;
149 
151 };
152 
153 #endif
b2BendingModel bendingModel
Definition: b2_rope.h:67
b2Vec2 * m_bindPositions
Definition: b2_rope.h:142
#define B2_API
Definition: b2_api.h:49
b2RopeBend * m_bendConstraints
Definition: b2_rope.h:140
float bendDamping
Definition: b2_rope.h:74
float * masses
Definition: b2_rope.h:95
b2RopeDef()
Definition: b2_rope.h:83
b2StretchingModel stretchingModel
Definition: b2_rope.h:66
float stretchDamping
Definition: b2_rope.h:71
b2Vec2 m_gravity
Definition: b2_rope.h:148
b2Vec2 gravity
Definition: b2_rope.h:96
A 2D column vector.
Definition: b2_math.h:41
int32 m_stretchCount
Definition: b2_rope.h:136
float damping
Definition: b2_rope.h:68
signed int int32
Definition: b2_types.h:28
int32 m_bendCount
Definition: b2_rope.h:137
b2BendingModel
Definition: b2_rope.h:39
Definition: b2_draw.h:48
b2RopeTuning()
Definition: b2_rope.h:52
float bendStiffness
Definition: b2_rope.h:72
b2Vec2 position
Definition: b2_rope.h:92
bool isometric
Definition: b2_rope.h:75
b2RopeTuning tuning
Definition: b2_rope.h:97
b2StretchingModel
Definition: b2_rope.h:33
int32 m_count
Definition: b2_rope.h:135
b2Vec2 * vertices
Definition: b2_rope.h:93
int32 count
Definition: b2_rope.h:94
bool warmStart
Definition: b2_rope.h:77
b2Vec2 * m_ps
Definition: b2_rope.h:143
b2RopeTuning m_tuning
Definition: b2_rope.h:150
b2Vec2 m_position
Definition: b2_rope.h:133
float * m_invMasses
Definition: b2_rope.h:147
b2Vec2 * m_p0s
Definition: b2_rope.h:144
b2RopeStretch * m_stretchConstraints
Definition: b2_rope.h:139
bool fixedEffectiveMass
Definition: b2_rope.h:76
float bendHertz
Definition: b2_rope.h:73
float stretchStiffness
Definition: b2_rope.h:69
float stretchHertz
Definition: b2_rope.h:70
b2Vec2 * m_vs
Definition: b2_rope.h:145


mvsim
Author(s):
autogenerated on Tue Jul 4 2023 03:08:19