aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/libraries/ode-0.9/ode/demo/demo_convex_cd.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'libraries/ode-0.9/ode/demo/demo_convex_cd.cpp')
-rw-r--r--libraries/ode-0.9/ode/demo/demo_convex_cd.cpp195
1 files changed, 195 insertions, 0 deletions
diff --git a/libraries/ode-0.9/ode/demo/demo_convex_cd.cpp b/libraries/ode-0.9/ode/demo/demo_convex_cd.cpp
new file mode 100644
index 0000000..e1764f3
--- /dev/null
+++ b/libraries/ode-0.9/ode/demo/demo_convex_cd.cpp
@@ -0,0 +1,195 @@
1/*************************************************************************
2 * *
3 * Open Dynamics Engine, Copyright (C) 2001,2002 Russell L. Smith. *
4 * All rights reserved. Email: russ@q12.org 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
23#include <stdio.h>
24#include <math.h>
25#include <ode/ode.h>
26#include <drawstuff/drawstuff.h>
27#ifdef _MSC_VER
28#pragma warning(disable:4244 4305) // for VC++, no precision loss complaints
29#endif
30
31
32#ifndef M_PI
33#define M_PI (3.14159265358979323846)
34#endif
35
36//<---- Convex Object
37dReal planes[]= // planes for a cube
38 {
39 1.0f ,0.0f ,0.0f ,0.25f,
40 0.0f ,1.0f ,0.0f ,0.25f,
41 0.0f ,0.0f ,1.0f ,0.25f,
42 -1.0f,0.0f ,0.0f ,0.25f,
43 0.0f ,-1.0f,0.0f ,0.25f,
44 0.0f ,0.0f ,-1.0f,0.25f
45 /*
46 1.0f ,0.0f ,0.0f ,2.0f,
47 0.0f ,1.0f ,0.0f ,1.0f,
48 0.0f ,0.0f ,1.0f ,1.0f,
49 0.0f ,0.0f ,-1.0f,1.0f,
50 0.0f ,-1.0f,0.0f ,1.0f,
51 -1.0f,0.0f ,0.0f ,0.0f
52 */
53 };
54const unsigned int planecount=6;
55
56dReal points[]= // points for a cube
57 {
58 0.25f,0.25f,0.25f, // point 0
59 -0.25f,0.25f,0.25f, // point 1
60
61 0.25f,-0.25f,0.25f, // point 2
62 -0.25f,-0.25f,0.25f,// point 3
63
64 0.25f,0.25f,-0.25f, // point 4
65 -0.25f,0.25f,-0.25f,// point 5
66
67 0.25f,-0.25f,-0.25f,// point 6
68 -0.25f,-0.25f,-0.25f,// point 7
69 };
70const unsigned int pointcount=8;
71unsigned int polygons[] = //Polygons for a cube (6 squares)
72 {
73 4,0,2,6,4, // positive X
74 4,1,0,4,5, // positive Y
75 4,0,1,3,2, // positive Z
76 4,3,1,5,7, // negative X
77 4,2,3,7,6, // negative Y
78 4,5,4,6,7, // negative Z
79 };
80//----> Convex Object
81
82#ifdef dDOUBLE
83#define dsDrawConvex dsDrawConvexD
84#define dsDrawBox dsDrawBoxD
85#endif
86
87dGeomID geoms[2];
88dSpaceID space;
89dWorldID world;
90dJointGroupID contactgroup;
91
92void start()
93{
94 // adjust the starting viewpoint a bit
95 float xyz[3],hpr[3];
96 dsGetViewpoint (xyz,hpr);
97 hpr[0] += 7;
98 dsSetViewpoint (xyz,hpr);
99 geoms[0]=dCreateConvex (space,
100 planes,
101 planecount,
102 points,
103 pointcount,
104 polygons);
105 dGeomSetPosition (geoms[0],0,0,0.25);
106 geoms[1]=dCreateConvex (space,
107 planes,
108 planecount,
109 points,
110 pointcount,
111 polygons);
112 dGeomSetPosition (geoms[1],0.25,0.25,0.70);
113
114}
115
116int dCollideConvexConvex (dxGeom *o1, dxGeom *o2, int flags,
117 dContactGeom *contact, int skip);
118void simLoop (int pause)
119{
120 static bool DumpInfo=true;
121 const dReal ss[3] = {0.02,0.02,0.02};
122 dContactGeom contacts[8];
123 int contactcount = dCollideConvexConvex(geoms[0],geoms[1],8,contacts,sizeof(dContactGeom));
124 //fprintf(stdout,"Contact Count %d\n",contactcount);
125 const dReal* pos;
126 const dReal* R;
127 dsSetTexture (DS_WOOD);
128 pos = dGeomGetPosition (geoms[0]);
129 R = dGeomGetRotation (geoms[0]);
130 dsSetColor (0.6f,0.6f,1);
131 dsDrawConvex(pos,R,planes,
132 planecount,
133 points,
134 pointcount,
135 polygons);
136 pos = dGeomGetPosition (geoms[1]);
137 R = dGeomGetRotation (geoms[1]);
138 dsSetColor (0.4f,1,1);
139 dsDrawConvex(pos,R,planes,
140 planecount,
141 points,
142 pointcount,
143 polygons);
144 /*if (show_contacts) */
145 dMatrix3 RI;
146 dRSetIdentity (RI);
147 dsSetColor (1.0f,0,0);
148 for(int i=0;i<contactcount;++i)
149 {
150 if(DumpInfo)
151 {
152 //DumpInfo=false;
153 fprintf(stdout,"Contact %d Normal %f,%f,%f Depth %f\n",
154 i,
155 contacts[i].normal[0],
156 contacts[i].normal[1],
157 contacts[i].normal[2],
158 contacts[i].depth);
159 }
160 dsDrawBox (contacts[i].pos,RI,ss);
161 }
162 if(DumpInfo)
163 DumpInfo=false;
164
165}
166
167
168void command (int cmd)
169{
170 dsPrint ("received command %d (`%c')\n",cmd,cmd);
171}
172
173
174int main (int argc, char **argv)
175{
176 // setup pointers to callback functions
177 dsFunctions fn;
178 fn.version = DS_VERSION;
179 fn.start = &start;
180 fn.step = &simLoop;
181 fn.command = command;
182 fn.stop = 0;
183 fn.path_to_textures = "../../drawstuff/textures"; // uses default
184 world = dWorldCreate();
185 space = dHashSpaceCreate (0);
186 contactgroup = dJointGroupCreate (0);
187
188 // run simulation
189 dsSimulationLoop (argc,argv,400,400,&fn);
190 dJointGroupDestroy (contactgroup);
191 dSpaceDestroy (space);
192 dWorldDestroy (world);
193
194 return 0;
195}