Box2D: /build/box2d/src/box2d-2.4.2/include/box2d/b2_gear_joint.h Source File

| Box2D 2.4.1 A 2D physics engine for games

Loading...
Searching...
No Matches
b2_gear_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_GEAR_JOINT_H
24#define B2_GEAR_JOINT_H
25
26#include "b2_joint.h"
27
31 struct B2_API b2GearJointDef : public b2JointDef
32{
33 b2GearJointDef()
34 {
35 type = e_gearJoint;
36 joint1 = nullptr;
37 joint2 = nullptr;
38 ratio = 1.0f;
39 }
40
42 b2Joint* joint1;
43
45 b2Joint* joint2;
46
49 float ratio;
50};
51
61 class B2_API b2GearJoint : public b2Joint
62{
63public:
64 b2Vec2 GetAnchorA() const override;
65 b2Vec2 GetAnchorB() const override;
66
67 b2Vec2 GetReactionForce(float inv_dt) const override;
68 float GetReactionTorque(float inv_dt) const override;
69
71 b2Joint* GetJoint1() { return m_joint1; }
72
74 b2Joint* GetJoint2() { return m_joint2; }
75
77 void SetRatio(float ratio);
78 float GetRatio() const;
79
81 void Dump() override;
82
83protected:
84
85 friend class b2Joint;
86 b2GearJoint(const b2GearJointDef* data);
87
88 void InitVelocityConstraints(const b2SolverData& data) override;
89 void SolveVelocityConstraints(const b2SolverData& data) override;
90 bool SolvePositionConstraints(const b2SolverData& data) override;
91
92 b2Joint* m_joint1;
93 b2Joint* m_joint2;
94
95 b2JointType m_typeA;
96 b2JointType m_typeB;
97
98 // Body A is connected to body C
99 // Body B is connected to body D
100 b2Body* m_bodyC;
101 b2Body* m_bodyD;
102
103 // Solver shared
104 b2Vec2 m_localAnchorA;
105 b2Vec2 m_localAnchorB;
106 b2Vec2 m_localAnchorC;
107 b2Vec2 m_localAnchorD;
108
109 b2Vec2 m_localAxisC;
110 b2Vec2 m_localAxisD;
111
112 float m_referenceAngleA;
113 float m_referenceAngleB;
114
115 float m_constant;
116 float m_ratio;
117 float m_tolerance;
118
119 float m_impulse;
120
121 // Solver temp
122 int32 m_indexA, m_indexB, m_indexC, m_indexD;
123 b2Vec2 m_lcA, m_lcB, m_lcC, m_lcD;
124 float m_mA, m_mB, m_mC, m_mD;
125 float m_iA, m_iB, m_iC, m_iD;
126 b2Vec2 m_JvAC, m_JvBD;
127 float m_JwA, m_JwB, m_JwC, m_JwD;
128 float m_mass;
129};
130
131#endif
b2Body
A rigid body. These are created via b2World::CreateBody.
Definition b2_body.h:129
b2GearJoint
Definition b2_gear_joint.h:62
b2GearJoint::GetAnchorA
b2Vec2 GetAnchorA() const override
Get the anchor point on bodyA in world coordinates.
b2GearJoint::GetReactionForce
b2Vec2 GetReactionForce(float inv_dt) const override
Get the reaction force on bodyB at the joint anchor in Newtons.
b2GearJoint::GetAnchorB
b2Vec2 GetAnchorB() const override
Get the anchor point on bodyB in world coordinates.
b2GearJoint::Dump
void Dump() override
Dump joint to dmLog.
b2GearJoint::GetReactionTorque
float GetReactionTorque(float inv_dt) const override
Get the reaction torque on bodyB in N*m.
b2GearJoint::GetJoint1
b2Joint * GetJoint1()
Get the first joint.
Definition b2_gear_joint.h:71
b2GearJoint::GetJoint2
b2Joint * GetJoint2()
Get the second joint.
Definition b2_gear_joint.h:74
b2GearJoint::SetRatio
void SetRatio(float ratio)
Set/Get the gear ratio.
b2Joint
Definition b2_joint.h:110
b2GearJointDef
Definition b2_gear_joint.h:32
b2GearJointDef::joint2
b2Joint * joint2
The second revolute/prismatic joint attached to the gear joint.
Definition b2_gear_joint.h:45
b2GearJointDef::ratio
float ratio
Definition b2_gear_joint.h:49
b2GearJointDef::joint1
b2Joint * joint1
The first revolute/prismatic joint attached to the gear joint.
Definition b2_gear_joint.h:42
b2JointDef
Joint definitions are used to construct joints.
Definition b2_joint.h:72
b2SolverData
Solver Data.
Definition b2_time_step.h:68
b2Vec2
A 2D column vector.
Definition b2_math.h:42