Box2D 2.3.0 A 2D Physics Engine for Games

- Main Page
- Classes
- Files

- File List
- File Members

All Classes Files Functions Variables Enumerations Enumerator Macros Pages
b2MotorJoint.h
1 /*
2 * Copyright (c) 2006-2012 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_MOTOR_JOINT_H
20 #define B2_MOTOR_JOINT_H
21
22 #include <Box2D/Dynamics/Joints/b2Joint.h>
23
25 struct b2MotorJointDef : public b2JointDef
26 {
27 b2MotorJointDef()
28 {
29 type = e_motorJoint;
30 linearOffset.SetZero();
31 angularOffset = 0.0f;
32 maxForce = 1.0f;
33 maxTorque = 1.0f;
34 correctionFactor = 0.3f;
35 }
36
38 void Initialize(b2Body* bodyA, b2Body* bodyB);
39
41 b2Vec2 linearOffset;
42
44 float32 angularOffset;
45
47 float32 maxForce;
48
50 float32 maxTorque;
51
53 float32 correctionFactor;
54 };
55
59 class b2MotorJoint : public b2Joint
60 {
61 public:
62 b2Vec2 GetAnchorA() const;
63 b2Vec2 GetAnchorB() const;
64
65 b2Vec2 GetReactionForce(float32 inv_dt) const;
66 float32 GetReactionTorque(float32 inv_dt) const;
67
69 void SetLinearOffset(const b2Vec2& linearOffset);
70 const b2Vec2& GetLinearOffset() const;
71
73 void SetAngularOffset(float32 angularOffset);
74 float32 GetAngularOffset() const;
75
77 void SetMaxForce(float32 force);
78
80 float32 GetMaxForce() const;
81
83 void SetMaxTorque(float32 torque);
84
86 float32 GetMaxTorque() const;
87
89 void SetCorrectionFactor(float32 factor);
90
92 float32 GetCorrectionFactor() const;
93
95 void Dump();
96
97 protected:
98
99 friend class b2Joint;
100
101 b2MotorJoint(const b2MotorJointDef* def);
102
103 void InitVelocityConstraints(const b2SolverData& data);
104 void SolveVelocityConstraints(const b2SolverData& data);
105 bool SolvePositionConstraints(const b2SolverData& data);
106
107 // Solver shared
108 b2Vec2 m_linearOffset;
109 float32 m_angularOffset;
110 b2Vec2 m_linearImpulse;
111 float32 m_angularImpulse;
112 float32 m_maxForce;
113 float32 m_maxTorque;
114 float32 m_correctionFactor;
115
116 // Solver temp
117 int32 m_indexA;
118 int32 m_indexB;
119 b2Vec2 m_rA;
120 b2Vec2 m_rB;
121 b2Vec2 m_localCenterA;
122 b2Vec2 m_localCenterB;
123 b2Vec2 m_linearError;
124 float32 m_angularError;
125 float32 m_invMassA;
126 float32 m_invMassB;
127 float32 m_invIA;
128 float32 m_invIB;
129 b2Mat22 m_linearMass;
130 float32 m_angularMass;
131 };
132
133 #endif
b2MotorJoint::GetAnchorA
b2Vec2 GetAnchorA() const
Get the anchor point on bodyA in world coordinates.
Definition: b2MotorJoint.cpp:206
b2JointDef::bodyA
b2Body * bodyA
The first attached body.
Definition: b2Joint.h:92
b2MotorJoint
Definition: b2MotorJoint.h:59
b2MotorJoint::SetMaxTorque
void SetMaxTorque(float32 torque)
Set the maximum friction torque in N*m.
Definition: b2MotorJoint.cpp:237
b2MotorJoint::Dump
void Dump()
Dump to b2Log.
Definition: b2MotorJoint.cpp:289
b2MotorJoint::SetLinearOffset
void SetLinearOffset(const b2Vec2 &linearOffset)
Set/get the target linear offset, in frame A, in meters.
Definition: b2MotorJoint.cpp:259
b2MotorJoint::GetMaxTorque
float32 GetMaxTorque() const
Get the maximum friction torque in N*m.
Definition: b2MotorJoint.cpp:243
b2JointDef::bodyB
b2Body * bodyB
The second attached body.
Definition: b2Joint.h:95
b2MotorJoint::GetAnchorB
b2Vec2 GetAnchorB() const
Get the anchor point on bodyB in world coordinates.
Definition: b2MotorJoint.cpp:211
b2MotorJoint::SetMaxForce
void SetMaxForce(float32 force)
Set the maximum friction force in N.
Definition: b2MotorJoint.cpp:226
b2MotorJointDef::maxTorque
float32 maxTorque
The maximum motor torque in N-m.
Definition: b2MotorJoint.h:50
b2MotorJointDef
Motor joint definition.
Definition: b2MotorJoint.h:25
b2Joint
Definition: b2Joint.h:103
b2Vec2::SetZero
void SetZero()
Set this vector to all zeros.
Definition: b2Math.h:62
b2MotorJointDef::angularOffset
float32 angularOffset
The bodyB angle minus bodyA angle in radians.
Definition: b2MotorJoint.h:44
b2MotorJoint::GetReactionForce
b2Vec2 GetReactionForce(float32 inv_dt) const
Get the reaction force on bodyB at the joint anchor in Newtons.
Definition: b2MotorJoint.cpp:216
b2MotorJoint::GetMaxForce
float32 GetMaxForce() const
Get the maximum friction force in N.
Definition: b2MotorJoint.cpp:232
b2JointDef::type
b2JointType type
The joint type is set automatically for concrete joint types.
Definition: b2Joint.h:86
b2MotorJoint::GetReactionTorque
float32 GetReactionTorque(float32 inv_dt) const
Get the reaction torque on bodyB in N*m.
Definition: b2MotorJoint.cpp:221
b2SolverData
Solver Data.
Definition: b2TimeStep.h:63
b2MotorJointDef::maxForce
float32 maxForce
The maximum motor force in N.
Definition: b2MotorJoint.h:47
b2Mat22
A 2-by-2 matrix. Stored in column-major order.
Definition: b2Math.h:183
b2MotorJointDef::correctionFactor
float32 correctionFactor
Position correction factor in the range [0,1].
Definition: b2MotorJoint.h:53
b2JointDef
Joint definitions are used to construct joints.
Definition: b2Joint.h:74
b2Body
A rigid body. These are created via b2World::CreateBody.
Definition: b2Body.h:126
b2MotorJoint::GetCorrectionFactor
float32 GetCorrectionFactor() const
Get the position correction factor in the range [0,1].
Definition: b2MotorJoint.cpp:254
b2MotorJoint::SetCorrectionFactor
void SetCorrectionFactor(float32 factor)
Set the position correction factor in the range [0,1].
Definition: b2MotorJoint.cpp:248
b2Vec2
A 2D column vector.
Definition: b2Math.h:53
b2MotorJoint::SetAngularOffset
void SetAngularOffset(float32 angularOffset)
Set/get the target angular offset, in radians.
Definition: b2MotorJoint.cpp:274
b2MotorJointDef::linearOffset
b2Vec2 linearOffset
Position of bodyB minus the position of bodyA, in bodyA&#39;s frame, in meters.
Definition: b2MotorJoint.h:41
b2MotorJointDef::Initialize
void Initialize(b2Body *bodyA, b2Body *bodyB)
Initialize the bodies and offsets using the current transforms.
Definition: b2MotorJoint.cpp:35