- Main Page
- Classes
- Files

- File List
- File Members

# Box2D/Box2D/Dynamics/Joints/b2MouseJoint.h

Go to the documentation of this file.

    00001 /*
    00002 * Copyright (c) 2006-2007 Erin Catto http://www.gphysics.com
    00003 *
    00004 * This software is provided 'as-is', without any express or implied
    00005 * warranty.  In no event will the authors be held liable for any damages
    00006 * arising from the use of this software.
    00007 * Permission is granted to anyone to use this software for any purpose,
    00008 * including commercial applications, and to alter it and redistribute it
    00009 * freely, subject to the following restrictions:
    00010 * 1. The origin of this software must not be misrepresented; you must not
    00011 * claim that you wrote the original software. If you use this software
    00012 * in a product, an acknowledgment in the product documentation would be
    00013 * appreciated but is not required.
    00014 * 2. Altered source versions must be plainly marked as such, and must not be
    00015 * misrepresented as being the original software.
    00016 * 3. This notice may not be removed or altered from any source distribution.
    00017 */
    00018
    00019 #ifndef B2_MOUSE_JOINT_H
    00020 #define B2_MOUSE_JOINT_H
    00021
    00022 #include <Box2D/Dynamics/Joints/b2Joint.h>
    00023
    00026 struct b2MouseJointDef : public b2JointDef
    00027 {
    00028         b2MouseJointDef()
    00029         {
    00030                 type = e_mouseJoint;
    00031                 target.Set(0.0f, 0.0f);
    00032                 maxForce = 0.0f;
    00033                 frequencyHz = 5.0f;
    00034                 dampingRatio = 0.7f;
    00035         }
    00036
    00039         b2Vec2 target;
    00040
    00044         float32 maxForce;
    00045
    00047         float32 frequencyHz;
    00048
    00050         float32 dampingRatio;
    00051 };
    00052
    00060 class b2MouseJoint : public b2Joint
    00061 {
    00062 public:
    00063
    00065         b2Vec2 GetAnchorA() const;
    00066
    00068         b2Vec2 GetAnchorB() const;
    00069
    00071         b2Vec2 GetReactionForce(float32 inv_dt) const;
    00072
    00074         float32 GetReactionTorque(float32 inv_dt) const;
    00075
    00077         void SetTarget(const b2Vec2& target);
    00078         const b2Vec2& GetTarget() const;
    00079
    00081         void SetMaxForce(float32 force);
    00082         float32 GetMaxForce() const;
    00083
    00085         void SetFrequency(float32 hz);
    00086         float32 GetFrequency() const;
    00087
    00089         void SetDampingRatio(float32 ratio);
    00090         float32 GetDampingRatio() const;
    00091
    00092 protected:
    00093         friend class b2Joint;
    00094
    00095         b2MouseJoint(const b2MouseJointDef* def);
    00096
    00097         void InitVelocityConstraints(const b2TimeStep& step);
    00098         void SolveVelocityConstraints(const b2TimeStep& step);
    00099         bool SolvePositionConstraints(float32 baumgarte) { B2_NOT_USED(baumgarte); return true; }
    00100
    00101         b2Vec2 m_localAnchor;
    00102         b2Vec2 m_target;
    00103         b2Vec2 m_impulse;
    00104
    00105         b2Mat22 m_mass;         // effective mass for point-to-point constraint.
    00106         b2Vec2 m_C;                             // position error
    00107         float32 m_maxForce;
    00108         float32 m_frequencyHz;
    00109         float32 m_dampingRatio;
    00110         float32 m_beta;
    00111         float32 m_gamma;
    00112 };
    00113
    00114 #endif