Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 2963 in orxonox.OLD for orxonox/trunk/importer/framework.cc


Ignore:
Timestamp:
Nov 23, 2004, 3:44:06 PM (19 years ago)
Author:
bensch
Message:

orxonox/trunk/importer: rotation now with quaternion, BIG BUG fix in the mathematics of my quaternion-calculation

File:
1 edited

Legend:

Unmodified
Added
Removed
  • orxonox/trunk/importer/framework.cc

    r2953 r2963  
    2121  glLoadIdentity();     
    2222  gluPerspective(45.0f,500/375,0.1f,dist * 5.0f);
    23   gluLookAt (dist* dir.x, dist *dir.y, -dist *dir.z, 0,0,0, 0,1,0);
    24 
     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);
    2529  obj->draw();
     30
     31  glPopMatrix();
    2632
    2733  SDL_GL_SwapBuffers(); // Swap the buffers
     
    5662  rotAxis = Vector (0.0,1.0,0.0);
    5763  rotAngle = 0;
     64
     65  matQ[0][0] = matQ[1][1] = matQ[2][2] = matQ[3][3] = 1;
    5866  rotQ = Quaternion (rotAngle, rotAxis);
    59 
     67  rotQlast = rotQ;
    6068  dir = Vector (0.0, 0.0, 1.0);
     69  up = Vector (0.0, 1.0, 0.0);
    6170
    6271  glEnable(GL_LIGHTING);
     
    104113        if (mouse1Down)
    105114          {
    106             Vector tmpV (event.button.x, event.button.y, 2.0*sqrt ( (float) event.button.x * event.button.x *event.button.y * event.button.y / (wHandler.screen->h *wHandler.screen->h)));
     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);
    107121            p2 = tmpV-M;
    108            
    109122            rotAxis = p1.cross(p2);
    110             rotAngle = angle_deg (p1, p2)/1000;
    111             rotQ = Quaternion (rotAngle, rotAxis);
    112             dir = rotQ.apply(dir);
    113             dir.normalize();
    114             printf ("%f, %f, %f, %f\n", dir.x, dir.y, dir.z, rotAngle);
    115 
     123            //  printf ("rotAxis: %f, %f, %f\n", rotAxis.x, rotAxis.y, rotAxis.z);
     124
     125            // in case that there is no rotation-axis defined
     126            if (rotAxis.x != 0 || rotAxis.y != 0 || rotAxis.z != 0)
     127              {
     128                rotAxis.normalize();
     129                printf ("rotAxis: %f, %f, %f\n", rotAxis.x, rotAxis.y, rotAxis.z, rotAngle);
     130                               
     131                rotAngle = angle_rad (p1, p2);
     132                rotQ = Quaternion (rotAngle, rotAxis);
     133                rotQ = rotQ * rotQlast;
     134                rotQ.norm();
     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;
    116141            p1 = p2;
     142
    117143          }
    118144        break;
     
    131157          {
    132158            mouse1Down = true;
    133             Vector tmpV (event.button.x, event.button.y, 2.0*sqrt ( (float) event.button.x * event.button.x *event.button.y * event.button.y / (wHandler.screen->h *wHandler.screen->h)));
     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)) ));
    134164            p1 = tmpV-M;
    135165
Note: See TracChangeset for help on using the changeset viewer.