Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 8628 in orxonox.OLD for branches/water/src/world_entities


Ignore:
Timestamp:
Jun 20, 2006, 2:18:30 PM (18 years ago)
Author:
stefalie
Message:

water: cleanup and waste of time, but i got nothing better to do ;-)

Location:
branches/water/src/world_entities/environments
Files:
2 edited

Legend:

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

    r8622 r8628  
    3232  this->toList(OM_ENVIRON);
    3333
     34  /// sets start values and parameters
     35  this->initParams();
     36  // now the standard values were loaded, if the values are specified in the .oxw file
     37  // loadParams will overwrite the standard values with the specified values
     38  if (root != NULL)
     39    this->loadParams(root);
     40
     41  /// initialization of the textures
     42  this->initTextures();
     43
     44  /// initialization of the shaders
     45  this->initShaders();
     46}
     47
     48/**
     49 * @brief deltes shader and the uniform used by the camera
     50 */
     51MappedWater::~MappedWater()
     52{
     53  delete shader;
     54  delete cam_uni;
     55}
     56
     57/**
     58 * @brief initialization of loadable parameters, sets start standard values
     59 */
     60void MappedWater::initParams()
     61{
    3462  // those standardvalues will be overwritten if they're also set in the oxw file
    3563  this->setWaterPos(0, 0, 0);
     
    4169  this->setNormalMapScale(0.25f);
    4270
    43 
    44   if (root != NULL)
    45     this->loadParams(root);
    46 
    47   /// loads the textures
     71  // initialization of the texture coords, speeds etc...
     72  // normalUV wont change anymore
     73  this->normalUV = this->waterUV * this->kNormalMapScale;
     74  // move and move2 are used for the reflection and refraction, the values are changed in tick()
     75  this->move = 0;
     76  this->move2 = this->move * this->kNormalMapScale;
     77}
     78
     79/**
     80 * @brief initialization of the textures
     81 */
     82void MappedWater::initTextures()
     83{
    4884  // sets parameters for the textures
    4985  this->textureSize = 512;
    5086  unsigned int channels = 32;
    5187  GLenum type = GL_RGBA;
     88
    5289  // set up refleciton texture
    5390  Texture reflTex(GL_TEXTURE_2D, this->textureSize, this->textureSize, channels, type);
    5491  mat.setDiffuseMap(reflTex, 0);
    55   //mat.setDiffuseMap("pictures/refl.bmp", GL_TEXTURE_2D, 0);
    56   // load refraction texture
     92  // set up refraction texture
    5793  Texture refrTex(GL_TEXTURE_2D, this->textureSize, this->textureSize, channels, type);
    5894  mat.setDiffuseMap(refrTex, 1);
    59   //mat.setDiffuseMap("pictures/refr.bmp", GL_TEXTURE_2D, 1);
    6095  // load normal map
    6196  mat.setDiffuseMap("pictures/normalmap.bmp", GL_TEXTURE_2D, 2);
    6297  // load dudv map
    6398  mat.setDiffuseMap("pictures/dudvmap.bmp", GL_TEXTURE_2D, 3);
    64   // set up depth texture
    65   //mat.setDiffuseMap("pictures/sky-replace.jpg", GL_TEXTURE_2D, 4);
    66 
    67 
    68   // set the size of the refraction and reflection textures
    69 
    70 
    71   // initialization of the texture coords, speeds etc...
    72   // normalUV wont change anymore
    73   this->normalUV = this->waterUV * this->kNormalMapScale;
    74   // move and move2 are used for the reflection and refraction, the values are changed in tick()
    75   this->move = 0.0f;
    76   this->move2 = this->move * this->kNormalMapScale;
    77 
    78 
    79   //unsigned int channels = 32;
    80   //GLenum type = GL_RGBA;
    81   //unsigned int* pTextureReflection = new unsigned int [this->textureSize * this->textureSize * channels];
    82   //memset(pTextureReflection, 0, this->textureSize * this->textureSize * channels * sizeof(unsigned int));
    83   //unsigned int* pTextureRefraction = new unsigned int [this->textureSize * this->textureSize * channels];
    84   //memset(pTextureRefraction, 0, this->textureSize * this->textureSize * channels * sizeof(unsigned int));
    85   // Register the texture with OpenGL and bind it to the texture ID
    86   //mat.select();
    87   //glBindTexture(GL_TEXTURE_2D, this->mat.getDiffuseTexture(0));
    88 
    89   // Create the texture and store it on the video card
    90   //glTexImage2D(GL_TEXTURE_2D, 0, channels, this->textureSize, this->textureSize, 0, type, GL_UNSIGNED_INT, pTextureReflection);
    91 
    92   //gluBuild2DMipmaps(GL_TEXTURE_2D, channels, this->textureSize, this->textureSize, type,  GL_UNSIGNED_INT, pTexture);
    93 
    94   //the same for the refraction
    95   //glBindTexture(GL_TEXTURE_2D, this->mat.getDiffuseTexture(1));
    96   //glTexImage2D(GL_TEXTURE_2D, 0, channels, this->textureSize, this->textureSize, 0, type, GL_UNSIGNED_INT, pTextureRefraction);
    97 /*
    98   unsigned int channels = 32;
    99   GLenum type = GL_RGBA;
    100   unsigned int* pTextureReflection = new unsigned int [this->textureSize * this->textureSize * channels];
    101   memset(pTextureReflection, 0, this->textureSize * this->textureSize * channels * sizeof(unsigned int));
    102   //mat.select();*/
     99
     100  // sets texture parameters for reflection texture
    103101  glBindTexture(GL_TEXTURE_2D, this->mat.getDiffuseTexture(0));
    104102  glTexParameterf(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR);
     
    106104  glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
    107105  glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
    108   //glTexImage2D(GL_TEXTURE_2D, 0, channels, this->textureSize, this->textureSize, 0, type, GL_UNSIGNED_INT, pTextureReflection);
    109 
    110 
    111   //unsigned int* pTextureRefraction = new unsigned int [this->textureSize * this->textureSize * channels];
    112   //memset(pTextureRefraction, 0, this->textureSize * this->textureSize * channels * sizeof(unsigned int));
     106  // sets texture parameters for refraction texture
    113107  glBindTexture(GL_TEXTURE_2D, this->mat.getDiffuseTexture(1));
    114108  glTexParameterf(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR);
     
    116110  glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
    117111  glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
    118   //glTexImage2D(GL_TEXTURE_2D, 0, channels, this->textureSize, this->textureSize, 0, type, GL_UNSIGNED_INT, pTextureRefraction);
    119 
    120   // Set the texture quality
    121 
    122 
    123   // Since we stored the texture space with OpenGL, we can delete the image data
    124   //delete [] pTextureReflection;
    125   //delete [] pTextureRefraction;
    126 
    127 
    128   /// initialization of the shaders
    129   this->initShaders();
    130 
    131   /// fog, doesnt work the way i want it to work
    132   /*this->fog = new FogEffect();
    133   fog->setFogColor(0.1f, 0.2f, 0.4f);
    134   fog->setFogRange(0.0f, 500.0f);
    135   fog->setFogDensity(0.03f);*/
    136 }
    137 
    138 /**
    139  * @brief deltes shader and the uniform used by the camera
    140  */
    141 MappedWater::~MappedWater()
    142 {
    143   delete shader;
    144   delete cam_uni;
    145   //delete fog;
    146112}
    147113
     
    215181  glBegin(GL_QUADS);
    216182  // The back left vertice for the water
    217   glMultiTexCoord2f(GL_TEXTURE0, 0.0f, waterUV);            // Reflection texture
    218   glMultiTexCoord2f(GL_TEXTURE1, 0.0f, waterUV - move);        // Refraction texture
    219   glMultiTexCoord2f(GL_TEXTURE2, 0.0f, normalUV + move2);     // Normal map texture
     183  glMultiTexCoord2f(GL_TEXTURE0, 0, waterUV);            // Reflection texture
     184  glMultiTexCoord2f(GL_TEXTURE1, 0, waterUV - move);        // Refraction texture
     185  glMultiTexCoord2f(GL_TEXTURE2, 0, normalUV + move2);     // Normal map texture
    220186  glMultiTexCoord2f(GL_TEXTURE3, 0, 0);                       // DUDV map texture
    221   glVertex3f(0.0f, this->waterPos.y, 0.0f);
     187  glVertex3f(0, this->waterPos.y, 0);
    222188
    223189  // The front left vertice for the water
    224   glMultiTexCoord2f(GL_TEXTURE0, 0.0f, 0.0f);                  // Reflection texture
    225   glMultiTexCoord2f(GL_TEXTURE1, 0.0f, 0.0f - move);           // Refraction texture
    226   glMultiTexCoord2f(GL_TEXTURE2, 0.0f, 0.0f + move2);          // Normal map texture
     190  glMultiTexCoord2f(GL_TEXTURE0, 0, 0);                  // Reflection texture
     191  glMultiTexCoord2f(GL_TEXTURE1, 0, -move);           // Refraction texture
     192  glMultiTexCoord2f(GL_TEXTURE2, 0, move2);          // Normal map texture
    227193  glMultiTexCoord2f(GL_TEXTURE3, 0, 0);                        // DUDV map texture
    228   glVertex3f(0.0f, this->waterPos.y, this->zWidth);
     194  glVertex3f(0, this->waterPos.y, this->zWidth);
    229195
    230196  // The front right vertice for the water
    231   glMultiTexCoord2f(GL_TEXTURE0, waterUV, 0.0f);             // Reflection texture
    232   glMultiTexCoord2f(GL_TEXTURE1, waterUV, 0.0f - move);         // Refraction texture
    233   glMultiTexCoord2f(GL_TEXTURE2, normalUV, 0.0f + move2);      // Normal map texture
     197  glMultiTexCoord2f(GL_TEXTURE0, waterUV, 0);             // Reflection texture
     198  glMultiTexCoord2f(GL_TEXTURE1, waterUV, -move);         // Refraction texture
     199  glMultiTexCoord2f(GL_TEXTURE2, normalUV, move2);      // Normal map texture
    234200  glMultiTexCoord2f(GL_TEXTURE3, 0, 0);                        // DUDV map texture
    235201  glVertex3f(this->xWidth, this->waterPos.y, this->zWidth);
     
    240206  glMultiTexCoord2f(GL_TEXTURE2, normalUV, normalUV + move2);  // Normal map texture
    241207  glMultiTexCoord2f(GL_TEXTURE3, 0, 0);                        // DUDV map texture
    242   glVertex3f(this->xWidth, this->waterPos.y, 0.0f);
     208  glVertex3f(this->xWidth, this->waterPos.y, 0);
    243209  glEnd();
    244210
     
    291257  {
    292258    // Translate the world, then flip it upside down
    293     glTranslatef(0.0f, waterPos.y*2.0f, 0.0f);
    294     glScalef(1.0, -1.0, 1.0);
     259    glTranslatef(0, waterPos.y*2, 0);
     260    glScalef(1, -1, 1);
    295261
    296262    // Since the world is updside down we need to change the culling to FRONT
     
    298264
    299265    // Set our plane equation and turn clipping on
    300     double plane[4] = {0.0, 1.0, 0.0, -waterPos.y};
     266    double plane[4] = {0, 1, 0, -waterPos.y};
    301267    glClipPlane(GL_CLIP_PLANE0, plane);
    302268  }
     
    305271    // If the camera is below the water we don't want to flip the world,
    306272    // but just render it clipped so only the top is drawn.
    307     double plane[4] = {0.0, 1.0, 0.0, waterPos.y};
     273    double plane[4] = {0, 1, 0, waterPos.y};
    308274    glClipPlane(GL_CLIP_PLANE0, plane);
    309275  }
     
    352318  if(pos.y > waterPos.y)
    353319  {
    354     double plane[4] = {0.0, -1.0, 0.0, waterPos.y};
     320    double plane[4] = {0, -1, 0, waterPos.y};
    355321    glClipPlane(GL_CLIP_PLANE0, plane);
    356322
     
    360326  {
    361327    glCullFace(GL_FRONT);
    362     double plane[4] = {0.0, 1.0, 0.0, -waterPos.y};
     328    double plane[4] = {0, 1, 0, -waterPos.y};
    363329    glClipPlane(GL_CLIP_PLANE0, plane);
    364330  }
  • branches/water/src/world_entities/environments/mapped_water.h

    r8622 r8628  
    11/*!
    22 * @file mapped_water.h
    3  *
     3 *  worldentity for flat, cool looking, mapped water
    44*/
    5 /* example input in .oxw file with the standard values
     5/*! example input in .oxw file with the standard values
    66<MappedWater>
    77  <waterpos>0,0,0</waterpos>
     
    1616
    1717
    18 
    1918#ifndef _MAPPED_WATER_H
    2019#define _MAPPED_WATER_H
     
    2322#include "material.h"
    2423#include "shader.h"
    25 #include "effects/fog_effect.h"
    2624
    2725
     
    5351
    5452  private:
     53    void initParams();
     54    void initTextures();
    5555    void initShaders();
    5656
    5757  private:
    58     Vector              waterPos;                   //!< position of the water
    59     float               xWidth, zWidth;             //!< size of the water quad
    60     Vector              lightPos;                   //!< position of the light that is used to render the reflection
    61     float               waterAngle;                 //!< defines how much the water will be turned around the point waterPos
     58    Vector              waterPos;               //!< position of the water
     59    float               xWidth, zWidth;         //!< size of the water quad
     60    Vector              lightPos;               //!< position of the light that is used to render the reflection
     61    float               waterAngle;             //!< defines how much the water will be turned around the point waterPos
    6262
    63     float               move;                       //!< textures coords, speeds, positions for the shaded textures....
     63    float               move;                   //!< textures coords, speeds, positions for the shaded textures....
    6464    float               move2;
    65     float               waterUV;                    //!< size of the waves
    66     float               waterFlow;                  //!< speed of the water
     65    float               waterUV;                //!< size of the waves
     66    float               waterFlow;              //!< speed of the water
    6767    float               normalUV;
    6868    float               kNormalMapScale;
    6969
    70     int                 textureSize;                //!< height and width of the texture
     70    int                 textureSize;            //!< height and width of the texture
    7171    Material            mat;
    7272    Shader*             shader;
    73     Shader::Uniform*    cam_uni;                    //!< uniform that is used for the camera position
     73    Shader::Uniform*    cam_uni;                //!< uniform that is used for the camera position
    7474};
    7575
Note: See TracChangeset for help on using the changeset viewer.