Changeset 8628 in orxonox.OLD for branches/water/src/world_entities/environments
- Timestamp:
- Jun 20, 2006, 2:18:30 PM (19 years ago)
- 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 32 32 this->toList(OM_ENVIRON); 33 33 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 */ 51 MappedWater::~MappedWater() 52 { 53 delete shader; 54 delete cam_uni; 55 } 56 57 /** 58 * @brief initialization of loadable parameters, sets start standard values 59 */ 60 void MappedWater::initParams() 61 { 34 62 // those standardvalues will be overwritten if they're also set in the oxw file 35 63 this->setWaterPos(0, 0, 0); … … 41 69 this->setNormalMapScale(0.25f); 42 70 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 */ 82 void MappedWater::initTextures() 83 { 48 84 // sets parameters for the textures 49 85 this->textureSize = 512; 50 86 unsigned int channels = 32; 51 87 GLenum type = GL_RGBA; 88 52 89 // set up refleciton texture 53 90 Texture reflTex(GL_TEXTURE_2D, this->textureSize, this->textureSize, channels, type); 54 91 mat.setDiffuseMap(reflTex, 0); 55 //mat.setDiffuseMap("pictures/refl.bmp", GL_TEXTURE_2D, 0); 56 // load refraction texture 92 // set up refraction texture 57 93 Texture refrTex(GL_TEXTURE_2D, this->textureSize, this->textureSize, channels, type); 58 94 mat.setDiffuseMap(refrTex, 1); 59 //mat.setDiffuseMap("pictures/refr.bmp", GL_TEXTURE_2D, 1);60 95 // load normal map 61 96 mat.setDiffuseMap("pictures/normalmap.bmp", GL_TEXTURE_2D, 2); 62 97 // load dudv map 63 98 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 103 101 glBindTexture(GL_TEXTURE_2D, this->mat.getDiffuseTexture(0)); 104 102 glTexParameterf(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR); … … 106 104 glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); 107 105 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 113 107 glBindTexture(GL_TEXTURE_2D, this->mat.getDiffuseTexture(1)); 114 108 glTexParameterf(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR); … … 116 110 glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); 117 111 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 quality121 122 123 // Since we stored the texture space with OpenGL, we can delete the image data124 //delete [] pTextureReflection;125 //delete [] pTextureRefraction;126 127 128 /// initialization of the shaders129 this->initShaders();130 131 /// fog, doesnt work the way i want it to work132 /*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 camera140 */141 MappedWater::~MappedWater()142 {143 delete shader;144 delete cam_uni;145 //delete fog;146 112 } 147 113 … … 215 181 glBegin(GL_QUADS); 216 182 // The back left vertice for the water 217 glMultiTexCoord2f(GL_TEXTURE0, 0 .0f, waterUV); // Reflection texture218 glMultiTexCoord2f(GL_TEXTURE1, 0 .0f, waterUV - move); // Refraction texture219 glMultiTexCoord2f(GL_TEXTURE2, 0 .0f, normalUV + move2); // Normal map texture183 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 220 186 glMultiTexCoord2f(GL_TEXTURE3, 0, 0); // DUDV map texture 221 glVertex3f(0 .0f, this->waterPos.y, 0.0f);187 glVertex3f(0, this->waterPos.y, 0); 222 188 223 189 // The front left vertice for the water 224 glMultiTexCoord2f(GL_TEXTURE0, 0 .0f, 0.0f); // Reflection texture225 glMultiTexCoord2f(GL_TEXTURE1, 0 .0f, 0.0f -move); // Refraction texture226 glMultiTexCoord2f(GL_TEXTURE2, 0 .0f, 0.0f +move2); // Normal map texture190 glMultiTexCoord2f(GL_TEXTURE0, 0, 0); // Reflection texture 191 glMultiTexCoord2f(GL_TEXTURE1, 0, -move); // Refraction texture 192 glMultiTexCoord2f(GL_TEXTURE2, 0, move2); // Normal map texture 227 193 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); 229 195 230 196 // The front right vertice for the water 231 glMultiTexCoord2f(GL_TEXTURE0, waterUV, 0 .0f); // Reflection texture232 glMultiTexCoord2f(GL_TEXTURE1, waterUV, 0.0f -move); // Refraction texture233 glMultiTexCoord2f(GL_TEXTURE2, normalUV, 0.0f +move2); // Normal map texture197 glMultiTexCoord2f(GL_TEXTURE0, waterUV, 0); // Reflection texture 198 glMultiTexCoord2f(GL_TEXTURE1, waterUV, -move); // Refraction texture 199 glMultiTexCoord2f(GL_TEXTURE2, normalUV, move2); // Normal map texture 234 200 glMultiTexCoord2f(GL_TEXTURE3, 0, 0); // DUDV map texture 235 201 glVertex3f(this->xWidth, this->waterPos.y, this->zWidth); … … 240 206 glMultiTexCoord2f(GL_TEXTURE2, normalUV, normalUV + move2); // Normal map texture 241 207 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); 243 209 glEnd(); 244 210 … … 291 257 { 292 258 // 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); 295 261 296 262 // Since the world is updside down we need to change the culling to FRONT … … 298 264 299 265 // 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}; 301 267 glClipPlane(GL_CLIP_PLANE0, plane); 302 268 } … … 305 271 // If the camera is below the water we don't want to flip the world, 306 272 // 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}; 308 274 glClipPlane(GL_CLIP_PLANE0, plane); 309 275 } … … 352 318 if(pos.y > waterPos.y) 353 319 { 354 double plane[4] = {0 .0, -1.0, 0.0, waterPos.y};320 double plane[4] = {0, -1, 0, waterPos.y}; 355 321 glClipPlane(GL_CLIP_PLANE0, plane); 356 322 … … 360 326 { 361 327 glCullFace(GL_FRONT); 362 double plane[4] = {0 .0, 1.0, 0.0, -waterPos.y};328 double plane[4] = {0, 1, 0, -waterPos.y}; 363 329 glClipPlane(GL_CLIP_PLANE0, plane); 364 330 } -
branches/water/src/world_entities/environments/mapped_water.h
r8622 r8628 1 1 /*! 2 2 * @file mapped_water.h 3 * 3 * worldentity for flat, cool looking, mapped water 4 4 */ 5 /* example input in .oxw file with the standard values5 /*! example input in .oxw file with the standard values 6 6 <MappedWater> 7 7 <waterpos>0,0,0</waterpos> … … 16 16 17 17 18 19 18 #ifndef _MAPPED_WATER_H 20 19 #define _MAPPED_WATER_H … … 23 22 #include "material.h" 24 23 #include "shader.h" 25 #include "effects/fog_effect.h"26 24 27 25 … … 53 51 54 52 private: 53 void initParams(); 54 void initTextures(); 55 55 void initShaders(); 56 56 57 57 private: 58 Vector waterPos; 59 float xWidth, zWidth; 60 Vector lightPos; 61 float waterAngle; 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 62 62 63 float move; 63 float move; //!< textures coords, speeds, positions for the shaded textures.... 64 64 float move2; 65 float waterUV; 66 float waterFlow; 65 float waterUV; //!< size of the waves 66 float waterFlow; //!< speed of the water 67 67 float normalUV; 68 68 float kNormalMapScale; 69 69 70 int textureSize; 70 int textureSize; //!< height and width of the texture 71 71 Material mat; 72 72 Shader* shader; 73 Shader::Uniform* cam_uni; 73 Shader::Uniform* cam_uni; //!< uniform that is used for the camera position 74 74 }; 75 75
Note: See TracChangeset
for help on using the changeset viewer.