~ubuntu-branches/ubuntu/saucy/emscripten/saucy-proposed

« back to all changes in this revision

Viewing changes to tests/box2d/Box2D/Dynamics/Joints/b2WheelJoint.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_WHEEL_JOINT_H
 
20
#define B2_WHEEL_JOINT_H
 
21
 
 
22
#include <Box2D/Dynamics/Joints/b2Joint.h>
 
23
 
 
24
/// Wheel joint definition. This requires defining a line of
 
25
/// motion using an axis and an anchor point. The definition uses local
 
26
/// anchor points and a local axis so that the initial configuration
 
27
/// can violate the constraint slightly. The joint translation is zero
 
28
/// when the local anchor points coincide in world space. Using local
 
29
/// anchors and a local axis helps when saving and loading a game.
 
30
// emscripten - b2WheelJointDef: add functions to set/get base class members
 
31
struct b2WheelJointDef : public b2JointDef
 
32
{
 
33
        b2WheelJointDef()
 
34
        {
 
35
                type = e_wheelJoint;
 
36
                localAnchorA.SetZero();
 
37
                localAnchorB.SetZero();
 
38
                localAxisA.Set(1.0f, 0.0f);
 
39
                enableMotor = false;
 
40
                maxMotorTorque = 0.0f;
 
41
                motorSpeed = 0.0f;
 
42
                frequencyHz = 2.0f;
 
43
                dampingRatio = 0.7f;
 
44
        }
 
45
 
 
46
        /// Initialize the bodies, anchors, axis, and reference angle using the world
 
47
        /// anchor and world axis.
 
48
        void Initialize(b2Body* bodyA, b2Body* bodyB, const b2Vec2& anchor, const b2Vec2& axis);
 
49
 
 
50
        /// The local anchor point relative to bodyA's origin.
 
51
        b2Vec2 localAnchorA;
 
52
 
 
53
        /// The local anchor point relative to bodyB's origin.
 
54
        b2Vec2 localAnchorB;
 
55
 
 
56
        /// The local translation axis in bodyA.
 
57
        b2Vec2 localAxisA;
 
58
 
 
59
        /// Enable/disable the joint motor.
 
60
        bool enableMotor;
 
61
 
 
62
        /// The maximum motor torque, usually in N-m.
 
63
        float32 maxMotorTorque;
 
64
 
 
65
        /// The desired motor speed in radians per second.
 
66
        float32 motorSpeed;
 
67
 
 
68
        /// Suspension frequency, zero indicates no suspension
 
69
        float32 frequencyHz;
 
70
 
 
71
        /// Suspension damping ratio, one indicates critical damping
 
72
        float32 dampingRatio;
 
73
 
 
74
        // to generate javascript bindings
 
75
        void set_bodyA(b2Body* b) { bodyA = b; }
 
76
        void set_bodyB(b2Body* b) { bodyB = b; }
 
77
        void set_collideConnected(bool b) { collideConnected = b; }
 
78
        b2Body* get_bodyA(b2Body* b) { return bodyA; }
 
79
        b2Body* get_bodyB(b2Body* b) { return bodyB; }
 
80
        bool get_collideConnected(bool b) { return collideConnected; }
 
81
};
 
82
 
 
83
/// A wheel joint. This joint provides two degrees of freedom: translation
 
84
/// along an axis fixed in bodyA and rotation in the plane. You can use a
 
85
/// joint limit to restrict the range of motion and a joint motor to drive
 
86
/// the rotation or to model rotational friction.
 
87
/// This joint is designed for vehicle suspensions.
 
88
// emscripten - b2WheelJoint: make constructor public
 
89
class b2WheelJoint : public b2Joint
 
