| Box2D 2.2.1 A 2D Physics Engine for Games

- Main Page
- Classes
- Files

- File List
- File Members

b2Joint.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_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 };
    00043
    00044 enum b2LimitState
    00045 {
    00046         e_inactiveLimit,
    00047         e_atLowerLimit,
    00048         e_atUpperLimit,
    00049         e_equalLimits
    00050 };
    00051
    00052 struct b2Jacobian
    00053 {
    00054         b2Vec2 linear;
    00055         float32 angularA;
    00056         float32 angularB;
    00057 };
    00058
    00064 struct b2JointEdge
    00065 {
    00066         b2Body* other;
    00067         b2Joint* joint;
    00068         b2JointEdge* prev;
    00069         b2JointEdge* next;
    00070 };
    00071
    00073 struct b2JointDef
    00074 {
    00075         b2JointDef()
    00076         {
    00077                 type = e_unknownJoint;
    00078                 userData = NULL;
    00079                 bodyA = NULL;
    00080                 bodyB = NULL;
    00081                 collideConnected = false;
    00082         }
    00083
    00085         b2JointType type;
    00086
    00088         void* userData;
    00089
    00091         b2Body* bodyA;
    00092
    00094         b2Body* bodyB;
    00095
    00097         bool collideConnected;
    00098 };
    00099
    00102 class b2Joint
    00103 {
    00104 public:
    00105
    00107         b2JointType GetType() const;
    00108
    00110         b2Body* GetBodyA();
    00111
    00113         b2Body* GetBodyB();
    00114
    00116         virtual b2Vec2 GetAnchorA() const = 0;
    00117
    00119         virtual b2Vec2 GetAnchorB() const = 0;
    00120
    00122         virtual b2Vec2 GetReactionForce(float32 inv_dt) const = 0;
    00123
    00125         virtual float32 GetReactionTorque(float32 inv_dt) const = 0;
    00126
    00128         b2Joint* GetNext();
    00129         const b2Joint* GetNext() const;
    00130
    00132         void* GetUserData() const;
    00133
    00135         void SetUserData(void* data);
    00136
    00138         bool IsActive() const;
    00139
    00143         bool GetCollideConnected() const;
    00144
    00146         virtual void Dump() { b2Log("// Dump is not supported for this joint type.\n"); }
    00147
    00148 protected:
    00149         friend class b2World;
    00150         friend class b2Body;
    00151         friend class b2Island;
    00152         friend class b2GearJoint;
    00153
    00154         static b2Joint* Create(const b2JointDef* def, b2BlockAllocator* allocator);
    00155         static void Destroy(b2Joint* joint, b2BlockAllocator* allocator);
    00156
    00157         b2Joint(const b2JointDef* def);
    00158         virtual ~b2Joint() {}
    00159
    00160         virtual void InitVelocityConstraints(const b2SolverData& data) = 0;
    00161         virtual void SolveVelocityConstraints(const b2SolverData& data) = 0;
    00162
    00163         // This returns true if the position errors are within tolerance.
    00164         virtual bool SolvePositionConstraints(const b2SolverData& data) = 0;
    00165
    00166         b2JointType m_type;
    00167         b2Joint* m_prev;
    00168         b2Joint* m_next;
    00169         b2JointEdge m_edgeA;
    00170         b2JointEdge m_edgeB;
    00171         b2Body* m_bodyA;
    00172         b2Body* m_bodyB;
    00173
    00174         int32 m_index;
    00175
    00176         bool m_islandFlag;
    00177         bool m_collideConnected;
    00178
    00179         void* m_userData;
    00180 };
    00181
    00182 inline b2JointType b2Joint::GetType() const
    00183 {
    00184         return m_type;
    00185 }
    00186
    00187 inline b2Body* b2Joint::GetBodyA()
    00188 {
    00189         return m_bodyA;
    00190 }
    00191
    00192 inline b2Body* b2Joint::GetBodyB()
    00193 {
    00194         return m_bodyB;
    00195 }
    00196
    00197 inline b2Joint* b2Joint::GetNext()
    00198 {
    00199         return m_next;
    00200 }
    00201
    00202 inline const b2Joint* b2Joint::GetNext() const
    00203 {
    00204         return m_next;
    00205 }
    00206
    00207 inline void* b2Joint::GetUserData() const
    00208 {
    00209         return m_userData;
    00210 }
    00211
    00212 inline void b2Joint::SetUserData(void* data)
    00213 {
    00214         m_userData = data;
    00215 }
    00216
    00217 inline bool b2Joint::GetCollideConnected() const
    00218 {
    00219         return m_collideConnected;
    00220 }
    00221
    00222 #endif

All Classes Files Functions Variables Enumerations Enumerator Defines