1 | //
|
---|
2 | // BtPhysTest
|
---|
3 | //
|
---|
4 | // Copyright: (c) 2009-2012 Benjamin Huet <huet.benjamin@gmail.com>
|
---|
5 | // (c) 2012 Sam Hocevar <sam@hocevar.net>
|
---|
6 | //
|
---|
7 |
|
---|
8 | #if defined HAVE_CONFIG_H
|
---|
9 | # include "config.h"
|
---|
10 | #endif
|
---|
11 |
|
---|
12 | #if defined _WIN32
|
---|
13 | # include <direct.h>
|
---|
14 | #endif
|
---|
15 |
|
---|
16 | #if defined _XBOX
|
---|
17 | # define _USE_MATH_DEFINES /* for M_PI */
|
---|
18 | # include <xtl.h>
|
---|
19 | # undef near /* Fuck Microsoft */
|
---|
20 | # undef far /* Fuck Microsoft again */
|
---|
21 | #elif defined _WIN32
|
---|
22 | # define _USE_MATH_DEFINES /* for M_PI */
|
---|
23 | # define WIN32_LEAN_AND_MEAN
|
---|
24 | # include <windows.h>
|
---|
25 | # undef near /* Fuck Microsoft */
|
---|
26 | # undef far /* Fuck Microsoft again */
|
---|
27 | #else
|
---|
28 | # include <cmath>
|
---|
29 | #endif
|
---|
30 |
|
---|
31 | #include "core.h"
|
---|
32 | #include "loldebug.h"
|
---|
33 |
|
---|
34 | using namespace lol;
|
---|
35 |
|
---|
36 | #ifndef HAVE_PHYS_USE_BULLET
|
---|
37 | #define HAVE_PHYS_USE_BULLET
|
---|
38 | #endif /* HAVE_PHYS_USE_BULLET */
|
---|
39 |
|
---|
40 | #include "Physics/LolPhysics.h"
|
---|
41 | #include "Physics/EasyPhysics.h"
|
---|
42 | #include "PhysicObject.h"
|
---|
43 | #include "BtPhysTest.h"
|
---|
44 |
|
---|
45 | using namespace lol::phys;
|
---|
46 |
|
---|
47 | #define CUBE_HALF_EXTENTS .5f
|
---|
48 | #define EXTRA_HEIGHT 1.f
|
---|
49 |
|
---|
50 | int gNumObjects = 64;
|
---|
51 |
|
---|
52 | BtPhysTest::BtPhysTest(bool editor)
|
---|
53 | {
|
---|
54 | /* Create a camera that matches the settings of XNA BtPhysTest */
|
---|
55 | m_camera = new Camera(vec3(0.f, 600.f, 0.f),
|
---|
56 | vec3(0.f, 0.f, 0.f),
|
---|
57 | vec3(0, 1, 0));
|
---|
58 | m_camera->SetRotation(quat::fromeuler_xyz(0.f, 0.f, 0.f));
|
---|
59 | m_camera->SetPerspective(45.f, 1280.f, 960.f, .1f, 1000.f);
|
---|
60 | //m_camera->SetOrtho(1280.f / 6, 960.f / 6, -1000.f, 1000.f);
|
---|
61 | Ticker::Ref(m_camera);
|
---|
62 |
|
---|
63 | m_ready = false;
|
---|
64 |
|
---|
65 | m_simulation = new Simulation();
|
---|
66 | m_simulation->Init();
|
---|
67 | vec3 NewGravity = vec3(.0f, -10.0f, .0f);
|
---|
68 | m_simulation->SetGravity(NewGravity);
|
---|
69 | m_simulation->SetContinuousDetection(true);
|
---|
70 | m_simulation->SetTimestep(1.f / 120.f);
|
---|
71 | Ticker::Ref(m_simulation);
|
---|
72 |
|
---|
73 | float offset = 29.5f;
|
---|
74 | vec3 pos_offset = vec3(.0f, 30.f, .0f);
|
---|
75 | for (int i=0; i < 6; i++)
|
---|
76 | {
|
---|
77 | vec3 NewPosition = vec3(.0f);
|
---|
78 | quat NewRotation = quat(1.f);
|
---|
79 |
|
---|
80 | PhysicsObject* NewPhyobj = new PhysicsObject(m_simulation, NewPosition, NewRotation);
|
---|
81 |
|
---|
82 | int idx = i/2;
|
---|
83 | NewPosition = pos_offset;
|
---|
84 | NewPosition[idx] += offset;
|
---|
85 | offset *= -1.f;
|
---|
86 |
|
---|
87 | if (idx != 1)
|
---|
88 | {
|
---|
89 | vec3 axis = vec3(.0f);
|
---|
90 | axis[2 - idx] = 1;
|
---|
91 | NewRotation = quat::rotate(90.f, axis);
|
---|
92 | }
|
---|
93 |
|
---|
94 | NewPhyobj->SetTransform(NewPosition, NewRotation);
|
---|
95 | Ticker::Ref(NewPhyobj);
|
---|
96 | m_ground_list << NewPhyobj;
|
---|
97 | }
|
---|
98 |
|
---|
99 | if (1)
|
---|
100 | {
|
---|
101 | for (int x=0; x < 6; x++)
|
---|
102 | {
|
---|
103 | for (int y=0; y < 6; y++)
|
---|
104 | {
|
---|
105 | for (int z=0; z < 5; z++)
|
---|
106 | {
|
---|
107 | PhysicsObject* new_physobj = new PhysicsObject(m_simulation, 1000.f,
|
---|
108 | vec3(-20.f, 15.f, -20.f) +
|
---|
109 | vec3(8.f * (float)x, 8.f * (float)y, 8.f * (float)z));
|
---|
110 | m_physobj_list << new_physobj;
|
---|
111 | Ticker::Ref(new_physobj);
|
---|
112 | }
|
---|
113 | }
|
---|
114 | }
|
---|
115 | }
|
---|
116 |
|
---|
117 | if (1)
|
---|
118 | {
|
---|
119 | Array<PhysicsObject*> RopeElements;
|
---|
120 | for (int i = 0; i < 14; i++)
|
---|
121 | {
|
---|
122 | PhysicsObject* new_physobj = new PhysicsObject(m_simulation, 1000.f,
|
---|
123 | vec3(0.f, 15.f, -20.f) +
|
---|
124 | vec3(0.f, 0.f, 2.f * (float)i), 1);
|
---|
125 | RopeElements << new_physobj;
|
---|
126 | m_physobj_list << new_physobj;
|
---|
127 | Ticker::Ref(new_physobj);
|
---|
128 | if (RopeElements.Count() > 1)
|
---|
129 | {
|
---|
130 | EasyConstraint* new_constraint = new EasyConstraint();
|
---|
131 |
|
---|
132 | vec3 A2B = .5f * (RopeElements[i]->GetPhysic()->GetTransform().v3.xyz -
|
---|
133 | RopeElements[i - 1]->GetPhysic()->GetTransform().v3.xyz);
|
---|
134 | new_constraint->SetPhysObjA(RopeElements[i - 1]->GetPhysic(), lol::mat4::translate(A2B));
|
---|
135 | new_constraint->SetPhysObjB(RopeElements[i]->GetPhysic(), lol::mat4::translate(-A2B));
|
---|
136 | new_constraint->InitConstraintToPoint2Point();
|
---|
137 | new_constraint->DisableCollisionBetweenObjs(true);
|
---|
138 | new_constraint->AddToSimulation(m_simulation);
|
---|
139 | m_constraint_list << new_constraint;
|
---|
140 | }
|
---|
141 | }
|
---|
142 | }
|
---|
143 |
|
---|
144 | #if 0
|
---|
145 | //init Physics
|
---|
146 | {
|
---|
147 | m_bt_ccd_mode = USE_CCD;
|
---|
148 |
|
---|
149 | //collision configuration contains default setup for memory, collision setup
|
---|
150 | m_bt_collision_config = new btDefaultCollisionConfiguration();
|
---|
151 |
|
---|
152 | //use the default collision dispatcher. For parallel processing you can use a diffent dispatcher (see Extras/BulletMultiThreaded)
|
---|
153 | m_bt_dispatcher = new btCollisionDispatcher(m_bt_collision_config);
|
---|
154 | m_bt_dispatcher->registerCollisionCreateFunc(BOX_SHAPE_PROXYTYPE,
|
---|
155 | BOX_SHAPE_PROXYTYPE,
|
---|
156 | m_bt_collision_config->getCollisionAlgorithmCreateFunc(CONVEX_SHAPE_PROXYTYPE,
|
---|
157 | CONVEX_SHAPE_PROXYTYPE));
|
---|
158 |
|
---|
159 | m_bt_broadphase = new btDbvtBroadphase();
|
---|
160 |
|
---|
161 | ///the default constraint solver. For parallel processing you can use a different solver (see Extras/BulletMultiThreaded)
|
---|
162 | m_bt_solver = new btSequentialImpulseConstraintSolver;
|
---|
163 |
|
---|
164 | m_bt_world = new btDiscreteDynamicsWorld(m_bt_dispatcher, m_bt_broadphase, m_bt_solver, m_bt_collision_config);
|
---|
165 | //m_bt_world->setDebugDrawer(&sDebugDrawer);
|
---|
166 | m_bt_world->getSolverInfo().m_splitImpulse = true;
|
---|
167 | m_bt_world->getSolverInfo().m_numIterations = 20;
|
---|
168 |
|
---|
169 | m_bt_world->getDispatchInfo().m_useContinuous = (m_bt_ccd_mode == USE_CCD);
|
---|
170 | m_bt_world->setGravity(btVector3(0,-10,0));
|
---|
171 |
|
---|
172 | ///create a few basic rigid bodies
|
---|
173 | btBoxShape* box = new btBoxShape(btVector3(btScalar(110.),btScalar(1.),btScalar(110.)));
|
---|
174 | btCollisionShape* groundShape = box;
|
---|
175 | m_bt_collision_shapes << groundShape;
|
---|
176 | m_ground_mesh.Compile("[sc#ddd afcb220 2 220 -1]");
|
---|
177 |
|
---|
178 | //m_bt_collision_shapes << new btCylinderShape(btVector3(.5f,.5f,.5f));
|
---|
179 |
|
---|
180 | btTransform groundTransform;
|
---|
181 | groundTransform.setIdentity();
|
---|
182 |
|
---|
183 | //We can also use DemoApplication::localCreateRigidBody, but for clarity it is provided here:
|
---|
184 | {
|
---|
185 | btScalar mass(0.);
|
---|
186 |
|
---|
187 | //rigidbody is dynamic if and only if mass is non zero, otherwise static
|
---|
188 | bool isDynamic = (mass != 0.f);
|
---|
189 |
|
---|
190 | btVector3 localInertia(0,0,0);
|
---|
191 | if (isDynamic)
|
---|
192 | groundShape->calculateLocalInertia(mass,localInertia);
|
---|
193 |
|
---|
194 | //using motionstate is recommended, it provides interpolation capabilities, and only synchronizes 'active' objects
|
---|
195 | btDefaultMotionState* myMotionState = new btDefaultMotionState(groundTransform);
|
---|
196 | btRigidBody::btRigidBodyConstructionInfo rbInfo(mass,myMotionState,groundShape,localInertia);
|
---|
197 | btRigidBody* body = new btRigidBody(rbInfo);
|
---|
198 |
|
---|
199 | //add the body to the dynamics world
|
---|
200 | m_bt_world->addRigidBody(body);
|
---|
201 | }
|
---|
202 |
|
---|
203 | //Adding Shapes
|
---|
204 | {
|
---|
205 | //create a few dynamic rigidbodies
|
---|
206 | // Re-using the same collision is better for memory usage and performance
|
---|
207 | btCollisionShape* colShape = new btBoxShape(btVector3(1,1,1));
|
---|
208 | m_rigid_mesh[0].Compile("[sc#add afcb2 2 2 -.1]");
|
---|
209 | m_rigid_mesh[1].Compile("[sc#dad afcb2 2 2 -.1]");
|
---|
210 | m_rigid_mesh[2].Compile("[sc#dda afcb2 2 2 -.1]");
|
---|
211 | m_rigid_mesh[3].Compile("[sc#daa afcb2 2 2 -.1]");
|
---|
212 | m_rigid_mesh[4].Compile("[sc#ada afcb2 2 2 -.1]");
|
---|
213 | m_rigid_mesh[5].Compile("[sc#aad afcb2 2 2 -.1]");
|
---|
214 |
|
---|
215 | m_bt_collision_shapes << colShape;
|
---|
216 | m_bt_dynamic_shapes << colShape;
|
---|
217 |
|
---|
218 | /// Create Dynamic Objects
|
---|
219 | btTransform startTransform;
|
---|
220 | startTransform.setIdentity();
|
---|
221 | btScalar mass(1.f);
|
---|
222 |
|
---|
223 | //rigidbody is dynamic if and only if mass is non zero, otherwise static
|
---|
224 | bool isDynamic = (mass != 0.f);
|
---|
225 |
|
---|
226 | btVector3 localInertia(0,0,0);
|
---|
227 | if (isDynamic)
|
---|
228 | colShape->calculateLocalInertia(mass,localInertia);
|
---|
229 |
|
---|
230 | int i;
|
---|
231 | for (i=0;i<gNumObjects;i++)
|
---|
232 | {
|
---|
233 | btCollisionShape* shape = colShape;
|
---|
234 | btTransform trans;
|
---|
235 | trans.setIdentity();
|
---|
236 |
|
---|
237 | //stack them
|
---|
238 | int colsize = 10;
|
---|
239 | int row = int(((float)i*CUBE_HALF_EXTENTS*2.0f)/((float)colsize*2.0f*CUBE_HALF_EXTENTS));
|
---|
240 | int row2 = row;
|
---|
241 | int col = (i)%(colsize)-colsize/2;
|
---|
242 |
|
---|
243 | if (col>3)
|
---|
244 | {
|
---|
245 | col=11;
|
---|
246 | row2 |=1;
|
---|
247 | }
|
---|
248 |
|
---|
249 | btVector3 pos(((row+col+row2) % 4)*CUBE_HALF_EXTENTS,
|
---|
250 | 20.0f + row*8*CUBE_HALF_EXTENTS+CUBE_HALF_EXTENTS+EXTRA_HEIGHT,
|
---|
251 | col*8*CUBE_HALF_EXTENTS + 2 * (row2%2)*CUBE_HALF_EXTENTS);
|
---|
252 |
|
---|
253 | trans.setOrigin(pos);
|
---|
254 |
|
---|
255 | float mass = 1.f;
|
---|
256 |
|
---|
257 |
|
---|
258 | btAssert((!shape || shape->getShapeType() != INVALID_SHAPE_PROXYTYPE));
|
---|
259 |
|
---|
260 | //rigidbody is dynamic if and only if mass is non zero, otherwise static
|
---|
261 | bool isDynamic = (mass != 0.f);
|
---|
262 |
|
---|
263 | btVector3 localInertia(0,0,0);
|
---|
264 | if (isDynamic)
|
---|
265 | shape->calculateLocalInertia(mass,localInertia);
|
---|
266 |
|
---|
267 | //using motionstate is recommended, it provides interpolation capabilities, and only synchronizes 'active' objects
|
---|
268 |
|
---|
269 | btDefaultMotionState* myMotionState = new btDefaultMotionState(trans);
|
---|
270 |
|
---|
271 | btRigidBody::btRigidBodyConstructionInfo cInfo(mass,myMotionState,shape,localInertia);
|
---|
272 |
|
---|
273 | btRigidBody* body = new btRigidBody(cInfo);
|
---|
274 | body->setContactProcessingThreshold(BT_LARGE_FLOAT);
|
---|
275 |
|
---|
276 | m_bt_world->addRigidBody(body);
|
---|
277 |
|
---|
278 | ///when using m_ccdMode
|
---|
279 | if (m_bt_ccd_mode == USE_CCD)
|
---|
280 | {
|
---|
281 | body->setCcdMotionThreshold(CUBE_HALF_EXTENTS);
|
---|
282 | body->setCcdSweptSphereRadius(0.9*CUBE_HALF_EXTENTS);
|
---|
283 | }
|
---|
284 | }
|
---|
285 | }
|
---|
286 | }
|
---|
287 | #endif
|
---|
288 | }
|
---|
289 |
|
---|
290 | void BtPhysTest::TickGame(float seconds)
|
---|
291 | {
|
---|
292 | WorldEntity::TickGame(seconds);
|
---|
293 |
|
---|
294 | if (Input::GetButtonState(27 /*SDLK_ESCAPE*/))
|
---|
295 | Ticker::Shutdown();
|
---|
296 |
|
---|
297 | vec3 GroundBarycenter = vec3(.0f);
|
---|
298 | vec3 PhysObjBarycenter = vec3(.0f);
|
---|
299 | float factor = .0f;
|
---|
300 |
|
---|
301 | for (int i = 0; i < m_ground_list.Count(); i++)
|
---|
302 | {
|
---|
303 | PhysicsObject* PhysObj = m_ground_list[i];
|
---|
304 | mat4 GroundMat = PhysObj->GetTransform();
|
---|
305 |
|
---|
306 | GroundBarycenter += GroundMat.v3.xyz;
|
---|
307 | factor += 1.f;
|
---|
308 | }
|
---|
309 |
|
---|
310 | GroundBarycenter /= factor;
|
---|
311 |
|
---|
312 | for (int i = 0; i < m_ground_list.Count(); i++)
|
---|
313 | {
|
---|
314 | PhysicsObject* PhysObj = m_ground_list[i];
|
---|
315 |
|
---|
316 | mat4 GroundMat = PhysObj->GetTransform();
|
---|
317 | vec3 CenterToGround = GroundMat.v3.xyz - GroundBarycenter;
|
---|
318 | vec3 CenterToCam = m_camera->m_position - GroundBarycenter;
|
---|
319 |
|
---|
320 | if (dot(normalize(CenterToCam - CenterToGround),
|
---|
321 | normalize(CenterToGround)) > 0.f)
|
---|
322 | PhysObj->SetRender(false);
|
---|
323 | else
|
---|
324 | PhysObj->SetRender(true);
|
---|
325 | }
|
---|
326 |
|
---|
327 | if (1)
|
---|
328 | {
|
---|
329 | for (int i = 0; i < m_ground_list.Count(); i++)
|
---|
330 | {
|
---|
331 | PhysicsObject* PhysObj = m_ground_list[i];
|
---|
332 |
|
---|
333 | mat4 GroundMat = PhysObj->GetTransform();
|
---|
334 | mat4 CenterMx = mat4::translate(GroundBarycenter);
|
---|
335 | GroundMat = inverse(CenterMx) * GroundMat;
|
---|
336 | GroundMat = CenterMx *
|
---|
337 | mat4(quat::fromeuler_xyz(vec3(.0f, 20.f, 20.0f) * seconds))
|
---|
338 | * GroundMat;
|
---|
339 | PhysObj->SetTransform(GroundMat.v3.xyz, quat(GroundMat));
|
---|
340 | }
|
---|
341 | }
|
---|
342 |
|
---|
343 | PhysObjBarycenter = vec3(.0f);
|
---|
344 | for (int i = 0; i < m_physobj_list.Count(); i++)
|
---|
345 | {
|
---|
346 | PhysicsObject* PhysObj = m_physobj_list[i];
|
---|
347 | mat4 GroundMat = PhysObj->GetTransform();
|
---|
348 |
|
---|
349 | PhysObjBarycenter += GroundMat.v3.xyz;
|
---|
350 | factor += 1.f;
|
---|
351 | }
|
---|
352 |
|
---|
353 | PhysObjBarycenter /= factor;
|
---|
354 |
|
---|
355 | m_camera->SetTarget(PhysObjBarycenter);
|
---|
356 | m_camera->SetPosition(GroundBarycenter + normalize(GroundBarycenter - PhysObjBarycenter) * 60.0f);
|
---|
357 |
|
---|
358 | #if 0
|
---|
359 | ///step the simulation
|
---|
360 | if (m_bt_world)
|
---|
361 | {
|
---|
362 | //int steps = (int)(seconds / 0.005f);
|
---|
363 | //for (int i = 0; i < steps; i++)
|
---|
364 | m_bt_world->stepSimulation(seconds /*/ steps*/);
|
---|
365 | //optional but useful: debug drawing
|
---|
366 | //m_bt_world->debugDrawWorld();
|
---|
367 | }
|
---|
368 | #endif
|
---|
369 | }
|
---|
370 |
|
---|
371 | void BtPhysTest::TickDraw(float seconds)
|
---|
372 | {
|
---|
373 | WorldEntity::TickDraw(seconds);
|
---|
374 |
|
---|
375 | if (!m_ready)
|
---|
376 | {
|
---|
377 | #if 0
|
---|
378 | m_ground_mesh.MeshConvert();
|
---|
379 | m_rigid_mesh[0].MeshConvert();
|
---|
380 | m_rigid_mesh[1].MeshConvert();
|
---|
381 | m_rigid_mesh[2].MeshConvert();
|
---|
382 | m_rigid_mesh[3].MeshConvert();
|
---|
383 | m_rigid_mesh[4].MeshConvert();
|
---|
384 | m_rigid_mesh[5].MeshConvert();
|
---|
385 | #endif
|
---|
386 | /* FIXME: this object never cleans up */
|
---|
387 | m_ready = true;
|
---|
388 | }
|
---|
389 |
|
---|
390 | Video::SetClearColor(vec4(0.0f, 0.0f, 0.12f, 1.0f));
|
---|
391 |
|
---|
392 | #if 0
|
---|
393 | vec3 BarycenterLocation = vec3(.0f);
|
---|
394 | float BarycenterFactor = 0.0f;
|
---|
395 | for(int i=0;i<gNumObjects;i++)
|
---|
396 | {
|
---|
397 | mat4 m(1.0f);
|
---|
398 | btMatrix3x3 rot; rot.setIdentity();
|
---|
399 | btCollisionObject* colObj = m_bt_world->getCollisionObjectArray()[i];
|
---|
400 | btRigidBody* body = btRigidBody::upcast(colObj);
|
---|
401 | if(body && body->getMotionState())
|
---|
402 | {
|
---|
403 | btDefaultMotionState* myMotionState = (btDefaultMotionState*)body->getMotionState();
|
---|
404 | myMotionState->m_graphicsWorldTrans.getOpenGLMatrix(&m[0][0]);
|
---|
405 | rot = myMotionState->m_graphicsWorldTrans.getBasis();
|
---|
406 | }
|
---|
407 | else
|
---|
408 | {
|
---|
409 | colObj->getWorldTransform().getOpenGLMatrix(&m[0][0]);
|
---|
410 | rot = colObj->getWorldTransform().getBasis();
|
---|
411 | }
|
---|
412 | if (i > 0)
|
---|
413 | {
|
---|
414 | BarycenterLocation += m.v3.xyz;
|
---|
415 | BarycenterFactor += 1.0f;
|
---|
416 | }
|
---|
417 | if (i == 0)
|
---|
418 | m_ground_mesh.Render(m);
|
---|
419 | else
|
---|
420 | m_rigid_mesh[i % 6].Render(m);
|
---|
421 | }
|
---|
422 | if (BarycenterFactor > .0f)
|
---|
423 | {
|
---|
424 | BarycenterLocation /= BarycenterFactor;
|
---|
425 |
|
---|
426 | m_camera->SetTarget(BarycenterLocation);
|
---|
427 | m_camera->SetPosition(BarycenterLocation + vec3(-20.0f, 8.0f, .0f));
|
---|
428 | }
|
---|
429 | #endif
|
---|
430 | }
|
---|
431 |
|
---|
432 | BtPhysTest::~BtPhysTest()
|
---|
433 | {
|
---|
434 | Ticker::Unref(m_camera);
|
---|
435 |
|
---|
436 | while (m_constraint_list.Count())
|
---|
437 | {
|
---|
438 | EasyConstraint* CurPop = m_constraint_list.Last();
|
---|
439 | m_constraint_list.Pop();
|
---|
440 | CurPop->RemoveFromSimulation(m_simulation);
|
---|
441 | delete CurPop;
|
---|
442 | }
|
---|
443 | while (m_ground_list.Count())
|
---|
444 | {
|
---|
445 | PhysicsObject* CurPop = m_ground_list.Last();
|
---|
446 | m_ground_list.Pop();
|
---|
447 | CurPop->GetPhysic()->RemoveFromSimulation(m_simulation);
|
---|
448 | Ticker::Unref(CurPop);
|
---|
449 | }
|
---|
450 | while (m_physobj_list.Count())
|
---|
451 | {
|
---|
452 | PhysicsObject* CurPop = m_physobj_list.Last();
|
---|
453 | m_physobj_list.Pop();
|
---|
454 | CurPop->GetPhysic()->RemoveFromSimulation(m_simulation);
|
---|
455 | Ticker::Unref(CurPop);
|
---|
456 | }
|
---|
457 | Ticker::Unref(m_simulation);
|
---|
458 |
|
---|
459 | #if 0
|
---|
460 | //Exit Physics
|
---|
461 | {
|
---|
462 | //cleanup in the reverse order of creation/initialization
|
---|
463 | //remove the rigidbodies from the dynamics world and delete them
|
---|
464 | for (int i = m_bt_world->getNumCollisionObjects() - 1; i >= 0 ;i--)
|
---|
465 | {
|
---|
466 | btCollisionObject* obj = m_bt_world->getCollisionObjectArray()[i];
|
---|
467 | btRigidBody* body = btRigidBody::upcast(obj);
|
---|
468 | if (body && body->getMotionState())
|
---|
469 | delete body->getMotionState();
|
---|
470 |
|
---|
471 | m_bt_world->removeCollisionObject(obj);
|
---|
472 | delete obj;
|
---|
473 | }
|
---|
474 |
|
---|
475 | //delete collision shapes
|
---|
476 | for (int j = 0; j < m_bt_collision_shapes.Count(); j++)
|
---|
477 | {
|
---|
478 | btCollisionShape* shape = m_bt_collision_shapes[j];
|
---|
479 | delete shape;
|
---|
480 | }
|
---|
481 | m_bt_collision_shapes.Empty();
|
---|
482 |
|
---|
483 | delete m_bt_world;
|
---|
484 | delete m_bt_solver;
|
---|
485 | delete m_bt_broadphase;
|
---|
486 | delete m_bt_dispatcher;
|
---|
487 | delete m_bt_collision_config;
|
---|
488 | }
|
---|
489 | #endif
|
---|
490 | }
|
---|
491 |
|
---|
492 | int main(int argc, char **argv)
|
---|
493 | {
|
---|
494 | Application app("BtPhysTest", ivec2(1280, 720), 60.0f);
|
---|
495 |
|
---|
496 | #if defined _MSC_VER && !defined _XBOX
|
---|
497 | _chdir("..");
|
---|
498 | #elif defined _WIN32 && !defined _XBOX
|
---|
499 | _chdir("../..");
|
---|
500 | #endif
|
---|
501 |
|
---|
502 | new BtPhysTest(argc > 1);
|
---|
503 | app.ShowPointer(false);
|
---|
504 |
|
---|
505 | app.Run();
|
---|
506 |
|
---|
507 | return EXIT_SUCCESS;
|
---|
508 | }
|
---|
509 |
|
---|