Box2D  2.3.0
A 2D Physics Engine for Games
b2MouseJoint.h
1 /*
2 * Copyright (c) 2006-2007 Erin Catto http://www.box2d.org
3 *
4 * This software is provided 'as-is', without any express or implied
5 * warranty. In no event will the authors be held liable for any damages
6 * arising from the use of this software.
7 * Permission is granted to anyone to use this software for any purpose,
8 * including commercial applications, and to alter it and redistribute it
9 * freely, subject to the following restrictions:
10 * 1. The origin of this software must not be misrepresented; you must not
11 * claim that you wrote the original software. If you use this software
12 * in a product, an acknowledgment in the product documentation would be
13 * appreciated but is not required.
14 * 2. Altered source versions must be plainly marked as such, and must not be
15 * misrepresented as being the original software.
16 * 3. This notice may not be removed or altered from any source distribution.
17 */
18 
19 #ifndef B2_MOUSE_JOINT_H
20 #define B2_MOUSE_JOINT_H
21 
22 #include <Box2D/Dynamics/Joints/b2Joint.h>
23 
26 struct b2MouseJointDef : public b2JointDef
27 {
29  {
30  type = e_mouseJoint;
31  target.Set(0.0f, 0.0f);
32  maxForce = 0.0f;
33  frequencyHz = 5.0f;
34  dampingRatio = 0.7f;
35  }
36 
40 
44  float32 maxForce;
45 
47  float32 frequencyHz;
48 
50  float32 dampingRatio;
51 };
52 
60 class b2MouseJoint : public b2Joint
61 {
62 public:
63 
65  b2Vec2 GetAnchorA() const;
66 
68  b2Vec2 GetAnchorB() const;
69 
71  b2Vec2 GetReactionForce(float32 inv_dt) const;
72 
74  float32 GetReactionTorque(float32 inv_dt) const;
75 
77  void SetTarget(const b2Vec2& target);
78  const b2Vec2& GetTarget() const;
79 
81  void SetMaxForce(float32 force);
82  float32 GetMaxForce() const;
83 
85  void SetFrequency(float32 hz);
86  float32 GetFrequency() const;
87 
89  void SetDampingRatio(float32 ratio);
90  float32 GetDampingRatio() const;
91 
93  void Dump() { b2Log("Mouse joint dumping is not supported.\n"); }
94 
96  void ShiftOrigin(const b2Vec2& newOrigin);
97 
98 protected:
99  friend class b2Joint;
100 
101  b2MouseJoint(const b2MouseJointDef* def);
102 
103  void InitVelocityConstraints(const b2SolverData& data);
104  void SolveVelocityConstraints(const b2SolverData& data);
105  bool SolvePositionConstraints(const b2SolverData& data);
106 
107  b2Vec2 m_localAnchorB;
108  b2Vec2 m_targetA;
109  float32 m_frequencyHz;
110  float32 m_dampingRatio;
111  float32 m_beta;
112 
113  // Solver shared
114  b2Vec2 m_impulse;
115  float32 m_maxForce;
116  float32 m_gamma;
117 
118  // Solver temp
119  int32 m_indexA;
120  int32 m_indexB;
121  b2Vec2 m_rB;
122  b2Vec2 m_localCenterB;
123  float32 m_invMassB;
124  float32 m_invIB;
125  b2Mat22 m_mass;
126  b2Vec2 m_C;
127 };
128 
129 #endif