~ubuntu-branches/ubuntu/vivid/emscripten/vivid

« back to all changes in this revision

Viewing changes to tests/box2d/Box2D/Dynamics/Joints/b2MouseJoint.h

  • Committer: Package Import Robot
  • Author(s): Sylvestre Ledru
  • Date: 2013-05-02 13:11:51 UTC
  • Revision ID: package-import@ubuntu.com-20130502131151-q8dvteqr1ef2x7xz
Tags: upstream-1.4.1~20130504~adb56cb
ImportĀ upstreamĀ versionĀ 1.4.1~20130504~adb56cb

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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
 
 
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
 
28
{
 
29
        b2MouseJointDef()
 
30
        {
 
31
                type = e_mouseJoint;
 
32
                target.Set(0.0f, 0.0f);
 
33
                maxForce = 0.0f;
 
34
                frequencyHz = 5.0f;
 
35
                dampingRatio = 0.7f;
 
36
        }
 
37
 
 
38
        /// The initial world target point. This is assumed
 
39
        /// to coincide with the body anchor initially.
 
40
        b2Vec2 target;
 
41
 
 
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).
 
45
        float32 maxForce;
 
46
 
 
47
        /// The response speed.
 
48
        float32 frequencyHz;
 
49
 
 
50
        /// The damping ratio. 0 = no damping, 1 = critical damping.
 
51
        float32 dampingRatio;
 
52
 
 
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; }
 
60
};
 
61
 
 
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
 
71
{
 
72
public:
 
73
 
 
74
        /// Implements b2Joint.
 
75
        b2Vec2 GetAnchorA() const;
 
76
 
 
77
        /// Implements b2Joint.
 
78
        b2Vec2 GetAnchorB() const;
 
79
 
 
80
        /// Implements b2Joint.
 
81
        b2Vec2 GetReactionForce(float32 inv_dt) const;
 
82
 
 
83
        /// Implements b2Joint.
 
84
        float32 GetReactionTorque(float32 inv_dt) const;
 
85
 
 
86
        /// Use this to update the target point.
 
87
        void SetTarget(const b2Vec2& target);
 
88
        const b2Vec2& GetTarget() const;
 
89
 
 
90
        /// Set/get the maximum force in Newtons.
 
91
        void SetMaxForce(float32 force);
 
92
        float32 GetMaxForce() const;
 
93
 
 
94
        /// Set/get the frequency in Hertz.
 
95
        void SetFrequency(float32 hz);
 
96
        float32 GetFrequency() const;
 
97
 
 
98
        /// Set/get the damping ratio (dimensionless).
 
99
        void SetDampingRatio(float32 ratio);
 
100
        float32 GetDampingRatio() const;
 
101
 
 
102
        /// The mouse joint does not support dumping.
 
103
        void Dump() { b2Log("Mouse joint dumping is not supported.\n"); }
 
104
 
 
105
        b2MouseJoint(const b2MouseJointDef* def);
 
106
 
 
107
protected:
 
108
        friend class b2Joint;
 
109
 
 
110
        void InitVelocityConstraints(const b2SolverData& data);
 
111
        void SolveVelocityConstraints(const b2SolverData& data);
 
112
        bool SolvePositionConstraints(const b2SolverData& data);
 
113
 
 
114
        b2Vec2 m_localAnchorB;
 
115
        b2Vec2 m_targetA;
 
116
        float32 m_frequencyHz;
 
117
        float32 m_dampingRatio;
 
118
        float32 m_beta;
 
119
        
 
120
        // Solver shared
 
121
        b2Vec2 m_impulse;
 
122
        float32 m_maxForce;
 
123
        float32 m_gamma;
 
124
 
 
125
        // Solver temp
 
126
        int32 m_indexA;
 
127
        int32 m_indexB;
 
128
        b2Vec2 m_rB;
 
129
        b2Vec2 m_localCenterB;
 
130
        float32 m_invMassB;
 
131
        float32 m_invIB;
 
132
        b2Mat22 m_mass;
 
133
        b2Vec2 m_C;
 
134
};
 
135
 
 
136
#endif