Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Jan 25, 2006, 2:19:46 PM (18 years ago)
Author:
patrick
Message:

branches: removed spaceshipcontrol branche

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/network/src/world_entities/environments/water.cc

    r6686 r6693  
    5454  this->rebuildGrid();
    5555  this->waterMaterial = new Material();
    56   this->waterShader = (Shader*)ResourceManager::getInstance()->load("shaders/water.vert", SHADER, RP_GAME, (void*)"shaders/water.frag");
     56  this->waterShader = (Shader*)ResourceManager::getInstance()->load("shaders/water.vert", SHADER, RP_GAME, "shaders/water.frag");
    5757
    5858  this->grid->height(this->grid->columns()/2,this->grid->rows()/2) = 100;
     
    7070
    7171  LoadParam(root, "size", this, Water, setSize)
    72       .describe("the size of the WaterSurface")
    73       .defaultValues(2, 1.0f, 1.0f);
     72  .describe("the size of the WaterSurface")
     73  .defaultValues(2, 1.0f, 1.0f);
    7474
    7575  LoadParam(root, "resolution", this, Water, setResolution)
    76       .describe("sets the resolution of the water surface")
    77       .defaultValues(2, 10, 10);
     76  .describe("sets the resolution of the water surface")
     77  .defaultValues(2, 10, 10);
    7878
    7979  LoadParam(root, "height", this, Water, setHeight)
    80       .describe("the height of the Waves")
    81       .defaultValues(1, 0.5f);
     80  .describe("the height of the Waves")
     81  .defaultValues(1, 0.5f);
    8282}
    8383
     
    9292  }
    9393
    94 //   WE DO NOT NEED THIS AS IT IS DONE IN WORLDENTITY->setModel();
    95 //   if (this->grid != NULL)
    96 //     this->grid = NULL;
     94  //   WE DO NOT NEED THIS AS IT IS DONE IN WORLDENTITY->setModel();
     95  //   if (this->grid != NULL)
     96  //     this->grid = NULL;
    9797
    9898  this->grid = new Grid(this->sizeX, this->sizeY, this->resX, this->resY);
     
    127127void Water::draw() const
    128128{
    129   //SkyBox::enableCubeMap();
    130 
    131   glBindTexture(GL_TEXTURE_2D, 15);
    132   glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
    133 
    134   glTexGeni(GL_S, GL_TEXTURE_GEN_MODE, GL_SPHERE_MAP);
    135   glTexGeni(GL_T, GL_TEXTURE_GEN_MODE, GL_SPHERE_MAP);
    136   glEnable(GL_TEXTURE_GEN_S);
    137   glEnable(GL_TEXTURE_GEN_T);
    138 
    139   glEnable(GL_BLEND);
    140   glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
    141   // this->waterShader->activateShader();
    142 //  this->waterMaterial->select();
    143   WorldEntity::draw();
    144   //Shader::deactivateShader();
    145 
    146   SkyBox::disableCubeMap();
     129  if (this->grid != NULL)
     130  {
     131    //SkyBox::enableCubeMap();
     132    WorldEntity::draw();
     133    glBindTexture(GL_TEXTURE_2D, 15);
     134    glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
     135
     136    glTexGeni(GL_S, GL_TEXTURE_GEN_MODE, GL_SPHERE_MAP);
     137    glTexGeni(GL_T, GL_TEXTURE_GEN_MODE, GL_SPHERE_MAP);
     138    glEnable(GL_TEXTURE_GEN_S);
     139    glEnable(GL_TEXTURE_GEN_T);
     140
     141    glEnable(GL_BLEND);
     142    glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
     143    // this->waterShader->activateShader();
     144    //  this->waterMaterial->select();
     145    //Shader::deactivateShader();
     146
     147    SkyBox::disableCubeMap();
     148  }
    147149}
    148150
    149151void Water::tick(float dt)
    150152{
    151 /*
    152     THE OLD USELESS ALGORITHM
    153   phase += dt *.1;
    154   for (unsigned int i = 0; i < this->grid->rows(); i++)
    155   {
    156     for (unsigned int j = 0; j < this->grid->columns(); j++)
     153  if (unlikely(this->velocities == NULL))
     154    return;
     155  /*
     156      THE OLD USELESS ALGORITHM
     157    phase += dt *.1;
     158    for (unsigned int i = 0; i < this->grid->rows(); i++)
    157159    {
    158       this->grid->height(i,j) = this->height*sin(((float)i/(float)this->grid->rows() *phase)+
    159           this->height*cos((float)j/(float)this->grid->columns()) * phase * 2.0);
     160      for (unsigned int j = 0; j < this->grid->columns(); j++)
     161      {
     162        this->grid->height(i,j) = this->height*sin(((float)i/(float)this->grid->rows() *phase)+
     163            this->height*cos((float)j/(float)this->grid->columns()) * phase * 2.0);
     164      }
    160165    }
    161   }
    162   this->grid->rebuildNormals(this->height);*/
     166    this->grid->rebuildNormals(this->height);*/
    163167
    164168
     
    168172  // wave/advection
    169173  // calc movement
    170   for(j = 1; j < this->grid->rows() - 1; j++) {
    171     for(i = 1; i < this->grid->columns() - 1; i++) {
     174  for(j = 1; j < this->grid->rows() - 1; j++)
     175  {
     176    for(i = 1; i < this->grid->columns() - 1; i++)
     177    {
    172178      u =  this->grid->height(i+1,j)+ this->grid->height(i-1, j) +
    173           this->grid->height(i, j+1) + this->grid->height(i, j-1) -
    174           4 * this->grid->height(i, j);
     179           this->grid->height(i, j+1) + this->grid->height(i, j-1) -
     180           4 * this->grid->height(i, j);
    175181      this->velocities[i][j] += dt * this->viscosity * this->viscosity * u / this->height;
    176182      this->grid->height(i, j) += dt * this->velocities[i][j];
    177183    }
    178184  }
    179 /*  // advect
    180   for(j = 1; j < this->grid->rows() - 1; j++) {
    181     for(i = 1; i < this->grid->columns() - 1; i++) {
    182       this->grid->height(i, j) += dt * this->velocities[i][j];
    183     }
    184   }*/
     185  // boundraries
     186  for (j = 0; j < this->grid->rows(); j++)
     187  {
     188    this->grid->height(0,j) = this->grid->height(1,j);
     189    this->grid->height(this->grid->rows()-1,j) = this->grid->height(this->grid->rows()-2, j);
     190  }
     191  for (i = 0; i < this->grid->rows(); i++)
     192  {
     193    this->grid->height(i,0) = this->grid->height(i,1);
     194    this->grid->height(i,this->grid->columns()-1) = this->grid->height(i, this->grid->columns()-2);
     195  }
     196  /*  // advect
     197    for(j = 1; j < this->grid->rows() - 1; j++) {
     198      for(i = 1; i < this->grid->columns() - 1; i++) {
     199        this->grid->height(i, j) += dt * this->velocities[i][j];
     200      }
     201    }*/
    185202  // bound
    186 //   unsigned int w = this->grid->columns - 1;
    187 //   for(i = 0; i < this->grid->columns; i++) {
    188 //     _map[i][0].u[1] = _map[i][1  ].u[1];
    189 //     _map[i][w].u[1] = _map[i][w-1].u[1];
    190 //     _map[0][i].u[1] = _map[1  ][i].u[1];
    191 //     _map[w][i].u[1] = _map[w-1][i].u[1];
    192 //   }
     203  //   unsigned int w = this->grid->columns - 1;
     204  //   for(i = 0; i < this->grid->columns; i++) {
     205  //     _map[i][0].u[1] = _map[i][1  ].u[1];
     206  //     _map[i][w].u[1] = _map[i][w-1].u[1];
     207  //     _map[0][i].u[1] = _map[1  ][i].u[1];
     208  //     _map[w][i].u[1] = _map[w-1][i].u[1];
     209  //   }
    193210
    194211  // diffusion
    195   for(j = 1; j < this->grid->rows() - 1; j++) {
    196     for(i = 1; i < this->grid->columns() - 1 ; i++) {
     212  for(j = 1; j < this->grid->rows() - 1; j++)
     213  {
     214    for(i = 1; i < this->grid->columns() - 1 ; i++)
     215    {
    197216      u = this->grid->height(i+1, j) + this->grid->height(i-1, j) +
    198217          this->grid->height(i, j+1) + this->grid->height(i, j-1) -
     
    203222
    204223  // calc normals
    205 //   float l[3];
    206 //   float m[3];
    207 //   for(j = 1; j < this->grid->rows() -1; j++) {
    208 //     for(i = 1; i < this->grid->columns() - 1; i++) {
    209 //       l[0] = this->grid->vertexG(i, j-1).x - this->grid->vertexG(i, j+1).x;
    210 //       l[1] = this->grid->vertexG(i, j-1).y - this->grid->vertexG(i, j+1).y;
    211 //       l[2] = this->grid->vertexG(i, j-1).z - this->grid->vertexG(i, j+1).z;
    212 //       m[0] = this->grid->vertexG(i-1,j).x - this->grid->vertexG(i+1, j).x;
    213 //       m[1] = this->grid->vertexG(i-1,j).y - this->grid->vertexG(i+1, j).y;
    214 //       m[2] = this->grid->vertexG(i-1,j).z - this->grid->vertexG(i+1, j).z;
    215 //       this->grid->normalG(i, j).x = l[1] * m[2] - l[2] * m[1];
    216 //       this->grid->normalG(i, j).y = l[2] * m[0] - l[0] * m[2];
    217 //       this->grid->normalG(i, j).z = l[0] * m[1] - l[1] * m[0];
    218 //     }
    219 //   }
     224  //   float l[3];
     225  //   float m[3];
     226  //   for(j = 1; j < this->grid->rows() -1; j++) {
     227  //     for(i = 1; i < this->grid->columns() - 1; i++) {
     228  //       l[0] = this->grid->vertexG(i, j-1).x - this->grid->vertexG(i, j+1).x;
     229  //       l[1] = this->grid->vertexG(i, j-1).y - this->grid->vertexG(i, j+1).y;
     230  //       l[2] = this->grid->vertexG(i, j-1).z - this->grid->vertexG(i, j+1).z;
     231  //       m[0] = this->grid->vertexG(i-1,j).x - this->grid->vertexG(i+1, j).x;
     232  //       m[1] = this->grid->vertexG(i-1,j).y - this->grid->vertexG(i+1, j).y;
     233  //       m[2] = this->grid->vertexG(i-1,j).z - this->grid->vertexG(i+1, j).z;
     234  //       this->grid->normalG(i, j).x = l[1] * m[2] - l[2] * m[1];
     235  //       this->grid->normalG(i, j).y = l[2] * m[0] - l[0] * m[2];
     236  //       this->grid->normalG(i, j).z = l[0] * m[1] - l[1] * m[0];
     237  //     }
     238  //   }
    220239  this->grid->rebuildNormals(this->height);
    221240}
Note: See TracChangeset for help on using the changeset viewer.