2 * Copyright (c) 2006-2007 Erin Catto http://www.gphysics.com
4 * This software is provided 'as-is', without any express or implied
5 * warranty. In no event will the authors be held liable for any damages
6 * arising from the use of this software.
7 * Permission is granted to anyone to use this software for any purpose,
8 * including commercial applications, and to alter it and redistribute it
9 * freely, subject to the following restrictions:
10 * 1. The origin of this software must not be misrepresented; you must not
11 * claim that you wrote the original software. If you use this software
12 * in a product, an acknowledgment in the product documentation would be
13 * appreciated but is not required.
14 * 2. Altered source versions must be plainly marked as such, and must not be
15 * misrepresented as being the original software.
16 * 3. This notice may not be removed or altered from any source distribution.
20 #include "b2DistanceJoint.h"
21 #include "b2MouseJoint.h"
22 #include "b2RevoluteJoint.h"
23 #include "b2PrismaticJoint.h"
24 #include "b2PulleyJoint.h"
25 #include "b2GearJoint.h"
26 #include "../b2Body.h"
27 #include "../b2World.h"
28 #include "../../Common/b2BlockAllocator.h"
29 #include "../../Collision/b2BroadPhase.h"
33 b2Joint* b2Joint::Create(const b2JointDef* def, b2BlockAllocator* allocator)
35 b2Joint* joint = NULL;
41 void* mem = allocator->Allocate(sizeof(b2DistanceJoint));
42 joint = new (mem) b2DistanceJoint((b2DistanceJointDef*)def);
48 void* mem = allocator->Allocate(sizeof(b2MouseJoint));
49 joint = new (mem) b2MouseJoint((b2MouseJointDef*)def);
53 case e_prismaticJoint:
55 void* mem = allocator->Allocate(sizeof(b2PrismaticJoint));
56 joint = new (mem) b2PrismaticJoint((b2PrismaticJointDef*)def);
62 void* mem = allocator->Allocate(sizeof(b2RevoluteJoint));
63 joint = new (mem) b2RevoluteJoint((b2RevoluteJointDef*)def);
69 void* mem = allocator->Allocate(sizeof(b2PulleyJoint));
70 joint = new (mem) b2PulleyJoint((b2PulleyJointDef*)def);
76 void* mem = allocator->Allocate(sizeof(b2GearJoint));
77 joint = new (mem) b2GearJoint((b2GearJointDef*)def);
89 void b2Joint::Destroy(b2Joint* joint, b2BlockAllocator* allocator)
92 switch (joint->m_type)
95 allocator->Free(joint, sizeof(b2DistanceJoint));
99 allocator->Free(joint, sizeof(b2MouseJoint));
102 case e_prismaticJoint:
103 allocator->Free(joint, sizeof(b2PrismaticJoint));
106 case e_revoluteJoint:
107 allocator->Free(joint, sizeof(b2RevoluteJoint));
111 allocator->Free(joint, sizeof(b2PulleyJoint));
115 allocator->Free(joint, sizeof(b2GearJoint));
124 b2Joint::b2Joint(const b2JointDef* def)
129 m_body1 = def->body1;
130 m_body2 = def->body2;
131 m_collideConnected = def->collideConnected;
132 m_islandFlag = false;
133 m_userData = def->userData;