Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 4597 in orxonox.OLD for orxonox/trunk/src/world_entities/terrain.cc


Ignore:
Timestamp:
Jun 11, 2005, 12:55:48 AM (19 years ago)
Author:
bensch
Message:

orxonox/trunk: setClassID implemented in all files

File:
1 edited

Legend:

Unmodified
Added
Removed
  • orxonox/trunk/src/world_entities/terrain.cc

    r4320 r4597  
    1 /* 
     1/*
    22   orxonox - the future of 3D-vertical-scrollers
    33
     
    2828
    2929*/
    30 Terrain::Terrain () 
     30Terrain::Terrain ()
    3131{
    3232  this->init();
     
    3636   \brief Constructor for loading a Terrain out of a file
    3737   \param fileName The file to load data from.
    38  
     38
    3939   this either loads out of an OBJ-file, or loads a heightmap if no .obj-extension is found.
    4040*/
    41 Terrain::Terrain(char* fileName)
     41Terrain::Terrain(const char* fileName)
    4242{
    4343  this->init();
     
    6868
    6969*/
    70 Terrain::~Terrain () 
     70Terrain::~Terrain ()
    7171{
    7272  if (objectList)
     
    7878{
    7979  this->setClassID(CL_TERRAIN, "Terrain");
     80
    8081  this->objectList = 0;
    8182}
     
    8485
    8586void Terrain::draw ()
    86 { 
     87{
    8788  glMatrixMode(GL_MODELVIEW);
    8889  glPushMatrix();
    8990  float matrix[4][4];
    90  
     91
    9192  /* translate */
    92   glTranslatef (this->getAbsCoor ().x, 
    93                 this->getAbsCoor ().y,
    94                 this->getAbsCoor ().z);
     93  glTranslatef (this->getAbsCoor ().x,
     94                this->getAbsCoor ().y,
     95                this->getAbsCoor ().z);
    9596  /* rotate */
    9697  this->getAbsDir ().matrix (matrix);
     
    112113      objectList = glGenLists(1);
    113114      glNewList (objectList, GL_COMPILE);
    114      
     115
    115116      glColor3f(1.0,0,0);
    116      
     117
    117118      int sizeX = 100;
    118119      int sizeZ = 80;
     
    121122      float widthX = float (length /sizeX);
    122123      float widthZ = float (width /sizeZ);
    123      
     124
    124125      float height [sizeX][sizeZ];
    125126      Vector normal_vectors[sizeX][sizeZ];
    126      
    127      
     127
     128
    128129      for ( int i = 0; i<sizeX-1; i+=1)
    129         for (int j = 0; j<sizeZ-1;j+=1)
    130           //height[i][j] = rand()/20046 + (j-25)*(j-25)/30;
     130        for (int j = 0; j<sizeZ-1;j+=1)
     131          //height[i][j] = rand()/20046 + (j-25)*(j-25)/30;
    131132#ifdef __WIN32__
    132           height[i][j]=(sin((float)j/3)*rand()*i/182400)*.5;
     133          height[i][j]=(sin((float)j/3)*rand()*i/182400)*.5;
    133134#else
    134135      height[i][j]=(sin((float)j/3)*rand()*(long)i/6282450500.0)*.5;
    135136#endif
    136      
     137
    137138      //Die Huegel ein wenig glaetten
    138139      for (int h=1; h<2;h++)
    139         for (int i=1;i<sizeX-2 ;i+=1 )
    140           for(int j=1;j<sizeZ-2;j+=1)
    141             height[i][j]=(height[i+1][j]+height[i][j+1]+height[i-1][j]+height[i][j-1])/4;
    142      
     140        for (int i=1;i<sizeX-2 ;i+=1 )
     141          for(int j=1;j<sizeZ-2;j+=1)
     142            height[i][j]=(height[i+1][j]+height[i][j+1]+height[i-1][j]+height[i][j-1])/4;
     143
    143144      //Berechnung von normalen Vektoren
    144145      for(int i=1;i<sizeX-2;i+=1)
    145         for(int j=1;j<sizeZ-2 ;j+=1)
    146           {
    147             Vector v1 = Vector (widthX*(1),      height[i][j],      widthZ*(j) );
    148             Vector v2 = Vector (widthX*(i-1),    height[i-1][j],    widthZ*(j));
    149             Vector v3 = Vector (widthX*(i),      height[i][j+1],    widthZ*(j+1));
    150             Vector v4 = Vector (widthX*(i+1),    height[i+1][j],    widthZ*(j));
    151             Vector v5 = Vector (widthX*(i),      height[i][j-1],    widthZ*(j-1));
    152            
    153             Vector c1 = v2 - v1;
    154             Vector c2 = v3 - v1;
    155             Vector c3=  v4 - v1;
    156             Vector c4 = v5 - v1;
    157             Vector zero = Vector (0,0,0);
    158             normal_vectors[i][j]=c1.cross(v3-v5)+c2.cross(v4-v2)+c3.cross(v5-v3)+c4.cross(v2-v4);
    159             normal_vectors[i][j].normalize();
    160           }
    161      
     146        for(int j=1;j<sizeZ-2 ;j+=1)
     147          {
     148            Vector v1 = Vector (widthX*(1),      height[i][j],      widthZ*(j) );
     149            Vector v2 = Vector (widthX*(i-1),    height[i-1][j],    widthZ*(j));
     150            Vector v3 = Vector (widthX*(i),      height[i][j+1],    widthZ*(j+1));
     151            Vector v4 = Vector (widthX*(i+1),    height[i+1][j],    widthZ*(j));
     152            Vector v5 = Vector (widthX*(i),      height[i][j-1],    widthZ*(j-1));
     153
     154            Vector c1 = v2 - v1;
     155            Vector c2 = v3 - v1;
     156            Vector c3=  v4 - v1;
     157            Vector c4 = v5 - v1;
     158            Vector zero = Vector (0,0,0);
     159            normal_vectors[i][j]=c1.cross(v3-v5)+c2.cross(v4-v2)+c3.cross(v5-v3)+c4.cross(v2-v4);
     160            normal_vectors[i][j].normalize();
     161          }
     162
    162163      glBegin(GL_QUADS);
    163164      int snowheight=3;
    164165      for ( int i = 0; i<sizeX; i+=1)
    165         for (int j = 0; j<sizeZ;j+=1)
    166           {       
    167             Vector v1 = Vector (widthX*(i),      height[i][j]-20,       widthZ*(j)  -width/2);
    168             Vector v2 = Vector (widthX*(i+1),    height[i+1][j]-20,     widthZ*(j)  -width/2);
    169             Vector v3 = Vector (widthX*(i+1),    height[i+1][j+1]-20,   widthZ*(j+1)-width/2);
    170             Vector v4 = Vector (widthX*(i),      height[i][j+1]-20,     widthZ*(j+1)-width/2);
    171             float a[3];
    172             if(height[i][j]<snowheight){
    173               a[0]=0;
    174               a[1]=1.0-height[i][j]/10-.3;
    175               a[2]=0;
    176               glMaterialfv(GL_FRONT,GL_DIFFUSE,a);
    177             }
    178             else{
    179               a[0]=1.0;
    180               a[1]=1.0;
    181               a[2]=1.0;
    182               glMaterialfv(GL_FRONT,GL_DIFFUSE,a);
    183              
    184             }
    185             glNormal3f(normal_vectors[i][j].x, normal_vectors[i][j].y, normal_vectors[i][j].z);
    186             glVertex3f(v1.x, v1.y, v1.z);
    187             if(height[i+1][j]<snowheight){
    188               a[0]=0;
    189               a[1] =1.0-height[i+1][j]/10-.3;
    190               a[2]=0;
    191               glMaterialfv(GL_FRONT,GL_DIFFUSE,a);
    192             }
    193             else{
    194               a[0]=1.0;
    195               a[1]=1.0;
    196               a[2]=1.0;
    197               glMaterialfv(GL_FRONT,GL_DIFFUSE,a);
    198              
    199             }
    200             glNormal3f(normal_vectors[i+1][j].x, normal_vectors[i+1][j].y, normal_vectors[i+1][j].z);
    201             glVertex3f(v2.x, v2.y, v2.z);
    202             if(height[i+1][j+1]<snowheight){
    203               a[0]=0;
    204               a[1] =1.0-height[i+1][j+1]/10-.3;
    205               a[2]=0;
    206               glMaterialfv(GL_FRONT,GL_DIFFUSE,a);
    207             }
    208             else{
    209               a[0]=1.0;
    210               a[1]=1.0;
    211               a[2]=1.0;
    212               glMaterialfv(GL_FRONT,GL_DIFFUSE,a);
    213              
    214              
    215             }
    216             glNormal3f(normal_vectors[i+1][j+1].x, normal_vectors[i+1][j+1].y, normal_vectors[i+1][j+1].z);
    217             glVertex3f(v3.x, v3.y, v3.z);
    218             if(height[i][j+1]<snowheight){
    219               a[0]=0;
    220               a[1] =1.0-height[i+1][j+1]/10-.3;
    221               a[2]=0;
    222               glMaterialfv(GL_FRONT,GL_DIFFUSE,a);
    223             }
    224             else{
    225               a[0]=1.0;
    226               a[1]=1.0;
    227               a[2]=1.0;
    228               glMaterialfv(GL_FRONT,GL_DIFFUSE,a);
    229             }
    230             glNormal3f(normal_vectors[i][j+1].x, normal_vectors[i][j+1].y, normal_vectors[i][j+1].z);
    231             glVertex3f(v4.x, v4.y, v4.z);
    232            
    233           }
     166        for (int j = 0; j<sizeZ;j+=1)
     167          {
     168            Vector v1 = Vector (widthX*(i),      height[i][j]-20,       widthZ*(j)  -width/2);
     169            Vector v2 = Vector (widthX*(i+1),    height[i+1][j]-20,     widthZ*(j)  -width/2);
     170            Vector v3 = Vector (widthX*(i+1),    height[i+1][j+1]-20,   widthZ*(j+1)-width/2);
     171            Vector v4 = Vector (widthX*(i),      height[i][j+1]-20,     widthZ*(j+1)-width/2);
     172            float a[3];
     173            if(height[i][j]<snowheight){
     174              a[0]=0;
     175              a[1]=1.0-height[i][j]/10-.3;
     176              a[2]=0;
     177              glMaterialfv(GL_FRONT,GL_DIFFUSE,a);
     178            }
     179            else{
     180              a[0]=1.0;
     181              a[1]=1.0;
     182              a[2]=1.0;
     183              glMaterialfv(GL_FRONT,GL_DIFFUSE,a);
     184
     185            }
     186            glNormal3f(normal_vectors[i][j].x, normal_vectors[i][j].y, normal_vectors[i][j].z);
     187            glVertex3f(v1.x, v1.y, v1.z);
     188            if(height[i+1][j]<snowheight){
     189              a[0]=0;
     190              a[1] =1.0-height[i+1][j]/10-.3;
     191              a[2]=0;
     192              glMaterialfv(GL_FRONT,GL_DIFFUSE,a);
     193            }
     194            else{
     195              a[0]=1.0;
     196              a[1]=1.0;
     197              a[2]=1.0;
     198              glMaterialfv(GL_FRONT,GL_DIFFUSE,a);
     199
     200            }
     201            glNormal3f(normal_vectors[i+1][j].x, normal_vectors[i+1][j].y, normal_vectors[i+1][j].z);
     202            glVertex3f(v2.x, v2.y, v2.z);
     203            if(height[i+1][j+1]<snowheight){
     204              a[0]=0;
     205              a[1] =1.0-height[i+1][j+1]/10-.3;
     206              a[2]=0;
     207              glMaterialfv(GL_FRONT,GL_DIFFUSE,a);
     208            }
     209            else{
     210              a[0]=1.0;
     211              a[1]=1.0;
     212              a[2]=1.0;
     213              glMaterialfv(GL_FRONT,GL_DIFFUSE,a);
     214
     215
     216            }
     217            glNormal3f(normal_vectors[i+1][j+1].x, normal_vectors[i+1][j+1].y, normal_vectors[i+1][j+1].z);
     218            glVertex3f(v3.x, v3.y, v3.z);
     219            if(height[i][j+1]<snowheight){
     220              a[0]=0;
     221              a[1] =1.0-height[i+1][j+1]/10-.3;
     222              a[2]=0;
     223              glMaterialfv(GL_FRONT,GL_DIFFUSE,a);
     224            }
     225            else{
     226              a[0]=1.0;
     227              a[1]=1.0;
     228              a[2]=1.0;
     229              glMaterialfv(GL_FRONT,GL_DIFFUSE,a);
     230            }
     231            glNormal3f(normal_vectors[i][j+1].x, normal_vectors[i][j+1].y, normal_vectors[i][j+1].z);
     232            glVertex3f(v4.x, v4.y, v4.z);
     233
     234          }
    234235      glEnd();
    235236      glEndList();
     
    239240    {
    240241      /*
    241         this->model = (OBJModel*) new Model();
     242        this->model = (OBJModel*) new Model();
    242243      this->model->setName("CUBE");
    243244      this->model->addVertex (-0.5, -0.5, 0.5);
     
    249250      this->model->addVertex (-0.5, -0.5, -0.5);
    250251      this->model->addVertex (0.5, -0.5, -0.5);
    251      
     252
    252253      this->model->addVertexTexture (0.0, 0.0);
    253254      this->model->addVertexTexture (1.0, 0.0);
     
    268269      */
    269270    }
    270  
    271 }
     271
     272}
Note: See TracChangeset for help on using the changeset viewer.