Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 3564 in orxonox.OLD


Ignore:
Timestamp:
Mar 15, 2005, 6:38:56 PM (19 years ago)
Author:
bensch
Message:

orxonox/trunk: posible to build new Worlds now with new constructor

Location:
orxonox/trunk/src
Files:
5 edited

Legend:

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

    r3560 r3564  
    305305  glEndList();
    306306
    307   terrain = new Terrain();
     307  terrain = new Terrain(TERRAIN_BENSCH);
    308308  this->spawn(terrain);
    309309  // LIGHT initialisation
  • orxonox/trunk/src/world_entities/terrain.cc

    r3559 r3564  
    2828Terrain::Terrain ()
    2929{
    30    this->setClassName ("Terrain");
    31    this->build();
     30  this->init();
     31}
     32
     33/**
     34   \brief a Constructor for the Debug-Worlds
     35
     36   \todo make it not compileable when not in debug-mode
     37*/
     38Terrain::Terrain(DebugTerrain debugTerrain)
     39{
     40  this->init();
     41  this->buildDebugTerrain(debugTerrain);
    3242}
    3343
     
    3949Terrain::~Terrain ()
    4050{
    41   // delete what has to be deleted here
    42   //  delete this->model;
    43  
    44   glDeleteLists(this->objectList, 1);
    45 }
    46 
    47 
    48 void Terrain::build()
    49 {
    50   objectList = glGenLists(1);
    51   glNewList (objectList, GL_COMPILE);
    52 
    53   glColor3f(1.0,0,0);
    54 
    55   int sizeX = 100;
    56   int sizeZ = 80;
    57   float length = 1000;
    58   float width = 200;
    59   float widthX = float (length /sizeX);
    60   float widthZ = float (width /sizeZ);
    61  
    62   float height [sizeX][sizeZ];
    63   Vector normal_vectors[sizeX][sizeZ];
    64  
    65  
    66   for ( int i = 0; i<sizeX-1; i+=1)
    67     for (int j = 0; j<sizeZ-1;j+=1)
    68       //height[i][j] = rand()/20046 + (j-25)*(j-25)/30;
    69 #ifdef __WIN32__
    70       height[i][j]=(sin((float)j/3)*rand()*i/182400)*.5;
    71 #else
    72       height[i][j]=(sin((float)j/3)*rand()*(long)i/6282450500.0)*.5;
    73 #endif
    74 
    75   //Die Huegel ein wenig glaetten
    76   for (int h=1; h<2;h++)
    77     for (int i=1;i<sizeX-2 ;i+=1 )
    78       for(int j=1;j<sizeZ-2;j+=1)
    79         height[i][j]=(height[i+1][j]+height[i][j+1]+height[i-1][j]+height[i][j-1])/4;
    80  
    81   //Berechnung von normalen Vektoren
    82   for(int i=1;i<sizeX-2;i+=1)
    83     for(int j=1;j<sizeZ-2 ;j+=1)
    84       {
    85         Vector v1 = Vector (widthX*(1),      height[i][j],      widthZ*(j) );
    86         Vector v2 = Vector (widthX*(i-1),    height[i-1][j],    widthZ*(j));
    87         Vector v3 = Vector (widthX*(i),      height[i][j+1],    widthZ*(j+1));
    88         Vector v4 = Vector (widthX*(i+1),    height[i+1][j],    widthZ*(j));
    89         Vector v5 = Vector (widthX*(i),      height[i][j-1],    widthZ*(j-1));
    90        
    91         Vector c1 = v2 - v1;
    92         Vector c2 = v3 - v1;
    93         Vector c3=  v4 - v1;
    94         Vector c4 = v5 - v1;
    95         Vector zero = Vector (0,0,0);
    96         normal_vectors[i][j]=c1.cross(v3-v5)+c2.cross(v4-v2)+c3.cross(v5-v3)+c4.cross(v2-v4);
    97         normal_vectors[i][j].normalize();
    98       }
    99 
    100   glBegin(GL_QUADS);
    101   int snowheight=3;
    102   for ( int i = 0; i<sizeX; i+=1)
    103     for (int j = 0; j<sizeZ;j+=1)
    104       {   
    105         Vector v1 = Vector (widthX*(i),      height[i][j]-20,       widthZ*(j)  -width/2);
    106         Vector v2 = Vector (widthX*(i+1),    height[i+1][j]-20,     widthZ*(j)  -width/2);
    107         Vector v3 = Vector (widthX*(i+1),    height[i+1][j+1]-20,   widthZ*(j+1)-width/2);
    108         Vector v4 = Vector (widthX*(i),      height[i][j+1]-20,     widthZ*(j+1)-width/2);
    109         float a[3];
    110         if(height[i][j]<snowheight){
    111           a[0]=0;
    112           a[1]=1.0-height[i][j]/10-.3;
    113           a[2]=0;
    114           glMaterialfv(GL_FRONT,GL_DIFFUSE,a);
    115         }
    116         else{
    117             a[0]=1.0;
    118             a[1]=1.0;
    119             a[2]=1.0;
    120             glMaterialfv(GL_FRONT,GL_DIFFUSE,a);
    121            
    122         }
    123         glNormal3f(normal_vectors[i][j].x, normal_vectors[i][j].y, normal_vectors[i][j].z);
    124         glVertex3f(v1.x, v1.y, v1.z);
    125         if(height[i+1][j]<snowheight){
    126           a[0]=0;
    127           a[1] =1.0-height[i+1][j]/10-.3;
    128           a[2]=0;
    129           glMaterialfv(GL_FRONT,GL_DIFFUSE,a);
    130         }
    131         else{
    132           a[0]=1.0;
    133           a[1]=1.0;
    134           a[2]=1.0;
    135           glMaterialfv(GL_FRONT,GL_DIFFUSE,a);
    136          
    137         }
    138         glNormal3f(normal_vectors[i+1][j].x, normal_vectors[i+1][j].y, normal_vectors[i+1][j].z);
    139         glVertex3f(v2.x, v2.y, v2.z);
    140         if(height[i+1][j+1]<snowheight){
    141           a[0]=0;
    142           a[1] =1.0-height[i+1][j+1]/10-.3;
    143           a[2]=0;
    144           glMaterialfv(GL_FRONT,GL_DIFFUSE,a);
    145         }
    146         else{
    147           a[0]=1.0;
    148           a[1]=1.0;
    149           a[2]=1.0;
    150           glMaterialfv(GL_FRONT,GL_DIFFUSE,a);
    151          
    152          
    153         }
    154         glNormal3f(normal_vectors[i+1][j+1].x, normal_vectors[i+1][j+1].y, normal_vectors[i+1][j+1].z);
    155         glVertex3f(v3.x, v3.y, v3.z);
    156         if(height[i][j+1]<snowheight){
    157           a[0]=0;
    158           a[1] =1.0-height[i+1][j+1]/10-.3;
    159           a[2]=0;
    160           glMaterialfv(GL_FRONT,GL_DIFFUSE,a);
    161         }
    162         else{
    163           a[0]=1.0;
    164           a[1]=1.0;
    165           a[2]=1.0;
    166           glMaterialfv(GL_FRONT,GL_DIFFUSE,a);
    167         }
    168         glNormal3f(normal_vectors[i][j+1].x, normal_vectors[i][j+1].y, normal_vectors[i][j+1].z);
    169         glVertex3f(v4.x, v4.y, v4.z);
    170        
    171       }
    172   glEnd();
    173   glEndList();
    174 }
    175 
     51  if (objectList)
     52    glDeleteLists(this->objectList, 1);
     53}
     54
     55
     56void Terrain::init(void)
     57{
     58   this->setClassName ("Terrain");
     59   this->objectList = 0;
     60}
    17661
    17762
     
    19479  glPopMatrix();
    19580}
     81
     82
     83void Terrain::buildDebugTerrain(DebugTerrain debugTerrain)
     84{
     85  // if the terrain is the Terrain of Dave
     86  if (debugTerrain == TERRAIN_DAVE)
     87    {
     88      objectList = glGenLists(1);
     89      glNewList (objectList, GL_COMPILE);
     90     
     91      glColor3f(1.0,0,0);
     92     
     93      int sizeX = 100;
     94      int sizeZ = 80;
     95      float length = 1000;
     96      float width = 200;
     97      float widthX = float (length /sizeX);
     98      float widthZ = float (width /sizeZ);
     99     
     100      float height [sizeX][sizeZ];
     101      Vector normal_vectors[sizeX][sizeZ];
     102     
     103     
     104      for ( int i = 0; i<sizeX-1; i+=1)
     105        for (int j = 0; j<sizeZ-1;j+=1)
     106          //height[i][j] = rand()/20046 + (j-25)*(j-25)/30;
     107#ifdef __WIN32__
     108          height[i][j]=(sin((float)j/3)*rand()*i/182400)*.5;
     109#else
     110      height[i][j]=(sin((float)j/3)*rand()*(long)i/6282450500.0)*.5;
     111#endif
     112     
     113      //Die Huegel ein wenig glaetten
     114      for (int h=1; h<2;h++)
     115        for (int i=1;i<sizeX-2 ;i+=1 )
     116          for(int j=1;j<sizeZ-2;j+=1)
     117            height[i][j]=(height[i+1][j]+height[i][j+1]+height[i-1][j]+height[i][j-1])/4;
     118     
     119      //Berechnung von normalen Vektoren
     120      for(int i=1;i<sizeX-2;i+=1)
     121        for(int j=1;j<sizeZ-2 ;j+=1)
     122          {
     123            Vector v1 = Vector (widthX*(1),      height[i][j],      widthZ*(j) );
     124            Vector v2 = Vector (widthX*(i-1),    height[i-1][j],    widthZ*(j));
     125            Vector v3 = Vector (widthX*(i),      height[i][j+1],    widthZ*(j+1));
     126            Vector v4 = Vector (widthX*(i+1),    height[i+1][j],    widthZ*(j));
     127            Vector v5 = Vector (widthX*(i),      height[i][j-1],    widthZ*(j-1));
     128           
     129            Vector c1 = v2 - v1;
     130            Vector c2 = v3 - v1;
     131            Vector c3=  v4 - v1;
     132            Vector c4 = v5 - v1;
     133            Vector zero = Vector (0,0,0);
     134            normal_vectors[i][j]=c1.cross(v3-v5)+c2.cross(v4-v2)+c3.cross(v5-v3)+c4.cross(v2-v4);
     135            normal_vectors[i][j].normalize();
     136          }
     137     
     138      glBegin(GL_QUADS);
     139      int snowheight=3;
     140      for ( int i = 0; i<sizeX; i+=1)
     141        for (int j = 0; j<sizeZ;j+=1)
     142          {       
     143            Vector v1 = Vector (widthX*(i),      height[i][j]-20,       widthZ*(j)  -width/2);
     144            Vector v2 = Vector (widthX*(i+1),    height[i+1][j]-20,     widthZ*(j)  -width/2);
     145            Vector v3 = Vector (widthX*(i+1),    height[i+1][j+1]-20,   widthZ*(j+1)-width/2);
     146            Vector v4 = Vector (widthX*(i),      height[i][j+1]-20,     widthZ*(j+1)-width/2);
     147            float a[3];
     148            if(height[i][j]<snowheight){
     149              a[0]=0;
     150              a[1]=1.0-height[i][j]/10-.3;
     151              a[2]=0;
     152              glMaterialfv(GL_FRONT,GL_DIFFUSE,a);
     153            }
     154            else{
     155              a[0]=1.0;
     156              a[1]=1.0;
     157              a[2]=1.0;
     158              glMaterialfv(GL_FRONT,GL_DIFFUSE,a);
     159             
     160            }
     161            glNormal3f(normal_vectors[i][j].x, normal_vectors[i][j].y, normal_vectors[i][j].z);
     162            glVertex3f(v1.x, v1.y, v1.z);
     163            if(height[i+1][j]<snowheight){
     164              a[0]=0;
     165              a[1] =1.0-height[i+1][j]/10-.3;
     166              a[2]=0;
     167              glMaterialfv(GL_FRONT,GL_DIFFUSE,a);
     168            }
     169            else{
     170              a[0]=1.0;
     171              a[1]=1.0;
     172              a[2]=1.0;
     173              glMaterialfv(GL_FRONT,GL_DIFFUSE,a);
     174             
     175            }
     176            glNormal3f(normal_vectors[i+1][j].x, normal_vectors[i+1][j].y, normal_vectors[i+1][j].z);
     177            glVertex3f(v2.x, v2.y, v2.z);
     178            if(height[i+1][j+1]<snowheight){
     179              a[0]=0;
     180              a[1] =1.0-height[i+1][j+1]/10-.3;
     181              a[2]=0;
     182              glMaterialfv(GL_FRONT,GL_DIFFUSE,a);
     183            }
     184            else{
     185              a[0]=1.0;
     186              a[1]=1.0;
     187              a[2]=1.0;
     188              glMaterialfv(GL_FRONT,GL_DIFFUSE,a);
     189             
     190             
     191            }
     192            glNormal3f(normal_vectors[i+1][j+1].x, normal_vectors[i+1][j+1].y, normal_vectors[i+1][j+1].z);
     193            glVertex3f(v3.x, v3.y, v3.z);
     194            if(height[i][j+1]<snowheight){
     195              a[0]=0;
     196              a[1] =1.0-height[i+1][j+1]/10-.3;
     197              a[2]=0;
     198              glMaterialfv(GL_FRONT,GL_DIFFUSE,a);
     199            }
     200            else{
     201              a[0]=1.0;
     202              a[1]=1.0;
     203              a[2]=1.0;
     204              glMaterialfv(GL_FRONT,GL_DIFFUSE,a);
     205            }
     206            glNormal3f(normal_vectors[i][j+1].x, normal_vectors[i][j+1].y, normal_vectors[i][j+1].z);
     207            glVertex3f(v4.x, v4.y, v4.z);
     208           
     209          }
     210      glEnd();
     211      glEndList();
     212    }
     213
     214  if (debugTerrain == TERRAIN_BENSCH)
     215    {
     216      /*
     217        this->model = (OBJModel*) new Model();
     218      this->model->setName("CUBE");
     219      this->model->addVertex (-0.5, -0.5, 0.5);
     220      this->model->addVertex (0.5, -0.5, 0.5);
     221      this->model->addVertex (-0.5, 0.5, 0.5);
     222      this->model->addVertex (0.5, 0.5, 0.5);
     223      this->model->addVertex (-0.5, 0.5, -0.5);
     224      this->model->addVertex (0.5, 0.5, -0.5);
     225      this->model->addVertex (-0.5, -0.5, -0.5);
     226      this->model->addVertex (0.5, -0.5, -0.5);
     227     
     228      this->model->addVertexTexture (0.0, 0.0);
     229      this->model->addVertexTexture (1.0, 0.0);
     230      this->model->addVertexTexture (0.0, 1.0);
     231      this->model->addVertexTexture (1.0, 1.0);
     232      this->model->addVertexTexture (0.0, 2.0);
     233      this->model->addVertexTexture (1.0, 2.0);
     234      this->model->addVertexTexture (0.0, 3.0);
     235      this->model->addVertexTexture (1.0, 3.0);
     236      this->model->addVertexTexture (0.0, 4.0);
     237      this->model->addVertexTexture (1.0, 4.0);
     238      this->model->addVertexTexture (2.0, 0.0);
     239      this->model->addVertexTexture (2.0, 1.0);
     240      this->model->addVertexTexture (-1.0, 0.0);
     241      this->model->addVertexTexture (-1.0, 1.0);
     242
     243      this->model->finalize();
     244      */
     245    }
     246 
     247}
  • orxonox/trunk/src/world_entities/terrain.h

    r3559 r3564  
    1515// FORWARD DEFINITION \\
    1616
     17//! A simple method to call a desired debug world.
     18enum DebugTerrain {TERRAIN_DAVE, TERRAIN_BENSCH};
     19
     20
    1721//! A Class to handle Terrain of orxonox
    1822class Terrain : public WorldEntity
     
    2125 public:
    2226  Terrain();
     27  Terrain(DebugTerrain debugTerrain);
    2328  virtual ~Terrain();
    24 
    25   void build();
     29  void init();
     30 
     31  void buildDebugTerrain(DebugTerrain debugTerrain);
    2632  virtual void draw();
    2733
  • orxonox/trunk/src/world_entities/world_entity.cc

    r3544 r3564  
    3838  this->setClassName ("WorldEntity");
    3939  this->bDraw = true;
     40  this->model = NULL;
    4041  //  collisioncluster = NULL;
    4142}
  • orxonox/trunk/src/world_entities/world_entity.h

    r3544 r3564  
    99#include "stdincl.h"
    1010#include "p_node.h"
     11#include "model.h"
    1112
    1213//class CollisionCluster;
Note: See TracChangeset for help on using the changeset viewer.