Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 3200 in orxonox.OLD for orxonox/trunk/src


Ignore:
Timestamp:
Dec 17, 2004, 11:36:49 AM (19 years ago)
Author:
bensch
Message:

orxonox/trunk: a little bit more dynamic Mountain-creation (dave-algorithm)

File:
1 edited

Legend:

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

    r3199 r3200  
    190190  glColor3f(1.0,0,0);
    191191  glBegin(GL_QUADS);
    192   float height [500][100];
    193   Vector normal_vectors[500][100];
    194   float size = 2;
    195  
    196  
    197   for ( int i = 0; i<400; i+=1)
    198     {
    199       for (int j = 0; j<100;j+=1)
    200         {
    201             //height[i][j] = rand()/20046 + (j-25)*(j-25)/30;
     192
     193  int sizeX = 100;
     194  int sizeY = 80;
     195  float length = 1000;
     196  float width = 200;
     197  float widthX = float (length /sizeX);
     198  float widthY = float (width /sizeY);
     199 
     200  float height [sizeX][sizeY];
     201  Vector normal_vectors[sizeX][sizeY];
     202 
     203 
     204  for ( int i = 0; i<sizeX-1; i+=1)
     205    for (int j = 0; j<sizeY-1;j+=1)
     206      //height[i][j] = rand()/20046 + (j-25)*(j-25)/30;
    202207#ifdef __WIN32__
    203           height[i][j]=(sin((float)j/3)*rand()*i/182400)*.2;
     208      height[i][j]=(sin((float)j/3)*rand()*i/182400)*.5;
    204209#else
    205           height[i][j]=(sin((float)j/3)*rand()*(long)i/6282450500.0)*.2;
     210      height[i][j]=(sin((float)j/3)*rand()*(long)i/6282450500.0)*.5;
    206211#endif
    207         }
    208     }
     212
    209213  //Die Hügel ein wenig glätten
    210214  for (int h=1; h<2;h++)
    211     for (int i=1;i<399 ;i+=1 )
    212       for(int j=1;j<99;j+=1)
     215    for (int i=1;i<sizeX-2 ;i+=1 )
     216      for(int j=1;j<sizeY-2;j+=1)
    213217        height[i][j]=(height[i+1][j]+height[i][j+1]+height[i-1][j]+height[i][j-1])/4;
    214218 
    215219  //Berechnung von normalen Vektoren
    216  
    217   for(int i=1;i<399;i+=1){
    218     for(int j=1;j<99 ;j+=1)
    219      
     220
     221  for(int i=1;i<sizeX-2;i+=1)
     222    for(int j=1;j<sizeY-2 ;j+=1)
    220223      {
    221         Vector* v1 = new Vector (size*i,size*(j-25)-50,height[i][j]-20 );
    222         Vector* v2 = new Vector (size*(i+1),size*(j-25)-50,height[i+1][j]-20);
    223         Vector* v3 = new Vector (size*(i),size*(j-24)-50,height[i][j+1]-20);
    224         Vector* v4 = new Vector (size*(i-1),size*(j-25)-50,height[i-1][j]-20);
    225         Vector* v5 = new Vector (size*(i),size*(j-26)-50,height[i][j-1]-20);
     224        Vector v1 = Vector (widthX*(1),      widthY*(j)  ,      height[i][j]);
     225        Vector v2 = Vector (widthX*(i-1),    widthY*(j)  ,      height[i-1][j]);
     226        Vector v3 = Vector (widthX*(i),      widthY*(j+1),      height[i][j+1]);
     227        Vector v4 = Vector (widthX*(i+1),    widthY*(j),        height[i+1][j]);
     228        Vector v5 = Vector (widthX*(i),      widthY*(j-1),      height[i][j-1]);
    226229       
    227         Vector c1 = *v1 - *v2;
    228         Vector c2 = *v1 - *v3;
    229         Vector c3= *v1 - *v4;
    230         Vector c4 = *v1 - *v5;
    231         normal_vectors[i][j]=c1.cross(*v1-*v3)+c2.cross(*v1-*v4)+c3.cross(*v1-*v5)+c4.cross(*v1-*v2);
     230        Vector c1 = v2 - v1;
     231        Vector c2 = v3 - v1;
     232        Vector c3=  v4 - v1;
     233        Vector c4 = v5 - v1;
     234        Vector zero = Vector (0,0,0);
     235        normal_vectors[i][j]=c1.cross(v4-v2)+c2.cross(v1-v3)+c3.cross(v2-v4)+c4.cross(v3-v1);
    232236        normal_vectors[i][j].normalize();
    233        
    234        
    235        
    236        
    237         }
    238   }
     237      }
     238
    239239  int snowheight=3;
    240   for ( int i = 0; i<400; i+=1)
    241     {
    242       for (int j = 0; j<100;j+=1)
    243         {         
    244           Vector* v1 = new Vector (size*i,        size*(j-25)-50,      height[i][j]-20 );
    245           Vector* v2 = new Vector (size*(i+1),    size*(j-25)-50,      height[i+1][j]-20);
    246           Vector* v3 = new Vector (size*(i+1),    size*(j-24)-50,  height[i+1][j+1]-20);
    247           Vector* v4 = new Vector (size*(i),        size*(j-24)-50,  height[i][j+1]-20);
    248           float a[3];
    249           if(height[i][j]<snowheight){
    250             a[0]=0;
    251             a[1]=1.0-height[i][j]/10-.3;
    252             a[2]=0;
    253             glMaterialfv(GL_FRONT,GL_DIFFUSE,a);
    254           }
    255           else{
     240  for ( int i = 0; i<sizeX; i+=1)
     241    for (int j = 0; j<sizeY;j+=1)
     242      {   
     243        Vector v1 = Vector (widthX*(i),      widthY*(j)  -width/2,      height[i][j]-20 );
     244        Vector v2 = Vector (widthX*(i+1),    widthY*(j)  -width/2,      height[i+1][j]-20);
     245        Vector v3 = Vector (widthX*(i+1),    widthY*(j+1)-width/2,    height[i+1][j+1]-20);
     246        Vector v4 = Vector (widthX*(i),      widthY*(j+1)-width/2,    height[i][j+1]-20);
     247        float a[3];
     248        if(height[i][j]<snowheight){
     249          a[0]=0;
     250          a[1]=1.0-height[i][j]/10-.3;
     251          a[2]=0;
     252          glMaterialfv(GL_FRONT,GL_DIFFUSE,a);
     253        }
     254        else{
    256255            a[0]=1.0;
    257256            a[1]=1.0;
     
    259258            glMaterialfv(GL_FRONT,GL_DIFFUSE,a);
    260259           
    261           }
    262                 glNormal3f(normal_vectors[i][j].x, normal_vectors[i][j].y, normal_vectors[i][j].z);
    263                 glVertex3f(v1->x, v1->y, v1->z);
    264                 if(height[i+1][j]<snowheight){
    265                   a[0]=0;
    266                   a[1] =1.0-height[i+1][j]/10-.3;
    267                   a[2]=0;
    268                   glMaterialfv(GL_FRONT,GL_DIFFUSE,a);
    269                 }
    270                 else{
    271                   a[0]=1.0;
    272                   a[1]=1.0;
    273                   a[2]=1.0;
    274                   glMaterialfv(GL_FRONT,GL_DIFFUSE,a);
    275                  
    276                 }
    277                 glNormal3f(normal_vectors[i+1][j].x, normal_vectors[i+1][j].y, normal_vectors[i+1][j].z);
    278                 glVertex3f(v2->x, v2->y, v2->z);
    279                 if(height[i+1][j+1]<snowheight){
    280                   a[0]=0;
    281                   a[1] =1.0-height[i+1][j+1]/10-.3;
    282                   a[2]=0;
    283                   glMaterialfv(GL_FRONT,GL_DIFFUSE,a);
    284                 }
    285                 else{
    286                   a[0]=1.0;
    287                   a[1]=1.0;
    288                   a[2]=1.0;
    289                   glMaterialfv(GL_FRONT,GL_DIFFUSE,a);
    290                  
    291                  
    292                 }
    293                 glNormal3f(normal_vectors[i+1][j+1].x, normal_vectors[i+1][j+1].y, normal_vectors[i+1][j+1].z);
    294                 glVertex3f(v3->x, v3->y, v3->z);
    295                 if(height[i][j+1]<snowheight){
    296                   a[0]=0;
    297                   a[1] =1.0-height[i+1][j+1]/10-.3;
    298                   a[2]=0;
    299                   glMaterialfv(GL_FRONT,GL_DIFFUSE,a);
    300                 }
    301                 else{
    302                   a[0]=1.0;
    303                   a[1]=1.0;
    304                   a[2]=1.0;
    305                   glMaterialfv(GL_FRONT,GL_DIFFUSE,a);
    306                 }
    307                 glNormal3f(normal_vectors[i][j+1].x, normal_vectors[i][j+1].y, normal_vectors[i][j+1].z);
    308                 glVertex3f(v4->x, v4->y, v4->z);
    309                
    310         }
    311     }
     260        }
     261        glNormal3f(normal_vectors[i][j].x, normal_vectors[i][j].y, normal_vectors[i][j].z);
     262        glVertex3f(v1.x, v1.y, v1.z);
     263        if(height[i+1][j]<snowheight){
     264          a[0]=0;
     265          a[1] =1.0-height[i+1][j]/10-.3;
     266          a[2]=0;
     267          glMaterialfv(GL_FRONT,GL_DIFFUSE,a);
     268        }
     269        else{
     270          a[0]=1.0;
     271          a[1]=1.0;
     272          a[2]=1.0;
     273          glMaterialfv(GL_FRONT,GL_DIFFUSE,a);
     274         
     275        }
     276        glNormal3f(normal_vectors[i+1][j].x, normal_vectors[i+1][j].y, normal_vectors[i+1][j].z);
     277        glVertex3f(v2.x, v2.y, v2.z);
     278        if(height[i+1][j+1]<snowheight){
     279          a[0]=0;
     280          a[1] =1.0-height[i+1][j+1]/10-.3;
     281          a[2]=0;
     282          glMaterialfv(GL_FRONT,GL_DIFFUSE,a);
     283        }
     284        else{
     285          a[0]=1.0;
     286          a[1]=1.0;
     287          a[2]=1.0;
     288          glMaterialfv(GL_FRONT,GL_DIFFUSE,a);
     289         
     290         
     291        }
     292        glNormal3f(normal_vectors[i+1][j+1].x, normal_vectors[i+1][j+1].y, normal_vectors[i+1][j+1].z);
     293        glVertex3f(v3.x, v3.y, v3.z);
     294        if(height[i][j+1]<snowheight){
     295          a[0]=0;
     296          a[1] =1.0-height[i+1][j+1]/10-.3;
     297          a[2]=0;
     298          glMaterialfv(GL_FRONT,GL_DIFFUSE,a);
     299        }
     300        else{
     301          a[0]=1.0;
     302          a[1]=1.0;
     303          a[2]=1.0;
     304          glMaterialfv(GL_FRONT,GL_DIFFUSE,a);
     305        }
     306        glNormal3f(normal_vectors[i][j+1].x, normal_vectors[i][j+1].y, normal_vectors[i][j+1].z);
     307        glVertex3f(v4.x, v4.y, v4.z);
     308       
     309      }
    312310  glEnd();
    313311  /* 
Note: See TracChangeset for help on using the changeset viewer.