demo_trimesh.cpp 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605
  1. /*************************************************************************
  2. * *
  3. * Open Dynamics Engine, Copyright (C) 2001-2003 Russell L. Smith. *
  4. * All rights reserved. Email: [email protected] Web: www.q12.org *
  5. * *
  6. * This library is free software; you can redistribute it and/or *
  7. * modify it under the terms of EITHER: *
  8. * (1) The GNU Lesser General Public License as published by the Free *
  9. * Software Foundation; either version 2.1 of the License, or (at *
  10. * your option) any later version. The text of the GNU Lesser *
  11. * General Public License is included with this library in the *
  12. * file LICENSE.TXT. *
  13. * (2) The BSD-style license that is included with this library in *
  14. * the file LICENSE-BSD.TXT. *
  15. * *
  16. * This library is distributed in the hope that it will be useful, *
  17. * but WITHOUT ANY WARRANTY; without even the implied warranty of *
  18. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the files *
  19. * LICENSE.TXT and LICENSE-BSD.TXT for more details. *
  20. * *
  21. *************************************************************************/
  22. // TriMesh test by Erwin de Vries
  23. #include <ode/ode.h>
  24. #include <drawstuff/drawstuff.h>
  25. #include "texturepath.h"
  26. #ifdef _MSC_VER
  27. #pragma warning(disable:4244 4305) // for VC++, no precision loss complaints
  28. #endif
  29. //<---- Convex Object
  30. static const dReal planes[] = // planes for a cube
  31. {
  32. 1.0f ,0.0f ,0.0f ,0.25f,
  33. 0.0f ,1.0f ,0.0f ,0.25f,
  34. 0.0f ,0.0f ,1.0f ,0.25f,
  35. 0.0f ,0.0f ,-1.0f,0.25f,
  36. 0.0f ,-1.0f,0.0f ,0.25f,
  37. -1.0f,0.0f ,0.0f ,0.25f
  38. /*
  39. 1.0f ,0.0f ,0.0f ,2.0f,
  40. 0.0f ,1.0f ,0.0f ,1.0f,
  41. 0.0f ,0.0f ,1.0f ,1.0f,
  42. 0.0f ,0.0f ,-1.0f,1.0f,
  43. 0.0f ,-1.0f,0.0f ,1.0f,
  44. -1.0f,0.0f ,0.0f ,0.0f
  45. */
  46. };
  47. static const unsigned int planecount=6;
  48. static const dReal points[] = // points for a cube
  49. {
  50. 0.25f,0.25f,0.25f,
  51. -0.25f,0.25f,0.25f,
  52. 0.25f,-0.25f,0.25f,
  53. -0.25f,-0.25f,0.25f,
  54. 0.25f,0.25f,-0.25f,
  55. -0.25f,0.25f,-0.25f,
  56. 0.25f,-0.25f,-0.25f,
  57. -0.25f,-0.25f,-0.25f,
  58. };
  59. static const unsigned int pointcount=8;
  60. static const unsigned int polygons[] = //Polygons for a cube (6 squares)
  61. {
  62. 4,0,2,6,4, // positive X
  63. 4,1,0,4,5, // positive Y
  64. 4,0,1,3,2, // positive Z
  65. 4,3,1,5,7, // negative X
  66. 4,2,3,7,6, // negative Y
  67. 4,5,4,6,7, // negative Z
  68. };
  69. //----> Convex Object
  70. // select correct drawing functions
  71. #ifdef dDOUBLE
  72. #define dsDrawBox dsDrawBoxD
  73. #define dsDrawSphere dsDrawSphereD
  74. #define dsDrawCylinder dsDrawCylinderD
  75. #define dsDrawCapsule dsDrawCapsuleD
  76. #define dsDrawLine dsDrawLineD
  77. #define dsDrawTriangle dsDrawTriangleD
  78. #define dsDrawConvex dsDrawConvexD
  79. #endif
  80. // some constants
  81. #define NUM 200 // max number of objects
  82. #define DENSITY (5.0) // density of all objects
  83. #define GPB 3 // maximum number of geometries per body
  84. #define MAX_CONTACTS 40 // maximum number of contact points per body
  85. // dynamics and collision objects
  86. struct MyObject {
  87. dBodyID body; // the body
  88. dGeomID geom[GPB]; // geometries representing this body
  89. };
  90. static int num=0; // number of objects in simulation
  91. static int nextobj=0; // next object to recycle if num==NUM
  92. static dWorldID world;
  93. static dSpaceID space;
  94. static MyObject obj[NUM];
  95. static dJointGroupID contactgroup;
  96. static int selected = -1; // selected object
  97. static int show_aabb = 0; // show geom AABBs?
  98. static int show_contacts = 0; // show contact points?
  99. static int random_pos = 1; // drop objects from random position?
  100. #define VertexCount 5
  101. #define IndexCount 12
  102. static dVector3 Size;
  103. static float Vertices[VertexCount][3];
  104. static dTriIndex Indices[IndexCount];
  105. static dGeomID TriMesh;
  106. static dGeomID Ray;
  107. // this is called by dSpaceCollide when two objects in space are
  108. // potentially colliding.
  109. static void nearCallback (void *, dGeomID o1, dGeomID o2)
  110. {
  111. int i;
  112. // if (o1->body && o2->body) return;
  113. // exit without doing anything if the two bodies are connected by a joint
  114. dBodyID b1 = dGeomGetBody(o1);
  115. dBodyID b2 = dGeomGetBody(o2);
  116. if (b1 && b2 && dAreConnectedExcluding (b1,b2,dJointTypeContact)) return;
  117. dContact contact[MAX_CONTACTS]; // up to MAX_CONTACTS contacts per box-box
  118. for (i=0; i<MAX_CONTACTS; i++) {
  119. contact[i].surface.mode = dContactBounce | dContactSoftCFM;
  120. contact[i].surface.mu = dInfinity;
  121. contact[i].surface.mu2 = 0;
  122. contact[i].surface.bounce = 0.1;
  123. contact[i].surface.bounce_vel = 0.1;
  124. contact[i].surface.soft_cfm = 0.01;
  125. }
  126. if (int numc = dCollide (o1,o2,MAX_CONTACTS,&contact[0].geom,
  127. sizeof(dContact))) {
  128. dMatrix3 RI;
  129. dRSetIdentity (RI);
  130. const dReal ss[3] = {0.02,0.02,0.02};
  131. for (i=0; i<numc; i++) {
  132. if (dGeomGetClass(o1) == dRayClass || dGeomGetClass(o2) == dRayClass){
  133. dMatrix3 Rotation;
  134. dRSetIdentity(Rotation);
  135. dsDrawSphere(contact[i].geom.pos, Rotation, REAL(0.01));
  136. dVector3 End;
  137. End[0] = contact[i].geom.pos[0] + (contact[i].geom.normal[0] * contact[i].geom.depth);
  138. End[1] = contact[i].geom.pos[1] + (contact[i].geom.normal[1] * contact[i].geom.depth);
  139. End[2] = contact[i].geom.pos[2] + (contact[i].geom.normal[2] * contact[i].geom.depth);
  140. End[3] = contact[i].geom.pos[3] + (contact[i].geom.normal[3] * contact[i].geom.depth);
  141. dsDrawLine(contact[i].geom.pos, End);
  142. continue;
  143. }
  144. dJointID c = dJointCreateContact (world,contactgroup,contact+i);
  145. dJointAttach (c,b1,b2);
  146. if (show_contacts) dsDrawBox (contact[i].geom.pos,RI,ss);
  147. }
  148. }
  149. }
  150. // start simulation - set viewpoint
  151. static void start()
  152. {
  153. dAllocateODEDataForThread(dAllocateMaskAll);
  154. static float xyz[3] = {2.1640f,-1.3079f,1.7600f};
  155. static float hpr[3] = {125.5000f,-17.0000f,0.0000f};
  156. dsSetViewpoint (xyz,hpr);
  157. printf ("To drop another object, press:\n");
  158. printf (" b for box.\n");
  159. printf (" s for sphere.\n");
  160. printf (" c for cylinder.\n");
  161. printf( " v for a convex.\n" );
  162. printf (" x for a composite object.\n");
  163. printf ("To select an object, press space.\n");
  164. printf ("To disable the selected object, press d.\n");
  165. printf ("To enable the selected object, press e.\n");
  166. printf ("To toggle showing the geom AABBs, press a.\n");
  167. printf ("To toggle showing the contact points, press t.\n");
  168. printf ("To toggle dropping from random position/orientation, press r.\n");
  169. }
  170. char locase (char c)
  171. {
  172. if (c >= 'A' && c <= 'Z') return c - ('a'-'A');
  173. else return c;
  174. }
  175. // called when a key pressed
  176. static void command (int cmd)
  177. {
  178. int i,j,k;
  179. dReal sides[3];
  180. dMass m;
  181. bool setBody = false;
  182. cmd = locase (cmd);
  183. if (cmd == 'b' || cmd == 's' || cmd == 'c' || cmd == 'x' || cmd == 'v'
  184. /* || cmd == 'l' */) {
  185. if (num < NUM) {
  186. i = num;
  187. num++;
  188. }
  189. else {
  190. i = nextobj;
  191. nextobj++;
  192. if (nextobj >= num) nextobj = 0;
  193. // destroy the body and geoms for slot i
  194. dBodyDestroy (obj[i].body);
  195. for (k=0; k < GPB; k++) {
  196. if (obj[i].geom[k]) dGeomDestroy (obj[i].geom[k]);
  197. }
  198. memset (&obj[i],0,sizeof(obj[i]));
  199. }
  200. obj[i].body = dBodyCreate (world);
  201. for (k=0; k<3; k++) sides[k] = dRandReal()*0.5+0.1;
  202. dMatrix3 R;
  203. if (random_pos) {
  204. dBodySetPosition (obj[i].body,
  205. dRandReal()*2-1,dRandReal()*2-1,dRandReal()+1);
  206. dRFromAxisAndAngle (R,dRandReal()*2.0-1.0,dRandReal()*2.0-1.0,
  207. dRandReal()*2.0-1.0,dRandReal()*10.0-5.0);
  208. }
  209. else {
  210. dReal maxheight = 0;
  211. for (k=0; k<num; k++) {
  212. const dReal *pos = dBodyGetPosition (obj[k].body);
  213. if (pos[2] > maxheight) maxheight = pos[2];
  214. }
  215. dBodySetPosition (obj[i].body, 0,0,maxheight+1);
  216. dRFromAxisAndAngle (R,0,0,1,dRandReal()*10.0-5.0);
  217. }
  218. dBodySetRotation (obj[i].body,R);
  219. dBodySetData (obj[i].body,(void*)(size_t)i);
  220. if (cmd == 'b') {
  221. dMassSetBox (&m,DENSITY,sides[0],sides[1],sides[2]);
  222. obj[i].geom[0] = dCreateBox (space,sides[0],sides[1],sides[2]);
  223. }
  224. else if (cmd == 'c') {
  225. sides[0] *= 0.5;
  226. dMassSetCapsule (&m,DENSITY,3,sides[0],sides[1]);
  227. obj[i].geom[0] = dCreateCapsule (space,sides[0],sides[1]);
  228. }
  229. /*
  230. // cylinder option not yet implemented
  231. else if (cmd == 'l') {
  232. sides[1] *= 0.5;
  233. dMassSetCapsule (&m,DENSITY,3,sides[0],sides[1]);
  234. obj[i].geom[0] = dCreateCylinder (space,sides[0],sides[1]);
  235. }
  236. */
  237. else if (cmd == 's') {
  238. sides[0] *= 0.5;
  239. dMassSetSphere (&m,DENSITY,sides[0]);
  240. obj[i].geom[0] = dCreateSphere (space,sides[0]);
  241. }
  242. else if (cmd == 'x') {
  243. setBody = true;
  244. // start accumulating masses for the composite geometries
  245. dMass m2;
  246. dMassSetZero (&m);
  247. dReal dpos[GPB][3]; // delta-positions for composite geometries
  248. dMatrix3 drot[GPB];
  249. // set random delta positions
  250. for (j=0; j<GPB; j++)
  251. for (k=0; k<3; k++)
  252. dpos[j][k] = dRandReal()*0.3-0.15;
  253. for (k=0; k<GPB; k++) {
  254. if (k==0) {
  255. dReal radius = dRandReal()*0.25+0.05;
  256. obj[i].geom[k] = dCreateSphere (space,radius);
  257. dMassSetSphere (&m2,DENSITY,radius);
  258. } else if (k==1) {
  259. obj[i].geom[k] = dCreateBox(space,sides[0],sides[1],sides[2]);
  260. dMassSetBox(&m2,DENSITY,sides[0],sides[1],sides[2]);
  261. } else {
  262. dReal radius = dRandReal()*0.1+0.05;
  263. dReal length = dRandReal()*1.0+0.1;
  264. obj[i].geom[k] = dCreateCapsule(space,radius,length);
  265. dMassSetCapsule(&m2,DENSITY,3,radius,length);
  266. }
  267. dRFromAxisAndAngle(drot[k],dRandReal()*2.0-1.0,dRandReal()*2.0-1.0,
  268. dRandReal()*2.0-1.0,dRandReal()*10.0-5.0);
  269. dMassRotate(&m2,drot[k]);
  270. dMassTranslate(&m2,dpos[k][0],dpos[k][1],dpos[k][2]);
  271. // add to the total mass
  272. dMassAdd(&m,&m2);
  273. }
  274. for (k=0; k<GPB; k++) {
  275. dGeomSetBody(obj[i].geom[k],obj[i].body);
  276. dGeomSetOffsetPosition(obj[i].geom[k],
  277. dpos[k][0]-m.c[0],
  278. dpos[k][1]-m.c[1],
  279. dpos[k][2]-m.c[2]);
  280. dGeomSetOffsetRotation(obj[i].geom[k], drot[k]);
  281. }
  282. dMassTranslate(&m,-m.c[0],-m.c[1],-m.c[2]);
  283. dBodySetMass(obj[i].body,&m);
  284. } else if (cmd == 'v') {
  285. dMassSetBox (&m,DENSITY,0.25,0.25,0.25);
  286. obj[i].geom[0] = dCreateConvex(space,
  287. planes,
  288. planecount,
  289. points,
  290. pointcount,
  291. polygons);
  292. }
  293. if (!setBody) { // avoid calling for composite geometries
  294. for (k=0; k < GPB; k++)
  295. if (obj[i].geom[k])
  296. dGeomSetBody(obj[i].geom[k],obj[i].body);
  297. dBodySetMass(obj[i].body,&m);
  298. }
  299. }
  300. if (cmd == ' ') {
  301. selected++;
  302. if (selected >= num) selected = 0;
  303. if (selected < 0) selected = 0;
  304. }
  305. else if (cmd == 'd' && selected >= 0 && selected < num) {
  306. dBodyDisable (obj[selected].body);
  307. }
  308. else if (cmd == 'e' && selected >= 0 && selected < num) {
  309. dBodyEnable (obj[selected].body);
  310. }
  311. else if (cmd == 'a') {
  312. show_aabb ^= 1;
  313. }
  314. else if (cmd == 't') {
  315. show_contacts ^= 1;
  316. }
  317. else if (cmd == 'r') {
  318. random_pos ^= 1;
  319. }
  320. }
  321. // draw a geom
  322. void drawGeom (dGeomID g, const dReal *pos, const dReal *R, int show_aabb)
  323. {
  324. if (!g) return;
  325. if (!pos) pos = dGeomGetPosition (g);
  326. if (!R) R = dGeomGetRotation (g);
  327. int type = dGeomGetClass (g);
  328. if (type == dBoxClass) {
  329. dVector3 sides;
  330. dGeomBoxGetLengths (g,sides);
  331. dsDrawBox (pos,R,sides);
  332. }
  333. else if (type == dSphereClass) {
  334. dsDrawSphere (pos,R,dGeomSphereGetRadius (g));
  335. }
  336. else if (type == dCapsuleClass) {
  337. dReal radius,length;
  338. dGeomCapsuleGetParams (g,&radius,&length);
  339. dsDrawCapsule (pos,R,length,radius);
  340. } else if (type == dConvexClass) {
  341. //dVector3 sides={0.50,0.50,0.50};
  342. dsDrawConvex(pos,R,planes,
  343. planecount,
  344. points,
  345. pointcount,
  346. polygons);
  347. }
  348. /*
  349. // cylinder option not yet implemented
  350. else if (type == dCylinderClass) {
  351. dReal radius,length;
  352. dGeomCylinderGetParams (g,&radius,&length);
  353. dsDrawCylinder (pos,R,length,radius);
  354. }
  355. */
  356. if (show_aabb) {
  357. // draw the bounding box for this geom
  358. dReal aabb[6];
  359. dGeomGetAABB (g,aabb);
  360. dVector3 bbpos;
  361. for (int i=0; i<3; i++) bbpos[i] = 0.5*(aabb[i*2] + aabb[i*2+1]);
  362. dVector3 bbsides;
  363. for (int j=0; j<3; j++) bbsides[j] = aabb[j*2+1] - aabb[j*2];
  364. dMatrix3 RI;
  365. dRSetIdentity (RI);
  366. dsSetColorAlpha (1,0,0,0.5);
  367. dsDrawBox (bbpos,RI,bbsides);
  368. }
  369. }
  370. // simulation loop
  371. static void simLoop (int pause)
  372. {
  373. dsSetColor (0,0,2);
  374. dSpaceCollide (space,0,&nearCallback);
  375. if (!pause) dWorldStep (world,0.05);
  376. //if (!pause) dWorldStepFast (world,0.05, 1);
  377. // remove all contact joints
  378. dJointGroupEmpty (contactgroup);
  379. dsSetColor (1,1,0);
  380. dsSetTexture (DS_WOOD);
  381. for (int i=0; i<num; i++) {
  382. for (int j=0; j < GPB; j++) {
  383. if (i==selected) {
  384. dsSetColor (0,0.7,1);
  385. }
  386. else if (! dBodyIsEnabled (obj[i].body)) {
  387. dsSetColor (1,0,0);
  388. }
  389. else {
  390. dsSetColor (1,1,0);
  391. }
  392. drawGeom (obj[i].geom[j],0,0,show_aabb);
  393. }
  394. }
  395. /*{
  396. for (int i = 1; i < IndexCount; i++) {
  397. dsDrawLine(Vertices[Indices[i - 1]], Vertices[Indices[i]]);
  398. }
  399. }*/
  400. {const dReal* Pos = dGeomGetPosition(TriMesh);
  401. const dReal* Rot = dGeomGetRotation(TriMesh);
  402. {for (int i = 0; i < IndexCount / 3; i++){
  403. const float *p = Vertices[Indices[i * 3 + 0]];
  404. const dVector3 v0 = { p[0], p[1], p[2] };
  405. p = Vertices[Indices[i * 3 + 1]];
  406. const dVector3 v1 = { p[0], p[1], p[2] };
  407. p = Vertices[Indices[i * 3 + 2]];
  408. const dVector3 v2 = { p[0], p[1], p[2] };
  409. dsDrawTriangle(Pos, Rot, v0, v1, v2, 0);
  410. }}}
  411. if (Ray){
  412. dVector3 Origin, Direction;
  413. dGeomRayGet(Ray, Origin, Direction);
  414. dReal Length = dGeomRayGetLength(Ray);
  415. dVector3 End;
  416. End[0] = Origin[0] + (Direction[0] * Length);
  417. End[1] = Origin[1] + (Direction[1] * Length);
  418. End[2] = Origin[2] + (Direction[2] * Length);
  419. End[3] = Origin[3] + (Direction[3] * Length);
  420. dsDrawLine(Origin, End);
  421. }
  422. }
  423. int main (int argc, char **argv)
  424. {
  425. // setup pointers to drawstuff callback functions
  426. dsFunctions fn;
  427. fn.version = DS_VERSION;
  428. fn.start = &start;
  429. fn.step = &simLoop;
  430. fn.command = &command;
  431. fn.stop = 0;
  432. fn.path_to_textures = DRAWSTUFF_TEXTURE_PATH;
  433. // create world
  434. dInitODE2(0);
  435. world = dWorldCreate();
  436. space = dSimpleSpaceCreate(0);
  437. contactgroup = dJointGroupCreate (0);
  438. dWorldSetGravity (world,0,0,-0.5);
  439. dWorldSetCFM (world,1e-5);
  440. //dCreatePlane (space,0,0,1,0);
  441. memset (obj,0,sizeof(obj));
  442. Size[0] = 5.0f;
  443. Size[1] = 5.0f;
  444. Size[2] = 2.5f;
  445. Vertices[0][0] = -Size[0];
  446. Vertices[0][1] = -Size[1];
  447. Vertices[0][2] = Size[2];
  448. Vertices[1][0] = Size[0];
  449. Vertices[1][1] = -Size[1];
  450. Vertices[1][2] = Size[2];
  451. Vertices[2][0] = Size[0];
  452. Vertices[2][1] = Size[1];
  453. Vertices[2][2] = Size[2];
  454. Vertices[3][0] = -Size[0];
  455. Vertices[3][1] = Size[1];
  456. Vertices[3][2] = Size[2];
  457. Vertices[4][0] = 0;
  458. Vertices[4][1] = 0;
  459. Vertices[4][2] = 0;
  460. Indices[0] = 0;
  461. Indices[1] = 1;
  462. Indices[2] = 4;
  463. Indices[3] = 1;
  464. Indices[4] = 2;
  465. Indices[5] = 4;
  466. Indices[6] = 2;
  467. Indices[7] = 3;
  468. Indices[8] = 4;
  469. Indices[9] = 3;
  470. Indices[10] = 0;
  471. Indices[11] = 4;
  472. dTriMeshDataID Data = dGeomTriMeshDataCreate();
  473. //dGeomTriMeshDataBuildSimple(Data, (dReal*)Vertices, VertexCount, Indices, IndexCount);
  474. dGeomTriMeshDataBuildSingle(Data, Vertices[0], 3 * sizeof(float), VertexCount, &Indices[0], IndexCount, 3 * sizeof(dTriIndex));
  475. dGeomTriMeshDataPreprocess2(Data, (1U << dTRIDATAPREPROCESS_BUILD_FACE_ANGLES), NULL);
  476. TriMesh = dCreateTriMesh(space, Data, 0, 0, 0);
  477. //dGeomSetPosition(TriMesh, 0, 0, 1.0);
  478. Ray = dCreateRay(space, 0.9);
  479. dVector3 Origin, Direction;
  480. Origin[0] = 0.0;
  481. Origin[1] = 0;
  482. Origin[2] = 0.5;
  483. Origin[3] = 0;
  484. Direction[0] = 0;
  485. Direction[1] = 1.1f;
  486. Direction[2] = -1;
  487. Direction[3] = 0;
  488. dNormalize3(Direction);
  489. dGeomRaySet(Ray, Origin[0], Origin[1], Origin[2], Direction[0], Direction[1], Direction[2]);
  490. dThreadingImplementationID threading = dThreadingAllocateMultiThreadedImplementation();
  491. dThreadingThreadPoolID pool = dThreadingAllocateThreadPool(4, 0, dAllocateFlagBasicData, NULL);
  492. dThreadingThreadPoolServeMultiThreadedImplementation(pool, threading);
  493. // dWorldSetStepIslandsProcessingMaxThreadCount(world, 1);
  494. dWorldSetStepThreadingImplementation(world, dThreadingImplementationGetFunctions(threading), threading);
  495. // run simulation
  496. dsSimulationLoop (argc,argv,352,288,&fn);
  497. dThreadingImplementationShutdownProcessing(threading);
  498. dThreadingFreeThreadPool(pool);
  499. dWorldSetStepThreadingImplementation(world, NULL, NULL);
  500. dThreadingFreeImplementation(threading);
  501. dJointGroupDestroy (contactgroup);
  502. dSpaceDestroy (space);
  503. dWorldDestroy (world);
  504. dCloseODE();
  505. return 0;
  506. }