Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 2977 in orxonox.OLD for orxonox/branches/osX/importer/framework.cc


Ignore:
Timestamp:
Nov 24, 2004, 12:50:55 PM (20 years ago)
Author:
bensch
Message:

orxonox/branches/importer: merged back from the trunk again: command: svn merge trunk/ branches/osX -r 2887:HEAD

File:
1 edited

Legend:

Unmodified
Added
Removed
  • orxonox/branches/osX/importer/framework.cc

    r2863 r2977  
    1 #include "windowHandler.h" // Include the Whandler Basecode
    2 #include "object.h"
     1#include "framework.h"
    32
    43int verbose = 1;
    5 WindowHandler wHandler;  // Create an instance of the whandler basecode class
    6 Object* obj;
    7 float rotator = 0.0;
    8   GLfloat whiteLight[] = {1.0, 1.0, 0.0,1.0};
    94
    105void DrawGLScene()
    116{
    12   rotator +=.001;
    13  
     7  currFrame = SDL_GetTicks();
     8  dt = currFrame - lastFrame;
     9  if (dt == 0)
     10    dist += (zoomTo-dist)/500;
     11  else
     12    dist += (zoomTo-dist)/500 *(float)dt;
     13
     14  rotatorP += rotatorV *(float)dt;
     15 
     16
    1417  glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
    1518  glLoadIdentity(); // Reset the view
     
    1720  glMatrixMode(GL_PROJECTION);
    1821  glLoadIdentity();     
    19   gluPerspective(45.0f,500/375,0.1f,100.0f);
    20   gluLookAt (5*sin(rotator),7.5,5*cos(rotator), 0,0,0, 0,1,0);
    21   whiteLight[1] = .5+.5*sin(rotator*10);
    22   whiteLight[2] = .5+.5*sin(rotator*10);
    23 
    24   GLfloat lightPosition[] = {10.0*sin(rotator*10), 10, 19.0, 0.0};
    25   glLightfv(GL_LIGHT0, GL_POSITION, lightPosition);
    26 
    27   glLightfv(GL_LIGHT0, GL_DIFFUSE, whiteLight);
     22  gluPerspective(45.0f,500/375,0.1f,dist * 5.0f);
     23    gluLookAt (0, dist , dist, 0,0,0, up.x,up.y,up.z);
     24
     25  glMatrixMode(GL_MODELVIEW);
     26  glPushMatrix();
     27  //  glRotatef (180, dir.x, dir.y, dir.z);
     28  glMultMatrixf (*matQ);
    2829  obj->draw();
    2930
     31  glPopMatrix();
     32
    3033  SDL_GL_SwapBuffers(); // Swap the buffers
     34  lastFrame = currFrame;
    3135}
    3236
     
    4650    return 0;
    4751  }
     52 
     53  printf ("%i, %i\n", wHandler.screen->w, wHandler.screen->h);
    4854  if (argc>=3)
    4955    obj = new Object (argv[1], atof(argv[2]));
     
    5359    obj = new Object();
    5460 
     61  M = Vector(wHandler.screen->w/2, wHandler.screen->h/2, 0);
     62  rotAxis = Vector (0.0,1.0,0.0);
     63  rotAngle = 0;
     64
     65  matQ[0][0] = matQ[1][1] = matQ[2][2] = matQ[3][3] = 1;
     66  rotQ = Quaternion (rotAngle, rotAxis);
     67  rotQlast = rotQ;
     68  dir = Vector (0.0, 0.0, 1.0);
     69  up = Vector (0.0, 1.0, 0.0);
     70
     71  glEnable(GL_LIGHTING);
     72  glEnable(GL_DEPTH_TEST);
     73
     74  GLfloat whiteLight[] = {1.0, 1.0, 1.0,1.0};
     75  GLfloat light0Position[] = {10.0, 10.0, 10.0, 0.0};
     76  GLfloat light1Position[] = {-10.0, -7.0, -6.0, 0.0};
    5577  GLfloat lmodelAmbient[] = {.1, .1, .1, 1.0};
     78
     79  glEnable(GL_LIGHT0);
     80  glLightfv(GL_LIGHT0, GL_POSITION, light0Position);
    5681  glLightfv(GL_LIGHT0, GL_DIFFUSE, whiteLight);
    5782  glLightfv(GL_LIGHT0, GL_SPECULAR, whiteLight);
    58   glEnable(GL_LIGHTING);
    59   glEnable(GL_LIGHT0);
    60   glEnable(GL_DEPTH_TEST);
    61 
     83 
     84  glEnable(GL_LIGHT1);
     85  glLightfv(GL_LIGHT1, GL_POSITION, light1Position);
     86  glLightfv(GL_LIGHT1, GL_DIFFUSE, whiteLight);
     87  glLightfv(GL_LIGHT1, GL_SPECULAR, whiteLight);
     88 
     89  rotatorP = .0;
     90  rotatorV = .0;
     91  dist = 5.0;
     92  zoomTo = dist;
    6293  // Build the font from a TGA image font.tga in the data directory
    6394  // Hide the mouse cursor
    64   SDL_ShowCursor(0);
     95    SDL_ShowCursor(2);
     96    mouse1Down = false;
    6597
    6698  // This is the main loop for the entire program and it will run until done==TRUE
     
    73105    while ( SDL_PollEvent(&event) ) {
    74106      switch (event.type) {
     107      case SDL_MOUSEMOTION:
     108        if (verbose >=3)
     109          printf("Mouse motion about %d,%d Pixels to (%d,%d).\n",
     110                 event.motion.xrel, event.motion.yrel,
     111                 event.motion.x, event.motion.y);
     112        // TRACKBALL
     113        if (mouse1Down)
     114          {
     115            int mX = event.button.x;
     116            int mY = event.button.y;
     117            int wH = wHandler.screen->h;
     118            int wW = wHandler.screen->w;
     119            Vector tmpV (mX, mY, sqrt ( (float) abs(wH * wH/4 - (wW/2-mX) * (wW/2-mX) - (wH/2-mY) * (wH/2-mY)) ));
     120            //      printf ("tmpV: %f, %f, %f\n", tmpV.x, tmpV.y, tmpV.z);
     121            p2 = tmpV-M;
     122            p2.y = -p2.y;
     123            rotAxis = p1.cross(p2);
     124            //  printf ("rotAxis: %f, %f, %f\n", rotAxis.x, rotAxis.y, rotAxis.z);
     125
     126            // in case that there is no rotation-axis defined
     127            if (rotAxis.x != 0 || rotAxis.y != 0 || rotAxis.z != 0)
     128              {
     129                rotAxis.normalize();
     130                //              printf ("rotAxis: %f, %f, %f\n", rotAxis.x, rotAxis.y, rotAxis.z, rotAngle);
     131                               
     132                rotAngle = angle_rad (p1, p2);
     133                rotQ = Quaternion (rotAngle, rotAxis);
     134                rotQ = rotQ * rotQlast;
     135                rotQ.matrix (matQ);
     136                //      dir = rotQ.apply(dir);
     137                //      dir.normalize();
     138                //      printf ("rotAxis: %f, %f, %f, %f\n", dir.x, dir.y, dir.z, rotAngle);
     139              }
     140            rotQlast = rotQ;
     141            p1 = p2;
     142
     143          }
     144        break;
     145      case SDL_MOUSEBUTTONDOWN:
     146        if (event.button.button == 4)
     147          {
     148            printf("MouseWheel up\n");
     149            zoomTo *= .5;
     150          }
     151        else if (event.button.button == 5)
     152          {
     153            printf("MouseWheel down\n");
     154            zoomTo *= 2.0;
     155          }
     156        else if (event.button.button == 1)
     157          {
     158            mouse1Down = true;
     159            int mX = event.button.x;
     160            int mY = event.button.y;
     161            int wH = wHandler.screen->h;
     162            int wW = wHandler.screen->w;
     163            Vector tmpV (mX, mY, sqrt ( (float) abs(wH * wH/4 - (wW/2-mX) * (wW/2-mX) - (wH/2-mY) * (wH/2-mY)) ));
     164            p1 = tmpV-M;
     165            p1.y = -p1.y;
     166
     167          }
     168        else
     169          {
     170            printf("MouseButton %d pressed at (%d,%d).\n",
     171                   event.button.button, event.button.x, event.button.y);
     172            rotatorV = ( (float)wHandler.screen->w/2 -event.button.x) / (float)wHandler.screen->w / 100.0;
     173          }
     174           
     175        break;
     176      case SDL_MOUSEBUTTONUP:
     177        if (event.button.button == 4);
     178        else if (event.button.button == 5);
     179        else if (event.button.button == 1)
     180          mouse1Down =false;
     181        else
     182            {
     183        printf("MouseButton %d released at (%d,%d).\n",
     184               event.button.button, event.button.x, event.button.y);
     185            }
     186        break;
     187           
    75188        // If a quit event was recieved
    76189      case SDL_QUIT:
     
    81194          break;
    82195      }
     196
     197
    83198    }
    84199
Note: See TracChangeset for help on using the changeset viewer.