Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 6458 in orxonox.OLD for trunk


Ignore:
Timestamp:
Jan 10, 2006, 1:20:12 AM (19 years ago)
Author:
bensch
Message:

orxonox/trunk: wave now also rebuilds the Normals (do not know if this is really necesarry, but i sure hope so for all the work :)

Location:
trunk/src
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/lib/graphics/importer/grid.cc

    r6454 r6458  
    3333  this->_sizeX = sizeX;
    3434  this->_sizeY = sizeY;
     35  this->_gridSpacingX = sizeX / rows;
     36  this->_gridSpacingY = sizeY / columns;
    3537}
    3638
     
    4345  // delete what has to be deleted here
    4446}
     47
     48
     49void Grid::rebuildNormals(float maxHeight)
     50{
     51  for (unsigned int i = 1; i < this->_rows-1; i++)
     52  {
     53    for (unsigned int j = 1; j < this->_columns-1; j++)
     54    {
     55     Vector test(
     56          (this->vertex(i*_columns+j).y + this->vertex((i-1)*_columns+j).y - this->vertex((i+1)*_columns+j).y ) /maxHeight,
     57          1.0,
     58          (this->vertex(i*_columns+j).y - this->vertex(i*_columns+j-1).y + this->vertex(i*_columns+j+1).y)/maxHeight
     59                );
     60      this->normal( i*_columns+j) = test.getNormalized();
     61    }
     62
     63  }
     64
     65}
  • trunk/src/lib/graphics/importer/grid.h

    r6457 r6458  
    2929
    3030
    31   void rebuidNormals();
     31  void rebuildNormals(float maxHeight);
    3232
    3333private:
    3434  float             _sizeX;
    3535  float             _sizeY;
     36
     37  float             _gridSpacingX;
     38  float             _gridSpacingY;
    3639
    3740  unsigned int      _rows;
  • trunk/src/world_entities/environments/water.cc

    r6457 r6458  
    3434
    3535  this->resX = this->resY = 10;
    36   this->sizeX = this->sizeY = 1.0;
     36  this->sizeX = this->sizeY = 1.0f;
     37  this->height = 0.5f;
    3738  this->grid = NULL;
    3839
     
    6162      .describe("sets the resolution of the water surface")
    6263      .defaultValues(2, 10, 10);
     64
     65  LoadParam(root, "height", this, Water, setHeight)
     66      .describe("the height of the Waves")
     67      .defaultValues(1, 0.5f);
    6368}
    6469
     
    6974  this->grid = new Grid(this->sizeX, this->sizeY, this->resX, this->resY);
    7075
    71   this->grid->debug();
    7276  this->setModel(this->grid, 0);
    7377}
     
    8589}
    8690
     91void Water::setHeight(float height)
     92{
     93  this->height = height;
     94}
     95
     96
    8797void Water::draw() const
    8898{
     
    98108    for (unsigned int j = 0; j < this->grid->columns(); j++)
    99109    {
    100       this->grid->height(i,j) = 15.0*sin(((float)i/(float)this->grid->rows() *phase)+
    101           15*cos((float)j/(float)this->grid->columns()) * phase);
     110      this->grid->height(i,j) = this->height*sin(((float)i/(float)this->grid->rows() *phase)+
     111          this->height*cos((float)j/(float)this->grid->columns()) * phase);
    102112    }
    103113  }
     114  this->grid->rebuildNormals(this->height);
    104115}
  • trunk/src/world_entities/environments/water.h

    r6457 r6458  
    2828   void setResolution(unsigned int resX, unsigned int resY);
    2929   void setSize(float sizeX, float sizeY);
     30   void setHeight(float height);
    3031   void rebuildGrid();
    3132
     
    3637    Grid*           grid;            //!< The water-surface-model to render with
    3738    Material*       waterMaterial;
     39    float           height;          //!< The hight of the Water
    3840
    3941    unsigned int    resX, resY;
Note: See TracChangeset for help on using the changeset viewer.