b2_mouse_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_MOUSE_JOINT_H
24 #define B2_MOUSE_JOINT_H
25 
26 #include "b2_api.h"
27 #include "b2_joint.h"
28 
32 {
34  {
36  target.Set(0.0f, 0.0f);
37  maxForce = 0.0f;
38  stiffness = 0.0f;
39  damping = 0.0f;
40  }
41 
45 
49  float maxForce;
50 
52  float stiffness;
53 
55  float damping;
56 };
57 
65 class B2_API b2MouseJoint : public b2Joint
66 {
67 public:
68 
70  b2Vec2 GetAnchorA() const override;
71 
73  b2Vec2 GetAnchorB() const override;
74 
76  b2Vec2 GetReactionForce(float inv_dt) const override;
77 
79  float GetReactionTorque(float inv_dt) const override;
80 
82  void SetTarget(const b2Vec2& target);
83  const b2Vec2& GetTarget() const;
84 
86  void SetMaxForce(float force);
87  float GetMaxForce() const;
88 
90  void SetStiffness(float stiffness) { m_stiffness = stiffness; }
91  float GetStiffness() const { return m_stiffness; }
92 
94  void SetDamping(float damping) { m_damping = damping; }
95  float GetDamping() const { return m_damping; }
96 
98  void Dump() override { b2Log("Mouse joint dumping is not supported.\n"); }
99 
101  void ShiftOrigin(const b2Vec2& newOrigin) override;
102 
103 protected:
104  friend class b2Joint;
105 
106  b2MouseJoint(const b2MouseJointDef* def);
107 
108  void InitVelocityConstraints(const b2SolverData& data) override;
109  void SolveVelocityConstraints(const b2SolverData& data) override;
110  bool SolvePositionConstraints(const b2SolverData& data) override;
111 
114  float m_stiffness;
115  float m_damping;
116  float m_beta;
117 
118  // Solver shared
120  float m_maxForce;
121  float m_gamma;
122 
123  // Solver temp
128  float m_invMassB;
129  float m_invIB;
132 };
133 
134 #endif
b2_api.h
b2Joint::GetReactionTorque
virtual float GetReactionTorque(float inv_dt) const =0
Get the reaction torque on bodyB in N*m.
b2MouseJoint::m_invIB
float m_invIB
Definition: b2_mouse_joint.h:129
b2MouseJoint::SetDamping
void SetDamping(float damping)
Set/get linear damping in N*s/m.
Definition: b2_mouse_joint.h:94
b2MouseJointDef::damping
float damping
The linear damping in N*s/m.
Definition: b2_mouse_joint.h:55
b2Joint::SolvePositionConstraints
virtual bool SolvePositionConstraints(const b2SolverData &data)=0
b2Log
void b2Log(const char *string,...)
Implement this to use your own logging.
Definition: b2_settings.h:115
b2MouseJoint::m_indexB
int32 m_indexB
Definition: b2_mouse_joint.h:125
b2SolverData
Solver Data.
Definition: b2_time_step.h:67
b2_joint.h
b2MouseJoint::m_mass
b2Mat22 m_mass
Definition: b2_mouse_joint.h:130
b2Joint::InitVelocityConstraints
virtual void InitVelocityConstraints(const b2SolverData &data)=0
b2Mat22
A 2-by-2 matrix. Stored in column-major order.
Definition: b2_math.h:171
B2_API
#define B2_API
Definition: b2_api.h:49
b2Vec2
A 2D column vector.
Definition: b2_math.h:41
b2MouseJoint::m_targetA
b2Vec2 m_targetA
Definition: b2_mouse_joint.h:113
b2MouseJoint::Dump
void Dump() override
The mouse joint does not support dumping.
Definition: b2_mouse_joint.h:98
f
f
b2Joint::SolveVelocityConstraints
virtual void SolveVelocityConstraints(const b2SolverData &data)=0
b2MouseJoint::m_localAnchorB
b2Vec2 m_localAnchorB
Definition: b2_mouse_joint.h:112
b2Joint::GetAnchorA
virtual b2Vec2 GetAnchorA() const =0
Get the anchor point on bodyA in world coordinates.
b2Joint
Definition: b2_joint.h:110
b2MouseJointDef::target
b2Vec2 target
Definition: b2_mouse_joint.h:44
b2MouseJoint::m_rB
b2Vec2 m_rB
Definition: b2_mouse_joint.h:126
b2JointDef
Joint definitions are used to construct joints.
Definition: b2_joint.h:72
b2MouseJoint::m_maxForce
float m_maxForce
Definition: b2_mouse_joint.h:120
b2MouseJoint::m_C
b2Vec2 m_C
Definition: b2_mouse_joint.h:131
b2MouseJointDef
Definition: b2_mouse_joint.h:31
b2MouseJoint::m_beta
float m_beta
Definition: b2_mouse_joint.h:116
e_mouseJoint
@ e_mouseJoint
Definition: b2_joint.h:42
b2MouseJoint::m_localCenterB
b2Vec2 m_localCenterB
Definition: b2_mouse_joint.h:127
b2MouseJoint::m_gamma
float m_gamma
Definition: b2_mouse_joint.h:121
b2MouseJointDef::stiffness
float stiffness
The linear stiffness in N/m.
Definition: b2_mouse_joint.h:52
b2MouseJoint::m_stiffness
float m_stiffness
Definition: b2_mouse_joint.h:114
b2MouseJoint::GetStiffness
float GetStiffness() const
Definition: b2_mouse_joint.h:91
b2MouseJoint::m_damping
float m_damping
Definition: b2_mouse_joint.h:115
b2MouseJoint::GetDamping
float GetDamping() const
Definition: b2_mouse_joint.h:95
b2MouseJointDef::b2MouseJointDef
b2MouseJointDef()
Definition: b2_mouse_joint.h:33
b2MouseJoint::m_invMassB
float m_invMassB
Definition: b2_mouse_joint.h:128
b2MouseJointDef::maxForce
float maxForce
Definition: b2_mouse_joint.h:49
int32
signed int int32
Definition: b2_types.h:28
b2Joint::ShiftOrigin
virtual void ShiftOrigin(const b2Vec2 &newOrigin)
Shift the origin for any points stored in world coordinates.
Definition: b2_joint.h:154
type
GLenum type
Definition: gl.h:1033
b2MouseJoint::m_impulse
b2Vec2 m_impulse
Definition: b2_mouse_joint.h:119
b2Joint::GetAnchorB
virtual b2Vec2 GetAnchorB() const =0
Get the anchor point on bodyB in world coordinates.
b2MouseJoint
Definition: b2_mouse_joint.h:65
b2MouseJoint::m_indexA
int32 m_indexA
Definition: b2_mouse_joint.h:124
b2MouseJoint::SetStiffness
void SetStiffness(float stiffness)
Set/get the linear stiffness in N/m.
Definition: b2_mouse_joint.h:90
b2Joint::GetReactionForce
virtual b2Vec2 GetReactionForce(float inv_dt) const =0
Get the reaction force on bodyB at the joint anchor in Newtons.


mvsim
Author(s):
autogenerated on Wed May 28 2025 02:13:07