Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 8467 in orxonox.OLD


Ignore:
Timestamp:
Jun 15, 2006, 2:51:54 PM (18 years ago)
Author:
stefalie
Message:

water: works fine so far…

Location:
branches/water/src
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • branches/water/src/lib/event/event_handler.cc

    r8448 r8467  
    355355  else
    356356  {
    357 //    SDL_WM_GrabInput(SDL_GRAB_ON);
     357    SDL_WM_GrabInput(SDL_GRAB_ON);
    358358    SDL_ShowCursor(SDL_DISABLE);
    359359  }
  • branches/water/src/world_entities/environments/mapped_water.cc

    r8312 r8467  
    2020#include "state.h"
    2121
    22 
     22//#include "fog_effect.h"
    2323
    2424
     
    138138MappedWater::~MappedWater()
    139139{
    140   //delete shader;
    141   //delete cam_uni;
     140  delete shader;
     141  delete cam_uni;
    142142}
    143143
     
    146146  WorldEntity::loadParams(root);
    147147
    148   LoadParam(root, "waterHeight", this, MappedWater, setHeight);
     148  LoadParam(root, "waterPos", this, MappedWater, setWaterPos);
    149149  LoadParam(root, "lightPos", this, MappedWater, setLightPosition);
    150150}
     
    156156
    157157  glPushMatrix();
    158   glTranslatef(0,this->waterHeight,0);
     158  glTranslatef(this->waterPos.x,this->waterPos.y,this->waterPos.z);
    159159
    160160  mat.unselect();
     
    178178  glMultiTexCoord2f(GL_TEXTURE3, 0, 0);                       // DUDV map texture
    179179  //glMultiTexCoord2f(GL_TEXTURE4, 0, 0);                       // Depth texture
    180   glVertex3f(0.0f, waterHeight, 0.0f);
     180  glVertex3f(0.0f, waterPos.y, 0.0f);
    181181
    182182  // The front left vertice for the water
     
    188188  glMultiTexCoord2f(GL_TEXTURE3, 0, 0);                        // DUDV map texture
    189189  //glMultiTexCoord2f(GL_TEXTURE4, 0, 0);                        // Depth texture
    190   glVertex3f(0.0f, waterHeight, 1000.0f);
     190  glVertex3f(0.0f, waterPos.y, 1000.0f);
    191191
    192192  // The front right vertice for the water
     
    198198  glMultiTexCoord2f(GL_TEXTURE3, 0, 0);                        // DUDV map texture
    199199  //glMultiTexCoord2f(GL_TEXTURE4, 0, 0);                        // Depth texture
    200   glVertex3f(1000.0f, waterHeight, 1000.0f);
     200  glVertex3f(1000.0f, waterPos.y, 1000.0f);
    201201
    202202  // The back right vertice for the water
     
    208208  glMultiTexCoord2f(GL_TEXTURE3, 0, 0);                        // DUDV map texture
    209209  //glMultiTexCoord2f(GL_TEXTURE4, 0, 0);                        // Depth texture
    210   glVertex3f(1000.0f, waterHeight, 0.0f);
     210  glVertex3f(1000.0f, waterPos.y, 0.0f);
    211211  glEnd();
    212212
     
    214214
    215215  mat.unselect();
     216
     217  if(this->waterPos.y)
     218  {
     219    // draw some fog
     220    //FogEffect::activate();
     221  }
    216222
    217223  glPopMatrix();
     
    227233}
    228234
    229 void MappedWater::setHeight(float height)
    230 {
    231   this->waterHeight = height;
    232 }
    233 
    234235void MappedWater::activateReflection()
    235236{
     237  // save viewport matrix and change the viewport size
     238  glPushAttrib(GL_VIEWPORT_BIT);
     239  glViewport(0,0, textureSize, textureSize);
     240
     241  glMatrixMode(GL_MODELVIEW);
     242  glPushMatrix();
     243
     244  // If our camera is above the water we will render the scene flipped upside down.
     245  // In order to line up the reflection nicely with the world we have to translate
     246  // the world to the position of our reflected surface, multiplied by two.
     247  glEnable(GL_CLIP_PLANE0);
     248  Vector pos = State::getCameraNode()->getAbsCoor();
     249  //pos.debug();
     250  //PRINTF(0)("waterheight: %f\n", waterHeight);
     251  if(pos.y > waterPos.y)
     252  {
     253    // Translate the world, then flip it upside down
     254    glTranslatef(0.0f, waterPos.y*2.0f, 0.0f);
     255    glScalef(1.0, -1.0, 1.0);
     256
     257    // Since the world is updside down we need to change the culling to FRONT
     258    glCullFace(GL_FRONT);
     259
     260    // Set our plane equation and turn clipping on
     261    double plane[4] = {0.0, 1.0, 0.0, -waterPos.y};
     262    glClipPlane(GL_CLIP_PLANE0, plane);
     263  }
     264  else
     265  {
     266    // If the camera is below the water we don't want to flip the world,
     267    // but just render it clipped so only the top is drawn.
     268    double plane[4] = {0.0, 1.0, 0.0, waterPos.y};
     269    glClipPlane(GL_CLIP_PLANE0, plane);
     270  }
     271}
     272
     273
     274void MappedWater::deactivateReflection()
     275{
     276  glDisable(GL_CLIP_PLANE0);
     277  glCullFace(GL_BACK);
     278
     279  //mat.select();
     280  /////glCopyTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 0, 0, textureSize, textureSize);
     281  ///mat.renderToTexture(0, GL_TEXTURE_2D, 0, 0, 0, 0, 0, textureSize, textureSize);
     282  ///
     283
     284  glBindTexture(GL_TEXTURE_2D, this->mat.getDiffuseTexture(0));
     285
     286  // Create the texture and store it on the video card
     287  glCopyTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 0, 0, textureSize, textureSize);
     288
     289
     290  glPopMatrix();
     291  glPopAttrib();
     292}
     293
     294void MappedWater::activateRefraction()
     295{/*
    236296  // save viewport matrix and change the viewport size
    237297  glPushAttrib(GL_VIEWPORT_BIT);
     
    268328    glClipPlane(GL_CLIP_PLANE0, plane);
    269329  }
    270 }
    271 
    272 
    273 void MappedWater::deactivateReflection()
    274 {
    275   glDisable(GL_CLIP_PLANE0);
    276   glCullFace(GL_BACK);
    277 
    278   //mat.select();
    279   /////glCopyTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 0, 0, textureSize, textureSize);
    280   ///mat.renderToTexture(0, GL_TEXTURE_2D, 0, 0, 0, 0, 0, textureSize, textureSize);
    281   ///
    282 
    283   glBindTexture(GL_TEXTURE_2D, this->mat.getDiffuseTexture(0));
    284 
    285   // Create the texture and store it on the video card
    286   glCopyTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 0, 0, textureSize, textureSize);
    287 
    288 
    289   glPopMatrix();
    290   glPopAttrib();
    291 }
    292 
    293 void MappedWater::activateRefraction()
    294 {/*
    295   // save viewport matrix and change the viewport size
    296   glPushAttrib(GL_VIEWPORT_BIT);
    297   glViewport(0,0, textureSize, textureSize);
    298 
    299   glMatrixMode(GL_MODELVIEW);
    300   glPushMatrix();
    301 
    302   // If our camera is above the water we will render the scene flipped upside down.
    303   // In order to line up the reflection nicely with the world we have to translate
    304   // the world to the position of our reflected surface, multiplied by two.
    305   glEnable(GL_CLIP_PLANE0);
    306   Vector pos = State::getCameraNode()->getAbsCoor();
    307   //pos.debug();
    308   //PRINTF(0)("waterheight: %f\n", waterHeight);
    309   if(pos.y > waterHeight)
    310   {
    311     // Translate the world, then flip it upside down
    312     glTranslatef(0.0f, waterHeight*2.0f, 0.0f);
    313     glScalef(1.0, -1.0, 1.0);
    314 
    315     // Since the world is updside down we need to change the culling to FRONT
    316     glCullFace(GL_FRONT);
    317 
    318     // Set our plane equation and turn clipping on
    319     double plane[4] = {0.0, 1.0, 0.0, -waterHeight};
    320     glClipPlane(GL_CLIP_PLANE0, plane);
    321   }
    322   else
    323   {
    324     // If the camera is below the water we don't want to flip the world,
    325     // but just render it clipped so only the top is drawn.
    326     double plane[4] = {0.0, 1.0, 0.0, waterHeight};
    327     glClipPlane(GL_CLIP_PLANE0, plane);
    328   }
    329330*/
    330331
     
    349350  glEnable(GL_CLIP_PLANE0);
    350351  Vector pos = State::getCameraNode()->getAbsCoor();
    351   if(pos.y > waterHeight)
    352   {
    353     double plane[4] = {0.0, -1.0, 0.0, waterHeight};
     352  if(pos.y > waterPos.y)
     353  {
     354    double plane[4] = {0.0, -1.0, 0.0, waterPos.y};
    354355    glClipPlane(GL_CLIP_PLANE0, plane);
    355356
     
    359360  {
    360361    glCullFace(GL_FRONT);
    361     double plane[4] = {0.0, 1.0, 0.0, -waterHeight};
     362    double plane[4] = {0.0, 1.0, 0.0, -waterPos.y};
    362363    glClipPlane(GL_CLIP_PLANE0, plane);
    363364  }
  • branches/water/src/world_entities/environments/mapped_water.h

    r8037 r8467  
    3232  private:
    3333    void setLightPosition(float x, float y, float z) { this->lightPos = Vector(x,y,z); };
    34     void setHeight(float height);
     34    void setWaterPos(float x, float y, float z) { this->waterPos = Vector(x,y,z); };
    3535
    3636  private:
    37     float               waterHeight;                //!< y-coord of the Water
     37    Vector              waterPos;                   //!< position of the water
     38    Vector              lightPos;                   //!< position of the light that is used to render the reflection
    3839
    3940    float               move;                       //!< textures coords, speeds, positions for the shaded textures....
     
    4546    float               kNormalMapScale;            //!<
    4647
    47     int                 textureSize;                //!< size of the texture
    48     Vector              lightPos;
     48    int                 textureSize;                //!< height and width of the texture
    4949    Material            mat;
    5050    Shader*             shader;
    51     Shader::Uniform*    cam_uni;                        //!< uniform that is used for the camera position
     51    Shader::Uniform*    cam_uni;                    //!< uniform that is used for the camera position
    5252
    5353};
Note: See TracChangeset for help on using the changeset viewer.