90
{
 
91
public:
 
92
        void GetDefinition(b2WheelJointDef* def) const;
 
93
 
 
94
        b2Vec2 GetAnchorA() const;
 
95
        b2Vec2 GetAnchorB() const;
 
96
 
 
97
        b2Vec2 GetReactionForce(float32 inv_dt) const;
 
98
        float32 GetReactionTorque(float32 inv_dt) const;
 
99
 
 
100
        /// The local anchor point relative to bodyA's origin.
 
101
        const b2Vec2& GetLocalAnchorA() const { return m_localAnchorA; }
 
102
 
 
103
        /// The local anchor point relative to bodyB's origin.
 
104
        const b2Vec2& GetLocalAnchorB() const  { return m_localAnchorB; }
 
105
 
 
106
        /// The local joint axis relative to bodyA.
 
107
        const b2Vec2& GetLocalAxisA() const { return m_localXAxisA; }
 
108
 
 
109
        /// Get the current joint translation, usually in meters.
 
110
        float32 GetJointTranslation() const;
 
111
 
 
112
        /// Get the current joint translation speed, usually in meters per second.
 
113
        float32 GetJointSpeed() const;
 
114
 
 
115
        /// Is the joint motor enabled?
 
116
        bool IsMotorEnabled() const;
 
117
 
 
118
        /// Enable/disable the joint motor.
 
119
        void EnableMotor(bool flag);
 
120
 
 
121
        /// Set the motor speed, usually in radians per second.
 
122
        void SetMotorSpeed(float32 speed);
 
123
 
 
124
        /// Get the motor speed, usually in radians per second.
 
125
        float32 GetMotorSpeed() const;
 
126
 
 
127
        /// Set/Get the maximum motor force, usually in N-m.
 
128
        void SetMaxMotorTorque(float32 torque);
 
129
        float32 GetMaxMotorTorque() const;
 
130
 
 
131
        /// Get the current motor torque given the inverse time step, usually in N-m.
 
132
        float32 GetMotorTorque(float32 inv_dt) const;
 
133
 
 
134
        /// Set/Get the spring frequency in hertz. Setting the frequency to zero disables the spring.
 
135
        void SetSpringFrequencyHz(float32 hz);
 
136
        float32 GetSpringFrequencyHz() const;
 
137
 
 
138
        /// Set/Get the spring damping ratio
 
139
        void SetSpringDampingRatio(float32 ratio);
 
140
        float32 GetSpringDampingRatio() const;
 
141
 
 
142
        /// Dump to b2Log
 
143
        void Dump();
 
144
 
 
145
        b2WheelJoint(const b2WheelJointDef* def);
 
146
 
 
147
protected:
 
148
 
 
149
        friend class b2Joint;
 
150
 
 
151
        void InitVelocityConstraints(const b2SolverData& data);
 
152
        void SolveVelocityConstraints(const b2SolverData& data);
 
153
        bool SolvePositionConstraints(const b2SolverData& data);
 
154
 
 
155
        float32 m_frequencyHz;
 
156
        float32 m_dampingRatio;
 
157
 
 
158
        // Solver shared
 
159
        b2Vec2 m_localAnchorA;
 
160
        b2Vec2 m_localAnchorB;
 
161
        b2Vec2 m_localXAxisA;
 
162
        b2Vec2 m_localYAxisA;
 
163
 
 
164
        float32 m_impulse;
 
165
        float32 m_motorImpulse;
 
166
        float32 m_springImpulse;
 
167
 
 
168
        float32 m_maxMotorTorque;
 
169
        float32 m_motorSpeed;
 
170
        bool m_enableMotor;
 
171
 
 
172
        // Solver temp
 
173
        int32 m_indexA;
 
174
        int32 m_indexB;
 
175
        b2Vec2 m_localCenterA;
 
176
        b2Vec2 m_localCenterB;
 
177
        float32 m_invMassA;
 
178
        float32 m_invMassB;
 
179
        float32 m_invIA;
 
180
        float32 m_invIB;
 
181
 
 
182
        b2Vec2 m_ax, m_ay;
 
183
        float32 m_sAx, m_sBx;
 
184
        float32 m_sAy, m_sBy;
 
185
 
 
186
        float32 m_mass;
 
187
        float32 m_motorMass;
 
188
        float32 m_springMass;
 
189
 
 
190
        float32 m_bias;
 
191
        float32 m_gamma;
 
192
};
 
193
 
 
194
inline float32 b2WheelJoint::GetMotorSpeed() const
 
195
{
 
196
        return m_motorSpeed;
 
197
}
 
198
 
 
199
inline float32 b2WheelJoint::GetMaxMotorTorque() const
 
200
{
 
201
        return m_maxMotorTorque;
 
202
}
 
203
 
 
204
inline void b2WheelJoint::SetSpringFrequencyHz(float32 hz)
 
205
{
 
206
        m_frequencyHz = hz;
 
207
}
 
208
 
 
209
inline float32 b2WheelJoint::GetSpringFrequencyHz() const
 
210
{
 
211
        return m_frequencyHz;
 
212
}
 
213
 
 
214
inline void b2WheelJoint::SetSpringDampingRatio(float32 ratio)
 
215
{
 
216
        m_dampingRatio = ratio;
 
217
}
 
218
 
 
219
inline float32 b2WheelJoint::GetSpringDampingRatio() const
 
220
{
 
221
        return m_dampingRatio;
 
222
}
 
223
 
 
224
#endif