Box2D  2.2.0
A 2D Physics Engine for Games
b2FrictionJoint.h
00001 /*
00002 * Copyright (c) 2006-2007 Erin Catto http://www.box2d.org
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_FRICTION_JOINT_H
00020 #define B2_FRICTION_JOINT_H
00021 
00022 #include <Box2D/Dynamics/Joints/b2Joint.h>
00023 
00025 struct b2FrictionJointDef : public b2JointDef
00026 {
00027         b2FrictionJointDef()
00028         {
00029                 type = e_frictionJoint;
00030                 localAnchorA.SetZero();
00031                 localAnchorB.SetZero();
00032                 maxForce = 0.0f;
00033                 maxTorque = 0.0f;
00034         }
00035 
00038         void Initialize(b2Body* bodyA, b2Body* bodyB, const b2Vec2& anchor);
00039 
00041         b2Vec2 localAnchorA;
00042 
00044         b2Vec2 localAnchorB;
00045 
00047         float32 maxForce;
00048 
00050         float32 maxTorque;
00051 };
00052 
00055 class b2FrictionJoint : public b2Joint
00056 {
00057 public:
00058         b2Vec2 GetAnchorA() const;
00059         b2Vec2 GetAnchorB() const;
00060 
00061         b2Vec2 GetReactionForce(float32 inv_dt) const;
00062         float32 GetReactionTorque(float32 inv_dt) const;
00063 
00065         void SetMaxForce(float32 force);
00066 
00068         float32 GetMaxForce() const;
00069 
00071         void SetMaxTorque(float32 torque);
00072 
00074         float32 GetMaxTorque() const;
00075 
00076 protected:
00077 
00078         friend class b2Joint;
00079 
00080         b2FrictionJoint(const b2FrictionJointDef* def);
00081 
00082         void InitVelocityConstraints(const b2SolverData& data);
00083         void SolveVelocityConstraints(const b2SolverData& data);
00084         bool SolvePositionConstraints(const b2SolverData& data);
00085 
00086         b2Vec2 m_localAnchorA;
00087         b2Vec2 m_localAnchorB;
00088 
00089         // Solver shared
00090         b2Vec2 m_linearImpulse;
00091         float32 m_angularImpulse;
00092         float32 m_maxForce;
00093         float32 m_maxTorque;
00094 
00095         // Solver temp
00096         int32 m_indexA;
00097         int32 m_indexB;
00098         b2Vec2 m_rA;
00099         b2Vec2 m_rB;
00100         b2Vec2 m_localCenterA;
00101         b2Vec2 m_localCenterB;
00102         float32 m_invMassA;
00103         float32 m_invMassB;
00104         float32 m_invIA;
00105         float32 m_invIB;
00106         b2Mat22 m_linearMass;
00107         float32 m_angularMass;
00108 };
00109 
00110 #endif
 All Classes Files Functions Variables Enumerations Enumerator Defines