File indexing completed on 2024-12-29 03:29:26
0001 /* 0002 * Copyright (c) 2006-2007 Erin Catto http://www.box2d.org 0003 * 0004 * This software is provided 'as-is', without any express or implied 0005 * warranty. In no event will the authors be held liable for any damages 0006 * arising from the use of this software. 0007 * Permission is granted to anyone to use this software for any purpose, 0008 * including commercial applications, and to alter it and redistribute it 0009 * freely, subject to the following restrictions: 0010 * 1. The origin of this software must not be misrepresented; you must not 0011 * claim that you wrote the original software. If you use this software 0012 * in a product, an acknowledgment in the product documentation would be 0013 * appreciated but is not required. 0014 * 2. Altered source versions must be plainly marked as such, and must not be 0015 * misrepresented as being the original software. 0016 * 3. This notice may not be removed or altered from any source distribution. 0017 */ 0018 0019 #ifndef B2_FRICTION_JOINT_H 0020 #define B2_FRICTION_JOINT_H 0021 0022 #include <Box2D/Dynamics/Joints/b2Joint.h> 0023 0024 /// Friction joint definition. 0025 struct b2FrictionJointDef : public b2JointDef 0026 { 0027 b2FrictionJointDef() 0028 { 0029 type = e_frictionJoint; 0030 localAnchorA.SetZero(); 0031 localAnchorB.SetZero(); 0032 maxForce = 0.0f; 0033 maxTorque = 0.0f; 0034 } 0035 0036 /// Initialize the bodies, anchors, axis, and reference angle using the world 0037 /// anchor and world axis. 0038 void Initialize(b2Body* bodyA, b2Body* bodyB, const b2Vec2& anchor); 0039 0040 /// The local anchor point relative to bodyA's origin. 0041 b2Vec2 localAnchorA; 0042 0043 /// The local anchor point relative to bodyB's origin. 0044 b2Vec2 localAnchorB; 0045 0046 /// The maximum friction force in N. 0047 float32 maxForce; 0048 0049 /// The maximum friction torque in N-m. 0050 float32 maxTorque; 0051 }; 0052 0053 /// Friction joint. This is used for top-down friction. 0054 /// It provides 2D translational friction and angular friction. 0055 class b2FrictionJoint : public b2Joint 0056 { 0057 public: 0058 b2Vec2 GetAnchorA() const; 0059 b2Vec2 GetAnchorB() const; 0060 0061 b2Vec2 GetReactionForce(float32 inv_dt) const; 0062 float32 GetReactionTorque(float32 inv_dt) const; 0063 0064 /// The local anchor point relative to bodyA's origin. 0065 const b2Vec2& GetLocalAnchorA() const { return m_localAnchorA; } 0066 0067 /// The local anchor point relative to bodyB's origin. 0068 const b2Vec2& GetLocalAnchorB() const { return m_localAnchorB; } 0069 0070 /// Set the maximum friction force in N. 0071 void SetMaxForce(float32 force); 0072 0073 /// Get the maximum friction force in N. 0074 float32 GetMaxForce() const; 0075 0076 /// Set the maximum friction torque in N*m. 0077 void SetMaxTorque(float32 torque); 0078 0079 /// Get the maximum friction torque in N*m. 0080 float32 GetMaxTorque() const; 0081 0082 /// Dump joint to dmLog 0083 void Dump(); 0084 0085 protected: 0086 0087 friend class b2Joint; 0088 0089 b2FrictionJoint(const b2FrictionJointDef* def); 0090 0091 void InitVelocityConstraints(const b2SolverData& data); 0092 void SolveVelocityConstraints(const b2SolverData& data); 0093 bool SolvePositionConstraints(const b2SolverData& data); 0094 0095 b2Vec2 m_localAnchorA; 0096 b2Vec2 m_localAnchorB; 0097 0098 // Solver shared 0099 b2Vec2 m_linearImpulse; 0100 float32 m_angularImpulse; 0101 float32 m_maxForce; 0102 float32 m_maxTorque; 0103 0104 // Solver temp 0105 int32 m_indexA; 0106 int32 m_indexB; 0107 b2Vec2 m_rA; 0108 b2Vec2 m_rB; 0109 b2Vec2 m_localCenterA; 0110 b2Vec2 m_localCenterB; 0111 float32 m_invMassA; 0112 float32 m_invMassB; 0113 float32 m_invIA; 0114 float32 m_invIB; 0115 b2Mat22 m_linearMass; 0116 float32 m_angularMass; 0117 }; 0118 0119 #endif