~ubuntu-branches/ubuntu/vivid/emscripten/vivid

« back to all changes in this revision

Viewing changes to tests/box2d/Box2D/Dynamics/Joints/b2RopeJoint.h

  • Committer: Package Import Robot
  • Author(s): Sylvestre Ledru
  • Date: 2013-05-02 13:11:51 UTC
  • Revision ID: package-import@ubuntu.com-20130502131151-q8dvteqr1ef2x7xz
Tags: upstream-1.4.1~20130504~adb56cb
ImportĀ upstreamĀ versionĀ 1.4.1~20130504~adb56cb

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
* Copyright (c) 2006-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_JOINT_H
 
20
#define B2_ROPE_JOINT_H
 
21
 
 
22
#include <Box2D/Dynamics/Joints/b2Joint.h>
 
23
 
 
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
 
30
{
 
31
        b2RopeJointDef()
 
32
        {
 
33
                type = e_ropeJoint;
 
34
                localAnchorA.Set(-1.0f, 0.0f);
 
35
                localAnchorB.Set(1.0f, 0.0f);
 
36
                maxLength = 0.0f;
 
37
        }
 
38
 
 
39
        /// The local anchor point relative to bodyA's origin.
 
40
        b2Vec2 localAnchorA;
 
41
 
 
42
        /// The local anchor point relative to bodyB's origin.
 
43
        b2Vec2 localAnchorB;
 
44
 
 
45
        /// The maximum length of the rope.
 
46
        /// Warning: this must be larger than b2_linearSlop or
 
47
        /// the joint will have no effect.
 
48
        float32 maxLength;
 
49
 
 
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; }
 
57
};
 
58
 
 
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
 
66
/// control length.
 
67
// emscripten - b2RopeJoint: make constructor public
 
68
class b2RopeJoint : public b2Joint
 
69
{
 
70
public:
 
71
        b2Vec2 GetAnchorA() const;
 
72
        b2Vec2 GetAnchorB() const;
 
73
 
 
74
        b2Vec2 GetReactionForce(float32 inv_dt) const;
 
75
        float32 GetReactionTorque(float32 inv_dt) const;
 
76
 
 
77
        /// The local anchor point relative to bodyA's origin.
 
78
        const b2Vec2& GetLocalAnchorA() const { return m_localAnchorA; }
 
79
 
 
80
        /// The local anchor point relative to bodyB's origin.
 
81
        const b2Vec2& GetLocalAnchorB() const  { return m_localAnchorB; }
 
82
 
 
83
        /// Set/Get the maximum length of the rope.
 
84
        void SetMaxLength(float32 length) { m_maxLength = length; }
 
85
        float32 GetMaxLength() const;
 
86
 
 
87
        b2LimitState GetLimitState() const;
 
88
 
 
89
        /// Dump joint to dmLog
 
90
        void Dump();
 
91
 
 
92
        b2RopeJoint(const b2RopeJointDef* data);
 
93
 
 
94
protected:
 
95
 
 
96
        friend class b2Joint;
 
97
 
 
98
        void InitVelocityConstraints(const b2SolverData& data);
 
99
        void SolveVelocityConstraints(const b2SolverData& data);
 
100
        bool SolvePositionConstraints(const b2SolverData& data);
 
101
 
 
102
        // Solver shared
 
103
        b2Vec2 m_localAnchorA;
 
104
        b2Vec2 m_localAnchorB;
 
105
        float32 m_maxLength;
 
106
        float32 m_length;
 
107
        float32 m_impulse;
 
108
 
 
109
        // Solver temp
 
110
        int32 m_indexA;
 
111
        int32 m_indexB;
 
112
        b2Vec2 m_u;
 
113
        b2Vec2 m_rA;
 
114
        b2Vec2 m_rB;
 
115
        b2Vec2 m_localCenterA;
 
116
        b2Vec2 m_localCenterB;
 
117
        float32 m_invMassA;
 
118
        float32 m_invMassB;
 
119
        float32 m_invIA;
 
120
        float32 m_invIB;
 
121
        float32 m_mass;
 
122
        b2LimitState m_state;
 
123
};
 
124
 
 
125
#endif