Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 8859 in orxonox.OLD for branches


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

mountain_lake: rotating of the water works

Location:
branches/mountain_lake/src/world_entities/environments
Files:
2 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  }
  • branches/mountain_lake/src/world_entities/environments/mapped_water.h

    r8848 r8859  
    4545  // functions to set parameters for the water, usually they're called through loadparam
    4646  void setLightPos(float x, float y, float z) { this->lightPos = Vector(x,y,z); }
    47   void setWaterPos(float x, float y, float z) { this->waterPos = Vector(x,y,z); }
     47  void setWaterPos(float x, float y, float z) { this->waterHeight = y; this->waterVerts[0] = x; this->waterVerts[1] = z; }
    4848  void setWaterSize(float x, float z) { this->xWidth = x; this->zWidth = z; }
    4949  void setWaterAngle(float angle) { this->waterAngle = angle; }
     
    5959  void resetShininess(float shine);
    6060  void resetLightPos(float x, float y, float z);
     61  void resetWaterPos(float x, float y, float z) { this->setWaterPos(x, y, z); this->calcVerts(); }
     62  void resetWaterSize(float x, float z) { this->setWaterSize(x, z); this->calcVerts(); }
     63  void resetWaterAngle(float angle) { this->setWaterAngle(angle); this->calcVerts(); }
    6164
    6265  // fade functions
     
    6972  void initTextures();
    7073  void initShaders();
     74  void calcVerts();
    7175
    7276private:
    73   Vector              waterPos;               //!< position of the water
     77  float               waterHeight;            //!< position of the water
     78  float               waterVerts[8];          //!< coords of the 4 vertexes of the water quad
    7479  float               xWidth, zWidth;         //!< size of the water quad
    75   float               waterVerts[8];       //!< coords of the 4 vertexes of the water quad
    7680  Vector              lightPos;               //!< position of the light that is used to render the reflection
    7781  float               waterAngle;             //!< defines how much the water will be turned around the point waterPos
    7882  Vector              waterColor;             //!< color of the water
    79 
    80   Vector              newWaterColor;          //!< used to fade the water color
    81   float               colorFadeTime;
    8283
    8384  float               move;
     
    9697  Shader::Uniform*    color_uni;              //!< uniform that is used for the watercolor
    9798  Shader::Uniform*    shine_uni;              //!< uniform that is used for the specular shininessd of the water
    98  
    99  
     99
     100
     101
     102  Vector              newWaterColor;          //!< used to fade the water color
     103  float               colorFadeTime;
    100104  int tempcounter;
    101105};
Note: See TracChangeset for help on using the changeset viewer.