~ubuntu-branches/ubuntu/intrepid/blender/intrepid-updates

« back to all changes in this revision

Viewing changes to extern/bullet/Demos/OpenGL/GlutStuff.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Cyril Brulebois
  • Date: 2008-08-08 02:45:40 UTC
  • mfrom: (12.1.14 intrepid)
  • Revision ID: james.westby@ubuntu.com-20080808024540-kkjp7ekfivzhuw3l
Tags: 2.46+dfsg-4
* Fix python syntax warning in import_dxf.py, which led to nasty output
  in installation/upgrade logs during byte-compilation, using a patch
  provided by the script author (Closes: #492280):
   - debian/patches/45_fix_python_syntax_warning

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*
2
 
Bullet Continuous Collision Detection and Physics Library
3
 
Copyright (c) 2003-2006 Erwin Coumans  http://continuousphysics.com/Bullet/
4
 
 
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:
10
 
 
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.
14
 
*/
15
 
 
16
 
#ifdef WIN32//for glut.h
17
 
#include <windows.h>
18
 
#endif
19
 
#include <GL/glut.h>
20
 
#include <stdlib.h>
21
 
#include <stdio.h>
22
 
#include <math.h>
23
 
#include "IDebugDraw.h"
24
 
//see IDebugDraw.h for modes
25
 
static int      sDebugMode = 0;
26
 
 
27
 
int             getDebugMode()
28
 
{
29
 
        return sDebugMode ;
30
 
}
31
 
 
32
 
void    setDebugMode(int mode)
33
 
{
34
 
        sDebugMode = mode;
35
 
}
36
 
 
37
 
 
38
 
 
39
 
 
40
 
#include "GlutStuff.h"
41
 
 
42
 
void myinit(void) {
43
 
 
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 };
50
 
  
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);
55
 
  
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);
60
 
 
61
 
    glEnable(GL_LIGHTING);
62
 
    glEnable(GL_LIGHT0);
63
 
    glEnable(GL_LIGHT1);
64
 
 
65
 
 
66
 
    glShadeModel(GL_SMOOTH);
67
 
    glEnable(GL_DEPTH_TEST);
68
 
    glDepthFunc(GL_LESS);
69
 
 
70
 
        glClearColor(0.8,0.8,0.8,0);
71
 
 
72
 
    //  glEnable(GL_CULL_FACE);
73
 
    //  glCullFace(GL_BACK);
74
 
}
75
 
 
76
 
 
77
 
static float DISTANCE = 15; 
78
 
void    setCameraDistance(float dist)
79
 
{
80
 
        DISTANCE  = dist;
81
 
}
82
 
 
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;
88
 
 
89
 
bool stepping= true;
90
 
bool singleStep = false;
91
 
 
92
 
 
93
 
static bool idle = false;
94
 
  
95
 
void toggleIdle() {
96
 
 
97
 
        
98
 
    if (idle) {
99
 
                glutIdleFunc(clientMoveAndDisplay);
100
 
        idle = false;
101
 
    }
102
 
    else {
103
 
        glutIdleFunc(0);
104
 
        idle = true;
105
 
    }
106
 
}
107
 
 
108
 
 
109
 
void setCamera() {
110
 
 
111
 
    glMatrixMode(GL_PROJECTION);
112
 
    glLoadIdentity();
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);
118
 
 
119
 
 
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], 
123
 
              0, 1, 0);
124
 
    glMatrixMode(GL_MODELVIEW);
125
 
}
126
 
 
127
 
 
128
 
 
129
 
const float STEPSIZE = 5;
130
 
 
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(); }
137
 
 
138
 
 
139
 
int glutScreenWidth = 0;
140
 
int glutScreenHeight = 0;
141
 
 
142
 
void myReshape(int w, int h) {
143
 
        glutScreenWidth = w;
144
 
        glutScreenHeight = h;
145
 
 
146
 
    glViewport(0, 0, w, h);
147
 
    setCamera();
148
 
}
149
 
 
150
 
