Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

orxonox/trunk/importer: better smooth-Zoom, more dynamic… why diden't i thought of that before.

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