2
* Copyright (c) 2006-2011 Erin Catto http://www.box2d.org
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.
19
#ifndef B2_ROPE_JOINT_H
20
#define B2_ROPE_JOINT_H
22
#include <Box2D/Dynamics/Joints/b2Joint.h>
24
/// Rope joint definition. This requires two body anchor points and
25
/// a maximum lengths.
26
/// Note: by default the connected objects will not collide.
27
/// see collideConnected in b2JointDef.
28
// emscripten - b2RopeJointDef: add functions to set/get base class members
29
struct b2RopeJointDef : public b2JointDef
34
localAnchorA.Set(-1.0f, 0.0f);
35
localAnchorB.Set(1.0f, 0.0f);
39
/// The local anchor point relative to bodyA's origin.
42
/// The local anchor point relative to bodyB's origin.
45
/// The maximum length of the rope.
46
/// Warning: this must be larger than b2_linearSlop or
47
/// the joint will have no effect.
50
// to generate javascript bindings
51
void set_bodyA(b2Body* b) { bodyA = b; }
52
void set_bodyB(b2Body* b) { bodyB = b; }
53
void set_collideConnected(bool b) { collideConnected = b; }
54
b2Body* get_bodyA(b2Body* b) { return bodyA; }
55
b2Body* get_bodyB(b2Body* b) { return bodyB; }
56
bool get_collideConnected(bool b) { return collideConnected; }
59
/// A rope joint enforces a maximum distance between two points
60
/// on two bodies. It has no other effect.
61
/// Warning: if you attempt to change the maximum length during
62
/// the simulation you will get some non-physical behavior.
63
/// A model that would allow you to dynamically modify the length
64
/// would have some sponginess, so I chose not to implement it
65
/// that way. See b2DistanceJoint if you want to dynamically
67
// emscripten - b2RopeJoint: make constructor public
68
class b2RopeJoint : public b2Joint
71
b2Vec2 GetAnchorA() const;
72
b2Vec2 GetAnchorB() const;
74
b2Vec2 GetReactionForce(float32 inv_dt) const;
75
float32 GetReactionTorque(float32 inv_dt) const;
77
/// The local anchor point relative to bodyA's origin.
78
const b2Vec2& GetLocalAnchorA() const { return m_localAnchorA; }
80
/// The local anchor point relative to bodyB's origin.
81
const b2Vec2& GetLocalAnchorB() const { return m_localAnchorB; }
83
/// Set/Get the maximum length of the rope.
84
void SetMaxLength(float32 length) { m_maxLength = length; }
85
float32 GetMaxLength() const;
87
b2LimitState GetLimitState() const;
89
/// Dump joint to dmLog
92
b2RopeJoint(const b2RopeJointDef* data);
98
void InitVelocityConstraints(const b2SolverData& data);
99
void SolveVelocityConstraints(const b2SolverData& data);
100
bool SolvePositionConstraints(const b2SolverData& data);
103
b2Vec2 m_localAnchorA;
104
b2Vec2 m_localAnchorB;
115
b2Vec2 m_localCenterA;
116
b2Vec2 m_localCenterB;
122
b2LimitState m_state;