Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Jun 28, 2006, 3:07:55 PM (18 years ago)
Author:
stefalie
Message:

mountain_lake: rotating of the water works

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/mountain_lake/src/world_entities/environments/mapped_water.cc

    r8848 r8859  
    4747
    4848  /// calculation of the 4 verts of the water quad
    49   this->waterVerts[0] = this->waterPos.x;
    50   this->waterVerts[1] = this->waterPos.z;
    51   this->waterVerts[2] = this->waterVerts[0] + cos(this->waterAngle) * this->xWidth;
    52   this->waterVerts[3] = this->waterVerts[1] + sin(this->waterAngle) * this->xWidth;
    53   this->waterVerts[2] = this->waterVerts[0] - sin(this->waterAngle) * this->zWidth;
    54   this->waterVerts[3] = this->waterVerts[1] + cos(this->waterAngle) * this->zWidth;
    55   this->waterVerts[2] = this->waterVerts[0] + cos(this->waterAngle) * this->xWidth - sin(this->waterAngle) * this->zWidth;
    56   this->waterVerts[3] = this->waterVerts[1] + sin(this->waterAngle) * this->xWidth + cos(this->waterAngle) * this->zWidth;
     49  this->calcVerts();
    5750
    5851  tempcounter = 0;
     
    167160
    168161/**
     162 * @brief initialization of the shaders
     163 */
     164void MappedWater::calcVerts()
     165{
     166  float deg2radtemp = this->waterAngle / 180 * PI;
     167
     168  this->waterVerts[2] = this->waterVerts[0] + cos(deg2radtemp) * this->xWidth;
     169  this->waterVerts[3] = this->waterVerts[1] + sin(deg2radtemp) * this->xWidth;
     170  this->waterVerts[4] = this->waterVerts[0] + cos(deg2radtemp) * this->xWidth - sin(deg2radtemp) * this->zWidth;
     171  this->waterVerts[5] = this->waterVerts[1] + sin(deg2radtemp) * this->xWidth + cos(deg2radtemp) * this->zWidth;
     172  this->waterVerts[6] = this->waterVerts[0] - sin(deg2radtemp) * this->zWidth;
     173  this->waterVerts[7] = this->waterVerts[1] + cos(deg2radtemp) * this->zWidth;
     174}
     175
     176/**
    169177 * @brief resets the waterColor in the Shader
    170178 * @param r new value for red
     
    240248{
    241249  glMatrixMode(GL_MODELVIEW);
    242 
    243250  glPushMatrix();
    244   // don't use a glTranslate here, the reflection point won't be at the right place anymore
    245   glRotatef(this->waterAngle, 0, 1, 0);
     251
     252  // don't use glRotate or glTranslate here... the shader won't work anymore
    246253
    247254  mat.select();
     
    261268  glMultiTexCoord2f(GL_TEXTURE2, 0, normalUV + move2);          // Normal map texture
    262269  glMultiTexCoord2f(GL_TEXTURE3, 0, 0);                         // DUDV map texture
    263   glVertex3f(this->waterPos.x, this->waterPos.y, this->waterPos.z);
     270  glVertex3f(this->waterVerts[0], this->waterHeight, this->waterVerts[1]);
    264271
    265272  // The front left vertice for the water
     
    268275  glMultiTexCoord2f(GL_TEXTURE2, 0, move2);                     // Normal map texture
    269276  glMultiTexCoord2f(GL_TEXTURE3, 0, 0);                         // DUDV map texture
    270   glVertex3f(this->waterPos.x, this->waterPos.y, this->waterPos.z + this->zWidth);
     277  glVertex3f(this->waterVerts[2], this->waterHeight, this->waterVerts[3]);
    271278
    272279  // The front right vertice for the water
     
    275282  glMultiTexCoord2f(GL_TEXTURE2, normalUV, move2);              // Normal map texture
    276283  glMultiTexCoord2f(GL_TEXTURE3, 0, 0);                         // DUDV map texture
    277   glVertex3f(this->waterPos.x + this->xWidth, this->waterPos.y, this->waterPos.z + this->zWidth);
     284  glVertex3f(this->waterVerts[4], this->waterHeight, this->waterVerts[5]);
    278285
    279286  // The back right vertice for the water
     
    282289  glMultiTexCoord2f(GL_TEXTURE2, normalUV, normalUV + move2);   // Normal map texture
    283290  glMultiTexCoord2f(GL_TEXTURE3, 0, 0);                         // DUDV map texture
    284   glVertex3f(this->waterPos.x + this->xWidth, this->waterPos.y, this->waterPos.z);
     291  glVertex3f(this->waterVerts[6], this->waterHeight, this->waterVerts[7]);
    285292  glEnd();
    286293
     
    357364  Vector pos = State::getCameraNode()->getAbsCoor();
    358365
    359   if(pos.y > waterPos.y)
     366  if(pos.y > waterHeight)
    360367  {
    361368    // Translate the world, then flip it upside down
    362     glTranslatef(0, waterPos.y*2, 0);
     369    glTranslatef(0, waterHeight * 2, 0);
    363370    glScalef(1, -1, 1);
    364371
     
    367374
    368375    // Set our plane equation and turn clipping on
    369     double plane[4] = {0, 1, 0, -waterPos.y};
     376    double plane[4] = {0, 1, 0, -waterHeight};
    370377    glClipPlane(GL_CLIP_PLANE0, plane);
    371378  }
     
    374381    // If the camera is below the water we don't want to flip the world,
    375382    // but just render it clipped so only the top is drawn.
    376     double plane[4] = {0, 1, 0, waterPos.y};
     383    double plane[4] = {0, 1, 0, waterHeight};
    377384    glClipPlane(GL_CLIP_PLANE0, plane);
    378385  }
     
    419426  glEnable(GL_CLIP_PLANE0);
    420427  Vector pos = State::getCameraNode()->getAbsCoor();
    421   if(pos.y > waterPos.y)
     428  if(pos.y > waterHeight)
    422429  {
    423     double plane[4] = {0, -1, 0, waterPos.y};
     430    double plane[4] = {0, -1, 0, waterHeight};
    424431    glClipPlane(GL_CLIP_PLANE0, plane);
    425432  }
     
    428435  {
    429436    glCullFace(GL_FRONT);
    430     double plane[4] = {0, 1, 0, -waterPos.y};
     437    double plane[4] = {0, 1, 0, -waterHeight};
    431438    glClipPlane(GL_CLIP_PLANE0, plane);
    432439  }
Note: See TracChangeset for help on using the changeset viewer.