Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 6518 in orxonox.OLD for trunk/src/world_entities/environments


Ignore:
Timestamp:
Jan 18, 2006, 12:09:11 AM (19 years ago)
Author:
bensch
Message:

orxonox/trunk: some waves

Location:
trunk/src/world_entities/environments
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/world_entities/environments/water.cc

    r6471 r6518  
    4444  this->grid = NULL;
    4545
     46  this->velocities = NULL;
     47  this->viscosity = 5;
     48  this->cohesion = .00002;
     49
    4650  if (root != NULL)
    4751    this->loadParams(root);
     
    5155  this->waterShader = (Shader*)ResourceManager::getInstance()->load("shaders/water.vert", SHADER, RP_GAME, (void*)"shaders/water.frag");
    5256
     57  this->grid->height(this->grid->columns()/2,this->grid->rows()/2) = 1000;
    5358}
    5459
     
    7883void Water::rebuildGrid()
    7984{
     85  if (this->velocities != NULL)
     86  {
     87    assert (this->grid != NULL);
     88    for (unsigned int i = 0; i < this->grid->rows(); i++)
     89      delete[] this->velocities[i];
     90    delete[] this->velocities;
     91  }
    8092  if (this->grid != NULL)
    8193    delete this->grid;
    8294  this->grid = new Grid(this->sizeX, this->sizeY, this->resX, this->resY);
     95  this->velocities = new float*[this->resX];
     96  for (unsigned int i = 0; i < this->grid->rows(); i++)
     97    this->velocities[i] = new float[this->resY];
    8398
    8499  this->setModel(this->grid, 0);
     
    117132void Water::tick(float dt)
    118133{
     134/*
     135    THE OLD USELESS ALGORITHM
    119136  phase += dt *.1;
    120137  for (unsigned int i = 0; i < this->grid->rows(); i++)
     
    126143    }
    127144  }
    128   this->grid->rebuildNormals(this->height);
    129 }
     145  this->grid->rebuildNormals(this->height);*/
     146
     147
     148  unsigned int i, j;
     149  float u;
     150
     151  // wave/advection
     152  // calc movement
     153  for(j = 1; j < this->grid->rows() - 1; j++) {
     154    for(i = 1; i < this->grid->columns() - 1; i++) {
     155      u =  this->grid->height(i+1,j)+ this->grid->height(i-1, j) +
     156          this->grid->height(i, j+1) + this->grid->height(i, j-1) -
     157          4 * this->grid->height(i, j);
     158      this->velocities[i][j] += dt * this->viscosity * this->viscosity * u / this->height;
     159    }
     160  }
     161  // advect
     162  for(j = 1; j < this->grid->rows() - 1; j++) {
     163    for(i = 1; i < this->grid->columns() - 1; i++) {
     164      this->grid->height(i, j) += dt * this->velocities[i][j];
     165    }
     166  }
     167  // bound
     168//   unsigned int w = this->grid->columns - 1;
     169//   for(i = 0; i < this->grid->columns; i++) {
     170//     _map[i][0].u[1] = _map[i][1  ].u[1];
     171//     _map[i][w].u[1] = _map[i][w-1].u[1];
     172//     _map[0][i].u[1] = _map[1  ][i].u[1];
     173//     _map[w][i].u[1] = _map[w-1][i].u[1];
     174//   }
     175
     176  // diffusion
     177  for(j = 1; j < this->grid->rows() - 1; j++) {
     178    for(i = 1; i < this->grid->columns() - 1 ; i++) {
     179      u = this->grid->height(i+1, j) + this->grid->height(i-1, j) +
     180          this->grid->height(i, j+1) + this->grid->height(i, j-1) -
     181          4* this->grid->height(i, j);
     182      this->grid->height(i,j) += dt * this->cohesion * u / this->height;
     183    }
     184  }
     185
     186  // calc normals
     187/*  float l[3];
     188  float m[3];
     189  for(j = 1; j < _width-1; j++) {
     190    for(i = 1; i < _width - 1; i++) {
     191      l[0] = _map[i][j-1].u[0] - _map[i][j+1].u[0];
     192      l[1] = _map[i][j-1].u[1] - _map[i][j+1].u[1];
     193      l[2] = _map[i][j-1].u[2] - _map[i][j+1].u[2];
     194      m[0] = _map[i-1][j].u[0] - _map[i+1][j].u[0];
     195      m[1] = _map[i-1][j].u[1] - _map[i+1][j].u[1];
     196      m[2] = _map[i-1][j].u[2] - _map[i+1][j].u[2];
     197      _map[i][j].n[0] = l[1]*m[2]-l[2]*m[1];
     198      _map[i][j].n[1] = l[2]*m[0]-l[0]*m[2];
     199      _map[i][j].n[2] = l[0]*m[1]-l[1]*m[0];
     200    }
     201  }*/
     202}
  • trunk/src/world_entities/environments/water.h

    r6467 r6518  
    3737  private:
    3838    Grid*           grid;            //!< The water-surface-model to render with
     39    float**         velocities;      //!< Velocities.
     40    float           viscosity;       //!< Viscosity (bigger more like honey, smaller more like water).
     41    float           cohesion;        //!< Cohesion.
     42
    3943    Material*       waterMaterial;
    4044    Shader*         waterShader;
Note: See TracChangeset for help on using the changeset viewer.