Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 3559 in orxonox.OLD for orxonox/trunk/src/story_entities


Ignore:
Timestamp:
Mar 15, 2005, 12:44:19 PM (19 years ago)
Author:
bensch
Message:

orxonox/trunk: now terrain is out of the World.cc and is a world-entity

Location:
orxonox/trunk/src/story_entities
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • orxonox/trunk/src/story_entities/world.cc

    r3556 r3559  
    3131#include "fontset.h"
    3232#include "track_node.h"
     33#include "terrain.h"
    3334
    3435using namespace std;
     
    299300  objectList = glGenLists(1);
    300301  glNewList (objectList, GL_COMPILE);
    301 
    302   glColor3f(1.0,0,0);
    303 
    304   int sizeX = 100;
    305   int sizeZ = 80;
    306   float length = 1000;
    307   float width = 200;
    308   float widthX = float (length /sizeX);
    309   float widthZ = float (width /sizeZ);
    310  
    311   float height [sizeX][sizeZ];
    312   Vector normal_vectors[sizeX][sizeZ];
    313  
    314  
    315   for ( int i = 0; i<sizeX-1; i+=1)
    316     for (int j = 0; j<sizeZ-1;j+=1)
    317       //height[i][j] = rand()/20046 + (j-25)*(j-25)/30;
    318 #ifdef __WIN32__
    319       height[i][j]=(sin((float)j/3)*rand()*i/182400)*.5;
    320 #else
    321       height[i][j]=(sin((float)j/3)*rand()*(long)i/6282450500.0)*.5;
    322 #endif
    323 
    324   //Die Huegel ein wenig glaetten
    325   for (int h=1; h<2;h++)
    326     for (int i=1;i<sizeX-2 ;i+=1 )
    327       for(int j=1;j<sizeZ-2;j+=1)
    328         height[i][j]=(height[i+1][j]+height[i][j+1]+height[i-1][j]+height[i][j-1])/4;
    329  
    330   //Berechnung von normalen Vektoren
    331   for(int i=1;i<sizeX-2;i+=1)
    332     for(int j=1;j<sizeZ-2 ;j+=1)
    333       {
    334         Vector v1 = Vector (widthX*(1),      height[i][j],      widthZ*(j) );
    335         Vector v2 = Vector (widthX*(i-1),    height[i-1][j],    widthZ*(j));
    336         Vector v3 = Vector (widthX*(i),      height[i][j+1],    widthZ*(j+1));
    337         Vector v4 = Vector (widthX*(i+1),    height[i+1][j],    widthZ*(j));
    338         Vector v5 = Vector (widthX*(i),      height[i][j-1],    widthZ*(j-1));
    339        
    340         Vector c1 = v2 - v1;
    341         Vector c2 = v3 - v1;
    342         Vector c3=  v4 - v1;
    343         Vector c4 = v5 - v1;
    344         Vector zero = Vector (0,0,0);
    345         normal_vectors[i][j]=c1.cross(v3-v5)+c2.cross(v4-v2)+c3.cross(v5-v3)+c4.cross(v2-v4);
    346         normal_vectors[i][j].normalize();
    347       }
    348 
    349   glBegin(GL_QUADS);
    350   int snowheight=3;
    351   for ( int i = 0; i<sizeX; i+=1)
    352     for (int j = 0; j<sizeZ;j+=1)
    353       {   
    354         Vector v1 = Vector (widthX*(i),      height[i][j]-20,       widthZ*(j)  -width/2);
    355         Vector v2 = Vector (widthX*(i+1),    height[i+1][j]-20,     widthZ*(j)  -width/2);
    356         Vector v3 = Vector (widthX*(i+1),    height[i+1][j+1]-20,   widthZ*(j+1)-width/2);
    357         Vector v4 = Vector (widthX*(i),      height[i][j+1]-20,     widthZ*(j+1)-width/2);
    358         float a[3];
    359         if(height[i][j]<snowheight){
    360           a[0]=0;
    361           a[1]=1.0-height[i][j]/10-.3;
    362           a[2]=0;
    363           glMaterialfv(GL_FRONT,GL_DIFFUSE,a);
    364         }
    365         else{
    366             a[0]=1.0;
    367             a[1]=1.0;
    368             a[2]=1.0;
    369             glMaterialfv(GL_FRONT,GL_DIFFUSE,a);
    370            
    371         }
    372         glNormal3f(normal_vectors[i][j].x, normal_vectors[i][j].y, normal_vectors[i][j].z);
    373         glVertex3f(v1.x, v1.y, v1.z);
    374         if(height[i+1][j]<snowheight){
    375           a[0]=0;
    376           a[1] =1.0-height[i+1][j]/10-.3;
    377           a[2]=0;
    378           glMaterialfv(GL_FRONT,GL_DIFFUSE,a);
    379         }
    380         else{
    381           a[0]=1.0;
    382           a[1]=1.0;
    383           a[2]=1.0;
    384           glMaterialfv(GL_FRONT,GL_DIFFUSE,a);
    385          
    386         }
    387         glNormal3f(normal_vectors[i+1][j].x, normal_vectors[i+1][j].y, normal_vectors[i+1][j].z);
    388         glVertex3f(v2.x, v2.y, v2.z);
    389         if(height[i+1][j+1]<snowheight){
    390           a[0]=0;
    391           a[1] =1.0-height[i+1][j+1]/10-.3;
    392           a[2]=0;
    393           glMaterialfv(GL_FRONT,GL_DIFFUSE,a);
    394         }
    395         else{
    396           a[0]=1.0;
    397           a[1]=1.0;
    398           a[2]=1.0;
    399           glMaterialfv(GL_FRONT,GL_DIFFUSE,a);
    400          
    401          
    402         }
    403         glNormal3f(normal_vectors[i+1][j+1].x, normal_vectors[i+1][j+1].y, normal_vectors[i+1][j+1].z);
    404         glVertex3f(v3.x, v3.y, v3.z);
    405         if(height[i][j+1]<snowheight){
    406           a[0]=0;
    407           a[1] =1.0-height[i+1][j+1]/10-.3;
    408           a[2]=0;
    409           glMaterialfv(GL_FRONT,GL_DIFFUSE,a);
    410         }
    411         else{
    412           a[0]=1.0;
    413           a[1]=1.0;
    414           a[2]=1.0;
    415           glMaterialfv(GL_FRONT,GL_DIFFUSE,a);
    416         }
    417         glNormal3f(normal_vectors[i][j+1].x, normal_vectors[i][j+1].y, normal_vectors[i][j+1].z);
    418         glVertex3f(v4.x, v4.y, v4.z);
    419        
    420       }
    421   glEnd();
    422 
     302 
    423303  trackManager->drawGraph(.01);
    424304  trackManager->debug(2);
    425305  glEndList();
    426306
    427 
     307  terrain = new Terrain();
     308  this->spawn(terrain);
    428309  // LIGHT initialisation
    429310  light = Light::getInstance();
  • orxonox/trunk/src/story_entities/world.h

    r3551 r3559  
    1919class Light;
    2020class FontSet;
     21class Terrain;
    2122
    2223
     
    7576  Skysphere* skySphere;         //!< The Environmental Heaven of orxonox \todo insert this to environment insted
    7677  Light* light;                 //!< The Lights of the Level
     78  Terrain* terrain;             //!< The Terrain of the World.
    7779
    7880  GLuint objectList;            //!< temporary: \todo this will be ereased soon
Note: See TracChangeset for help on using the changeset viewer.