• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
26 ///
27 struct b2RopeDef
28 {
b2RopeDefb2RopeDef29 	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 
40 	///
41 	b2Vec2* vertices;
42 
43 	///
44 	int32 count;
45 
46 	///
47 	float32* masses;
48 
49 	///
50 	b2Vec2 gravity;
51 
52 	///
53 	float32 damping;
54 
55 	/// Stretching stiffness
56 	float32 k2;
57 
58 	/// Bending stiffness. Values above 0.5 can make the simulation blow up.
59 	float32 k3;
60 };
61 
62 ///
63 class b2Rope
64 {
65 public:
66 	b2Rope();
67 	~b2Rope();
68 
69 	///
70 	void Initialize(const b2RopeDef* def);
71 
72 	///
73 	void Step(float32 timeStep, int32 iterations);
74 
75 	///
GetVertexCount()76 	int32 GetVertexCount() const
77 	{
78 		return m_count;
79 	}
80 
81 	///
GetVertices()82 	const b2Vec2* GetVertices() const
83 	{
84 		return m_ps;
85 	}
86 
87 	///
88 	void Draw(b2Draw* draw) const;
89 
90 	///
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
116