Box2D: b2Rope.h Source File

| Box2D 2.3.0 A 2D Physics Engine for Games

b2Rope.h
1 /*
2 * Copyright (c) 2011 Erin Catto http://www.box2d.org
3 *
4 * This software is provided 'as-is', without any express or implied
5 * warranty. In no event will the authors be held liable for any damages
6 * arising from the use of this software.
7 * Permission is granted to anyone to use this software for any purpose,
8 * including commercial applications, and to alter it and redistribute it
9 * freely, subject to the following restrictions:
10 * 1. The origin of this software must not be misrepresented; you must not
11 * claim that you wrote the original software. If you use this software
12 * in a product, an acknowledgment in the product documentation would be
13 * appreciated but is not required.
14 * 2. Altered source versions must be plainly marked as such, and must not be
15 * misrepresented as being the original software.
16 * 3. This notice may not be removed or altered from any source distribution.
17 */
18
19 #ifndef B2_ROPE_H
20 #define B2_ROPE_H
21
22 #include <Box2D/Common/b2Math.h>
23
24 class b2Draw;
25
27 struct b2RopeDef
28 {
29 b2RopeDef()
30 {
31 vertices = NULL;
32 count = 0;
33 masses = NULL;
34 gravity.SetZero();
35 damping = 0.1f;
36 k2 = 0.9f;
37 k3 = 0.1f;
38 }
39
41 b2Vec2* vertices;
42
44 int32 count;
45
47 float32* masses;
48
50 b2Vec2 gravity;
51
53 float32 damping;
54
56 float32 k2;
57
59 float32 k3;
60 };
61
63 class b2Rope
64 {
65 public:
66 b2Rope();
67 ~b2Rope();
68
70 void Initialize(const b2RopeDef* def);
71
73 void Step(float32 timeStep, int32 iterations);
74
76 int32 GetVertexCount() const
77 {
78 return m_count;
79 }
80
82 const b2Vec2* GetVertices() const
83 {
84 return m_ps;
85 }
86
88 void Draw(b2Draw* draw) const;
89
91 void SetAngle(float32 angle);
92
93 private:
94
95 void SolveC2();
96 void SolveC3();
97
98 int32 m_count;
99 b2Vec2* m_ps;
100 b2Vec2* m_p0s;
101 b2Vec2* m_vs;
102
103 float32* m_ims;
104
105 float32* m_Ls;
106 float32* m_as;
107
108 b2Vec2 m_gravity;
109 float32 m_damping;
110
111 float32 m_k2;
112 float32 m_k3;
113 };
114
115 #endif
b2Vec2
A 2D column vector.
Definition: b2Math.h:53
b2RopeDef
Definition: b2Rope.h:27
b2RopeDef::k2
float32 k2
Stretching stiffness.
Definition: b2Rope.h:56
b2Draw
Definition: b2Draw.h:35
b2RopeDef::k3
float32 k3
Bending stiffness. Values above 0.5 can make the simulation blow up.
Definition: b2Rope.h:59
b2Vec2::SetZero
void SetZero()
Set this vector to all zeros.
Definition: b2Math.h:62
b2Rope
Definition: b2Rope.h:63