b2_wheel_joint.h
Go to the documentation of this file.
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_WHEEL_JOINT_H
24 #define B2_WHEEL_JOINT_H
25 
26 #include "b2_api.h"
27 #include "b2_joint.h"
28 
36 {
38  {
40  localAnchorA.SetZero();
41  localAnchorB.SetZero();
42  localAxisA.Set(1.0f, 0.0f);
43  enableLimit = false;
44  lowerTranslation = 0.0f;
45  upperTranslation = 0.0f;
46  enableMotor = false;
47  maxMotorTorque = 0.0f;
48  motorSpeed = 0.0f;
49  stiffness = 0.0f;
50  damping = 0.0f;
51  }
52 
55  void Initialize(b2Body* bodyA, b2Body* bodyB, const b2Vec2& anchor, const b2Vec2& axis);
56 
59 
62 
65 
68 
71 
74 
77 
80 
82  float motorSpeed;
83 
85  float stiffness;
86 
88  float damping;
89 };
90 
95 class B2_API b2WheelJoint : public b2Joint
96 {
97 public:
98  b2Vec2 GetAnchorA() const override;
99  b2Vec2 GetAnchorB() const override;
100 
101  b2Vec2 GetReactionForce(float inv_dt) const override;
102  float GetReactionTorque(float inv_dt) const override;
103 
105  const b2Vec2& GetLocalAnchorA() const { return m_localAnchorA; }
106 
108  const b2Vec2& GetLocalAnchorB() const { return m_localAnchorB; }
109 
111  const b2Vec2& GetLocalAxisA() const { return m_localXAxisA; }
112 
114  float GetJointTranslation() const;
115 
117  float GetJointLinearSpeed() const;
118 
120  float GetJointAngle() const;
121 
123  float GetJointAngularSpeed() const;
124 
126  bool IsLimitEnabled() const;
127 
129  void EnableLimit(bool flag);
130 
132  float GetLowerLimit() const;
133 
135  float GetUpperLimit() const;
136 
138  void SetLimits(float lower, float upper);
139 
141  bool IsMotorEnabled() const;
142 
144  void EnableMotor(bool flag);
145 
147  void SetMotorSpeed(float speed);
148 
150  float GetMotorSpeed() const;
151 
153  void SetMaxMotorTorque(float torque);
154  float GetMaxMotorTorque() const;
155 
157  float GetMotorTorque(float inv_dt) const;
158 
160  void SetStiffness(float stiffness);
161  float GetStiffness() const;
162 
164  void SetDamping(float damping);
165  float GetDamping() const;
166 
168  void Dump() override;
169 
171  void Draw(b2Draw* draw) const override;
172 
173 protected:
174 
175  friend class b2Joint;
176  b2WheelJoint(const b2WheelJointDef* def);
177 
178  void InitVelocityConstraints(const b2SolverData& data) override;
179  void SolveVelocityConstraints(const b2SolverData& data) override;
180  bool SolvePositionConstraints(const b2SolverData& data) override;
181 
186 
187  float m_impulse;
190 
196 
199 
202 
203  float m_stiffness;
204  float m_damping;
205 
206  // Solver temp
211  float m_invMassA;
212  float m_invMassB;
213  float m_invIA;
214  float m_invIB;
215 
216  b2Vec2 m_ax, m_ay;
217  float m_sAx, m_sBx;
218  float m_sAy, m_sBy;
219 
220  float m_mass;
221  float m_motorMass;
222  float m_axialMass;
224 
225  float m_bias;
226  float m_gamma;
227 
228 };
229 
230 inline float b2WheelJoint::GetMotorSpeed() const
231 {
232  return m_motorSpeed;
233 }
234 
236 {
237  return m_maxMotorTorque;
238 }
239 
240 #endif
virtual void SolveVelocityConstraints(const b2SolverData &data)=0
virtual b2Vec2 GetReactionForce(float inv_dt) const =0
Get the reaction force on bodyB at the joint anchor in Newtons.
f
Joint definitions are used to construct joints.
Definition: b2_joint.h:72
#define B2_API
Definition: b2_api.h:49
float m_lowerTranslation
float m_motorImpulse
float lowerTranslation
The lower translation limit, usually in meters.
Solver Data.
Definition: b2_time_step.h:67
const b2Vec2 & GetLocalAnchorB() const
The local anchor point relative to bodyB's origin.
b2Vec2 m_localAnchorB
A 2D column vector.
Definition: b2_math.h:41
signed int int32
Definition: b2_types.h:28
float GetMotorSpeed() const
Get the motor speed, usually in radians per second.
const b2Vec2 & GetLocalAxisA() const
The local joint axis relative to bodyA.
virtual float GetReactionTorque(float inv_dt) const =0
Get the reaction torque on bodyB in N*m.
A rigid body. These are created via b2World::CreateBody.
Definition: b2_body.h:128
b2Vec2 localAnchorA
The local anchor point relative to bodyA's origin.
float maxMotorTorque
The maximum motor torque, usually in N-m.
Definition: b2_draw.h:48
virtual b2Vec2 GetAnchorA() const =0
Get the anchor point on bodyA in world coordinates.
virtual void InitVelocityConstraints(const b2SolverData &data)=0
b2Vec2 localAxisA
The local translation axis in bodyA.
b2Vec2 m_localCenterA
virtual bool SolvePositionConstraints(const b2SolverData &data)=0
const b2Vec2 & GetLocalAnchorA() const
The local anchor point relative to bodyA's origin.
bool enableMotor
Enable/disable the joint motor.
IMGUI_API void Initialize(ImGuiContext *context)
Definition: imgui.cpp:3473
float m_upperImpulse
float m_springImpulse
float m_lowerImpulse
b2Vec2 m_localYAxisA
b2Vec2 m_localAnchorA
bool enableLimit
Enable/disable the joint limit.
virtual void Dump()
Dump this joint to the log file.
Definition: b2_joint.h:151
virtual b2Vec2 GetAnchorB() const =0
Get the anchor point on bodyB in world coordinates.
float m_upperTranslation
virtual void Draw(b2Draw *draw) const
Debug draw this joint.
Definition: b2_joint.cpp:255
b2Vec2 localAnchorB
The local anchor point relative to bodyB's origin.
float m_maxMotorTorque
b2Vec2 m_localCenterB
float motorSpeed
The desired motor speed in radians per second.
float damping
Suspension damping. Typically in units of N*s/m.
float stiffness
Suspension stiffness. Typically in units N/m.
float GetMaxMotorTorque() const
b2Vec2 m_localXAxisA
float upperTranslation
The upper translation limit, usually in meters.
GLenum type
Definition: gl.h:1033


mvsim
Author(s):
autogenerated on Tue Jul 4 2023 03:08:19