Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 6684 in orxonox.OLD


Ignore:
Timestamp:
Jan 25, 2006, 12:37:21 AM (18 years ago)
Author:
bensch
Message:

some water fixes

Location:
trunk/src
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/lib/event/event_handler.cc

    r6679 r6684  
    262262    SDL_WM_GrabInput(SDL_GRAB_OFF);
    263263  else
    264     ;// SDL_WM_GrabInput(SDL_GRAB_ON);
     264    SDL_WM_GrabInput(SDL_GRAB_ON);
    265265}
    266266
  • trunk/src/world_entities/environments/water.cc

    r6680 r6684  
    6969
    7070  LoadParam(root, "size", this, Water, setSize)
    71       .describe("the size of the WaterSurface")
    72       .defaultValues(2, 1.0f, 1.0f);
     71  .describe("the size of the WaterSurface")
     72  .defaultValues(2, 1.0f, 1.0f);
    7373
    7474  LoadParam(root, "resolution", this, Water, setResolution)
    75       .describe("sets the resolution of the water surface")
    76       .defaultValues(2, 10, 10);
     75  .describe("sets the resolution of the water surface")
     76  .defaultValues(2, 10, 10);
    7777
    7878  LoadParam(root, "height", this, Water, setHeight)
    79       .describe("the height of the Waves")
    80       .defaultValues(1, 0.5f);
     79  .describe("the height of the Waves")
     80  .defaultValues(1, 0.5f);
    8181}
    8282
     
    9191  }
    9292
    93 //   WE DO NOT NEED THIS AS IT IS DONE IN WORLDENTITY->setModel();
    94 //   if (this->grid != NULL)
    95 //     this->grid = NULL;
     93  //   WE DO NOT NEED THIS AS IT IS DONE IN WORLDENTITY->setModel();
     94  //   if (this->grid != NULL)
     95  //     this->grid = NULL;
    9696
    9797  this->grid = new Grid(this->sizeX, this->sizeY, this->resX, this->resY);
     
    126126void Water::draw() const
    127127{
    128   //SkyBox::enableCubeMap();
    129 
    130   glBindTexture(GL_TEXTURE_2D, 15);
    131   glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
    132 
    133   glTexGeni(GL_S, GL_TEXTURE_GEN_MODE, GL_SPHERE_MAP);
    134   glTexGeni(GL_T, GL_TEXTURE_GEN_MODE, GL_SPHERE_MAP);
    135   glEnable(GL_TEXTURE_GEN_S);
    136   glEnable(GL_TEXTURE_GEN_T);
    137 
    138   glEnable(GL_BLEND);
    139   glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
    140   // this->waterShader->activateShader();
    141 //  this->waterMaterial->select();
    142   WorldEntity::draw();
    143   //Shader::deactivateShader();
    144 
    145   SkyBox::disableCubeMap();
     128  if (this->grid != NULL)
     129  {
     130    //SkyBox::enableCubeMap();
     131    WorldEntity::draw();
     132    glBindTexture(GL_TEXTURE_2D, 15);
     133    glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
     134
     135    glTexGeni(GL_S, GL_TEXTURE_GEN_MODE, GL_SPHERE_MAP);
     136    glTexGeni(GL_T, GL_TEXTURE_GEN_MODE, GL_SPHERE_MAP);
     137    glEnable(GL_TEXTURE_GEN_S);
     138    glEnable(GL_TEXTURE_GEN_T);
     139
     140    glEnable(GL_BLEND);
     141    glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
     142    // this->waterShader->activateShader();
     143    //  this->waterMaterial->select();
     144    //Shader::deactivateShader();
     145
     146    SkyBox::disableCubeMap();
     147  }
    146148}
    147149
     
    150152  if (unlikely(this->velocities == NULL))
    151153    return;
    152 /*
    153     THE OLD USELESS ALGORITHM
    154   phase += dt *.1;
    155   for (unsigned int i = 0; i < this->grid->rows(); i++)
    156   {
    157     for (unsigned int j = 0; j < this->grid->columns(); j++)
     154  /*
     155      THE OLD USELESS ALGORITHM
     156    phase += dt *.1;
     157    for (unsigned int i = 0; i < this->grid->rows(); i++)
    158158    {
    159       this->grid->height(i,j) = this->height*sin(((float)i/(float)this->grid->rows() *phase)+
    160           this->height*cos((float)j/(float)this->grid->columns()) * phase * 2.0);
     159      for (unsigned int j = 0; j < this->grid->columns(); j++)
     160      {
     161        this->grid->height(i,j) = this->height*sin(((float)i/(float)this->grid->rows() *phase)+
     162            this->height*cos((float)j/(float)this->grid->columns()) * phase * 2.0);
     163      }
    161164    }
    162   }
    163   this->grid->rebuildNormals(this->height);*/
     165    this->grid->rebuildNormals(this->height);*/
    164166
    165167
     
    169171  // wave/advection
    170172  // calc movement
    171   for(j = 1; j < this->grid->rows() - 1; j++) {
    172     for(i = 1; i < this->grid->columns() - 1; i++) {
     173  for(j = 1; j < this->grid->rows() - 1; j++)
     174  {
     175    for(i = 1; i < this->grid->columns() - 1; i++)
     176    {
    173177      u =  this->grid->height(i+1,j)+ this->grid->height(i-1, j) +
    174           this->grid->height(i, j+1) + this->grid->height(i, j-1) -
    175           4 * this->grid->height(i, j);
     178           this->grid->height(i, j+1) + this->grid->height(i, j-1) -
     179           4 * this->grid->height(i, j);
    176180      this->velocities[i][j] += dt * this->viscosity * this->viscosity * u / this->height;
    177181      this->grid->height(i, j) += dt * this->velocities[i][j];
    178182    }
    179183  }
    180 /*  // advect
    181   for(j = 1; j < this->grid->rows() - 1; j++) {
    182     for(i = 1; i < this->grid->columns() - 1; i++) {
    183       this->grid->height(i, j) += dt * this->velocities[i][j];
    184     }
    185   }*/
     184  // boundraries
     185  for (j = 0; j < this->grid->rows(); j++)
     186  {
     187    this->grid->height(0,j) = this->grid->height(1,j);
     188    this->grid->height(this->grid->rows()-1,j) = this->grid->height(this->grid->rows()-2, j);
     189  }
     190  for (i = 0; i < this->grid->rows(); i++)
     191  {
     192    this->grid->height(i,0) = this->grid->height(i,1);
     193    this->grid->height(i,this->grid->columns()-1) = this->grid->height(i, this->grid->columns()-2);
     194  }
     195  /*  // advect
     196    for(j = 1; j < this->grid->rows() - 1; j++) {
     197      for(i = 1; i < this->grid->columns() - 1; i++) {
     198        this->grid->height(i, j) += dt * this->velocities[i][j];
     199      }
     200    }*/
    186201  // bound
    187 //   unsigned int w = this->grid->columns - 1;
    188 //   for(i = 0; i < this->grid->columns; i++) {
    189 //     _map[i][0].u[1] = _map[i][1  ].u[1];
    190 //     _map[i][w].u[1] = _map[i][w-1].u[1];
    191 //     _map[0][i].u[1] = _map[1  ][i].u[1];
    192 //     _map[w][i].u[1] = _map[w-1][i].u[1];
    193 //   }
     202  //   unsigned int w = this->grid->columns - 1;
     203  //   for(i = 0; i < this->grid->columns; i++) {
     204  //     _map[i][0].u[1] = _map[i][1  ].u[1];
     205  //     _map[i][w].u[1] = _map[i][w-1].u[1];
     206  //     _map[0][i].u[1] = _map[1  ][i].u[1];
     207  //     _map[w][i].u[1] = _map[w-1][i].u[1];
     208  //   }
    194209
    195210  // diffusion
    196   for(j = 1; j < this->grid->rows() - 1; j++) {
    197     for(i = 1; i < this->grid->columns() - 1 ; i++) {
     211  for(j = 1; j < this->grid->rows() - 1; j++)
     212  {
     213    for(i = 1; i < this->grid->columns() - 1 ; i++)
     214    {
    198215      u = this->grid->height(i+1, j) + this->grid->height(i-1, j) +
    199216          this->grid->height(i, j+1) + this->grid->height(i, j-1) -
     
    204221
    205222  // calc normals
    206 //   float l[3];
    207 //   float m[3];
    208 //   for(j = 1; j < this->grid->rows() -1; j++) {
    209 //     for(i = 1; i < this->grid->columns() - 1; i++) {
    210 //       l[0] = this->grid->vertexG(i, j-1).x - this->grid->vertexG(i, j+1).x;
    211 //       l[1] = this->grid->vertexG(i, j-1).y - this->grid->vertexG(i, j+1).y;
    212 //       l[2] = this->grid->vertexG(i, j-1).z - this->grid->vertexG(i, j+1).z;
    213 //       m[0] = this->grid->vertexG(i-1,j).x - this->grid->vertexG(i+1, j).x;
    214 //       m[1] = this->grid->vertexG(i-1,j).y - this->grid->vertexG(i+1, j).y;
    215 //       m[2] = this->grid->vertexG(i-1,j).z - this->grid->vertexG(i+1, j).z;
    216 //       this->grid->normalG(i, j).x = l[1] * m[2] - l[2] * m[1];
    217 //       this->grid->normalG(i, j).y = l[2] * m[0] - l[0] * m[2];
    218 //       this->grid->normalG(i, j).z = l[0] * m[1] - l[1] * m[0];
    219 //     }
    220 //   }
     223  //   float l[3];
     224  //   float m[3];
     225  //   for(j = 1; j < this->grid->rows() -1; j++) {
     226  //     for(i = 1; i < this->grid->columns() - 1; i++) {
     227  //       l[0] = this->grid->vertexG(i, j-1).x - this->grid->vertexG(i, j+1).x;
     228  //       l[1] = this->grid->vertexG(i, j-1).y - this->grid->vertexG(i, j+1).y;
     229  //       l[2] = this->grid->vertexG(i, j-1).z - this->grid->vertexG(i, j+1).z;
     230  //       m[0] = this->grid->vertexG(i-1,j).x - this->grid->vertexG(i+1, j).x;
     231  //       m[1] = this->grid->vertexG(i-1,j).y - this->grid->vertexG(i+1, j).y;
     232  //       m[2] = this->grid->vertexG(i-1,j).z - this->grid->vertexG(i+1, j).z;
     233  //       this->grid->normalG(i, j).x = l[1] * m[2] - l[2] * m[1];
     234  //       this->grid->normalG(i, j).y = l[2] * m[0] - l[0] * m[2];
     235  //       this->grid->normalG(i, j).z = l[0] * m[1] - l[1] * m[0];
     236  //     }
     237  //   }
    221238  this->grid->rebuildNormals(this->height);
    222239}
Note: See TracChangeset for help on using the changeset viewer.