- Timestamp:
- Jun 28, 2006, 3:07:55 PM (18 years ago)
- 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 47 47 48 48 /// 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(); 57 50 58 51 tempcounter = 0; … … 167 160 168 161 /** 162 * @brief initialization of the shaders 163 */ 164 void 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 /** 169 177 * @brief resets the waterColor in the Shader 170 178 * @param r new value for red … … 240 248 { 241 249 glMatrixMode(GL_MODELVIEW); 242 243 250 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 246 253 247 254 mat.select(); … … 261 268 glMultiTexCoord2f(GL_TEXTURE2, 0, normalUV + move2); // Normal map texture 262 269 glMultiTexCoord2f(GL_TEXTURE3, 0, 0); // DUDV map texture 263 glVertex3f(this->water Pos.x, this->waterPos.y, this->waterPos.z);270 glVertex3f(this->waterVerts[0], this->waterHeight, this->waterVerts[1]); 264 271 265 272 // The front left vertice for the water … … 268 275 glMultiTexCoord2f(GL_TEXTURE2, 0, move2); // Normal map texture 269 276 glMultiTexCoord2f(GL_TEXTURE3, 0, 0); // DUDV map texture 270 glVertex3f(this->water Pos.x, this->waterPos.y, this->waterPos.z + this->zWidth);277 glVertex3f(this->waterVerts[2], this->waterHeight, this->waterVerts[3]); 271 278 272 279 // The front right vertice for the water … … 275 282 glMultiTexCoord2f(GL_TEXTURE2, normalUV, move2); // Normal map texture 276 283 glMultiTexCoord2f(GL_TEXTURE3, 0, 0); // DUDV map texture 277 glVertex3f(this->water Pos.x + this->xWidth, this->waterPos.y, this->waterPos.z + this->zWidth);284 glVertex3f(this->waterVerts[4], this->waterHeight, this->waterVerts[5]); 278 285 279 286 // The back right vertice for the water … … 282 289 glMultiTexCoord2f(GL_TEXTURE2, normalUV, normalUV + move2); // Normal map texture 283 290 glMultiTexCoord2f(GL_TEXTURE3, 0, 0); // DUDV map texture 284 glVertex3f(this->water Pos.x + this->xWidth, this->waterPos.y, this->waterPos.z);291 glVertex3f(this->waterVerts[6], this->waterHeight, this->waterVerts[7]); 285 292 glEnd(); 286 293 … … 357 364 Vector pos = State::getCameraNode()->getAbsCoor(); 358 365 359 if(pos.y > water Pos.y)366 if(pos.y > waterHeight) 360 367 { 361 368 // Translate the world, then flip it upside down 362 glTranslatef(0, water Pos.y*2, 0);369 glTranslatef(0, waterHeight * 2, 0); 363 370 glScalef(1, -1, 1); 364 371 … … 367 374 368 375 // Set our plane equation and turn clipping on 369 double plane[4] = {0, 1, 0, -water Pos.y};376 double plane[4] = {0, 1, 0, -waterHeight}; 370 377 glClipPlane(GL_CLIP_PLANE0, plane); 371 378 } … … 374 381 // If the camera is below the water we don't want to flip the world, 375 382 // but just render it clipped so only the top is drawn. 376 double plane[4] = {0, 1, 0, water Pos.y};383 double plane[4] = {0, 1, 0, waterHeight}; 377 384 glClipPlane(GL_CLIP_PLANE0, plane); 378 385 } … … 419 426 glEnable(GL_CLIP_PLANE0); 420 427 Vector pos = State::getCameraNode()->getAbsCoor(); 421 if(pos.y > water Pos.y)428 if(pos.y > waterHeight) 422 429 { 423 double plane[4] = {0, -1, 0, water Pos.y};430 double plane[4] = {0, -1, 0, waterHeight}; 424 431 glClipPlane(GL_CLIP_PLANE0, plane); 425 432 } … … 428 435 { 429 436 glCullFace(GL_FRONT); 430 double plane[4] = {0, 1, 0, -water Pos.y};437 double plane[4] = {0, 1, 0, -waterHeight}; 431 438 glClipPlane(GL_CLIP_PLANE0, plane); 432 439 } -
branches/mountain_lake/src/world_entities/environments/mapped_water.h
r8848 r8859 45 45 // functions to set parameters for the water, usually they're called through loadparam 46 46 void setLightPos(float x, float y, float z) { this->lightPos = Vector(x,y,z); } 47 void setWaterPos(float x, float y, float z) { this->water Pos = Vector(x,y,z); }47 void setWaterPos(float x, float y, float z) { this->waterHeight = y; this->waterVerts[0] = x; this->waterVerts[1] = z; } 48 48 void setWaterSize(float x, float z) { this->xWidth = x; this->zWidth = z; } 49 49 void setWaterAngle(float angle) { this->waterAngle = angle; } … … 59 59 void resetShininess(float shine); 60 60 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(); } 61 64 62 65 // fade functions … … 69 72 void initTextures(); 70 73 void initShaders(); 74 void calcVerts(); 71 75 72 76 private: 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 74 79 float xWidth, zWidth; //!< size of the water quad 75 float waterVerts[8]; //!< coords of the 4 vertexes of the water quad76 80 Vector lightPos; //!< position of the light that is used to render the reflection 77 81 float waterAngle; //!< defines how much the water will be turned around the point waterPos 78 82 Vector waterColor; //!< color of the water 79 80 Vector newWaterColor; //!< used to fade the water color81 float colorFadeTime;82 83 83 84 float move; … … 96 97 Shader::Uniform* color_uni; //!< uniform that is used for the watercolor 97 98 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; 100 104 int tempcounter; 101 105 };
Note: See TracChangeset
for help on using the changeset viewer.