2
* Copyright (c) 2006-2007 Erin Catto http://www.box2d.org
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
22
#include <Box2D/Dynamics/Joints/b2Joint.h>
24
/// Mouse joint definition. This requires a world target point,
25
/// tuning parameters, and the time step.
26
// emscripten - b2MouseJointDef: add functions to set/get base class members
27
struct b2MouseJointDef : public b2JointDef
32
target.Set(0.0f, 0.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
// to generate javascript bindings
54
void set_bodyA(b2Body* b) { bodyA = b; }
55
void set_bodyB(b2Body* b) { bodyB = b; }
56
void set_collideConnected(bool b) { collideConnected = b; }
57
b2Body* get_bodyA(b2Body* b) { return bodyA; }
58
b2Body* get_bodyB(b2Body* b) { return bodyB; }
59
bool get_collideConnected(bool b) { return collideConnected; }
62
/// A mouse joint is used to make a point on a body track a
63
/// specified world point. This a soft constraint with a maximum
64
/// force. This allows the constraint to stretch and without
65
/// applying huge forces.
66
/// NOTE: this joint is not documented in the manual because it was
67
/// developed to be used in the testbed. If you want to learn how to
68
/// use the mouse joint, look at the testbed.
69
// emscripten - b2MouseJoint: make constructor public
70
class b2MouseJoint : public b2Joint
74
/// Implements b2Joint.
75
b2Vec2 GetAnchorA() const;
77
/// Implements b2Joint.
78
b2Vec2 GetAnchorB() const;
80
/// Implements b2Joint.
81
b2Vec2 GetReactionForce(float32 inv_dt) const;
83
/// Implements b2Joint.
84
float32 GetReactionTorque(float32 inv_dt) const;
86
/// Use this to update the target point.
87
void SetTarget(const b2Vec2& target);
88
const b2Vec2& GetTarget() const;
90
/// Set/get the maximum force in Newtons.
91
void SetMaxForce(float32 force);
92
float32 GetMaxForce() const;
94
/// Set/get the frequency in Hertz.
95
void SetFrequency(float32 hz);
96
float32 GetFrequency() const;
98
/// Set/get the damping ratio (dimensionless).
99
void SetDampingRatio(float32 ratio);
100
float32 GetDampingRatio() const;
102
/// The mouse joint does not support dumping.
103
void Dump() { b2Log("Mouse joint dumping is not supported.\n"); }
105
b2MouseJoint(const b2MouseJointDef* def);
108
friend class b2Joint;
110
void InitVelocityConstraints(const b2SolverData& data);
111
void SolveVelocityConstraints(const b2SolverData& data);
112
bool SolvePositionConstraints(const b2SolverData& data);
114
b2Vec2 m_localAnchorB;
116
float32 m_frequencyHz;
117
float32 m_dampingRatio;
129
b2Vec2 m_localCenterB;