Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/orxonox/trunk/importer/framework.cc @ 2938

Last change on this file since 2938 was 2938, checked in by bensch, 20 years ago

orxonox/trunk/importer: smoothZoom

File size: 3.6 KB
Line 
1#include "framework.h"
2
3int verbose = 1;
4
5void DrawGLScene()
6{
7  if (dist > zoomTo +.1)
8    dist -= .1;
9  else if (dist < zoomTo -.1)
10    dist += .1;
11  rotatorP += rotatorV;
12 
13  glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
14  glLoadIdentity(); // Reset the view
15 
16  glMatrixMode(GL_PROJECTION);
17  glLoadIdentity();     
18  gluPerspective(45.0f,500/375,0.1f,dist * 5.0f);
19  gluLookAt (dist*sin(rotatorP),dist ,dist*cos(rotatorP), 0,0,0, 0,1,0);
20
21  obj->draw();
22
23  SDL_GL_SwapBuffers(); // Swap the buffers
24}
25
26
27int main(int argc, char *argv[])
28{
29  Uint8* keys; // This variable will be used in the keyboard routine
30  int done=FALSE; // We aren't done yet, are we?
31
32  // Create a new OpenGL window with the title "Cone3D Basecode" at
33  // 640x480x32, fullscreen and check for errors along the way
34  if(wHandler.CreateGLWindow("Whandler Basecode", 500, 375, 32, FALSE) == FALSE)
35  {
36    // If an error is found, display a message, kill the GL and SDL screens (if they were created) and exit
37    printf("Could not initalize OpenGL :(\n\n");
38    wHandler.KillGLWindow();
39    return 0;
40  }
41 
42  printf ("%i, %i\n", wHandler.screen->w, wHandler.screen->h);
43  if (argc>=3)
44    obj = new Object (argv[1], atof(argv[2]));
45  else if (argc>=2)
46    obj = new Object(argv[1]);
47  else 
48    obj = new Object();
49 
50  glEnable(GL_LIGHTING);
51  glEnable(GL_DEPTH_TEST);
52
53  GLfloat whiteLight[] = {1.0, 1.0, 1.0,1.0};
54  GLfloat light0Position[] = {10.0, 10.0, 10.0, 0.0};
55  GLfloat light1Position[] = {-10.0, -7.0, -6.0, 0.0};
56  GLfloat lmodelAmbient[] = {.1, .1, .1, 1.0};
57
58  glEnable(GL_LIGHT0);
59  glLightfv(GL_LIGHT0, GL_POSITION, light0Position);
60  glLightfv(GL_LIGHT0, GL_DIFFUSE, whiteLight);
61  glLightfv(GL_LIGHT0, GL_SPECULAR, whiteLight);
62 
63  glEnable(GL_LIGHT1);
64  glLightfv(GL_LIGHT1, GL_POSITION, light1Position);
65  glLightfv(GL_LIGHT1, GL_DIFFUSE, whiteLight);
66  glLightfv(GL_LIGHT1, GL_SPECULAR, whiteLight);
67 
68  rotatorP = .0;
69  rotatorV = .0;
70  dist = 5.0;
71  zoomTo = dist;
72  // Build the font from a TGA image font.tga in the data directory
73  // Hide the mouse cursor
74    SDL_ShowCursor(2);
75
76  // This is the main loop for the entire program and it will run until done==TRUE
77  while(!done)
78  {
79    // Draw the scene
80    DrawGLScene();
81    // And poll for events
82    SDL_Event event;
83    while ( SDL_PollEvent(&event) ) {
84      switch (event.type) {
85      case SDL_MOUSEMOTION:
86        if (verbose >=3)
87          printf("Mouse motion about %d,%d Pixels to (%d,%d).\n", 
88                 event.motion.xrel, event.motion.yrel,
89                 event.motion.x, event.motion.y);
90        break;
91      case SDL_MOUSEBUTTONDOWN:
92        if (event.button.button == 4)
93          {
94            printf("MouseWheel up\n");
95            zoomTo *= .5;
96          }
97        else if (event.button.button == 5)
98          {
99            printf("MouseWheel down\n");
100            zoomTo *= 2;
101          }
102        else
103          {
104            printf("MouseButton %d pressed at (%d,%d).\n",
105                   event.button.button, event.button.x, event.button.y);
106            rotatorV = ( (float)wHandler.screen->w/2 -event.button.x) / (float)wHandler.screen->w / 100.0;
107          }
108           
109        break;
110            /*      case SDL_MOUSEBUTTONUP:
111        printf("MouseButton %d released at (%d,%d).\n",
112               event.button.button, event.button.x, event.button.y);
113        break;
114            */
115        // If a quit event was recieved
116      case SDL_QUIT:
117        // then we're done and we'll end this program
118          done=TRUE;
119          break;
120      default:
121          break;
122      }
123    }
124
125    // Get the state of the keyboard keys
126    keys = SDL_GetKeyState(NULL);
127
128    // and check if ESCAPE has been pressed. If so then quit
129    if(keys[SDLK_ESCAPE]) done=TRUE;
130  }
131
132  // Kill the GL & SDL screens
133  delete obj;
134  wHandler.KillGLWindow();
135  // And quit
136  return 0;
137}
Note: See TracBrowser for help on using the repository browser.