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

| Box2D 2.4.1 A 2D physics engine for games

Loading...
Searching...
No Matches
b2_prismatic_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_PRISMATIC_JOINT_H
24#define B2_PRISMATIC_JOINT_H
25
26#include "b2_api.h"
27#include "b2_joint.h"
28
35 struct B2_API b2PrismaticJointDef : public b2JointDef
36{
37 b2PrismaticJointDef()
38 {
39 type = e_prismaticJoint;
40 localAnchorA.SetZero();
41 localAnchorB.SetZero();
42 localAxisA.Set(1.0f, 0.0f);
43 referenceAngle = 0.0f;
44 enableLimit = false;
45 lowerTranslation = 0.0f;
46 upperTranslation = 0.0f;
47 enableMotor = false;
48 maxMotorForce = 0.0f;
49 motorSpeed = 0.0f;
50 }
51
54 void Initialize(b2Body* bodyA, b2Body* bodyB, const b2Vec2& anchor, const b2Vec2& axis);
55
57 b2Vec2 localAnchorA;
58
60 b2Vec2 localAnchorB;
61
63 b2Vec2 localAxisA;
64
66 float referenceAngle;
67
69 bool enableLimit;
70
72 float lowerTranslation;
73
75 float upperTranslation;
76
78 bool enableMotor;
79
81 float maxMotorForce;
82
84 float motorSpeed;
85};
86
91 class B2_API b2PrismaticJoint : public b2Joint
92{
93public:
94 b2Vec2 GetAnchorA() const override;
95 b2Vec2 GetAnchorB() const override;
96
97 b2Vec2 GetReactionForce(float inv_dt) const override;
98 float GetReactionTorque(float inv_dt) const override;
99
101 const b2Vec2& GetLocalAnchorA() const { return m_localAnchorA; }
102
104 const b2Vec2& GetLocalAnchorB() const { return m_localAnchorB; }
105
107 const b2Vec2& GetLocalAxisA() const { return m_localXAxisA; }
108
110 float GetReferenceAngle() const { return m_referenceAngle; }
111
113 float GetJointTranslation() const;
114
116 float GetJointSpeed() const;
117
119 bool IsLimitEnabled() const;
120
122 void EnableLimit(bool flag);
123
125 float GetLowerLimit() const;
126
128 float GetUpperLimit() const;
129
131 void SetLimits(float lower, float upper);
132
134 bool IsMotorEnabled() const;
135
137 void EnableMotor(bool flag);
138
140 void SetMotorSpeed(float speed);
141
143 float GetMotorSpeed() const;
144
146 void SetMaxMotorForce(float force);
147 float GetMaxMotorForce() const { return m_maxMotorForce; }
148
150 float GetMotorForce(float inv_dt) const;
151
153 void Dump() override;
154
156 void Draw(b2Draw* draw) const override;
157
158protected:
159 friend class b2Joint;
160 friend class b2GearJoint;
161 b2PrismaticJoint(const b2PrismaticJointDef* def);
162
163 void InitVelocityConstraints(const b2SolverData& data) override;
164 void SolveVelocityConstraints(const b2SolverData& data) override;
165 bool SolvePositionConstraints(const b2SolverData& data) override;
166
167 b2Vec2 m_localAnchorA;
168 b2Vec2 m_localAnchorB;
169 b2Vec2 m_localXAxisA;
170 b2Vec2 m_localYAxisA;
171 float m_referenceAngle;
172 b2Vec2 m_impulse;
173 float m_motorImpulse;
174 float m_lowerImpulse;
175 float m_upperImpulse;
176 float m_lowerTranslation;
177 float m_upperTranslation;
178 float m_maxMotorForce;
179 float m_motorSpeed;
180 bool m_enableLimit;
181 bool m_enableMotor;
182
183 // Solver temp
184 int32 m_indexA;
185 int32 m_indexB;
186 b2Vec2 m_localCenterA;
187 b2Vec2 m_localCenterB;
188 float m_invMassA;
189 float m_invMassB;
190 float m_invIA;
191 float m_invIB;
192 b2Vec2 m_axis, m_perp;
193 float m_s1, m_s2;
194 float m_a1, m_a2;
195 b2Mat22 m_K;
196 float m_translation;
197 float m_axialMass;
198};
199
200 inline float b2PrismaticJoint::GetMotorSpeed() const
201{
202 return m_motorSpeed;
203}
204
205#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:110
b2PrismaticJoint
Definition b2_prismatic_joint.h:92
b2PrismaticJoint::IsMotorEnabled
bool IsMotorEnabled() const
Is the joint motor enabled?
b2PrismaticJoint::GetReactionTorque
float GetReactionTorque(float inv_dt) const override
Get the reaction torque on bodyB in N*m.
b2PrismaticJoint::GetMotorSpeed
float GetMotorSpeed() const
Get the motor speed, usually in meters per second.
Definition b2_prismatic_joint.h:200
b2PrismaticJoint::SetLimits
void SetLimits(float lower, float upper)
Set the joint limits, usually in meters.
b2PrismaticJoint::GetReactionForce
b2Vec2 GetReactionForce(float inv_dt) const override
Get the reaction force on bodyB at the joint anchor in Newtons.
b2PrismaticJoint::IsLimitEnabled
bool IsLimitEnabled() const
Is the joint limit enabled?
b2PrismaticJoint::GetReferenceAngle
float GetReferenceAngle() const
Get the reference angle.
Definition b2_prismatic_joint.h:110
b2PrismaticJoint::Draw
void Draw(b2Draw *draw) const override
Debug draw this joint.
b2PrismaticJoint::EnableMotor
void EnableMotor(bool flag)
Enable/disable the joint motor.
b2PrismaticJoint::EnableLimit
void EnableLimit(bool flag)
Enable/disable the joint limit.
b2PrismaticJoint::GetUpperLimit
float GetUpperLimit() const
Get the upper joint limit, usually in meters.
b2PrismaticJoint::GetMotorForce
float GetMotorForce(float inv_dt) const
Get the current motor force given the inverse time step, usually in N.
b2PrismaticJoint::GetAnchorB
b2Vec2 GetAnchorB() const override
Get the anchor point on bodyB in world coordinates.
b2PrismaticJoint::Dump
void Dump() override
Dump to b2Log.
b2PrismaticJoint::GetJointSpeed
float GetJointSpeed() const
Get the current joint translation speed, usually in meters per second.
b2PrismaticJoint::GetLocalAnchorA
const b2Vec2 & GetLocalAnchorA() const
The local anchor point relative to bodyA's origin.
Definition b2_prismatic_joint.h:101
b2PrismaticJoint::SetMaxMotorForce
void SetMaxMotorForce(float force)
Set the maximum motor force, usually in N.
b2PrismaticJoint::SetMotorSpeed
void SetMotorSpeed(float speed)
Set the motor speed, usually in meters per second.
b2PrismaticJoint::GetLowerLimit
float GetLowerLimit() const
Get the lower joint limit, usually in meters.
b2PrismaticJoint::GetAnchorA
b2Vec2 GetAnchorA() const override
Get the anchor point on bodyA in world coordinates.
b2PrismaticJoint::GetLocalAnchorB
const b2Vec2 & GetLocalAnchorB() const
The local anchor point relative to bodyB's origin.
Definition b2_prismatic_joint.h:104
b2PrismaticJoint::GetLocalAxisA
const b2Vec2 & GetLocalAxisA() const
The local joint axis relative to bodyA.
Definition b2_prismatic_joint.h:107
b2PrismaticJoint::GetJointTranslation
float GetJointTranslation() const
Get the current joint translation, usually in meters.
b2JointDef
Joint definitions are used to construct joints.
Definition b2_joint.h:72
b2Mat22
A 2-by-2 matrix. Stored in column-major order.
Definition b2_math.h:172
b2PrismaticJointDef
Definition b2_prismatic_joint.h:36
b2PrismaticJointDef::lowerTranslation
float lowerTranslation
The lower translation limit, usually in meters.
Definition b2_prismatic_joint.h:72
b2PrismaticJointDef::enableMotor
bool enableMotor
Enable/disable the joint motor.
Definition b2_prismatic_joint.h:78
b2PrismaticJointDef::motorSpeed
float motorSpeed
The desired motor speed in radians per second.
Definition b2_prismatic_joint.h:84
b2PrismaticJointDef::localAnchorB
b2Vec2 localAnchorB
The local anchor point relative to bodyB's origin.
Definition b2_prismatic_joint.h:60
b2PrismaticJointDef::upperTranslation
float upperTranslation
The upper translation limit, usually in meters.
Definition b2_prismatic_joint.h:75
b2PrismaticJointDef::enableLimit
bool enableLimit
Enable/disable the joint limit.
Definition b2_prismatic_joint.h:69
b2PrismaticJointDef::localAnchorA
b2Vec2 localAnchorA
The local anchor point relative to bodyA's origin.
Definition b2_prismatic_joint.h:57
b2PrismaticJointDef::referenceAngle
float referenceAngle
The constrained angle between the bodies: bodyB_angle - bodyA_angle.
Definition b2_prismatic_joint.h:66
b2PrismaticJointDef::Initialize
void Initialize(b2Body *bodyA, b2Body *bodyB, const b2Vec2 &anchor, const b2Vec2 &axis)
b2PrismaticJointDef::localAxisA
b2Vec2 localAxisA
The local translation unit axis in bodyA.
Definition b2_prismatic_joint.h:63
b2PrismaticJointDef::maxMotorForce
float maxMotorForce
The maximum motor torque, usually in N-m.
Definition b2_prismatic_joint.h:81
b2SolverData
Solver Data.
Definition b2_time_step.h:68
b2Vec2
A 2D column vector.
Definition b2_math.h:42