int lastKey  = 0;
151
 
 
152
 
void defaultKeyboard(unsigned char key, int x, int y)
153
 
{
154
 
        lastKey = 0;
155
 
 
156
 
    switch (key) 
157
 
    {
158
 
    case 'q' : exit(0); break;
159
 
 
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;
167
 
        case 'h':
168
 
                        if (sDebugMode & IDebugDraw::DBG_NoHelpText)
169
 
                                sDebugMode = sDebugMode & (~IDebugDraw::DBG_NoHelpText);
170
 
                        else
171
 
                                sDebugMode |= IDebugDraw::DBG_NoHelpText;
172
 
                        break;
173
 
 
174
 
        case 'w':
175
 
                        if (sDebugMode & IDebugDraw::DBG_DrawWireframe)
176
 
                                sDebugMode = sDebugMode & (~IDebugDraw::DBG_DrawWireframe);
177
 
                        else
178
 
                                sDebugMode |= IDebugDraw::DBG_DrawWireframe;
179
 
                   break;
180
 
 
181
 
   case 'p':
182
 
           if (sDebugMode & IDebugDraw::DBG_ProfileTimings)
183
 
                sDebugMode = sDebugMode & (~IDebugDraw::DBG_ProfileTimings);
184
 
        else
185
 
                sDebugMode |= IDebugDraw::DBG_ProfileTimings;
186
 
   break;
187
 
 
188
 
   case 'm':
189
 
           if (sDebugMode & IDebugDraw::DBG_EnableSatComparison)
190
 
                sDebugMode = sDebugMode & (~IDebugDraw::DBG_EnableSatComparison);
191
 
        else
192
 
                sDebugMode |= IDebugDraw::DBG_EnableSatComparison;
193
 
   break;
194
 
 
195
 
   case 'n':
196
 
           if (sDebugMode & IDebugDraw::DBG_DisableBulletLCP)
197
 
                sDebugMode = sDebugMode & (~IDebugDraw::DBG_DisableBulletLCP);
198
 
        else
199
 
                sDebugMode |= IDebugDraw::DBG_DisableBulletLCP;
200
 
   break;
201
 
 
202
 
        case 't' : 
203
 
                        if (sDebugMode & IDebugDraw::DBG_DrawText)
204
 
                                sDebugMode = sDebugMode & (~IDebugDraw::DBG_DrawText);
205
 
                        else
206
 
                                sDebugMode |= IDebugDraw::DBG_DrawText;
207
 
                   break;
208
 
        case 'y':               
209
 
                        if (sDebugMode & IDebugDraw::DBG_DrawFeaturesText)
210
 
                                sDebugMode = sDebugMode & (~IDebugDraw::DBG_DrawFeaturesText);
211
 
                        else
212
 
                                sDebugMode |= IDebugDraw::DBG_DrawFeaturesText;
213
 
                break;
214
 
        case 'a':       
215
 
                if (sDebugMode & IDebugDraw::DBG_DrawAabb)
216
 
                                sDebugMode = sDebugMode & (~IDebugDraw::DBG_DrawAabb);
217
 
                        else
218
 
                                sDebugMode |= IDebugDraw::DBG_DrawAabb;
219
 
                        break;
220
 
                case 'c' : 
221
 
                        if (sDebugMode & IDebugDraw::DBG_DrawContactPoints)
222
 
                                sDebugMode = sDebugMode & (~IDebugDraw::DBG_DrawContactPoints);
223
 
                        else
224
 
                                sDebugMode |= IDebugDraw::DBG_DrawContactPoints;
225
 
                        break;
226
 
 
227
 
                case 'd' : 
228
 
                        if (sDebugMode & IDebugDraw::DBG_NoDeactivation)
229
 
                                sDebugMode = sDebugMode & (~IDebugDraw::DBG_NoDeactivation);
230
 
                        else
231
 
                                sDebugMode |= IDebugDraw::DBG_NoDeactivation;
232
 
                        break;
233
 
 
234
 
                
235
 
 
236
 
        case 'o' :
237
 
                {
238
 
                        stepping = !stepping;
239
 
                        break;
240
 
                }
241
 
        case 's' : clientMoveAndDisplay(); break;
242
 
//    case ' ' : newRandom(); break;
243
 
        case ' ':
244
 
                clientResetScene();
245
 
                        break;
246
 
        case '1':
247
 
                {
248
 
                        if (sDebugMode & IDebugDraw::DBG_EnableCCD)
249
 
                                sDebugMode = sDebugMode & (~IDebugDraw::DBG_EnableCCD);
250
 
                        else
251
 
                                sDebugMode |= IDebugDraw::DBG_EnableCCD;
252
 
                        break;
253
 
                }
254
 
    default:
255
 
//        std::cout << "unused key : " << key << std::endl;
256
 
        break;
257
 
    }
258
 
 
259
 
        glutPostRedisplay();
260
 
 
261
 
}
262
 
 
263
 
 
264
 
