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