Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019 #include <Box2D/Dynamics/Joints/b2Joint.h>
00020 #include <Box2D/Dynamics/Joints/b2DistanceJoint.h>
00021 #include <Box2D/Dynamics/Joints/b2WheelJoint.h>
00022 #include <Box2D/Dynamics/Joints/b2MouseJoint.h>
00023 #include <Box2D/Dynamics/Joints/b2RevoluteJoint.h>
00024 #include <Box2D/Dynamics/Joints/b2PrismaticJoint.h>
00025 #include <Box2D/Dynamics/Joints/b2PulleyJoint.h>
00026 #include <Box2D/Dynamics/Joints/b2GearJoint.h>
00027 #include <Box2D/Dynamics/Joints/b2WeldJoint.h>
00028 #include <Box2D/Dynamics/Joints/b2FrictionJoint.h>
00029 #include <Box2D/Dynamics/Joints/b2RopeJoint.h>
00030 #include <Box2D/Dynamics/Joints/b2MotorJoint.h>
00031 #include <Box2D/Dynamics/b2Body.h>
00032 #include <Box2D/Dynamics/b2World.h>
00033 #include <Box2D/Common/b2BlockAllocator.h>
00034
00035 #include <new>
00036
00037 b2Joint* b2Joint::Create(const b2JointDef* def, b2BlockAllocator* allocator)
00038 {
00039 b2Joint* joint = NULL;
00040
00041 switch (def->type)
00042 {
00043 case e_distanceJoint:
00044 {
00045 void* mem = allocator->Allocate(sizeof(b2DistanceJoint));
00046 joint = new (mem) b2DistanceJoint(static_cast<const b2DistanceJointDef*>(def));
00047 }
00048 break;
00049
00050 case e_mouseJoint:
00051 {
00052 void* mem = allocator->Allocate(sizeof(b2MouseJoint));
00053 joint = new (mem) b2MouseJoint(static_cast<const b2MouseJointDef*>(def));
00054 }
00055 break;
00056
00057 case e_prismaticJoint:
00058 {
00059 void* mem = allocator->Allocate(sizeof(b2PrismaticJoint));
00060 joint = new (mem) b2PrismaticJoint(static_cast<const b2PrismaticJointDef*>(def));
00061 }
00062 break;
00063
00064 case e_revoluteJoint:
00065 {
00066 void* mem = allocator->Allocate(sizeof(b2RevoluteJoint));
00067 joint = new (mem) b2RevoluteJoint(static_cast<const b2RevoluteJointDef*>(def));
00068 }
00069 break;
00070
00071 case e_pulleyJoint:
00072 {
00073 void* mem = allocator->Allocate(sizeof(b2PulleyJoint));
00074 joint = new (mem) b2PulleyJoint(static_cast<const b2PulleyJointDef*>(def));
00075 }
00076 break;
00077
00078 case e_gearJoint:
00079 {
00080 void* mem = allocator->Allocate(sizeof(b2GearJoint));
00081 joint = new (mem) b2GearJoint(static_cast<const b2GearJointDef*>(def));
00082 }
00083 break;
00084
00085 case e_wheelJoint:
00086 {
00087 void* mem = allocator->Allocate(sizeof(b2WheelJoint));
00088 joint = new (mem) b2WheelJoint(static_cast<const b2WheelJointDef*>(def));
00089 }
00090 break;
00091
00092 case e_weldJoint:
00093 {
00094 void* mem = allocator->Allocate(sizeof(b2WeldJoint));
00095 joint = new (mem) b2WeldJoint(static_cast<const b2WeldJointDef*>(def));
00096 }
00097 break;
00098
00099 case e_frictionJoint:
00100 {
00101 void* mem = allocator->Allocate(sizeof(b2FrictionJoint));
00102 joint = new (mem) b2FrictionJoint(static_cast<const b2FrictionJointDef*>(def));
00103 }
00104 break;
00105
00106 case e_ropeJoint:
00107 {
00108 void* mem = allocator->Allocate(sizeof(b2RopeJoint));
00109 joint = new (mem) b2RopeJoint(static_cast<const b2RopeJointDef*>(def));
00110 }
00111 break;
00112
00113 case e_motorJoint:
00114 {
00115 void* mem = allocator->Allocate(sizeof(b2MotorJoint));
00116 joint = new (mem) b2MotorJoint(static_cast<const b2MotorJointDef*>(def));
00117 }
00118 break;
00119
00120 default:
00121 b2Assert(false);
00122 break;
00123 }
00124
00125 return joint;
00126 }
00127
00128 void b2Joint::Destroy(b2Joint* joint, b2BlockAllocator* allocator)
00129 {
00130 joint->~b2Joint();
00131 switch (joint->m_type)
00132 {
00133 case e_distanceJoint:
00134 allocator->Free(joint, sizeof(b2DistanceJoint));
00135 break;
00136
00137 case e_mouseJoint:
00138 allocator->Free(joint, sizeof(b2MouseJoint));
00139 break;
00140
00141 case e_prismaticJoint:
00142 allocator->Free(joint, sizeof(b2PrismaticJoint));
00143 break;
00144
00145 case e_revoluteJoint:
00146 allocator->Free(joint, sizeof(b2RevoluteJoint));
00147 break;
00148
00149 case e_pulleyJoint:
00150 allocator->Free(joint, sizeof(b2PulleyJoint));
00151 break;
00152
00153 case e_gearJoint:
00154 allocator->Free(joint, sizeof(b2GearJoint));
00155 break;
00156
00157 case e_wheelJoint:
00158 allocator->Free(joint, sizeof(b2WheelJoint));
00159 break;
00160
00161 case e_weldJoint:
00162 allocator->Free(joint, sizeof(b2WeldJoint));
00163 break;
00164
00165 case e_frictionJoint:
00166 allocator->Free(joint, sizeof(b2FrictionJoint));
00167 break;
00168
00169 case e_ropeJoint:
00170 allocator->Free(joint, sizeof(b2RopeJoint));
00171 break;
00172
00173 case e_motorJoint:
00174 allocator->Free(joint, sizeof(b2MotorJoint));
00175 break;
00176
00177 default:
00178 b2Assert(false);
00179 break;
00180 }
00181 }
00182
00183 b2Joint::b2Joint(const b2JointDef* def)
00184 {
00185 b2Assert(def->bodyA != def->bodyB);
00186
00187 m_type = def->type;
00188 m_prev = NULL;
00189 m_next = NULL;
00190 m_bodyA = def->bodyA;
00191 m_bodyB = def->bodyB;
00192 m_index = 0;
00193 m_collideConnected = def->collideConnected;
00194 m_islandFlag = false;
00195 m_userData = def->userData;
00196
00197 m_edgeA.joint = NULL;
00198 m_edgeA.other = NULL;
00199 m_edgeA.prev = NULL;
00200 m_edgeA.next = NULL;
00201
00202 m_edgeB.joint = NULL;
00203 m_edgeB.other = NULL;
00204 m_edgeB.prev = NULL;
00205 m_edgeB.next = NULL;
00206 }
00207
00208 bool b2Joint::IsActive() const
00209 {
00210 return m_bodyA->IsActive() && m_bodyB->IsActive();
00211 }