aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/libraries/ode-0.9/contrib/Mac_CFMCarbon
diff options
context:
space:
mode:
authordan miller2007-10-19 05:24:38 +0000
committerdan miller2007-10-19 05:24:38 +0000
commitf205de7847da7ae1c10212d82e7042d0100b4ce0 (patch)
tree9acc9608a6880502aaeda43af52c33e278e95b9c /libraries/ode-0.9/contrib/Mac_CFMCarbon
parenttrying to fix my screwup part deux (diff)
downloadopensim-SC_OLD-f205de7847da7ae1c10212d82e7042d0100b4ce0.zip
opensim-SC_OLD-f205de7847da7ae1c10212d82e7042d0100b4ce0.tar.gz
opensim-SC_OLD-f205de7847da7ae1c10212d82e7042d0100b4ce0.tar.bz2
opensim-SC_OLD-f205de7847da7ae1c10212d82e7042d0100b4ce0.tar.xz
from the start... checking in ode-0.9
Diffstat (limited to 'libraries/ode-0.9/contrib/Mac_CFMCarbon')
-rw-r--r--libraries/ode-0.9/contrib/Mac_CFMCarbon/CW7_projects.sit.binbin0 -> 46592 bytes
-rw-r--r--libraries/ode-0.9/contrib/Mac_CFMCarbon/README.txt95
-rw-r--r--libraries/ode-0.9/contrib/Mac_CFMCarbon/mac_source/CommonPrefix.h6
-rw-r--r--libraries/ode-0.9/contrib/Mac_CFMCarbon/mac_source/DSPrefix.h6
-rw-r--r--libraries/ode-0.9/contrib/Mac_CFMCarbon/mac_source/DebugPrefix.h10
-rw-r--r--libraries/ode-0.9/contrib/Mac_CFMCarbon/mac_source/ExamplesPrefix.h13
-rw-r--r--libraries/ode-0.9/contrib/Mac_CFMCarbon/mac_source/ODETestPrefix.h13
-rw-r--r--libraries/ode-0.9/contrib/Mac_CFMCarbon/mac_source/ReleasePrefix.h6
-rw-r--r--libraries/ode-0.9/contrib/Mac_CFMCarbon/mac_source/drawstuff/src/mac_glut_carbon.cpp281
-rw-r--r--libraries/ode-0.9/contrib/Mac_CFMCarbon/mac_source/include/GL/gl.h2
-rw-r--r--libraries/ode-0.9/contrib/Mac_CFMCarbon/mac_source/include/GL/glu.h2
-rw-r--r--libraries/ode-0.9/contrib/Mac_CFMCarbon/mac_source/include/ode/config.h52
-rw-r--r--libraries/ode-0.9/contrib/Mac_CFMCarbon/mac_source/ode/test/test_stability1.cpp289
-rw-r--r--libraries/ode-0.9/contrib/Mac_CFMCarbon/mac_source/ode/test/test_stacktest.c197
14 files changed, 972 insertions, 0 deletions
diff --git a/libraries/ode-0.9/contrib/Mac_CFMCarbon/CW7_projects.sit.bin b/libraries/ode-0.9/contrib/Mac_CFMCarbon/CW7_projects.sit.bin
new file mode 100644
index 0000000..c06768c
--- /dev/null
+++ b/libraries/ode-0.9/contrib/Mac_CFMCarbon/CW7_projects.sit.bin
Binary files differ
diff --git a/libraries/ode-0.9/contrib/Mac_CFMCarbon/README.txt b/libraries/ode-0.9/contrib/Mac_CFMCarbon/README.txt
new file mode 100644
index 0000000..7c1f8a4
--- /dev/null
+++ b/libraries/ode-0.9/contrib/Mac_CFMCarbon/README.txt
@@ -0,0 +1,95 @@
1-----------------------------
2ODE - Mac CFM Carbon Port
3(contact Frank Condello <pox@planetquake.com> with questions regarding this port)
4
5Although ODE contains a MacOSX makefile, and some individuals have implemented ODE in
6Cocoa, I opted to use (and prefer) CodeWarrior. This also opens up ODE to MacOS8 & 9
7users, without scarfing functionality in MacOSX (same binaries run on both platforms).
8
9The 'ode_CW7.mcp' project contains release and debug targets to create static ODE and
10DrawStuff libraries.
11
12'examples_CW7.mcp' contains targets for the entire ODE test suite, plus a couple other
13test programs which were posted to the ODE mailing list.
14
15
16-----------------------------
17Compiling Notes:
18
19You'll need to extract the CodeWarrior projects from the 'CW7_projects.sit.bin' archive
20(They're nearly a meg uncompressed so this was done to be bandwith friendly on the CVS).
21
22Projects require CodeWarrior 7 or above (recreating them with earlier versions shouldn't
23be too difficult). The projects use relative paths and are meant to be compiled from
24'contrib/Mac_CFMCarbon/'. Don't move them!
25
26All the libraries build into the 'lib/' directory, all test applications build into
27'contrib/Mac_CFMCarbon/mac_testbin/' (and must be run from that directory since the
28texture path is hard-coded).
29
30You'll need to compile the release ODE library, and the DrawStuff library before
31compiling the examples.
32
33The ODE 'configurator' has not been ported, but a Mac-friendly 'config.h' header has been
34manually hacked together (all PPC Macs should be fine with this header). Single or double
35precision can be defined in the 'CommonPrefix.h' header found in
36'contrib/Mac_CFMCarbon/mac_source/'.
37
38'contrib/Mac_CFMCarbon/mac_source/' also contains any mac specific additions to the main source.
39The directory structure here matches the main source tree, and I would recommend that this
40format is maintained when making additions, since the access paths are touchy (more below...)
41
42Some issues were encountered with duplicate header names. CodeWarrior tends to be
43unforgiving about this sort of thing but fudging with the access paths eventually
44cleared up the problem. If ODE fails to compile, make sure the <ode/objects.h> and
45"objects.h" or <timer.h> and <Timer.h> are actually pointing to the correct header.
46
47You'll need Apple's OpenGL SDK (with GLUT) in your compiler path to build DrawStuff. I've
48added redirection headers in 'contrib/Mac_CFMCarbon/mac_source/include/GL/' to properly
49link with the Apple headers (since the projects are set to follow DOS paths).
50
51The examples link against a crapload of static libraries, but my initial builds using
52ODE, MSL, GLUT, and DrawStuff shared/merged DLL's proved unstable (mostly problems with
53SIOUX spawning multiple sessions, and crashes in Classic). Static libs just worked better
54in the end, but the test apps are a little bloated as a result, and need to be re-linked
55whenever a change to a library is made.
56
57IMPORTANT: You must use the same 'CommonPrefix.h' settings for libraries, and test apps
58(i.e. double or single precision).
59
60
61-----------------------------
62Running the test apps:
63
64The test apps will show the SIOUX CLI prompt when run. Just hit OK to ignore it, or add any
65DrawStuff arguments. You'll want to log output to a file for 'test_ode'.
66
67There are two extra test programs in the 'mac_source' directory. Both were posted to the ODE
68mailing list by OSX users. 'test_stability1' visualizes some internal issues with ODE, and
69'test_stacktest' is a standalone GLUT program (doesn't use DrawStuff) that can be useful
70to stress test the library, and give you an idea of just how much stack memory you're
71going to need for large systems.
72
73ISSUES:
74
75The carbon DrawStuff lib uses GLUT to make life easy, but GLUT isn't exactly bug-free
76or stable on the Mac... Try moving the mouse around if a simulation is running slowly
77on OS9 (it's not ODE's fault, but rather a poor carbon GLUT implementation - seems GLUT stalls
78when it's not getting system events - I haven't seen this problem on OSX).
79
80The 3D view may not update if typing in the SIOUX console window.
81
82You cannot pass startup args to GLUT due to the way the DrawStuff library initializes.
83
84'Write Frames' doesn't actually do anything at the moment.
85
86The 'test_joints' app seems broken (though I don't know what the intended effect should be)
87
88
89-----------------------------
90TODO:
91
92- Re-add shared library targets (if stability issues are resolved).
93- Implement 'Write Frames' in DrawStuff.
94- Write a Carbon compatible configurator
95- Create CodeWarrior 8 projects (once I scrounge up enough dough for the update). \ No newline at end of file
diff --git a/libraries/ode-0.9/contrib/Mac_CFMCarbon/mac_source/CommonPrefix.h b/libraries/ode-0.9/contrib/Mac_CFMCarbon/mac_source/CommonPrefix.h
new file mode 100644
index 0000000..5948b3e
--- /dev/null
+++ b/libraries/ode-0.9/contrib/Mac_CFMCarbon/mac_source/CommonPrefix.h
@@ -0,0 +1,6 @@
1#define TARGET_API_MAC_CARBON 1
2#define finite isfinite
3#define dNODEBUG 1
4
5// Comment out for single precision
6#define PRECISION_DOUBLE 1 \ No newline at end of file
diff --git a/libraries/ode-0.9/contrib/Mac_CFMCarbon/mac_source/DSPrefix.h b/libraries/ode-0.9/contrib/Mac_CFMCarbon/mac_source/DSPrefix.h
new file mode 100644
index 0000000..6122528
--- /dev/null
+++ b/libraries/ode-0.9/contrib/Mac_CFMCarbon/mac_source/DSPrefix.h
@@ -0,0 +1,6 @@
1#ifndef prefix_h
2#define prefix_h
3
4#include "CommonPrefix.h"
5
6#endif // prefix_h \ No newline at end of file
diff --git a/libraries/ode-0.9/contrib/Mac_CFMCarbon/mac_source/DebugPrefix.h b/libraries/ode-0.9/contrib/Mac_CFMCarbon/mac_source/DebugPrefix.h
new file mode 100644
index 0000000..0e328a9
--- /dev/null
+++ b/libraries/ode-0.9/contrib/Mac_CFMCarbon/mac_source/DebugPrefix.h
@@ -0,0 +1,10 @@
1#ifndef prefix_h
2#define prefix_h
3
4#include "CommonPrefix.h"
5
6#ifdef dNODEBUG
7#undef dNODEBUG
8#endif
9
10#endif // prefix_h \ No newline at end of file
diff --git a/libraries/ode-0.9/contrib/Mac_CFMCarbon/mac_source/ExamplesPrefix.h b/libraries/ode-0.9/contrib/Mac_CFMCarbon/mac_source/ExamplesPrefix.h
new file mode 100644
index 0000000..1dedfc9
--- /dev/null
+++ b/libraries/ode-0.9/contrib/Mac_CFMCarbon/mac_source/ExamplesPrefix.h
@@ -0,0 +1,13 @@
1#ifndef prefix_h
2#define prefix_h
3
4#include "CommonPrefix.h"
5
6// Hack to automatically call SIOUX's CLI interface for the test apps
7#include <console.h>
8#include <SIOUX.h>
9int fmain (int argc, char **argv);
10int main (int argc, char **argv) { argc = ccommand(&argv); return fmain(argc, argv); }
11#define main(argc, argv) fmain(argc, argv)
12
13#endif // prefix_h \ No newline at end of file
diff --git a/libraries/ode-0.9/contrib/Mac_CFMCarbon/mac_source/ODETestPrefix.h b/libraries/ode-0.9/contrib/Mac_CFMCarbon/mac_source/ODETestPrefix.h
new file mode 100644
index 0000000..f8f5022
--- /dev/null
+++ b/libraries/ode-0.9/contrib/Mac_CFMCarbon/mac_source/ODETestPrefix.h
@@ -0,0 +1,13 @@
1#ifndef prefix_h
2#define prefix_h
3
4#include "CommonPrefix.h"
5
6// Hack to automatically call SIOUX's CLI interface for the test apps
7#include <console.h>
8#include <SIOUX.h>
9int fmain ();
10int main (int argc, char **argv) { argc = ccommand(&argv); return fmain(); }
11#define main() fmain()
12
13#endif // prefix_h \ No newline at end of file
diff --git a/libraries/ode-0.9/contrib/Mac_CFMCarbon/mac_source/ReleasePrefix.h b/libraries/ode-0.9/contrib/Mac_CFMCarbon/mac_source/ReleasePrefix.h
new file mode 100644
index 0000000..6122528
--- /dev/null
+++ b/libraries/ode-0.9/contrib/Mac_CFMCarbon/mac_source/ReleasePrefix.h
@@ -0,0 +1,6 @@
1#ifndef prefix_h
2#define prefix_h
3
4#include "CommonPrefix.h"
5
6#endif // prefix_h \ No newline at end of file
diff --git a/libraries/ode-0.9/contrib/Mac_CFMCarbon/mac_source/drawstuff/src/mac_glut_carbon.cpp b/libraries/ode-0.9/contrib/Mac_CFMCarbon/mac_source/drawstuff/src/mac_glut_carbon.cpp
new file mode 100644
index 0000000..eb0b144
--- /dev/null
+++ b/libraries/ode-0.9/contrib/Mac_CFMCarbon/mac_source/drawstuff/src/mac_glut_carbon.cpp
@@ -0,0 +1,281 @@
1/*************************************************************************
2 * *
3 * DrawStuff Library, Copyright (C) 2001 Russell L. Smith. *
4 * 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 the GNU Lesser General Public *
8 * License as published by the Free Software Foundation; either *
9 * version 2.1 of the License, or (at your option) any later version. *
10 * *
11 * This library is distributed in the hope that it will be useful, *
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
14 * Lesser General Public License for more details. *
15 * *
16 * You should have received a copy of the GNU Lesser General Public *
17 * License along with this library (see the file LICENSE.TXT); if not, *
18 * write to the Free Software Foundation, Inc., 59 Temple Place, *
19 * Suite 330, Boston, MA 02111-1307 USA. *
20 * *
21 *************************************************************************/
22
23// main window and event handling for Mac CFM Carbon
24
25#include <ode/config.h>
26#include <stdlib.h>
27#include <string.h>
28#include <stdarg.h>
29#include <stdio.h>
30#include <glut.h>
31#include <SIOUX.h>
32
33#include <MacTypes.h>
34#include <Timer.h>
35
36#include <drawstuff/drawstuff.h>
37#include <drawstuff/version.h>
38#include "internal.h"
39
40
41//***************************************************************************
42// error handling for unix (works just fine with SIOUX)
43
44static void printMessage (char *msg1, char *msg2, va_list ap)
45{
46 fflush (stderr);
47 fflush (stdout);
48 fprintf (stderr,"\n%s: ",msg1);
49 vfprintf (stderr,msg2,ap);
50 fprintf (stderr,"\n");
51 fflush (stderr);
52}
53
54extern "C" void dsError (char *msg, ...)
55{
56 va_list ap;
57 va_start (ap,msg);
58 printMessage ("Error",msg,ap);
59 exit (1);
60}
61
62
63extern "C" void dsDebug (char *msg, ...)
64{
65 va_list ap;
66 va_start (ap,msg);
67 printMessage ("INTERNAL ERROR",msg,ap);
68 // *((char *)0) = 0; ... commit SEGVicide ?
69 abort();
70}
71
72extern "C" void dsPrint (char *msg, ...)
73{
74 va_list ap;
75 va_start (ap,msg);
76 vprintf (msg,ap);
77}
78
79//***************************************************************************
80// openGL window
81
82// window and openGL
83static int width=0,height=0; // window size
84static int last_key_pressed=0; // last key pressed in the window
85static int pause=0; // 1 if in `pause' mode
86static int singlestep=0; // 1 if single step key pressed
87static int writeframes=0; // 1 if frame files to be written
88static dsFunctions *gfn;
89static int frame = 1;
90
91float getTime (void)
92{
93 UnsignedWide ms;
94
95 Microseconds(&ms);
96 return ms.lo / 1000000.0;
97}
98
99
100static void captureFrame (int num)
101{
102// TODO
103}
104
105static void reshape(int w, int h)
106{
107 width = w;
108 height = h;
109}
110
111static void draw(void)
112{
113 dsDrawFrame (width,height,gfn,pause && !singlestep);
114 singlestep = 0;
115 glutSwapBuffers();
116
117 if (pause==0 && writeframes) {
118 captureFrame (frame);
119 frame++;
120 }
121}
122
123static void idle(void)
124{
125 static float lasttime=0;
126 float t;
127
128 // Try to maintain a reasonable rate (good enough for testing anyway)
129 t = getTime();
130 if (lasttime < t) {
131 lasttime = t+0.005;
132 draw();
133 }
134}
135
136static void key(unsigned char key, int x, int y)
137{
138 if (!glutGetModifiers()) {
139
140 if (key >= ' ' && key <= 126 && gfn->command) gfn->command (key);
141
142 // GLUT_ACTIVE_CTRL doesn't seem to be working, so we use Alt
143 } else if (glutGetModifiers()&GLUT_ACTIVE_ALT) {
144
145 switch (key) {
146 case 't': case 'T':
147 dsSetTextures (dsGetTextures() ^ 1);
148 break;
149 case 's': case 'S':
150 dsSetShadows (dsGetShadows() ^ 1);
151 break;
152 case 'p': case 'P':
153 pause ^= 1;
154 singlestep = 0;
155 break;
156 case 'o': case 'O':
157 if (pause) singlestep = 1;
158 break;
159 case 'v': case 'V': {
160 float xyz[3],hpr[3];
161 dsGetViewpoint (xyz,hpr);
162 printf ("Viewpoint = (%.4f,%.4f,%.4f,%.4f,%.4f,%.4f)\n",
163 xyz[0],xyz[1],xyz[2],hpr[0],hpr[1],hpr[2]);
164 break;
165 }
166 // No case 'X' - Quit works through the Mac system menu, or cmd-q
167 case 'w': case 'W':
168 writeframes ^= 1;
169 if (writeframes) printf ("Write frames not done yet!\n");// TODO
170 break;
171 }
172 }
173
174 last_key_pressed = key;
175}
176
177static int mx=0,my=0; // mouse position
178static int mode = 0; // mouse button bits
179
180static void MouseDown(int button, int state, int x, int y)
181{
182 if(button == GLUT_LEFT_BUTTON)
183 {
184 if(state == GLUT_DOWN)
185 mode |= 1;
186 else if(state == GLUT_UP)
187 mode &= (~1);
188 }
189 else if (button == GLUT_MIDDLE_BUTTON)
190 {
191 if(state == GLUT_DOWN)
192 mode |= 3;
193 else if(state == GLUT_UP)
194 mode &= (~3);
195 }
196 else if (button == GLUT_RIGHT_BUTTON)
197 {
198 if(state == GLUT_DOWN)
199 mode |= 2;
200 else if(state == GLUT_UP)
201 mode &= (~2);
202 }
203
204 mx = x;
205 my = y;
206}
207
208static void MouseMove(int x, int y)
209{
210 dsMotion (mode, x - mx, y - my);
211 mx = x;
212 my = y;
213}
214
215static void createMainWindow (int _width, int _height)
216{
217 // So GLUT doesn't complain
218 int argc = 0;
219 char **argv = NULL;
220
221 // initialize variables
222 width = _width;
223 height = _height;
224 last_key_pressed = 0;
225
226 if (width < 1 || height < 1) dsDebug (0,"bad window width or height");
227
228 glutInit(&argc, argv);
229 glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH);
230 glutInitWindowSize(_width, _height);
231 glutInitWindowPosition(100, 100);
232 glutCreateWindow("ODE Simulation");
233
234 glutKeyboardFunc(key);
235 glutMotionFunc(MouseMove);
236 glutMouseFunc(MouseDown);
237 glutReshapeFunc(reshape);
238 glutDisplayFunc(idle);
239 glutIdleFunc(idle);
240}
241
242void dsPlatformSimLoop (int window_width, int window_height, dsFunctions *fn,
243 int initial_pause)
244{
245 SIOUXSettings.initializeTB = false;
246 SIOUXSettings.standalone = false;
247 SIOUXSettings.setupmenus = false;
248 SIOUXSettings.autocloseonquit = true;
249 SIOUXSettings.asktosaveonclose = false;
250
251 gfn = fn;
252 pause = initial_pause;
253
254 printf (
255 "\n"
256 "Simulation test environment v%d.%02d\n"
257 " Option-P : pause / unpause (or say `-pause' on command line).\n"
258 " Option-O : single step when paused.\n"
259 " Option-T : toggle textures (or say `-notex' on command line).\n"
260 " Option-S : toggle shadows (or say `-noshadow' on command line).\n"
261 " Option-V : print current viewpoint coordinates (x,y,z,h,p,r).\n"
262 " Option-W : write frames to ppm files: frame/frameNNN.ppm\n"
263 "\n"
264 "Change the camera position by clicking + dragging in the window.\n"
265 " Left button - pan and tilt.\n"
266 " Right button - forward and sideways.\n"
267 " Left + Right button (or middle button) - sideways and up.\n"
268 "\n",DS_VERSION >> 8,DS_VERSION & 0xff);
269
270 createMainWindow (window_width, window_height);
271 dsStartGraphics (window_width,window_height,fn);
272
273 if (fn->start) fn->start();
274
275 glutMainLoop();
276
277 if (fn->stop) fn->stop();
278 dsStopGraphics();
279}
280
281extern "C" void dsStop(){ }// GLUT/MSL hooks into the system to exit
diff --git a/libraries/ode-0.9/contrib/Mac_CFMCarbon/mac_source/include/GL/gl.h b/libraries/ode-0.9/contrib/Mac_CFMCarbon/mac_source/include/GL/gl.h
new file mode 100644
index 0000000..4acaeed
--- /dev/null
+++ b/libraries/ode-0.9/contrib/Mac_CFMCarbon/mac_source/include/GL/gl.h
@@ -0,0 +1,2 @@
1// A little hackaround (Apple use / in the FILENAME, which doesn't work when following DOS paths)
2#include <gl.h> \ No newline at end of file
diff --git a/libraries/ode-0.9/contrib/Mac_CFMCarbon/mac_source/include/GL/glu.h b/libraries/ode-0.9/contrib/Mac_CFMCarbon/mac_source/include/GL/glu.h
new file mode 100644
index 0000000..5b4a791
--- /dev/null
+++ b/libraries/ode-0.9/contrib/Mac_CFMCarbon/mac_source/include/GL/glu.h
@@ -0,0 +1,2 @@
1// A little hackaround (Apple use / in the FILENAME, which doesn't work when following DOS paths)
2#include <glu.h> \ No newline at end of file
diff --git a/libraries/ode-0.9/contrib/Mac_CFMCarbon/mac_source/include/ode/config.h b/libraries/ode-0.9/contrib/Mac_CFMCarbon/mac_source/include/ode/config.h
new file mode 100644
index 0000000..bb889f9
--- /dev/null
+++ b/libraries/ode-0.9/contrib/Mac_CFMCarbon/mac_source/include/ode/config.h
@@ -0,0 +1,52 @@
1/* This file has been manually hacked together for the Mac CFM Carbon build - Frank. */
2
3#ifndef _ODE_CONFIG_H_
4#define _ODE_CONFIG_H_
5
6/* standard system headers */
7#include <stdio.h>
8#include <stdlib.h>
9#include <math.h>
10#include <string.h>
11#include <stdarg.h>
12#include <malloc.h>
13#include <alloca.h>
14#include <float.h>
15
16#ifdef __cplusplus
17extern "C" {
18#endif
19
20/* #define PENTIUM 1 -- not a pentium */
21
22/* integer types (we assume int >= 32 bits) */
23typedef char int8;
24typedef unsigned char uint8;
25typedef int int32;
26typedef unsigned int uint32;
27
28/* an integer type that we can safely cast a pointer to and from without loss of bits. */
29typedef unsigned int intP;
30
31#ifdef PRECISION_DOUBLE
32
33 /*select the base floating point type*/
34 #define dDOUBLE 1
35
36 /* the floating point infinity */
37 #define dInfinity DBL_MAX
38
39#else
40
41 /* select the base floating point type */
42 #define dSINGLE 1
43
44 /* the floating point infinity */
45 #define dInfinity FLT_MAX
46
47#endif
48
49#ifdef __cplusplus
50}
51#endif
52#endif \ No newline at end of file
diff --git a/libraries/ode-0.9/contrib/Mac_CFMCarbon/mac_source/ode/test/test_stability1.cpp b/libraries/ode-0.9/contrib/Mac_CFMCarbon/mac_source/ode/test/test_stability1.cpp
new file mode 100644
index 0000000..79c066a
--- /dev/null
+++ b/libraries/ode-0.9/contrib/Mac_CFMCarbon/mac_source/ode/test/test_stability1.cpp
@@ -0,0 +1,289 @@
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 <ode/ode.h>
24#include <drawstuff/drawstuff.h>
25
26#ifdef _MSC_VER
27#pragma warning(disable:4244 4305) // for VC++, no precision loss complaints
28#endif
29
30// select correct drawing functions
31
32#ifdef dDOUBLE
33#define dsDrawBox dsDrawBoxD
34#define dsDrawSphere dsDrawSphereD
35#define dsDrawCylinder dsDrawCylinderD
36#define dsDrawCappedCylinder dsDrawCappedCylinderD
37#endif
38
39
40// some constants
41
42#define DENSITY (5.0) // density of all objects
43
44// dynamics and collision objects
45
46struct MyObject {
47 dBodyID body; // the body
48 dGeomID geom; // geometry representing this body
49};
50
51static dWorldID world;
52static dSpaceID space;
53static MyObject fallingObject;
54static dGeomID box1, box2;
55static dJointGroupID contactgroup;
56
57
58// this is called by dSpaceCollide when two objects in space are
59// potentially colliding.
60
61static void nearCallback (void *data, dGeomID o1, dGeomID o2)
62{
63 int i;
64 // if (o1->body && o2->body) return;
65
66 // exit without doing anything if the two bodies are connected by a joint
67 dBodyID b1 = dGeomGetBody(o1);
68 dBodyID b2 = dGeomGetBody(o2);
69 if (b1 && b2 && dAreConnected (b1,b2)) return;
70
71 dContact contact[4]; // up to 3 contacts per box
72 for (i=0; i<4; i++) {
73 contact[i].surface.mode = dContactBounce; //dContactMu2;
74 contact[i].surface.mu = dInfinity;
75 contact[i].surface.mu2 = 0;
76 contact[i].surface.bounce = 0.5;
77 contact[i].surface.bounce_vel = 0.1;
78 }
79 if (int numc = dCollide (o1,o2,4,&contact[0].geom,sizeof(dContact))) {
80 // dMatrix3 RI;
81 // dRSetIdentity (RI);
82 // const dReal ss[3] = {0.02,0.02,0.02};
83 for (i=0; i<numc; i++) {
84 dJointID c = dJointCreateContact (world,contactgroup,contact+i);
85 dJointAttach (c,b1,b2);
86 // dsDrawBox (contact[i].geom.pos,RI,ss);
87 }
88 }
89}
90
91
92// start simulation - set viewpoint
93
94static void start()
95{
96 static float xyz[3] = {-4.0f, 0.0f, 3.0f};
97 static float hpr[3] = {0.0f,-15.0f,0.0f};
98 dsSetViewpoint (xyz,hpr);
99 printf ("To drop another object, press:\n");
100 printf (" b for box.\n");
101 printf (" s for sphere.\n");
102 printf (" c for cylinder.\n");
103 printf ("To select an object, press space.\n");
104}
105
106
107char locase (char c)
108{
109 if (c >= 'A' && c <= 'Z') return c - ('a'-'A');
110 else return c;
111}
112
113
114// called when a key pressed
115
116static void command (int cmd)
117{
118 int i,k;
119 dReal sides[3];
120 dMass m;
121
122 cmd = locase (cmd);
123 if (cmd == 'b' || cmd == 's' || cmd == 'c') {
124 // Destroy the currently falling object and replace it by an instance of the requested type
125 if (fallingObject.body) {
126 dBodyDestroy (fallingObject.body);
127 dGeomDestroy (fallingObject.geom);
128 memset (&fallingObject, 0, sizeof(fallingObject));
129 }
130
131 fallingObject.body = dBodyCreate (world);
132 for (k=0; k<3; k++) sides[k] = dRandReal()*0.5+0.1;
133
134 // Start out centered above the V-gap
135 dBodySetPosition (fallingObject.body, 0,0,5);
136
137#if 0
138 dMatrix3 R;
139 dRFromAxisAndAngle (R,dRandReal()*2.0-1.0,dRandReal()*2.0-1.0,
140 dRandReal()*2.0-1.0,dRandReal()*10.0-5.0);
141 dBodySetRotation (fallingObject.body,R);
142 dBodySetData (fallingObject.body,(void*) i);
143#endif
144
145 if (cmd == 'b') {
146 dMassSetBox (&m,DENSITY,sides[0],sides[1],sides[2]);
147 fallingObject.geom = dCreateBox (space,sides[0],sides[1],sides[2]);
148 }
149 else if (cmd == 'c') {
150 sides[0] *= 0.5;
151 dMassSetCappedCylinder (&m,DENSITY,3,sides[0],sides[1]);
152 fallingObject.geom = dCreateCCylinder (space,sides[0],sides[1]);
153 }
154 else if (cmd == 's') {
155 sides[0] *= 0.5;
156 dMassSetSphere (&m,DENSITY,sides[0]);
157 fallingObject.geom = dCreateSphere (space,sides[0]);
158 }
159
160 dGeomSetBody (fallingObject.geom,fallingObject.body);
161
162 dBodySetMass (fallingObject.body,&m);
163 }
164}
165
166
167// draw a geom
168
169void drawGeom (dGeomID g, const dReal *pos, const dReal *R)
170{
171 if (!g) return;
172 if (!pos) pos = dGeomGetPosition (g);
173 if (!R) R = dGeomGetRotation (g);
174
175 int type = dGeomGetClass (g);
176 if (type == dBoxClass) {
177 dVector3 sides;
178 dGeomBoxGetLengths (g,sides);
179 dsDrawBox (pos,R,sides);
180 }
181 else if (type == dSphereClass) {
182 dsDrawSphere (pos,R,dGeomSphereGetRadius (g));
183 }
184 else if (type == dCCylinderClass) {
185 dReal radius,length;
186 dGeomCCylinderGetParams (g,&radius,&length);
187 dsDrawCappedCylinder (pos,R,length,radius);
188 }
189 /*
190 else if (type == dGeomTransformClass) {
191 dGeomID g2 = dGeomTransformGetGeom (g);
192 const dReal *pos2 = dGeomGetPosition (g2);
193 const dReal *R2 = dGeomGetRotation (g2);
194 dVector3 actual_pos;
195 dMatrix3 actual_R;
196 dMULTIPLY0_331 (actual_pos,R,pos2);
197 actual_pos[0] += pos[0];
198 actual_pos[1] += pos[1];
199 actual_pos[2] += pos[2];
200 dMULTIPLY0_333 (actual_R,R,R2);
201 drawGeom (g2,actual_pos,actual_R);
202 }
203 */
204}
205
206
207// simulation loop
208
209static void simLoop (int pause)
210{
211 dsSetColor (0,0,2);
212 dSpaceCollide (space,0,&nearCallback);
213 if (!pause) dWorldStep (world,0.0005);
214
215 // remove all contact joints
216 dJointGroupEmpty (contactgroup);
217
218 dsSetColor (1,1,0);
219 dsSetTexture (DS_WOOD);
220
221 // draw the falling object
222 dsSetColor (1,0,0);
223 drawGeom (fallingObject.geom,0,0);
224
225 // draw the constraining boxes
226 dsSetColor(0.8, 1, 0.8);
227 drawGeom (box1,0,0);
228 drawGeom (box2,0,0);
229}
230
231
232int main (int argc, char **argv)
233{
234 // setup pointers to drawstuff callback functions
235 dsFunctions fn;
236 fn.version = DS_VERSION;
237 fn.start = &start;
238 fn.step = &simLoop;
239 fn.command = &command;
240 fn.stop = 0;
241 fn.path_to_textures = "../../drawstuff/textures";
242 if(argc==2)
243 {
244 fn.path_to_textures = argv[1];
245 }
246
247 // create world
248
249 world = dWorldCreate();
250 space = dHashSpaceCreate();
251 contactgroup = dJointGroupCreate (0);
252 dWorldSetGravity (world,0,0,-0.5);
253 dWorldSetCFM (world,1e-5);
254 dCreatePlane (space,0,0,1,0);
255 memset (&fallingObject,0,sizeof(fallingObject));
256
257 // Create two flat boxes, just slightly off vertical and a bit apart for stuff to fall in between.
258 // Don't create bodies for these boxes -- they'll be immovable instead.
259 {
260 dReal sides[3];
261 dMatrix3 R;
262
263 sides[0] = 4;
264 sides[1] = 0.2;
265 sides[2] = 3;
266
267 box1 = dCreateBox (space,sides[0],sides[1],sides[2]);
268 dGeomSetPosition (box1, 0, sides[1], sides[2]/2);
269 dRFromAxisAndAngle (R, 1, 0, 0, -0.1);
270 dGeomSetRotation (box1, R);
271
272 box2 = dCreateBox (space,sides[0],sides[1],sides[2]);
273 dGeomSetPosition (box2, 0, -sides[1], sides[2]/2);
274 dRFromAxisAndAngle (R, 1, 0, 0, 0.1);
275 dGeomSetRotation (box2, R);
276 }
277
278 // Pretend to drop a box to start
279 command('b');
280
281 // run simulation
282 dsSimulationLoop (argc,argv,640,480,&fn);
283
284 dJointGroupDestroy (contactgroup);
285 dSpaceDestroy (space);
286 dWorldDestroy (world);
287
288 return 0;
289}
diff --git a/libraries/ode-0.9/contrib/Mac_CFMCarbon/mac_source/ode/test/test_stacktest.c b/libraries/ode-0.9/contrib/Mac_CFMCarbon/mac_source/ode/test/test_stacktest.c
new file mode 100644
index 0000000..e49fd73
--- /dev/null
+++ b/libraries/ode-0.9/contrib/Mac_CFMCarbon/mac_source/ode/test/test_stacktest.c
@@ -0,0 +1,197 @@
1#include <stdio.h>
2#include <glut.h>
3#include "ode.h"
4
5#define NUMBODIES 80
6
7#define USE_SPHERE 0
8#define USE_HELIX 1
9#define USE_TORQUE 1
10#define USE_WEIRD_MATRIX_OPS 0
11
12#define CONTACTS 1
13
14dWorldID aWorld;
15dSpaceID aSpace;
16float cycle = 0, fade;
17dJointGroupID aContactGroup;
18dBodyID bodies[NUMBODIES];
19dGeomID geoms[NUMBODIES];
20GLfloat colors[NUMBODIES][4];
21unsigned int contactsThisFrame;
22
23void kglTransformByODEGeom(dGeomID geom) {
24 const dReal *p = dGeomGetPosition(geom);
25 const dReal *R = dGeomGetRotation(geom);
26 GLdouble glm[16];
27
28 glm[0] = R[0]; glm[1] = R[4]; glm[2] = R[8]; glm[3] = 0;
29 glm[4] = R[1]; glm[5] = R[5]; glm[6] = R[9]; glm[7] = 0;
30 glm[8] = R[2]; glm[9] = R[6]; glm[10] = R[10];glm[11] = 0;
31 glm[12] = p[0]; glm[13] = p[1]; glm[14] = p[2]; glm[15] = 1;
32
33 glMultMatrixd(glm);
34}
35
36static void odeNearCallback(void *data, dGeomID g1, dGeomID g2) {
37 dBodyID b1 = dGeomGetBody(g1),
38 b2 = dGeomGetBody(g2);
39 dContact contact[CONTACTS];
40 int contactsUsed, i;
41
42 if (b1 && b2 && dAreConnected(b1, b2)) return;
43
44 contactsUsed = dCollide(g1, g2, CONTACTS, &contact[0].geom,
45 sizeof(dContact));
46 if (contactsUsed > CONTACTS) contactsUsed = CONTACTS;
47
48 for (i = 0; i < contactsUsed; i++) {
49 contact[i].surface.mode = 0;
50 contact[i].surface.mu = 20.0;
51
52 dJointAttach(dJointCreateContact(aWorld, aContactGroup,
53 &(contact[i])), b1, b2);
54 contactsThisFrame++;
55 }
56}
57
58void myGlutResize(int w, int h) {
59 glViewport(0, 0, w, h);
60 glMatrixMode(GL_PROJECTION);
61 glLoadIdentity();
62 gluPerspective(45.0, (GLfloat)w / h, 1.0, 120.0);
63 glMatrixMode(GL_MODELVIEW);
64 glLoadIdentity();
65 glTranslatef(0, -6, -20);
66}
67
68void myGlutIdle(void) {
69 const float step = 1.0/120;
70 int i;
71
72 cycle = fmod(cycle + step / 4, 1);
73 fade = fabs(cycle * 2 - 1);
74
75 contactsThisFrame = 0;
76 dSpaceCollide(aSpace, NULL, &odeNearCallback);
77 //printf("%u\n", contactsThisFrame);
78 dWorldStep(aWorld, step);
79 dJointGroupEmpty(aContactGroup);
80
81 for (i = 0; i < NUMBODIES; i++) {
82 const dReal *cvel = dBodyGetLinearVel(bodies[i]);
83 dBodyAddForce(bodies[i],
84 -cvel[0] * 0.5,
85 -cvel[1] * 0.5,
86 -cvel[2] * 0.5
87 );
88 }
89
90 glutPostRedisplay();
91}
92
93void myGlutDisplay(void) {
94 int i;
95
96 glClearColor(fade * 0.15, 0, 0, 1);
97 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
98
99 if (USE_WEIRD_MATRIX_OPS) glPushMatrix();
100 for (i = 0; i < NUMBODIES; i++) {
101 if (!USE_WEIRD_MATRIX_OPS) glPushMatrix();
102 kglTransformByODEGeom(geoms[i]);
103 glMaterialfv(GL_FRONT, GL_AMBIENT_AND_DIFFUSE, colors[i]);
104 glColor3f(fade * 1.5, 0, 0);
105#if USE_SPHERE
106 glRotatef(90, 1, 0, 0);
107 glutSolidSphere(0.5, 9, 6);
108 glDisable(GL_LIGHTING);
109 glutWireSphere(0.5, 9, 6);
110#else
111 glutSolidCube(1);
112 glDisable(GL_LIGHTING);
113 glutWireCube(1);
114#endif
115 glEnable(GL_LIGHTING);
116 if (!USE_WEIRD_MATRIX_OPS) glPopMatrix();
117 }
118 if (USE_WEIRD_MATRIX_OPS) glPopMatrix();
119
120 glutSwapBuffers();
121}
122
123int main(int argc, char **argv) {
124 printf("Initializing GLUT\n");
125
126 glutInit(&argc, argv);
127 glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH);
128 glutInitWindowSize(400, 300);
129 glutInitWindowPosition(100, 100);
130 glutCreateWindow("ODE Crash Test");
131
132 glutDisplayFunc(myGlutDisplay);
133 glutReshapeFunc(myGlutResize);
134 glutIdleFunc(myGlutIdle);
135
136 glPolygonOffset(1, 1);
137 glDepthFunc(GL_LEQUAL);
138 glEnable(GL_POLYGON_OFFSET_FILL);
139 glEnable(GL_DEPTH_TEST);
140 glEnable(GL_CULL_FACE);
141 glEnable(GL_LIGHTING);
142 glEnable(GL_LIGHT0);
143 myGlutResize(400, 300);
144
145 printf("Creating ODE world\n");
146 aWorld = dWorldCreate();
147 aSpace = dHashSpaceCreate();
148 aContactGroup = dJointGroupCreate(0);
149 dCreatePlane(aSpace, 0, 1, 0, 0);
150 dWorldSetGravity(aWorld, 0, -9.81, 0);
151 dWorldSetERP(aWorld, 0.4);
152 dWorldSetCFM(aWorld, 1e-10);
153
154 printf("Creating objects\n");
155 {
156 int i;
157 dMass mass;
158
159 dMassSetBox(&mass, 1.0, 1, 1, 1);
160
161 for (i = 0; i < NUMBODIES; i++) {
162 float fraction = (float)i / NUMBODIES;
163
164 bodies[i] = dBodyCreate(aWorld);
165 dBodySetMass(bodies[i], &mass);
166#if USE_SPHERE
167 geoms[i] = dCreateSphere(aSpace, 0.5);
168#else
169 geoms[i] = dCreateBox(aSpace, 1, 1, 1);
170#endif
171 dGeomSetBody(geoms[i], bodies[i]);
172
173 if (USE_HELIX) {
174 float r = (i % 3 - 1) * (1.5+4*(1 - fraction)),
175 theta = (float)i / 4;
176 dBodySetPosition(bodies[i],
177 sin(theta) * r,
178 (float)i + 1,
179 cos(theta) * r
180 );
181 } else {
182 dBodySetPosition(bodies[i], 0, (float)i * 2 + 1, 0);
183 }
184 if (USE_TORQUE) dBodyAddTorque(bodies[i], fraction*10, fraction*20, fraction*30);
185
186 colors[i][0] = fraction;
187 colors[i][1] = 1 - fraction;
188 colors[i][2] = 1 - fabs(fraction * 2 - 1);
189 colors[i][3] = 1;
190 }
191 }
192
193 printf("Starting simulation\n");
194 glutMainLoop();
195
196 return 0;
197} \ No newline at end of file