Box2D: b2PrismaticJoint.h Source File

| Box2D 2.3.0 A 2D Physics Engine for Games

b2PrismaticJoint.h
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_PRISMATIC_JOINT_H
20 #define B2_PRISMATIC_JOINT_H
21
22 #include <Box2D/Dynamics/Joints/b2Joint.h>
23
30 struct b2PrismaticJointDef : public b2JointDef
31 {
32 b2PrismaticJointDef()
33 {
34 type = e_prismaticJoint;
35 localAnchorA.SetZero();
36 localAnchorB.SetZero();
37 localAxisA.Set(1.0f, 0.0f);
38 referenceAngle = 0.0f;
39 enableLimit = false;
40 lowerTranslation = 0.0f;
41 upperTranslation = 0.0f;
42 enableMotor = false;
43 maxMotorForce = 0.0f;
44 motorSpeed = 0.0f;
45 }
46
49 void Initialize(b2Body* bodyA, b2Body* bodyB, const b2Vec2& anchor, const b2Vec2& axis);
50
52 b2Vec2 localAnchorA;
53
55 b2Vec2 localAnchorB;
56
58 b2Vec2 localAxisA;
59
61 float32 referenceAngle;
62
64 bool enableLimit;
65
67 float32 lowerTranslation;
68
70 float32 upperTranslation;
71
73 bool enableMotor;
74
76 float32 maxMotorForce;
77
79 float32 motorSpeed;
80 };
81
86 class b2PrismaticJoint : public b2Joint
87 {
88 public:
89 b2Vec2 GetAnchorA() const;
90 b2Vec2 GetAnchorB() const;
91
92 b2Vec2 GetReactionForce(float32 inv_dt) const;
93 float32 GetReactionTorque(float32 inv_dt) const;
94
96 const b2Vec2& GetLocalAnchorA() const { return m_localAnchorA; }
97
99 const b2Vec2& GetLocalAnchorB() const { return m_localAnchorB; }
100
102 const b2Vec2& GetLocalAxisA() const { return m_localXAxisA; }
103
105 float32 GetReferenceAngle() const { return m_referenceAngle; }
106
108 float32 GetJointTranslation() const;
109
111 float32 GetJointSpeed() const;
112
114 bool IsLimitEnabled() const;
115
117 void EnableLimit(bool flag);
118
120 float32 GetLowerLimit() const;
121
123 float32 GetUpperLimit() const;
124
126 void SetLimits(float32 lower, float32 upper);
127
129 bool IsMotorEnabled() const;
130
132 void EnableMotor(bool flag);
133
135 void SetMotorSpeed(float32 speed);
136
138 float32 GetMotorSpeed() const;
139
141 void SetMaxMotorForce(float32 force);
142 float32 GetMaxMotorForce() const { return m_maxMotorForce; }
143
145 float32 GetMotorForce(float32 inv_dt) const;
146
148 void Dump();
149
150 protected:
151 friend class b2Joint;
152 friend class b2GearJoint;
153 b2PrismaticJoint(const b2PrismaticJointDef* def);
154
155 void InitVelocityConstraints(const b2SolverData& data);
156 void SolveVelocityConstraints(const b2SolverData& data);
157 bool SolvePositionConstraints(const b2SolverData& data);
158
159 // Solver shared
160 b2Vec2 m_localAnchorA;
161 b2Vec2 m_localAnchorB;
162 b2Vec2 m_localXAxisA;
163 b2Vec2 m_localYAxisA;
164 float32 m_referenceAngle;
165 b2Vec3 m_impulse;
166 float32 m_motorImpulse;
167 float32 m_lowerTranslation;
168 float32 m_upperTranslation;
169 float32 m_maxMotorForce;
170 float32 m_motorSpeed;
171 bool m_enableLimit;
172 bool m_enableMotor;
173 b2LimitState m_limitState;
174
175 // Solver temp
176 int32 m_indexA;
177 int32 m_indexB;
178 b2Vec2 m_localCenterA;
179 b2Vec2 m_localCenterB;
180 float32 m_invMassA;
181 float32 m_invMassB;
182 float32 m_invIA;
183 float32 m_invIB;
184 b2Vec2 m_axis, m_perp;
185 float32 m_s1, m_s2;
186 float32 m_a1, m_a2;
187 b2Mat33 m_K;
188 float32 m_motorMass;
189 };
190
191 inline float32 b2PrismaticJoint::GetMotorSpeed() const
192 {
193 return m_motorSpeed;
194 }
195
196 #endif
b2PrismaticJoint::EnableMotor
void EnableMotor(bool flag)
Enable/disable the joint motor.
Definition: b2PrismaticJoint.cpp:583
b2Vec3
A 2D column vector with 3 elements.
Definition: b2Math.h:144
b2PrismaticJointDef::enableMotor
bool enableMotor
Enable/disable the joint motor.
Definition: b2PrismaticJoint.h:73
b2PrismaticJoint::IsLimitEnabled
bool IsLimitEnabled() const
Is the joint limit enabled?
Definition: b2PrismaticJoint.cpp:539
b2PrismaticJointDef::enableLimit
bool enableLimit
Enable/disable the joint limit.
Definition: b2PrismaticJoint.h:64
b2JointDef::bodyA
b2Body * bodyA
The first attached body.
Definition: b2Joint.h:92
b2PrismaticJoint::GetJointTranslation
float32 GetJointTranslation() const
Get the current joint translation, usually in meters.
Definition: b2PrismaticJoint.cpp:507
b2PrismaticJoint::GetUpperLimit
float32 GetUpperLimit() const
Get the upper joint limit, usually in meters.
Definition: b2PrismaticJoint.cpp:560
b2Mat33
A 3-by-3 matrix. Stored in column-major order.
Definition: b2Math.h:257
b2PrismaticJointDef::lowerTranslation
float32 lowerTranslation
The lower translation limit, usually in meters.
Definition: b2PrismaticJoint.h:67
b2PrismaticJointDef::upperTranslation
float32 upperTranslation
The upper translation limit, usually in meters.
Definition: b2PrismaticJoint.h:70
b2PrismaticJointDef
Definition: b2PrismaticJoint.h:30
b2JointDef::bodyB
b2Body * bodyB
The second attached body.
Definition: b2Joint.h:95
b2PrismaticJoint::SetMotorSpeed
void SetMotorSpeed(float32 speed)
Set the motor speed, usually in meters per second.
Definition: b2PrismaticJoint.cpp:590
b2PrismaticJoint::GetMotorForce
float32 GetMotorForce(float32 inv_dt) const
Get the current motor force given the inverse time step, usually in N.
Definition: b2PrismaticJoint.cpp:604
b2PrismaticJoint::SetLimits
void SetLimits(float32 lower, float32 upper)
Set the joint limits, usually in meters.
Definition: b2PrismaticJoint.cpp:565
b2Joint
Definition: b2Joint.h:103
b2PrismaticJointDef::localAxisA
b2Vec2 localAxisA
The local translation unit axis in bodyA.
Definition: b2PrismaticJoint.h:58
b2PrismaticJoint::IsMotorEnabled
bool IsMotorEnabled() const
Is the joint motor enabled?
Definition: b2PrismaticJoint.cpp:578
b2PrismaticJoint
Definition: b2PrismaticJoint.h:86
b2Vec2::Set
void Set(float32 x_, float32 y_)
Set this vector to some specified coordinates.
Definition: b2Math.h:65
b2PrismaticJointDef::motorSpeed
float32 motorSpeed
The desired motor speed in radians per second.
Definition: b2PrismaticJoint.h:79
b2Vec2::SetZero
void SetZero()
Set this vector to all zeros.
Definition: b2Math.h:62
b2PrismaticJoint::GetReactionTorque
float32 GetReactionTorque(float32 inv_dt) const
Get the reaction torque on bodyB in N*m.
Definition: b2PrismaticJoint.cpp:502
b2PrismaticJointDef::maxMotorForce
float32 maxMotorForce
The maximum motor torque, usually in N-m.
Definition: b2PrismaticJoint.h:76
b2PrismaticJoint::GetMotorSpeed
float32 GetMotorSpeed() const
Get the motor speed, usually in meters per second.
Definition: b2PrismaticJoint.h:191
b2GearJoint
Definition: b2GearJoint.h:56
b2PrismaticJoint::GetLocalAnchorA
const b2Vec2 & GetLocalAnchorA() const
The local anchor point relative to bodyA&#39;s origin.
Definition: b2PrismaticJoint.h:96
b2JointDef::type
b2JointType type
The joint type is set automatically for concrete joint types.
Definition: b2Joint.h:86
b2SolverData
Solver Data.
Definition: b2TimeStep.h:63
b2PrismaticJoint::GetLocalAxisA
const b2Vec2 & GetLocalAxisA() const
The local joint axis relative to bodyA.
Definition: b2PrismaticJoint.h:102
b2PrismaticJointDef::localAnchorA
b2Vec2 localAnchorA
The local anchor point relative to bodyA&#39;s origin.
Definition: b2PrismaticJoint.h:52
b2PrismaticJointDef::localAnchorB
b2Vec2 localAnchorB
The local anchor point relative to bodyB&#39;s origin.
Definition: b2PrismaticJoint.h:55
b2PrismaticJoint::GetJointSpeed
float32 GetJointSpeed() const
Get the current joint translation speed, usually in meters per second.
Definition: b2PrismaticJoint.cpp:518
b2JointDef
Joint definitions are used to construct joints.
Definition: b2Joint.h:74
b2PrismaticJoint::GetAnchorB
b2Vec2 GetAnchorB() const
Get the anchor point on bodyB in world coordinates.
Definition: b2PrismaticJoint.cpp:492
b2Body
A rigid body. These are created via b2World::CreateBody.
Definition: b2Body.h:126
b2PrismaticJointDef::referenceAngle
float32 referenceAngle
The constrained angle between the bodies: bodyB_angle - bodyA_angle.
Definition: b2PrismaticJoint.h:61
b2PrismaticJoint::GetReferenceAngle
float32 GetReferenceAngle() const
Get the reference angle.
Definition: b2PrismaticJoint.h:105
b2PrismaticJoint::GetLocalAnchorB
const b2Vec2 & GetLocalAnchorB() const
The local anchor point relative to bodyB&#39;s origin.
Definition: b2PrismaticJoint.h:99
b2PrismaticJoint::GetReactionForce
b2Vec2 GetReactionForce(float32 inv_dt) const
Get the reaction force on bodyB at the joint anchor in Newtons.
Definition: b2PrismaticJoint.cpp:497
b2PrismaticJoint::GetAnchorA
b2Vec2 GetAnchorA() const
Get the anchor point on bodyA in world coordinates.
Definition: b2PrismaticJoint.cpp:487
b2PrismaticJoint::Dump
void Dump()
Dump to b2Log.
Definition: b2PrismaticJoint.cpp:609
b2PrismaticJoint::EnableLimit
void EnableLimit(bool flag)
Enable/disable the joint limit.
Definition: b2PrismaticJoint.cpp:544
b2Vec2
A 2D column vector.
Definition: b2Math.h:53
b2PrismaticJointDef::Initialize
void Initialize(b2Body *bodyA, b2Body *bodyB, const b2Vec2 &anchor, const b2Vec2 &axis)
Definition: b2PrismaticJoint.cpp:90
b2PrismaticJoint::GetLowerLimit
float32 GetLowerLimit() const
Get the lower joint limit, usually in meters.
Definition: b2PrismaticJoint.cpp:555
b2PrismaticJoint::SetMaxMotorForce
void SetMaxMotorForce(float32 force)
Set the maximum motor force, usually in N.
Definition: b2PrismaticJoint.cpp:597