2
Bullet Continuous Collision Detection and Physics Library
3
Copyright (c) 2003-2006 Erwin Coumans http://continuousphysics.com/Bullet/
5
This software is provided 'as-is', without any express or implied warranty.
6
In no event will the authors be held liable for any damages 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 freely,
9
subject to the following restrictions:
11
1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required.
12
2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software.
13
3. This notice may not be removed or altered from any source distribution.
16
#ifdef WIN32//for glut.h
23
#include "IDebugDraw.h"
24
//see IDebugDraw.h for modes
25
static int sDebugMode = 0;
32
void setDebugMode(int mode)
40
#include "GlutStuff.h"
44
GLfloat light_ambient[] = { 0.0, 0.0, 0.0, 1.0 };
45
GLfloat light_diffuse[] = { 1.0, 1.0, 1.0, 1.0 };
46
GLfloat light_specular[] = { 1.0, 1.0, 1.0, 1.0 };
47
/* light_position is NOT default value */
48
GLfloat light_position0[] = { 1.0, 1.0, 1.0, 0.0 };
49
GLfloat light_position1[] = { -1.0, -1.0, -1.0, 0.0 };
51
glLightfv(GL_LIGHT0, GL_AMBIENT, light_ambient);
52
glLightfv(GL_LIGHT0, GL_DIFFUSE, light_diffuse);
53
glLightfv(GL_LIGHT0, GL_SPECULAR, light_specular);
54
glLightfv(GL_LIGHT0, GL_POSITION, light_position0);
56
glLightfv(GL_LIGHT1, GL_AMBIENT, light_ambient);
57
glLightfv(GL_LIGHT1, GL_DIFFUSE, light_diffuse);
58
glLightfv(GL_LIGHT1, GL_SPECULAR, light_specular);
59
glLightfv(GL_LIGHT1, GL_POSITION, light_position1);
61
glEnable(GL_LIGHTING);
66
glShadeModel(GL_SMOOTH);
67
glEnable(GL_DEPTH_TEST);
70
glClearColor(0.8,0.8,0.8,0);
72
// glEnable(GL_CULL_FACE);
73
// glCullFace(GL_BACK);
77
static float DISTANCE = 15;
78
void setCameraDistance(float dist)
83
static float ele = 0, azi = 0;
84
float eye[3] = {0, 0, DISTANCE};
85
static float center[3] = {0, 0, 0};
86
static const double SCALE_BOTTOM = 0.5;
87
static const double SCALE_FACTOR = 2;
90
bool singleStep = false;
93
static bool idle = false;
99
glutIdleFunc(clientMoveAndDisplay);
111
glMatrixMode(GL_PROJECTION);
113
float rele = ele * 0.01745329251994329547;// rads per deg
114
float razi = azi * 0.01745329251994329547;// rads per deg
115
eye[0] = DISTANCE * sin(razi) * cos(rele);
116
eye[1] = DISTANCE * sin(rele);
117
eye[2] = DISTANCE * cos(razi) * cos(rele);
120
glFrustum(-1.0, 1.0, -1.0, 1.0, 1.0, 100.0);
121
gluLookAt(eye[0], eye[1], eye[2],
122
center[0], center[1], center[2],
124
glMatrixMode(GL_MODELVIEW);
129
const float STEPSIZE = 5;
131
void stepLeft() { azi -= STEPSIZE; if (azi < 0) azi += 360; setCamera(); }
132
void stepRight() { azi += STEPSIZE; if (azi >= 360) azi -= 360; setCamera(); }
133
void stepFront() { ele += STEPSIZE; if (azi >= 360) azi -= 360; setCamera(); }
134
void stepBack() { ele -= STEPSIZE; if (azi < 0) azi += 360; setCamera(); }
135
void zoomIn() { DISTANCE -= 1; setCamera(); }
136
void zoomOut() { DISTANCE += 1; setCamera(); }
139
int glutScreenWidth = 0;
140
int glutScreenHeight = 0;
142
void myReshape(int w, int h) {
144
glutScreenHeight = h;
146
glViewport(0, 0, w, h);
152
void defaultKeyboard(unsigned char key, int x, int y)
158
case 'q' : exit(0); break;
160
case 'l' : stepLeft(); break;
161
case 'r' : stepRight(); break;
162
case 'f' : stepFront(); break;
163
case 'b' : stepBack(); break;
164
case 'z' : zoomIn(); break;
165
case 'x' : zoomOut(); break;
166
case 'i' : toggleIdle(); break;
168
if (sDebugMode & IDebugDraw::DBG_NoHelpText)
169
sDebugMode = sDebugMode & (~IDebugDraw::DBG_NoHelpText);
171
sDebugMode |= IDebugDraw::DBG_NoHelpText;
175
if (sDebugMode & IDebugDraw::DBG_DrawWireframe)
176
sDebugMode = sDebugMode & (~IDebugDraw::DBG_DrawWireframe);
178
sDebugMode |= IDebugDraw::DBG_DrawWireframe;
182
if (sDebugMode & IDebugDraw::DBG_ProfileTimings)
183
sDebugMode = sDebugMode & (~IDebugDraw::DBG_ProfileTimings);
185
sDebugMode |= IDebugDraw::DBG_ProfileTimings;
189
if (sDebugMode & IDebugDraw::DBG_EnableSatComparison)
190
sDebugMode = sDebugMode & (~IDebugDraw::DBG_EnableSatComparison);
192
sDebugMode |= IDebugDraw::DBG_EnableSatComparison;
196
if (sDebugMode & IDebugDraw::DBG_DisableBulletLCP)
197
sDebugMode = sDebugMode & (~IDebugDraw::DBG_DisableBulletLCP);
199
sDebugMode |= IDebugDraw::DBG_DisableBulletLCP;
203
if (sDebugMode & IDebugDraw::DBG_DrawText)
204
sDebugMode = sDebugMode & (~IDebugDraw::DBG_DrawText);
206
sDebugMode |= IDebugDraw::DBG_DrawText;
209
if (sDebugMode & IDebugDraw::DBG_DrawFeaturesText)
210
sDebugMode = sDebugMode & (~IDebugDraw::DBG_DrawFeaturesText);
212
sDebugMode |= IDebugDraw::DBG_DrawFeaturesText;
215
if (sDebugMode & IDebugDraw::DBG_DrawAabb)
216
sDebugMode = sDebugMode & (~IDebugDraw::DBG_DrawAabb);
218
sDebugMode |= IDebugDraw::DBG_DrawAabb;
221
if (sDebugMode & IDebugDraw::DBG_DrawContactPoints)
222
sDebugMode = sDebugMode & (~IDebugDraw::DBG_DrawContactPoints);
224
sDebugMode |= IDebugDraw::DBG_DrawContactPoints;
228
if (sDebugMode & IDebugDraw::DBG_NoDeactivation)
229
sDebugMode = sDebugMode & (~IDebugDraw::DBG_NoDeactivation);
231
sDebugMode |= IDebugDraw::DBG_NoDeactivation;
238
stepping = !stepping;
241
case 's' : clientMoveAndDisplay(); break;
242
// case ' ' : newRandom(); break;
248
if (sDebugMode & IDebugDraw::DBG_EnableCCD)
249
sDebugMode = sDebugMode & (~IDebugDraw::DBG_EnableCCD);
251
sDebugMode |= IDebugDraw::DBG_EnableCCD;
255
// std::cout << "unused key : " << key << std::endl;
264
void mySpecial(int key, int x, int y)
268
case GLUT_KEY_LEFT : stepLeft(); break;
269
case GLUT_KEY_RIGHT : stepRight(); break;
270
case GLUT_KEY_UP : stepFront(); break;
271
case GLUT_KEY_DOWN : stepBack(); break;
272
case GLUT_KEY_PAGE_UP : zoomIn(); break;
273
case GLUT_KEY_PAGE_DOWN : zoomOut(); break;
274
case GLUT_KEY_HOME : toggleIdle(); break;
276
// std::cout << "unused (special) key : " << key << std::endl;
287
printf("goodbye \n");
292
void menu(int choice)
294
static int fullScreen = 0;
295
static int px, py, sx, sy;
299
if (fullScreen == 1) {
300
glutPositionWindow(px,py);
301
glutReshapeWindow(sx,sy);
302
glutChangeToMenuEntry(1,"Full Screen",1);
305
px=glutGet((GLenum)GLUT_WINDOW_X);
306
py=glutGet((GLenum)GLUT_WINDOW_Y);
307
sx=glutGet((GLenum)GLUT_WINDOW_WIDTH);
308
sy=glutGet((GLenum)GLUT_WINDOW_HEIGHT);
310
glutChangeToMenuEntry(1,"Close Full Screen",1);
327
glutCreateMenu(menu);
328
glutAddMenuEntry("Full Screen", 1);
329
glutAddMenuEntry("Toggle Idle (Start/Stop)", 2);
330
glutAddMenuEntry("Quit", 3);
331
glutAttachMenu(GLUT_RIGHT_BUTTON);
336
int glutmain(int argc, char **argv,int width,int height,const char* title) {
339
glutInit(&argc, argv);
340
glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGBA | GLUT_DEPTH);
341
glutInitWindowPosition(0, 0);
342
glutInitWindowSize(width, height);
343
glutCreateWindow(title);
346
glutKeyboardFunc(clientKeyboard);
347
glutSpecialFunc(mySpecial);
348
glutReshapeFunc(myReshape);
350
glutIdleFunc(clientMoveAndDisplay);
351
glutMouseFunc(clientMouseFunc);
352
glutMotionFunc(clientMotionFunc);
353
glutDisplayFunc( clientDisplay );