2 * Copyright (c) 2006-2007 Erin Catto http://www.gphysics.com
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.
19 #ifndef B2_MOUSE_JOINT_H
20 #define B2_MOUSE_JOINT_H
24 /// Mouse joint definition. This requires a world target point,
25 /// tuning parameters, and the time step.
26 struct b2MouseJointDef : public b2JointDef
31 target.Set(0.0f, 0.0f);
35 timeStep = 1.0f / 60.0f;
38 /// The initial world target point. This is assumed
39 /// to coincide with the body anchor initially.
42 /// The maximum constraint force that can be exerted
43 /// to move the candidate body. Usually you will express
44 /// as some multiple of the weight (multiplier * mass * gravity).
47 /// The response speed.
50 /// The damping ratio. 0 = no damping, 1 = critical damping.
53 /// The time step used in the simulation.
57 /// A mouse joint is used to make a point on a body track a
58 /// specified world point. This a soft constraint with a maximum
59 /// force. This allows the constraint to stretch and without
60 /// applying huge forces.
61 class b2MouseJoint : public b2Joint
65 /// Implements b2Joint.
66 b2Vec2 GetAnchor1() const;
68 /// Implements b2Joint.
69 b2Vec2 GetAnchor2() const;
71 /// Implements b2Joint.
72 b2Vec2 GetReactionForce() const;
74 /// Implements b2Joint.
75 float32 GetReactionTorque() const;
77 /// Use this to update the target point.
78 void SetTarget(const b2Vec2& target);
80 //--------------- Internals Below -------------------
82 b2MouseJoint(const b2MouseJointDef* def);
84 void InitVelocityConstraints(const b2TimeStep& step);
85 void SolveVelocityConstraints(const b2TimeStep& step);
86 bool SolvePositionConstraints()
95 b2Mat22 m_mass; // effective mass for point-to-point constraint.
96 b2Vec2 m_C; // position error
98 float32 m_beta; // bias factor
99 float32 m_gamma; // softness