b2Joint.h
Go to the documentation of this file.
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_JOINT_H
00020 #define B2_JOINT_H
00021 
00022 #include <Box2D/Common/b2Math.h>
00023 
00024 class b2Body;
00025 class b2Joint;
00026 struct b2SolverData;
00027 class b2BlockAllocator;
00028 
00029 enum b2JointType
00030 {
00031         e_unknownJoint,
00032         e_revoluteJoint,
00033         e_prismaticJoint,
00034         e_distanceJoint,
00035         e_pulleyJoint,
00036         e_mouseJoint,
00037         e_gearJoint,
00038         e_wheelJoint,
00039     e_weldJoint,
00040         e_frictionJoint,
00041         e_ropeJoint,
00042         e_motorJoint
00043 };
00044 
00045 enum b2LimitState
00046 {
00047         e_inactiveLimit,
00048         e_atLowerLimit,
00049         e_atUpperLimit,
00050         e_equalLimits
00051 };
00052 
00053 struct b2Jacobian
00054 {
00055         b2Vec2 linear;
00056         float32 angularA;
00057         float32 angularB;
00058 };
00059 
00065 struct b2JointEdge
00066 {
00067         b2Body* other;                  
00068         b2Joint* joint;                 
00069         b2JointEdge* prev;              
00070         b2JointEdge* next;              
00071 };
00072 
00074 struct b2JointDef
00075 {
00076         b2JointDef()
00077         {
00078                 type = e_unknownJoint;
00079                 userData = NULL;
00080                 bodyA = NULL;
00081                 bodyB = NULL;
00082                 collideConnected = false;
00083         }
00084 
00086         b2JointType type;
00087 
00089         void* userData;
00090 
00092         b2Body* bodyA;
00093 
00095         b2Body* bodyB;
00096 
00098         bool collideConnected;
00099 };
00100 
00103 class b2Joint
00104 {
00105 public:
00106 
00108         b2JointType GetType() const;
00109 
00111         b2Body* GetBodyA();
00112 
00114         b2Body* GetBodyB();
00115 
00117         virtual b2Vec2 GetAnchorA() const = 0;
00118 
00120         virtual b2Vec2 GetAnchorB() const = 0;
00121 
00123         virtual b2Vec2 GetReactionForce(float32 inv_dt) const = 0;
00124 
00126         virtual float32 GetReactionTorque(float32 inv_dt) const = 0;
00127 
00129         b2Joint* GetNext();
00130         const b2Joint* GetNext() const;
00131 
00133         void* GetUserData() const;
00134 
00136         void SetUserData(void* data);
00137 
00139         bool IsActive() const;
00140 
00144         bool GetCollideConnected() const;
00145 
00147         virtual void Dump() { b2Log("// Dump is not supported for this joint type.\n"); }
00148 
00150         virtual void ShiftOrigin(const b2Vec2& newOrigin) { B2_NOT_USED(newOrigin);  }
00151 
00152 protected:
00153         friend class b2World;
00154         friend class b2Body;
00155         friend class b2Island;
00156         friend class b2GearJoint;
00157 
00158         static b2Joint* Create(const b2JointDef* def, b2BlockAllocator* allocator);
00159         static void Destroy(b2Joint* joint, b2BlockAllocator* allocator);
00160 
00161         b2Joint(const b2JointDef* def);
00162         virtual ~b2Joint() {}
00163 
00164         virtual void InitVelocityConstraints(const b2SolverData& data) = 0;
00165         virtual void SolveVelocityConstraints(const b2SolverData& data) = 0;
00166 
00167         // This returns true if the position errors are within tolerance.
00168         virtual bool SolvePositionConstraints(const b2SolverData& data) = 0;
00169 
00170         b2JointType m_type;
00171         b2Joint* m_prev;
00172         b2Joint* m_next;
00173         b2JointEdge m_edgeA;
00174         b2JointEdge m_edgeB;
00175         b2Body* m_bodyA;
00176         b2Body* m_bodyB;
00177 
00178         int32 m_index;
00179 
00180         bool m_islandFlag;
00181         bool m_collideConnected;
00182 
00183         void* m_userData;
00184 };
00185 
00186 inline b2JointType b2Joint::GetType() const
00187 {
00188         return m_type;
00189 }
00190 
00191 inline b2Body* b2Joint::GetBodyA()
00192 {
00193         return m_bodyA;
00194 }
00195 
00196 inline b2Body* b2Joint::GetBodyB()
00197 {
00198         return m_bodyB;
00199 }
00200 
00201 inline b2Joint* b2Joint::GetNext()
00202 {
00203         return m_next;
00204 }
00205 
00206 inline const b2Joint* b2Joint::GetNext() const
00207 {
00208         return m_next;
00209 }
00210 
00211 inline void* b2Joint::GetUserData() const
00212 {
00213         return m_userData;
00214 }
00215 
00216 inline void b2Joint::SetUserData(void* data)
00217 {
00218         m_userData = data;
00219 }
00220 
00221 inline bool b2Joint::GetCollideConnected() const
00222 {
00223         return m_collideConnected;
00224 }
00225 
00226 #endif


mvsim
Author(s):
autogenerated on Thu Sep 7 2017 09:27:47