Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Jan 26, 2006, 12:54:16 PM (18 years ago)
Author:
bensch
Message:

trunk: splash splash

File:
1 edited

Legend:

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

    r6756 r6766  
    2727
    2828#include "skybox.h"
     29#include "state.h"
     30
    2931
    3032#include "network_game_manager.h"
     
    5658  this->waterShader = (Shader*)ResourceManager::getInstance()->load("shaders/water.vert", SHADER, RP_GAME, "shaders/water.frag");
    5759
    58   this->grid->height(this->grid->columns()/2,this->grid->rows()/2) = 100;
     60  // To test the Wave equation
     61  //this->wave(5.0,4.0, 1, 10);
    5962}
    6063
     
    107110}
    108111
     112void Water::wave(float x, float y, float z, float force)
     113{
     114  unsigned int row = 0, column = 0;
     115  if (!this->posToGridPoint( x, z, row, column))
     116    return;
     117  this->grid->height(row, column) -= force / ((y - this->getAbsCoor().y) +.1);
     118}
     119
    109120void Water::setResolution(unsigned int resX, unsigned int resY)
    110121{
     
    122133{
    123134  this->height = height;
     135}
     136
     137
     138bool Water::posToGridPoint(float x, float z, unsigned int& row, unsigned int& column)
     139{
     140  float lower = this->getAbsCoor().y - this->sizeY *.5;
     141  float left = this->getAbsCoor().x - this->sizeX *.5;
     142  if (x > left && x < left + this->sizeX)
     143    row = (unsigned int) ((x- left) / this->grid->gridSpacing());
     144  else return false;
     145  if (z > lower && z < lower + this->sizeY)
     146    column = (unsigned int)((z-lower) / this->grid->gridSpacing());
     147  else return false;
     148  return true;
    124149}
    125150
     
    151176void Water::tick(float dt)
    152177{
     178  std::list<WorldEntity*> entityList = State::getObjectManager()->getObjectList(OM_GROUP_01_PROJ);
     179  std::list<WorldEntity*>::iterator entity = entityList.begin();
     180  while (entity != entityList.end())
     181  {
     182    this->wave((*entity)->getAbsCoor(), 10.0*dt);
     183    entity++;
     184  }
     185
     186
    153187  if (unlikely(this->velocities == NULL))
    154188    return;
     
    180214           4 * this->grid->height(i, j);
    181215      this->velocities[i][j] += dt * this->viscosity * this->viscosity * u / this->height;
    182       this->grid->height(i, j) += dt * this->velocities[i][j] + dt * this->cohesion * u / this->height;;
     216      this->grid->height(i, j) += dt * this->velocities[i][j]  /* + dt * this->cohesion * u / this->height;*/;
     217      this->grid->height(i, j) *= .99;
    183218    }
    184219  }
Note: See TracChangeset for help on using the changeset viewer.