Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Feb 2, 2005, 1:04:00 PM (20 years ago)
Author:
bensch
Message:

orxonox/branches/nico: heightmap now compiles on all platforms

File:
1 edited

Legend:

Unmodified
Added
Removed
  • orxonox/branches/nico/src/importer/heightMapViewer.cc

    r3384 r3390  
    2121
    2222        upVector = Vector(0,1,0);
    23 
     23       
    2424        wireframe = false;
    2525        mousedown = false;
     26        smoothShading = false;
    2627       
    2728}
     
    3839        cout << "HeightMapViewer init()" << endl;
    3940       
    40         if (windowhandler.createOpenGLWindow(WIDTH,HEIGHT,FULLSCREEN) == false)
     41#ifdef FULLSCREEN
     42        if (!windowhandler.CreateGLWindow("height map viewer", WIDTH, HEIGHT, 32, true))
     43#else
     44        if (!windowhandler.CreateGLWindow("height map viewer", WIDTH, HEIGHT, 32, false))
     45#endif
    4146        {
    4247                cout << "could not create OpenGL-Window." << endl;
     
    4651        if (terrain.loadBitmap(fileName) == false)
    4752        {
    48                 cout << "could not create OpenGL-Window." << endl;
     53                cout << "could not load bitmap." << endl;
    4954                return false;
    5055        }
    5156       
    52         terrain.createDisplayLists(64, 64, 1);
     57        terrain.createDisplayLists(128, 128, 1);
    5358       
    5459        return true;
     
    7378                        {
    7479                                case SDL_MOUSEMOTION:
    75                                         if(mousedown)
     80                                        if (mousedown==true)
    7681                                        {
    77                                                 angleX = PI / 180 * event.motion.xrel * 0.1;
    78                                                 angleY = PI / 180 * event.motion.yrel * 0.1;
     82                                                angleX = PI / 180 * event.motion.xrel * 0.2;
     83                                                angleY = PI / 180 * event.motion.yrel * 0.2;
    7984
    8085                                                // Quaternion(angle,axis)
    81                                                 rotator = Quaternion(angleX,Vector(0,1,0));
     86                                                rotator = Quaternion(-angleX,Vector(0,1,0));
    8287                                                sightDirection = rotator.apply(sightDirection);
     88
     89                                        #ifdef FULLSCREEN
     90                                                rotator = Quaternion(angleY,perpendicular(sightDirection));
     91                                        #else
     92                                                rotator = Quaternion(-angleY,perpendicular(sightDirection));
     93                                        #endif
    8394                                               
    84                                                 rotator = Quaternion(-angleY,sightDirection.perpendicular());
    8595                                                sightDirection = rotator.apply(sightDirection);
    8696                                               
     
    99109                                        switch(event.key.keysym.sym)
    100110                                        {
     111                                                case SDLK_UP:
     112                                                        // move in direction of sight
     113                                                        cameraPos = cameraPos + sightDirection * 0.7;                                                   
     114                                                        updateView();
     115                                                        break;
     116
     117                                                case SDLK_DOWN:
     118                                                        // move in direction of sight
     119                                                        cameraPos = cameraPos - sightDirection * 0.7;
     120                                                        updateView();
     121                                                        break;
     122                                                       
     123                                                case SDLK_LEFT:
     124                                                        cameraPos = cameraPos + perpendicular(sightDirection) * 0.7;
     125                                                        updateView();
     126                                                        break;
     127                                                       
     128                                                case SDLK_RIGHT:
     129                                                        cameraPos = cameraPos - perpendicular(sightDirection) * 0.7;
     130                                                        updateView();
     131                                                        break;
     132                                                       
     133                                                case SDLK_s:
     134                                                        smoothShading = !smoothShading;
     135                                                        if (smoothShading)      glShadeModel(GL_SMOOTH);
     136                                                        else glShadeModel(GL_FLAT);
     137                                                        break;
     138                                                       
    101139                                                case SDLK_w:
    102140                                                        wireframe = !wireframe;
     
    105143                                                        break;
    106144                                                       
    107                                                 case SDLK_UP:
    108                                                         // move in direction of sight
    109                                                         cameraPos = cameraPos + sightDirection;
    110                                                         updateView();
    111                                                         break;
    112 
    113                                                 case SDLK_DOWN:
    114                                                         // move in direction of sight
    115                                                         cameraPos = cameraPos - sightDirection;
    116                                                         updateView();
    117                                                         break;
    118                                                        
    119                                                 case SDLK_LEFT:
    120                                                         cameraPos = cameraPos - sightDirection.perpendicular();
    121                                                         updateView();
    122                                                         break;
    123                                                        
    124                                                 case SDLK_RIGHT:
    125                                                         cameraPos = cameraPos + sightDirection.perpendicular();
    126                                                         updateView();
    127                                                         break;
    128                                                        
    129145                                                case SDLK_r:
    130                                                         // restore original view vectors
    131                                                         cameraPos = Vector(0,0,40);
    132                                                         sightDirection = Vector(0,0,-1);
     146                                                        // reset view vectors
     147                                                        //cameraPos = Vector(0,0,40);
     148                                                        //sightDirection = Vector(0,0,-1);                                                     
     149                                                        cameraPos = Vector(73.9871,172.496,286.137);
     150                                                        sightDirection = Vector(0.23429,-0.736527,-0.625574);
     151
    133152                                                        updateView();
    134153                                                        break;
     
    138157                                                        << "display list count:    " << terrain.displayListCount << endl
    139158                                                        << "first display list at: " << terrain.displayListStart << endl
     159                                                        << "camera position:       " << "(" << cameraPos.x << "," << cameraPos.y << "," << cameraPos.z << ")" << endl
     160                                                        << "sightDirection:        " << "(" << sightDirection.x << "," << sightDirection.y << "," << sightDirection.z << ")" << endl
    140161                                                        << endl;
    141162                                                       
     
    165186                SDL_GL_SwapBuffers();   
    166187
    167                 //SDL_Delay(100);
     188                SDL_Delay(1);
    168189        }
    169190       
     
    175196        // be sure to use up to date lookAt-vector
    176197        lookAt = cameraPos + sightDirection;
    177         upVector = sightDirection.cross(sightDirection.perpendicular()) * -1;
     198        upVector = sightDirection.cross(perpendicular(sightDirection));
    178199       
    179200        glMatrixMode(GL_PROJECTION); // Select The Projection Matrix
     
    181202       
    182203        // Calculate The Aspect Ratio Of The Window
    183         gluPerspective(45.0f,(GLfloat)WIDTH/(GLfloat)HEIGHT,0.1f,100.0f);
     204        gluPerspective(45.0f,(GLfloat)WIDTH/(GLfloat)HEIGHT,0.5f,300.0f);
    184205        gluLookAt (cameraPos.x,cameraPos.y,cameraPos.z,
    185206                           lookAt.x,lookAt.y,lookAt.z,
     
    191212
    192213void HeightMapViewer::drawScene()
    193 {
     214{       
    194215        glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    195216
    196         glutWireCube(1.0);
    197        
    198         int i;
    199        
    200         for (i=0; i<terrain.displayListCount; i++)
    201         {
    202                 glCallList(terrain.displayListStart + i);
    203         }
    204 }
     217        glPushMatrix();
     218        {
     219                //glTranslatef(0.0,1.0,0.0);
     220                glScalef(1,0.2,1);
     221       
     222                for (int i=0; i<terrain.displayListCount; i++)
     223                {
     224                        glCallList(terrain.displayListStart + i);
     225                }
     226        }
     227        glPopMatrix();
     228       
     229        glColor3f(0.0,1.0,0.0);
     230        //      glutWireCube(1.0);
     231       
     232        glColor3f(0.0,0.0,1.0);
     233        glBegin(GL_POINTS);
     234        for (float z=0;z<10;z++)
     235                for (float x=0;x<10;x++)
     236                        glVertex3f(x,0,z);
     237        glEnd();
     238       
     239}
     240
     241
     242
     243/**
     244   \brief returns a vector that is perpendicular and lies in the xz-plane
     245 */
     246Vector perpendicular (Vector perpendic)
     247{
     248        Vector r;
     249       
     250        r.x =  perpendic.z;
     251        r.z = -perpendic.x;
     252       
     253        r.normalize();
     254       
     255        return r;       
     256}
Note: See TracChangeset for help on using the changeset viewer.