void mySpecial(int key, int x, int y)
265
 
{
266
 
    switch (key) 
267
 
    {
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;
275
 
    default:
276
 
//        std::cout << "unused (special) key : " << key << std::endl;
277
 
        break;
278
 
    }
279
 
 
280
 
        glutPostRedisplay();
281
 
 
282
 
}
283
 
 
284
 
 
285
 
void goodbye( void)
286
 
{
287
 
    printf("goodbye \n");
288
 
    exit(0);
289
 
}
290
 
 
291
 
 
292
 
void menu(int choice)
293
 
{
294
 
    static int fullScreen = 0;
295
 
    static int px, py, sx, sy;
296
 
 
297
 
    switch(choice) {
298
 
    case 1:
299
 
        if (fullScreen == 1) {
300
 
            glutPositionWindow(px,py);
301
 
            glutReshapeWindow(sx,sy);
302
 
            glutChangeToMenuEntry(1,"Full Screen",1);
303
 
            fullScreen = 0;
304
 
        } else {
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);
309
 
            glutFullScreen();
310
 
            glutChangeToMenuEntry(1,"Close Full Screen",1);
311
 
            fullScreen = 1;
312
 
        }
313
 
        break;
314
 
    case 2:
315
 
        toggleIdle();
316
 
        break;
317
 
    case 3:
318
 
        goodbye();
319
 
        break;
320
 
    default:
321
 
        break;
322
 
    }
323
 
}
324
 
 
325
 
void createMenu()
326
 
{
327
 
    glutCreateMenu(menu);
328
 
    glutAddMenuEntry("Full Screen", 1);
329
 
    glutAddMenuEntry("Toggle Idle (Start/Stop)", 2);
330
 
    glutAddMenuEntry("Quit", 3);
331
 
    glutAttachMenu(GLUT_RIGHT_BUTTON);
332
 
}
333
 
 
334
 
 
335
 
 
336
 
int glutmain(int argc, char **argv,int width,int height,const char* title) {
337
 
    
338
 
 
339
 
        glutInit(&argc, argv);
340
 
    glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGBA | GLUT_DEPTH);
341
 
    glutInitWindowPosition(0, 0);
342
 
    glutInitWindowSize(width, height);
343
 
    glutCreateWindow(title);
344
 
        
345
 
    myinit();
346
 
    glutKeyboardFunc(clientKeyboard);
347
 
    glutSpecialFunc(mySpecial);
348
 
    glutReshapeFunc(myReshape);
349
 
    //createMenu();
350
 
        glutIdleFunc(clientMoveAndDisplay);
351
 
        glutMouseFunc(clientMouseFunc);
352
 
        glutMotionFunc(clientMotionFunc);
353
 
        glutDisplayFunc( clientDisplay );
354
 
 
355
 
        
356
 
    glutMainLoop();
357
 
    return 0;
358
 
}