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
Line 
1#include "framework.h"
2
3int verbose = 1;
4
5void DrawGLScene()
6{
7  dist -= (dist-zoomTo)/100;
8
9  rotatorP += rotatorV;
10 
11  glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
12  glLoadIdentity(); // Reset the view
13 
14  glMatrixMode(GL_PROJECTION);
15  glLoadIdentity();     
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);
18
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  }
39 
40  printf ("%i, %i\n", wHandler.screen->w, wHandler.screen->h);
41  if (argc>=3)
42    obj = new Object (argv[1], atof(argv[2]));
43  else if (argc>=2)
44    obj = new Object(argv[1]);
45  else 
46    obj = new Object();
47 
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};
54  GLfloat lmodelAmbient[] = {.1, .1, .1, 1.0};
55
56  glEnable(GL_LIGHT0);
57  glLightfv(GL_LIGHT0, GL_POSITION, light0Position);
58  glLightfv(GL_LIGHT0, GL_DIFFUSE, whiteLight);
59  glLightfv(GL_LIGHT0, GL_SPECULAR, whiteLight);
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;
68  dist = 5.0;
69  zoomTo = dist;
70  // Build the font from a TGA image font.tga in the data directory
71  // Hide the mouse cursor
72    SDL_ShowCursor(2);
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) {
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:
90        if (event.button.button == 4)
91          {
92            printf("MouseWheel up\n");
93            zoomTo *= .5;
94          }
95        else if (event.button.button == 5)
96          {
97            printf("MouseWheel down\n");
98            zoomTo *= 2;
99          }
100        else
101          {
102            printf("MouseButton %d pressed at (%d,%d).\n",
103                   event.button.button, event.button.x, event.button.y);
104            rotatorV = ( (float)wHandler.screen->w/2 -event.button.x) / (float)wHandler.screen->w / 100.0;
105          }
106           
107        break;
108            /*      case SDL_MOUSEBUTTONUP:
109        printf("MouseButton %d released at (%d,%d).\n",
110               event.button.button, event.button.x, event.button.y);
111        break;
112            */
113        // If a quit event was recieved
114      case SDL_QUIT:
115        // then we're done and we'll end this program
116          done=TRUE;
117          break;
118      default:
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
131  delete obj;
132  wHandler.KillGLWindow();
133  // And quit
134  return 0;
135}
Note: See TracBrowser for help on using the repository browser.