Box2D: /build/box2d/src/box2d-2.4.1/include/box2d/b2_revolute_joint.h Source File

| Box2D 2.4.1 A 2D physics engine for games

Loading...
Searching...
No Matches
b2_revolute_joint.h
1// MIT License
2
3// Copyright (c) 2019 Erin Catto
4
5// Permission is hereby granted, free of charge, to any person obtaining a copy
6// of this software and associated documentation files (the "Software"), to deal
7// in the Software without restriction, including without limitation the rights
8// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9// copies of the Software, and to permit persons to whom the Software is
10// furnished to do so, subject to the following conditions:
11
12// The above copyright notice and this permission notice shall be included in all
13// copies or substantial portions of the Software.
14
15// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21// SOFTWARE.
22
23#ifndef B2_REVOLUTE_JOINT_H
24#define B2_REVOLUTE_JOINT_H
25
26#include "b2_api.h"
27#include "b2_joint.h"
28
39 struct B2_API b2RevoluteJointDef : public b2JointDef
40{
41 b2RevoluteJointDef()
42 {
43 type = e_revoluteJoint;
44 localAnchorA.Set(0.0f, 0.0f);
45 localAnchorB.Set(0.0f, 0.0f);
46 referenceAngle = 0.0f;
47 lowerAngle = 0.0f;
48 upperAngle = 0.0f;
49 maxMotorTorque = 0.0f;
50 motorSpeed = 0.0f;
51 enableLimit = false;
52 enableMotor = false;
53 }
54
57 void Initialize(b2Body* bodyA, b2Body* bodyB, const b2Vec2& anchor);
58
60 b2Vec2 localAnchorA;
61
63 b2Vec2 localAnchorB;
64
66 float referenceAngle;
67
69 bool enableLimit;
70
72 float lowerAngle;
73
75 float upperAngle;
76
78 bool enableMotor;
79
81 float motorSpeed;
82
85 float maxMotorTorque;
86};
87
94 class B2_API b2RevoluteJoint : public b2Joint
95{
96public:
97 b2Vec2 GetAnchorA() const override;
98 b2Vec2 GetAnchorB() const override;
99
101 const b2Vec2& GetLocalAnchorA() const { return m_localAnchorA; }
102
104 const b2Vec2& GetLocalAnchorB() const { return m_localAnchorB; }
105
107 float GetReferenceAngle() const { return m_referenceAngle; }
108
110 float GetJointAngle() const;
111
113 float GetJointSpeed() const;
114
116 bool IsLimitEnabled() const;
117
119 void EnableLimit(bool flag);
120
122 float GetLowerLimit() const;
123
125 float GetUpperLimit() const;
126
128 void SetLimits(float lower, float upper);
129
131 bool IsMotorEnabled() const;
132
134 void EnableMotor(bool flag);
135
137 void SetMotorSpeed(float speed);
138
140 float GetMotorSpeed() const;
141
143 void SetMaxMotorTorque(float torque);
144 float GetMaxMotorTorque() const { return m_maxMotorTorque; }
145
148 b2Vec2 GetReactionForce(float inv_dt) const override;
149
152 float GetReactionTorque(float inv_dt) const override;
153
156 float GetMotorTorque(float inv_dt) const;
157
159 void Dump() override;
160
162 void Draw(b2Draw* draw) const override;
163
164protected:
165
166 friend class b2Joint;
167 friend class b2GearJoint;
168
169 b2RevoluteJoint(const b2RevoluteJointDef* def);
170
171 void InitVelocityConstraints(const b2SolverData& data) override;
172 void SolveVelocityConstraints(const b2SolverData& data) override;
173 bool SolvePositionConstraints(const b2SolverData& data) override;
174
175 // Solver shared
176 b2Vec2 m_localAnchorA;
177 b2Vec2 m_localAnchorB;
178 b2Vec2 m_impulse;
179 float m_motorImpulse;
180 float m_lowerImpulse;
181 float m_upperImpulse;
182 bool m_enableMotor;
183 float m_maxMotorTorque;
184 float m_motorSpeed;
185 bool m_enableLimit;
186 float m_referenceAngle;
187 float m_lowerAngle;
188 float m_upperAngle;
189
190 // Solver temp
191 int32 m_indexA;
192 int32 m_indexB;
193 b2Vec2 m_rA;
194 b2Vec2 m_rB;
195 b2Vec2 m_localCenterA;
196 b2Vec2 m_localCenterB;
197 float m_invMassA;
198 float m_invMassB;
199 float m_invIA;
200 float m_invIB;
201 b2Mat22 m_K;
202 float m_angle;
203 float m_axialMass;
204};
205
206 inline float b2RevoluteJoint::GetMotorSpeed() const
207{
208 return m_motorSpeed;
209}
210
211#endif
b2Body
A rigid body. These are created via b2World::CreateBody.
Definition b2_body.h:129
b2Draw
Definition b2_draw.h:49
b2GearJoint
Definition b2_gear_joint.h:62
b2Joint
Definition b2_joint.h:111
b2RevoluteJoint
Definition b2_revolute_joint.h:95
b2RevoluteJoint::GetJointAngle
float GetJointAngle() const
Get the current joint angle in radians.
b2RevoluteJoint::GetLocalAnchorB
const b2Vec2 & GetLocalAnchorB() const
The local anchor point relative to bodyB's origin.
Definition b2_revolute_joint.h:104
b2RevoluteJoint::IsMotorEnabled
bool IsMotorEnabled() const
Is the joint motor enabled?
b2RevoluteJoint::Dump
void Dump() override
Dump to b2Log.
b2RevoluteJoint::GetUpperLimit
float GetUpperLimit() const
Get the upper joint limit in radians.
b2RevoluteJoint::EnableLimit
void EnableLimit(bool flag)
Enable/disable the joint limit.
b2RevoluteJoint::GetMotorTorque
float GetMotorTorque(float inv_dt) const
b2RevoluteJoint::GetLocalAnchorA
const b2Vec2 & GetLocalAnchorA() const
The local anchor point relative to bodyA's origin.
Definition b2_revolute_joint.h:101
b2RevoluteJoint::SetMotorSpeed
void SetMotorSpeed(float speed)
Set the motor speed in radians per second.
b2RevoluteJoint::GetMotorSpeed
float GetMotorSpeed() const
Get the motor speed in radians per second.
Definition b2_revolute_joint.h:206
b2RevoluteJoint::GetReactionForce
b2Vec2 GetReactionForce(float inv_dt) const override
b2RevoluteJoint::SetMaxMotorTorque
void SetMaxMotorTorque(float torque)
Set the maximum motor torque, usually in N-m.
b2RevoluteJoint::GetJointSpeed
float GetJointSpeed() const
Get the current joint angle speed in radians per second.
b2RevoluteJoint::EnableMotor
void EnableMotor(bool flag)
Enable/disable the joint motor.
b2RevoluteJoint::GetReferenceAngle
float GetReferenceAngle() const
Get the reference angle.
Definition b2_revolute_joint.h:107
b2RevoluteJoint::IsLimitEnabled
bool IsLimitEnabled() const
Is the joint limit enabled?
b2RevoluteJoint::GetAnchorA
b2Vec2 GetAnchorA() const override
Get the anchor point on bodyA in world coordinates.
b2RevoluteJoint::GetAnchorB
b2Vec2 GetAnchorB() const override
Get the anchor point on bodyB in world coordinates.
b2RevoluteJoint::GetReactionTorque
float GetReactionTorque(float inv_dt) const override
b2RevoluteJoint::Draw
void Draw(b2Draw *draw) const override
Debug draw this joint.
b2RevoluteJoint::SetLimits
void SetLimits(float lower, float upper)
Set the joint limits in radians.
b2RevoluteJoint::GetLowerLimit
float GetLowerLimit() const
Get the lower joint limit in radians.
b2JointDef
Joint definitions are used to construct joints.
Definition b2_joint.h:73
b2Mat22
A 2-by-2 matrix. Stored in column-major order.
Definition b2_math.h:172
b2RevoluteJointDef
Definition b2_revolute_joint.h:40
b2RevoluteJointDef::lowerAngle
float lowerAngle
The lower angle for the joint limit (radians).
Definition b2_revolute_joint.h:72
b2RevoluteJointDef::enableLimit
bool enableLimit
A flag to enable joint limits.
Definition b2_revolute_joint.h:69
b2RevoluteJointDef::motorSpeed
float motorSpeed
The desired motor speed. Usually in radians per second.
Definition b2_revolute_joint.h:81
b2RevoluteJointDef::localAnchorB
b2Vec2 localAnchorB
The local anchor point relative to bodyB's origin.
Definition b2_revolute_joint.h:63
b2RevoluteJointDef::upperAngle
float upperAngle
The upper angle for the joint limit (radians).
Definition b2_revolute_joint.h:75
b2RevoluteJointDef::Initialize
void Initialize(b2Body *bodyA, b2Body *bodyB, const b2Vec2 &anchor)
b2RevoluteJointDef::localAnchorA
b2Vec2 localAnchorA
The local anchor point relative to bodyA's origin.
Definition b2_revolute_joint.h:60
b2RevoluteJointDef::referenceAngle
float referenceAngle
The bodyB angle minus bodyA angle in the reference state (radians).
Definition b2_revolute_joint.h:66
b2RevoluteJointDef::enableMotor
bool enableMotor
A flag to enable the joint motor.
Definition b2_revolute_joint.h:78
b2RevoluteJointDef::maxMotorTorque
float maxMotorTorque
Definition b2_revolute_joint.h:85
b2SolverData
Solver Data.
Definition b2_time_step.h:68
b2Vec2
A 2D column vector.
Definition b2_math.h:42