Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/orxonox/trunk/src/importer/framework.cc @ 3201

Last change on this file since 3201 was 3201, checked in by bensch, 19 years ago

orxonox/trunk/src/importer: how logging could be

File size: 6.2 KB
Line 
1/*
2   orxonox - the future of 3D-vertical-scrollers
3
4   Copyright (C) 2004 orx
5
6   This program is free software; you can redistribute it and/or modify
7   it under the terms of the GNU General Public License as published by
8   the Free Software Foundation; either version 2, or (at your option)
9   any later version.
10
11   ### File Specific:
12   main-programmer: Benjamin Grauer
13   co-programmer: ...
14*/
15
16#include "framework.h"
17#define PRINTF(x) \
18        if (verbose = x ) \
19           printf ("%s:%d:", __FILE__, __LINE__); printf
20
21
22void DrawGLScene()
23{
24  currFrame = SDL_GetTicks();
25  dt = currFrame - lastFrame; 
26  if (dt == 0)
27    dist += (zoomTo-dist)/500;
28  else 
29    dist += (zoomTo-dist)/500 *(float)dt;
30
31  rotatorP += rotatorV *(float)dt;
32 
33
34  glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
35  glLoadIdentity(); // Reset the view
36 
37  glMatrixMode(GL_PROJECTION);
38  glLoadIdentity();     
39  gluPerspective(45.0f,500/375,0.1f,dist * 5.0f);
40    gluLookAt (0, dist , dist, 0,0,0, up.x,up.y,up.z);
41
42  glMatrixMode(GL_MODELVIEW);
43  glPushMatrix();
44  //  glRotatef (180, dir.x, dir.y, dir.z);
45  glMultMatrixf (*matQ);
46  obj->draw();
47
48  glPopMatrix();
49
50  SDL_GL_SwapBuffers(); // Swap the buffers
51  lastFrame = currFrame;
52}
53
54
55int main(int argc, char *argv[])
56{
57
58  PRINTF(1)("This is The big verbose-Test %i, %s\n", 1, "cool");
59
60  int verbose = 2;
61  Uint8* keys; // This variable will be used in the keyboard routine
62  int done=FALSE; // We aren't done yet, are we?
63
64  // Create a new OpenGL window with the title "Cone3D Basecode" at
65  // 640x480x32, fullscreen and check for errors along the way
66  if(wHandler.CreateGLWindow("Whandler Basecode", 800, 600, 32, FALSE) == FALSE)
67  {
68    // If an error is found, display a message, kill the GL and SDL screens (if they were created) and exit
69    printf("Could not initalize OpenGL :(\n\n");
70    wHandler.KillGLWindow();
71    return 0;
72  }
73 
74  printf ("%i, %i\n", wHandler.screen->w, wHandler.screen->h);
75  if (argc>=3)
76    obj = new Object (argv[1], atof(argv[2]));
77  else if (argc>=2)
78    obj = new Object(argv[1]);
79  else 
80    obj = new Object();
81 
82  M = Vector(wHandler.screen->w/2, wHandler.screen->h/2, 0); 
83  rotAxis = Vector (0.0,1.0,0.0);
84  rotAngle = 0;
85
86  matQ[0][0] = matQ[1][1] = matQ[2][2] = matQ[3][3] = 1;
87  rotQ = Quaternion (rotAngle, rotAxis);
88  rotQlast = rotQ;
89  dir = Vector (0.0, 0.0, 1.0);
90  up = Vector (0.0, 1.0, 0.0);
91
92  glEnable(GL_LIGHTING);
93  glEnable(GL_DEPTH_TEST);
94
95  GLfloat whiteLight[] = {1.0, 1.0, 1.0,1.0};
96  GLfloat light0Position[] = {10.0, 10.0, 10.0, 0.0};
97  GLfloat light1Position[] = {-10.0, -7.0, -6.0, 0.0};
98  GLfloat lmodelAmbient[] = {.1, .1, .1, 1.0};
99
100  glEnable(GL_LIGHT0);
101  glLightfv(GL_LIGHT0, GL_POSITION, light0Position);
102  glLightfv(GL_LIGHT0, GL_DIFFUSE, whiteLight);
103  glLightfv(GL_LIGHT0, GL_SPECULAR, whiteLight);
104 
105  glEnable(GL_LIGHT1);
106  glLightfv(GL_LIGHT1, GL_POSITION, light1Position);
107  glLightfv(GL_LIGHT1, GL_DIFFUSE, whiteLight);
108  glLightfv(GL_LIGHT1, GL_SPECULAR, whiteLight);
109 
110
111  glEnable(GL_TEXTURE_2D);
112  rotatorP = .0;
113  rotatorV = .0;
114  dist = 5.0;
115  zoomTo = dist;
116  // Build the font from a TGA image font.tga in the data directory
117  // Hide the mouse cursor
118    SDL_ShowCursor(2);
119    mouse1Down = false;
120
121  // This is the main loop for the entire program and it will run until done==TRUE
122  while(!done)
123  {
124    // Draw the scene
125    DrawGLScene();
126    // And poll for events
127    SDL_Event event;
128    while ( SDL_PollEvent(&event) ) {
129      switch (event.type) {
130      case SDL_MOUSEMOTION:
131        if (verbose >=3)
132          printf("Mouse motion about %d,%d Pixels to (%d,%d).\n", 
133                 event.motion.xrel, event.motion.yrel,
134                 event.motion.x, event.motion.y);
135        // TRACKBALL
136        if (mouse1Down)
137          {
138            int mX = event.button.x;
139            int mY = event.button.y;
140            int wH = wHandler.screen->h;
141            int wW = wHandler.screen->w;
142            Vector tmpV (mX, mY, sqrt ( (float) abs(wH * wH/4 - (wW/2-mX) * (wW/2-mX) - (wH/2-mY) * (wH/2-mY)) ));
143            //      printf ("tmpV: %f, %f, %f\n", tmpV.x, tmpV.y, tmpV.z);
144            p2 = tmpV-M;
145            p2.y = -p2.y;
146            rotAxis = p1.cross(p2);
147            //  printf ("rotAxis: %f, %f, %f\n", rotAxis.x, rotAxis.y, rotAxis.z);
148
149            // in case that there is no rotation-axis defined
150            if (rotAxis.x != 0 || rotAxis.y != 0 || rotAxis.z != 0)
151              {
152                rotAxis.normalize();
153                //              printf ("rotAxis: %f, %f, %f\n", rotAxis.x, rotAxis.y, rotAxis.z, rotAngle);
154                               
155                rotAngle = angle_rad (p1, p2);
156                rotQ = Quaternion (rotAngle, rotAxis);
157                rotQ = rotQ * rotQlast;
158                rotQ.matrix (matQ);
159                //      dir = rotQ.apply(dir);
160                //      dir.normalize();
161                //      printf ("rotAxis: %f, %f, %f, %f\n", dir.x, dir.y, dir.z, rotAngle);
162              }
163            rotQlast = rotQ;
164            p1 = p2;
165
166          }
167        break;
168      case SDL_MOUSEBUTTONDOWN:
169        if (event.button.button == 4)
170          {
171            printf("MouseWheel up\n");
172            zoomTo *= .5;
173          }
174        else if (event.button.button == 5)
175          {
176            printf("MouseWheel down\n");
177            zoomTo *= 2.0;
178          }
179        else if (event.button.button == 1)
180          {
181            mouse1Down = true;
182            int mX = event.button.x;
183            int mY = event.button.y;
184            int wH = wHandler.screen->h;
185            int wW = wHandler.screen->w;
186            Vector tmpV (mX, mY, sqrt ( (float) abs(wH * wH/4 - (wW/2-mX) * (wW/2-mX) - (wH/2-mY) * (wH/2-mY)) ));
187            p1 = tmpV-M;
188            p1.y = -p1.y;
189
190          }
191        else
192          {
193            printf("MouseButton %d pressed at (%d,%d).\n",
194                   event.button.button, event.button.x, event.button.y);
195            rotatorV = ( (float)wHandler.screen->w/2 -event.button.x) / (float)wHandler.screen->w / 100.0;
196          }
197           
198        break;
199      case SDL_MOUSEBUTTONUP:
200        if (event.button.button == 4);
201        else if (event.button.button == 5);
202        else if (event.button.button == 1)
203          mouse1Down =false;
204        else 
205            {
206        printf("MouseButton %d released at (%d,%d).\n",
207               event.button.button, event.button.x, event.button.y);
208            }
209        break;
210           
211        // If a quit event was recieved
212      case SDL_QUIT:
213        // then we're done and we'll end this program
214          done=TRUE;
215          break;
216      default:
217          break;
218      }
219
220
221    }
222
223    // Get the state of the keyboard keys
224    keys = SDL_GetKeyState(NULL);
225
226    // and check if ESCAPE has been pressed. If so then quit
227    if(keys[SDLK_ESCAPE]) done=TRUE;
228  }
229
230  // Kill the GL & SDL screens
231  delete obj;
232  wHandler.KillGLWindow();
233  // And quit
234  return 0;
235}
Note: See TracBrowser for help on using the repository browser.