Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

orxonox/trunk/importer: mousewheel-zoom

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