Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/branches/water/src/world_entities/environments/mapped_water.cc @ 7700

Last change on this file since 7700 was 7700, checked in by stefalie, 18 years ago

branches/water: first attempt to realise reflection

File size: 4.5 KB
Line 
1/*
2   orxonox - the future of 3D-vertical-scrollers
3
4   Copyright (C) 2004 orx
5
6   This program is free software; you can redistribute it and/or modify
7   it under the terms of the GNU General Public License as published by
8   the Free Software Foundation; either version 2, or (at your option)
9   any later version.
10
11   ### File Specific:
12   main-programmer: Stefan Lienard
13   co-programmer: ...
14*/
15
16#include "mapped_water.h"
17#include "util/loading/load_param.h"
18#include "util/loading/factory.h"
19#include "material.h"
20
21
22CREATE_FACTORY(MappedWater, CL_MAPPED_WATER);
23
24
25MappedWater::MappedWater(const TiXmlElement* root)
26 : texture(GL_TEXTURE_2D)
27{
28  this->setClassID(CL_MAPPED_WATER, "MappedWater");
29  this->toList(OM_ENVIRON);
30 
31  if (root != NULL)
32    this->loadParams(root);
33   
34    mat.setDiffuseMap(&this->texture, 0);
35}
36
37MappedWater::~MappedWater()
38{
39 
40}
41
42void MappedWater::loadParams(const TiXmlElement* root)
43{
44  WorldEntity::loadParams(root);
45
46  LoadParam(root, "waterHeight", this, MappedWater, setHeight);
47}
48
49
50void MappedWater::draw() const
51{
52  glPushMatrix(); 
53 
54  /*
55  glTranslatef (this->getAbsCoor ().x,
56                this->getAbsCoor ().y,
57                this->getAbsCoor ().z);
58  */
59  glTranslatef(0,this->waterHeight,0);
60
61  //glEnable(GL_LIGHTING);
62
63 
64  //mat.setDiffuseMap("pictures/sky-replace.jpg", GL_TEXTURE_2D, 1);
65  //mat.setTransparency(1.0);
66  //mat.setDiffuse(1.0, 0, .1);
67 
68 
69  // HACK
70
71  //glDisable(GL_BLEND);
72  //glActiveTexture(GL_TEXTURE0);
73  //glBindTexture(GL_TEXTURE_2D, this->texture);
74
75  mat.select();
76
77  glBegin(GL_QUADS);
78    glNormal3f(0,1,0);
79    glTexCoord2f(0,0);
80    //glMultiTexCoord2f(GL_TEXTURE1, 0,0);
81    glVertex3f(0,0,0);
82    glTexCoord2f(1,0);
83    //glMultiTexCoord2f(GL_TEXTURE1, 1,0);
84    glVertex3f(100,0,0);
85    glTexCoord2f(1,1);
86    //glMultiTexCoord2f(GL_TEXTURE1, 1,1);
87    glVertex3f(100,0,-100);
88    glTexCoord2f(0,1);
89    //glMultiTexCoord2f(GL_TEXTURE1, 0,1);
90    glVertex3f(0,0,-100);
91  glEnd();
92
93  glPopMatrix();
94}
95
96void MappedWater::tick(float dt)
97{
98
99}
100
101void MappedWater::setHeight(float height)
102{
103  this->waterHeight = height;
104}
105
106void MappedWater::activateReflection()
107{
108  // Change the view port to be the size of the texture we will render to
109  // HACK
110  int textureSize = 512;
111  glPushAttrib(GL_VIEWPORT_BIT);
112  glViewport(0,0, textureSize, textureSize);
113
114  // Clear the color and depth bits, reset the matrix and position our camera.
115//  glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
116//  glLoadIdentity();
117  //g_Camera.Look();
118
119  // So we don't affect any other objects in the world we push on a new matrix
120  //glPushMatrix();
121
122  // If our camera is above the water we will render the scene flipped upside down.
123  // In order to line up the reflection nicely with the world we have to translate
124  // the world to the position of our reflected surface, multiplied by two.
125  //if(g_Camera.Position().y > waterHeight)
126  //{
127      // Translate the world, then flip it upside down
128   //   glTranslatef(0.0f, waterHeight*2.0f, 0.0f);
129    //  glScalef(1.0, -1.0, 1.0);
130
131      // Since the world is updside down we need to change the culling to FRONT
132      //glCullFace(GL_FRONT);
133
134      // Set our plane equation and turn clipping on
135     // double plane[4] = {0.0, 1.0, 0.0, -waterHeight};
136   //   glEnable(GL_CLIP_PLANE0);
137     // glClipPlane(GL_CLIP_PLANE0, plane);
138
139      // Render the world upside down and clipped (only render the top flipped).
140      // If we don't turn OFF caustics for the reflection texture we get horrible
141      // artifacts in the water.  That is why we set bRenderCaustics to FALSE.
142      //RenderWorld(false);
143
144      // Turn clipping off
145     // glDisable(GL_CLIP_PLANE0);
146
147      // Restore back-face culling
148    //  glCullFace(GL_BACK);
149  //}
150  /*else
151  {
152      // If the camera is below the water we don't want to flip the world,
153      // but just render it clipped so only the top is drawn.
154      double plane[4] = {0.0, 1.0, 0.0, waterHeight};
155      glEnable(GL_CLIP_PLANE0);
156      glClipPlane(GL_CLIP_PLANE0, plane);
157      RenderWorld(true);
158      glDisable(GL_CLIP_PLANE0);
159  }*/
160
161  // Restore the previous matrix
162  //glPopMatrix();
163
164    // Bind the current scene to our reflection texture
165  //glBindTexture(GL_TEXTURE_2D, g_Texture[REFLECTION_ID]);
166 
167 
168 
169 glBindTexture(GL_TEXTURE_2D, texture.getTexture());
170 // ;
171 // mat.setDiffuseMap(&texture, 0);
172 glCopyTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 0, 0, textureSize, textureSize);
173 
174  glPopAttrib();
175}
176
177void MappedWater::deactivateReflection()
178{
179
180}
181
182void MappedWater::activateRefraction()
183{
184
185}
186
187void MappedWater::deactivateRefraction()
188{
189
190}
Note: See TracBrowser for help on using the repository browser.