Changeset 8467 in orxonox.OLD for branches/water
- Timestamp:
- Jun 15, 2006, 2:51:54 PM (18 years ago)
- Location:
- branches/water/src
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/water/src/lib/event/event_handler.cc
r8448 r8467 355 355 else 356 356 { 357 //SDL_WM_GrabInput(SDL_GRAB_ON);357 SDL_WM_GrabInput(SDL_GRAB_ON); 358 358 SDL_ShowCursor(SDL_DISABLE); 359 359 } -
branches/water/src/world_entities/environments/mapped_water.cc
r8312 r8467 20 20 #include "state.h" 21 21 22 22 //#include "fog_effect.h" 23 23 24 24 … … 138 138 MappedWater::~MappedWater() 139 139 { 140 //delete shader;141 //delete cam_uni;140 delete shader; 141 delete cam_uni; 142 142 } 143 143 … … 146 146 WorldEntity::loadParams(root); 147 147 148 LoadParam(root, "water Height", this, MappedWater, setHeight);148 LoadParam(root, "waterPos", this, MappedWater, setWaterPos); 149 149 LoadParam(root, "lightPos", this, MappedWater, setLightPosition); 150 150 } … … 156 156 157 157 glPushMatrix(); 158 glTranslatef( 0,this->waterHeight,0);158 glTranslatef(this->waterPos.x,this->waterPos.y,this->waterPos.z); 159 159 160 160 mat.unselect(); … … 178 178 glMultiTexCoord2f(GL_TEXTURE3, 0, 0); // DUDV map texture 179 179 //glMultiTexCoord2f(GL_TEXTURE4, 0, 0); // Depth texture 180 glVertex3f(0.0f, water Height, 0.0f);180 glVertex3f(0.0f, waterPos.y, 0.0f); 181 181 182 182 // The front left vertice for the water … … 188 188 glMultiTexCoord2f(GL_TEXTURE3, 0, 0); // DUDV map texture 189 189 //glMultiTexCoord2f(GL_TEXTURE4, 0, 0); // Depth texture 190 glVertex3f(0.0f, water Height, 1000.0f);190 glVertex3f(0.0f, waterPos.y, 1000.0f); 191 191 192 192 // The front right vertice for the water … … 198 198 glMultiTexCoord2f(GL_TEXTURE3, 0, 0); // DUDV map texture 199 199 //glMultiTexCoord2f(GL_TEXTURE4, 0, 0); // Depth texture 200 glVertex3f(1000.0f, water Height, 1000.0f);200 glVertex3f(1000.0f, waterPos.y, 1000.0f); 201 201 202 202 // The back right vertice for the water … … 208 208 glMultiTexCoord2f(GL_TEXTURE3, 0, 0); // DUDV map texture 209 209 //glMultiTexCoord2f(GL_TEXTURE4, 0, 0); // Depth texture 210 glVertex3f(1000.0f, water Height, 0.0f);210 glVertex3f(1000.0f, waterPos.y, 0.0f); 211 211 glEnd(); 212 212 … … 214 214 215 215 mat.unselect(); 216 217 if(this->waterPos.y) 218 { 219 // draw some fog 220 //FogEffect::activate(); 221 } 216 222 217 223 glPopMatrix(); … … 227 233 } 228 234 229 void MappedWater::setHeight(float height)230 {231 this->waterHeight = height;232 }233 234 235 void MappedWater::activateReflection() 235 236 { 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 274 void 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 294 void MappedWater::activateRefraction() 295 {/* 236 296 // save viewport matrix and change the viewport size 237 297 glPushAttrib(GL_VIEWPORT_BIT); … … 268 328 glClipPlane(GL_CLIP_PLANE0, plane); 269 329 } 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 card286 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 size296 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 translate304 // 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 down312 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 FRONT316 glCullFace(GL_FRONT);317 318 // Set our plane equation and turn clipping on319 double plane[4] = {0.0, 1.0, 0.0, -waterHeight};320 glClipPlane(GL_CLIP_PLANE0, plane);321 }322 else323 {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 }329 330 */ 330 331 … … 349 350 glEnable(GL_CLIP_PLANE0); 350 351 Vector pos = State::getCameraNode()->getAbsCoor(); 351 if(pos.y > water Height)352 { 353 double plane[4] = {0.0, -1.0, 0.0, water Height};352 if(pos.y > waterPos.y) 353 { 354 double plane[4] = {0.0, -1.0, 0.0, waterPos.y}; 354 355 glClipPlane(GL_CLIP_PLANE0, plane); 355 356 … … 359 360 { 360 361 glCullFace(GL_FRONT); 361 double plane[4] = {0.0, 1.0, 0.0, -water Height};362 double plane[4] = {0.0, 1.0, 0.0, -waterPos.y}; 362 363 glClipPlane(GL_CLIP_PLANE0, plane); 363 364 } -
branches/water/src/world_entities/environments/mapped_water.h
r8037 r8467 32 32 private: 33 33 void setLightPosition(float x, float y, float z) { this->lightPos = Vector(x,y,z); }; 34 void set Height(float height);34 void setWaterPos(float x, float y, float z) { this->waterPos = Vector(x,y,z); }; 35 35 36 36 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 38 39 39 40 float move; //!< textures coords, speeds, positions for the shaded textures.... … … 45 46 float kNormalMapScale; //!< 46 47 47 int textureSize; //!< size of the texture 48 Vector lightPos; 48 int textureSize; //!< height and width of the texture 49 49 Material mat; 50 50 Shader* shader; 51 Shader::Uniform* cam_uni; 51 Shader::Uniform* cam_uni; //!< uniform that is used for the camera position 52 52 53 53 };
Note: See TracChangeset
for help on using the changeset viewer.