LiquidFun
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
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
void b2Log(const char *string,...)
Logging function.
Definition: b2Settings.cpp:116
float32 maxForce
Definition: b2MouseJoint.h:44
float32 GetReactionTorque(float32 inv_dt) const
Implements b2Joint.
Definition: b2MouseJoint.cpp:214
float32 dampingRatio
The damping ratio. 0 = no damping, 1 = critical damping.
Definition: b2MouseJoint.h:50
void SetDampingRatio(float32 ratio)
Set/get the damping ratio (dimensionless).
Definition: b2MouseJoint.cpp:86
b2Vec2 target
Definition: b2MouseJoint.h:39
Definition: b2Joint.h:103
void Dump()
The mouse joint does not support dumping.
Definition: b2MouseJoint.h:93
Definition: b2MouseJoint.h:60
void Set(float32 x_, float32 y_)
Set this vector to some specified coordinates.
Definition: b2Math.h:68
void ShiftOrigin(const b2Vec2 &newOrigin)
Implement b2Joint::ShiftOrigin.
Definition: b2MouseJoint.cpp:219
b2Vec2 GetAnchorB() const
Implements b2Joint.
Definition: b2MouseJoint.cpp:204
b2Vec2 GetReactionForce(float32 inv_dt) const
Implements b2Joint.
Definition: b2MouseJoint.cpp:209
b2Vec2 GetAnchorA() const
Implements b2Joint.
Definition: b2MouseJoint.cpp:199
b2JointType type
The joint type is set automatically for concrete joint types.
Definition: b2Joint.h:86
Solver Data.
Definition: b2TimeStep.h:65
void SetMaxForce(float32 force)
Set/get the maximum force in Newtons.
Definition: b2MouseJoint.cpp:66
A 2-by-2 matrix. Stored in column-major order.
Definition: b2Math.h:244
void SetFrequency(float32 hz)
Set/get the frequency in Hertz.
Definition: b2MouseJoint.cpp:76
Joint definitions are used to construct joints.
Definition: b2Joint.h:74
float32 frequencyHz
The response speed.
Definition: b2MouseJoint.h:47
Definition: b2MouseJoint.h:26
A 2D column vector.
Definition: b2Math.h:56
void SetTarget(const b2Vec2 &target)
Use this to update the target point.
Definition: b2MouseJoint.cpp:52