b2Joint.cpp
Go to the documentation of this file.
1 /*
2 * Copyright (c) 2006-2007 Erin Catto http://www.box2d.org
3 *
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.
17 */
18 
31 #include <Box2D/Dynamics/b2Body.h>
32 #include <Box2D/Dynamics/b2World.h>
34 
35 #include <new>
36 
38 {
39  b2Joint* joint = NULL;
40 
41  switch (def->type)
42  {
43  case e_distanceJoint:
44  {
45  void* mem = allocator->Allocate(sizeof(b2DistanceJoint));
46  joint = new (mem) b2DistanceJoint(static_cast<const b2DistanceJointDef*>(def));
47  }
48  break;
49 
50  case e_mouseJoint:
51  {
52  void* mem = allocator->Allocate(sizeof(b2MouseJoint));
53  joint = new (mem) b2MouseJoint(static_cast<const b2MouseJointDef*>(def));
54  }
55  break;
56 
57  case e_prismaticJoint:
58  {
59  void* mem = allocator->Allocate(sizeof(b2PrismaticJoint));
60  joint = new (mem) b2PrismaticJoint(static_cast<const b2PrismaticJointDef*>(def));
61  }
62  break;
63 
64  case e_revoluteJoint:
65  {
66  void* mem = allocator->Allocate(sizeof(b2RevoluteJoint));
67  joint = new (mem) b2RevoluteJoint(static_cast<const b2RevoluteJointDef*>(def));
68  }
69  break;
70 
71  case e_pulleyJoint:
72  {
73  void* mem = allocator->Allocate(sizeof(b2PulleyJoint));
74  joint = new (mem) b2PulleyJoint(static_cast<const b2PulleyJointDef*>(def));
75  }
76  break;
77 
78  case e_gearJoint:
79  {
80  void* mem = allocator->Allocate(sizeof(b2GearJoint));
81  joint = new (mem) b2GearJoint(static_cast<const b2GearJointDef*>(def));
82  }
83  break;
84 
85  case e_wheelJoint:
86  {
87  void* mem = allocator->Allocate(sizeof(b2WheelJoint));
88  joint = new (mem) b2WheelJoint(static_cast<const b2WheelJointDef*>(def));
89  }
90  break;
91 
92  case e_weldJoint:
93  {
94  void* mem = allocator->Allocate(sizeof(b2WeldJoint));
95  joint = new (mem) b2WeldJoint(static_cast<const b2WeldJointDef*>(def));
96  }
97  break;
98 
99  case e_frictionJoint:
100  {
101  void* mem = allocator->Allocate(sizeof(b2FrictionJoint));
102  joint = new (mem) b2FrictionJoint(static_cast<const b2FrictionJointDef*>(def));
103  }
104  break;
105 
106  case e_ropeJoint:
107  {
108  void* mem = allocator->Allocate(sizeof(b2RopeJoint));
109  joint = new (mem) b2RopeJoint(static_cast<const b2RopeJointDef*>(def));
110  }
111  break;
112 
113  case e_motorJoint:
114  {
115  void* mem = allocator->Allocate(sizeof(b2MotorJoint));
116  joint = new (mem) b2MotorJoint(static_cast<const b2MotorJointDef*>(def));
117  }
118  break;
119 
120  default:
121  b2Assert(false);
122  break;
123  }
124 
125  return joint;
126 }
127 
128 void b2Joint::Destroy(b2Joint* joint, b2BlockAllocator* allocator)
129 {
130  joint->~b2Joint();
131  switch (joint->m_type)
132  {
133  case e_distanceJoint:
134  allocator->Free(joint, sizeof(b2DistanceJoint));
135  break;
136 
137  case e_mouseJoint:
138  allocator->Free(joint, sizeof(b2MouseJoint));
139  break;
140 
141  case e_prismaticJoint:
142  allocator->Free(joint, sizeof(b2PrismaticJoint));
143  break;
144 
145  case e_revoluteJoint:
146  allocator->Free(joint, sizeof(b2RevoluteJoint));
147  break;
148 
149  case e_pulleyJoint:
150  allocator->Free(joint, sizeof(b2PulleyJoint));
151  break;
152 
153  case e_gearJoint:
154  allocator->Free(joint, sizeof(b2GearJoint));
155  break;
156 
157  case e_wheelJoint:
158  allocator->Free(joint, sizeof(b2WheelJoint));
159  break;
160 
161  case e_weldJoint:
162  allocator->Free(joint, sizeof(b2WeldJoint));
163  break;
164 
165  case e_frictionJoint:
166  allocator->Free(joint, sizeof(b2FrictionJoint));
167  break;
168 
169  case e_ropeJoint:
170  allocator->Free(joint, sizeof(b2RopeJoint));
171  break;
172 
173  case e_motorJoint:
174  allocator->Free(joint, sizeof(b2MotorJoint));
175  break;
176 
177  default:
178  b2Assert(false);
179  break;
180  }
181 }
182 
184 {
185  b2Assert(def->bodyA != def->bodyB);
186 
187  m_type = def->type;
188  m_prev = NULL;
189  m_next = NULL;
190  m_bodyA = def->bodyA;
191  m_bodyB = def->bodyB;
192  m_index = 0;
194  m_islandFlag = false;
195  m_userData = def->userData;
196 
197  m_edgeA.joint = NULL;
198  m_edgeA.other = NULL;
199  m_edgeA.prev = NULL;
200  m_edgeA.next = NULL;
201 
202  m_edgeB.joint = NULL;
203  m_edgeB.other = NULL;
204  m_edgeB.prev = NULL;
205  m_edgeB.next = NULL;
206 }
207 
208 bool b2Joint::IsActive() const
209 {
210  return m_bodyA->IsActive() && m_bodyB->IsActive();
211 }
static void Destroy(b2Joint *joint, b2BlockAllocator *allocator)
Definition: b2Joint.cpp:128
Joint definitions are used to construct joints.
Definition: b2Joint.h:74
b2JointEdge * prev
the previous joint edge in the body&#39;s joint list
Definition: b2Joint.h:69
bool m_collideConnected
Definition: b2Joint.h:181
void Free(void *p, int32 size)
Free memory. This will use b2Free if the size is larger than b2_maxBlockSize.
int32 m_index
Definition: b2Joint.h:178
b2Joint * m_prev
Definition: b2Joint.h:171
b2Body * other
provides quick access to the other body attached.
Definition: b2Joint.h:67
b2JointEdge m_edgeB
Definition: b2Joint.h:174
b2Joint * joint
the joint
Definition: b2Joint.h:68
void * Allocate(int32 size)
Allocate memory. This will use b2Alloc if the size is larger than b2_maxBlockSize.
b2Joint * m_next
Definition: b2Joint.h:172
bool collideConnected
Set this flag to true if the attached bodies should collide.
Definition: b2Joint.h:98
void * userData
Use this to attach application specific data to your joints.
Definition: b2Joint.h:89
b2JointType m_type
Definition: b2Joint.h:170
void * m_userData
Definition: b2Joint.h:183
b2Body * m_bodyA
Definition: b2Joint.h:175
bool IsActive() const
Get the active state of the body.
Definition: b2Body.h:659
b2Joint(const b2JointDef *def)
Definition: b2Joint.cpp:183
#define b2Assert(A)
Definition: b2Settings.h:27
b2JointType type
The joint type is set automatically for concrete joint types.
Definition: b2Joint.h:86
bool IsActive() const
Short-cut function to determine if either body is inactive.
Definition: b2Joint.cpp:208
virtual ~b2Joint()
Definition: b2Joint.h:162
friend class b2GearJoint
Definition: b2Joint.h:156
b2Body * bodyA
The first attached body.
Definition: b2Joint.h:92
static b2Joint * Create(const b2JointDef *def, b2BlockAllocator *allocator)
Definition: b2Joint.cpp:37
b2JointEdge m_edgeA
Definition: b2Joint.h:173
b2Body * bodyB
The second attached body.
Definition: b2Joint.h:95
b2JointEdge * next
the next joint edge in the body&#39;s joint list
Definition: b2Joint.h:70
b2Body * m_bodyB
Definition: b2Joint.h:176
bool m_islandFlag
Definition: b2Joint.h:180


mvsim
Author(s):
autogenerated on Fri May 7 2021 03:05:51