Index: trunk/src/world_entities/environments/mapped_water.cc
===================================================================
--- trunk/src/world_entities/environments/mapped_water.cc	(revision 8792)
+++ trunk/src/world_entities/environments/mapped_water.cc	(revision 9006)
@@ -19,8 +19,25 @@
 #include "util/loading/resource_manager.h"
 #include "state.h"
+#include "t_animation.h"
 #include "math.h"
-
+#include "glgui.h"
+#include "shell_command.h"
+#include "script_class.h"
 
 CREATE_FACTORY(MappedWater, CL_MAPPED_WATER);
+
+SHELL_COMMAND(gui, MappedWater, openGui);
+SHELL_COMMAND(output, MappedWater, saveParams);
+
+CREATE_SCRIPTABLE_CLASS(MappedWater, CL_MAPPED_WATER,
+                        addMethod("waterUV", ExecutorLua2<MappedWater, float, float>(&MappedWater::fadeWaterUV))
+                      ->addMethod("waterFlow", ExecutorLua2<MappedWater, float, float>(&MappedWater::fadeWaterFlow))
+                      ->addMethod("shineSize", ExecutorLua2<MappedWater, float, float>(&MappedWater::fadeShineSize))
+                      ->addMethod("shineStrength", ExecutorLua2<MappedWater, float, float>(&MappedWater::fadeShineStrength))
+                      ->addMethod("reflStrength", ExecutorLua2<MappedWater, float, float>(&MappedWater::fadeReflStrength))
+                      ->addMethod("refraction", ExecutorLua2<MappedWater, float, float>(&MappedWater::fadeRefraction))
+                      ->addMethod("waterHeight", ExecutorLua2<MappedWater, float, float>(&MappedWater::fadeWaterHeight))
+                      ->addMethod("waterColor", ExecutorLua4<MappedWater, float, float, float, float>(&MappedWater::fadeWaterColor)));
+
 
 /**
@@ -45,6 +62,10 @@
   /// initialization of the shaders
   this->initShaders();
-  
-  tempcounter = 0;
+
+  /// calculation of the 4 verts of the water quad
+  this->calcVerts();
+
+  // init gui
+  this->box = NULL;
 }
 
@@ -58,5 +79,8 @@
   delete color_uni;
   delete light_uni;
-  delete shine_uni;
+  delete shineSize_uni;
+  delete shineStrength_uni;
+  delete reflStrength_uni;
+  delete refr_uni;
 }
 
@@ -70,10 +94,13 @@
   this->setWaterSize(100, 100);
   this->setWaterUV(9);
-  this->setWaterFlow(0.08);
+  this->setWaterFlow(0.08f);
   this->setLightPos(0, 10, 0);
   this->setWaterAngle(0);
   this->setNormalMapScale(0.25f);
   this->setWaterColor(0.1f, 0.2f, 0.4f);
-  this->setShininess(128);
+  this->setShineSize(128);
+  this->setShineStrength(0.7f);
+  this->setReflStrength(1.0f);
+  this->setRefraction(0.009f);
 
   // initialization of the texture coords, speeds etc...
@@ -84,5 +111,13 @@
   this->move2 = this->move * this->kNormalMapScale;
 
-
+  // initalize fading bools
+  this->bFadeWaterHeight = false;
+  this->bFadeWaterUV = false;
+  this->bFadeWaterFlow = false;
+  this->bFadeShineSize = false;
+  this->bFadeShineStrength = false;
+  this->bFadeReflStrength = false;
+  this->bFadeRefraction = false;
+  this->bFadeWaterColor = false;
 }
 
@@ -104,7 +139,7 @@
   mat.setDiffuseMap(refrTex, 1);
   // load normal map
-  mat.setDiffuseMap("pictures/normalmap.bmp", GL_TEXTURE_2D, 2);
+  mat.setDiffuseMap("pictures/water_normalmap.bmp", GL_TEXTURE_2D, 2);
   // load dudv map
-  mat.setDiffuseMap("pictures/dudvmap.bmp", GL_TEXTURE_2D, 3);
+  mat.setDiffuseMap("pictures/water_dudvmap.bmp", GL_TEXTURE_2D, 3);
 
   // sets texture parameters for reflection texture
@@ -140,5 +175,5 @@
   Shader::Uniform(shader, "dudvMap").set(3);
   // Set the variable "depthMap" to correspond to the fifth texture unit
-  Shader::Uniform(shader, "depthMap").set(2);
+  Shader::Uniform(shader, "depthMap").set(1);
   // Give the variable "waterColor" a blue color
   color_uni = new Shader::Uniform(shader, "waterColor");
@@ -148,10 +183,34 @@
   light_uni->set(lightPos.x, lightPos.y, lightPos.z, 1.0f);
   // Set the variable "shine"
-  shine_uni = new Shader::Uniform(shader, "kShine");
-  shine_uni->set(this->shininess);
+  shineSize_uni = new Shader::Uniform(shader, "kShine");
+  shineSize_uni->set(this->shineSize);
+  // Set the variable "shineStrength"
+  shineStrength_uni = new Shader::Uniform(shader, "shineStrength");
+  shineStrength_uni->set(this->shineStrength);
+  // Set the variable "reflStrength"
+  reflStrength_uni = new Shader::Uniform(shader, "reflStrength");
+  reflStrength_uni->set(this->reflStrength);
+  // Set the variable "refraction"
+  refr_uni = new Shader::Uniform(shader, "kRefraction");
+  refr_uni->set(this->refraction);
   // uniform for the camera position
   cam_uni = new Shader::Uniform(shader, "cameraPos");
 
   this->shader->deactivateShader();
+}
+
+/**
+ * @brief calculates the 4 verts of the water quad
+ */
+void MappedWater::calcVerts()
+{
+  float deg2radtemp = this->waterAngle / 180 * PI;
+
+  this->waterVerts[2] = this->waterVerts[0] + cos(deg2radtemp) * this->xWidth;
+  this->waterVerts[3] = this->waterVerts[1] + sin(deg2radtemp) * this->xWidth;
+  this->waterVerts[4] = this->waterVerts[0] + cos(deg2radtemp) * this->xWidth - sin(deg2radtemp) * this->zWidth;
+  this->waterVerts[5] = this->waterVerts[1] + sin(deg2radtemp) * this->xWidth + cos(deg2radtemp) * this->zWidth;
+  this->waterVerts[6] = this->waterVerts[0] - sin(deg2radtemp) * this->zWidth;
+  this->waterVerts[7] = this->waterVerts[1] + cos(deg2radtemp) * this->zWidth;
 }
 
@@ -171,5 +230,5 @@
 
   this->shader->deactivateShader();
-};
+}
 
 /**
@@ -177,14 +236,59 @@
  * @param shine new value for the shininess
  */
-void MappedWater::resetShininess(float shine)
+void MappedWater::resetShineSize(float shine)
 {
   this->shader->activateShader();
-  this->shininess = shine;
+  this->shineSize = shine;
 
   // Set the variable "shine"
-  shine_uni->set(this->shininess);
+  shineSize_uni->set(this->shineSize);
 
   this->shader->deactivateShader();
-};
+}
+
+/**
+ * @brief resets the strength of the specular reflection in the Shader
+ * @param strength new value for the strength of the specular reflection
+ */
+void MappedWater::resetShineStrength(float strength)
+{
+  this->shader->activateShader();
+  this->shineStrength = strength;
+
+  // Set the variable "shine"
+  shineStrength_uni->set(this->shineStrength);
+
+  this->shader->deactivateShader();
+}
+
+/**
+ * @brief resets the strength of the reflection in the Shader
+ * @param strength new value for the strength of the reflection
+ */
+void MappedWater::resetReflStrength(float strength)
+{
+  this->shader->activateShader();
+  this->reflStrength = strength;
+
+  // Set the variable "shine"
+  reflStrength_uni->set(this->reflStrength);
+
+  this->shader->deactivateShader();
+}
+
+/**
+ * @brief resets the refraction in the Shader
+ * @param refraction new value for the refraction
+ */
+void MappedWater::resetRefraction(float refraction)
+{
+  this->shader->activateShader();
+  this->refraction = refraction;
+
+  // Set the variable "shine"
+  refr_uni->set(this->refraction);
+
+  this->shader->deactivateShader();
+}
 
 /**
@@ -203,5 +307,5 @@
 
   this->shader->deactivateShader();
-};
+}
 
 /**
@@ -215,11 +319,212 @@
   LoadParam(root, "waterpos", this, MappedWater, setWaterPos);
   LoadParam(root, "watersize", this, MappedWater, setWaterSize);
-  LoadParam(root, "lightpos", this, MappedWater, setLightPos);
   LoadParam(root, "wateruv", this, MappedWater, setWaterUV);
   LoadParam(root, "waterflow", this, MappedWater, setWaterFlow);
+  LoadParam(root, "lightpos", this, MappedWater, setLightPos);
+  LoadParam(root, "waterangle", this, MappedWater, setWaterAngle);
   LoadParam(root, "normalmapscale", this, MappedWater, setNormalMapScale);
-  LoadParam(root, "waterangle", this, MappedWater, setWaterAngle);
+  LoadParam(root, "shinesize", this, MappedWater, setShineSize);
+  LoadParam(root, "shinestrength", this, MappedWater, setShineStrength);
+  LoadParam(root, "reflstrength", this, MappedWater, setReflStrength);
+  LoadParam(root, "refraction", this, MappedWater, setRefraction);
   LoadParam(root, "watercolor", this, MappedWater, setWaterColor);
-  LoadParam(root, "shininess", this, MappedWater, setShininess);
+}
+
+/**
+ * @brief prints the xml code of the water params
+ */
+void MappedWater::saveParams()
+{
+  // it's not too nice, but it works fine
+  PRINTF(0)("\nMappedWater XML Code:\n<MappedWater>\n  <waterpos>%f, %f, %f</waterpos>\n  <watersize>%f, %f</watersize>\n  <wateruv>%f</wateruv>\n  <waterflow>%f</waterflow>\n  <lightpos>%f, %f, %f</lightpos>\n  <waterangle>%f</waterangle>\n  <normalmapscale>%f</normalmapscale>\n  <shinesize>%f</waterpos>\n  <shinestrength>%f</shinestrength>\n  <reflstrength>%f</reflstrength>\n  <refraction>%f</refraction>\n  <watercolor>%f, %f, %f</watercolor>\n</MappedWater>\n", this->waterVerts[0], this->waterHeight, this->waterVerts[1], this->xWidth, this->zWidth, this->waterUV, this->waterFlow, this->lightPos.x, this->lightPos.y, this->lightPos.z, this->waterAngle, this->kNormalMapScale, this->shineSize, this->shineStrength, this->reflStrength, this->refraction, this->waterColor.x, this->waterColor.y, this->waterColor.z);
+}
+
+/**
+ * @brief starts the slider gui that lets you edit all water parameters
+ */
+void MappedWater::openGui()
+{
+  if (this->box == NULL)
+  {
+    this->box = new OrxGui::GLGuiBox(OrxGui::Vertical);
+    {
+      OrxGui::GLGuiBox* waterColorBox = new OrxGui::GLGuiBox(OrxGui::Horizontal);
+      {
+        OrxGui::GLGuiInputLine* waterColorText = new OrxGui::GLGuiInputLine();
+        waterColorText->setText("WaterColor");
+        waterColorBox->pack(waterColorText);
+
+        OrxGui::GLGuiSlider* waterColorR = new OrxGui::GLGuiSlider();
+        waterColorR->setRange(0, 1.0f);
+        waterColorR->setValue(this->waterColor.x);
+        waterColorR->setStep(0.1f);
+        waterColorR->connect(SIGNAL(waterColorR, valueChanged), this, SLOT(MappedWater, resetWaterColorR));
+        waterColorBox->pack(waterColorR);
+
+        OrxGui::GLGuiSlider* waterColorG = new OrxGui::GLGuiSlider();
+        waterColorG->setRange(0, 1.0f);
+        waterColorG->setStep(0.1f);
+        waterColorG->setValue(this->waterColor.y);
+        waterColorG->connect(SIGNAL(waterColorG, valueChanged), this, SLOT(MappedWater, resetWaterColorG));
+        waterColorBox->pack(waterColorG);
+
+        OrxGui::GLGuiSlider* waterColorB = new OrxGui::GLGuiSlider();
+        waterColorB->setRange(0, 1.0f);
+        waterColorB->setStep(0.1f);
+        waterColorB->setValue(this->waterColor.z);
+        waterColorB->connect(SIGNAL(waterColorB, valueChanged), this, SLOT(MappedWater, resetWaterColorB));
+        waterColorBox->pack(waterColorB);
+      }
+      this->box->pack(waterColorBox);
+
+      OrxGui::GLGuiBox* waterUVBox = new OrxGui::GLGuiBox(OrxGui::Horizontal);
+      {
+        OrxGui::GLGuiInputLine* waterUVText = new OrxGui::GLGuiInputLine();
+        waterUVText->setText("WaterUV");
+        waterUVBox->pack(waterUVText);
+
+        OrxGui::GLGuiSlider* waterUV = new OrxGui::GLGuiSlider();
+        waterUV->setRange(1, 20);
+        waterUV->setValue(this->waterUV);
+        waterUV->setStep(1);
+        waterUV->connect(SIGNAL(waterUV, valueChanged), this, SLOT(MappedWater, setWaterUV));
+        waterUVBox->pack(waterUV);
+      }
+      this->box->pack(waterUVBox);
+
+      OrxGui::GLGuiBox* waterFlowBox = new OrxGui::GLGuiBox(OrxGui::Horizontal);
+      {
+        OrxGui::GLGuiInputLine* waterFlowText = new OrxGui::GLGuiInputLine();
+        waterFlowText->setText("WaterFlow");
+        waterFlowBox->pack(waterFlowText);
+
+        OrxGui::GLGuiSlider* waterFlow = new OrxGui::GLGuiSlider();
+        waterFlow->setRange(0.01f, 2);
+        waterFlow->setValue(this->waterFlow);
+        waterFlow->setStep(0.02f);
+        waterFlow->connect(SIGNAL(waterFlow, valueChanged), this, SLOT(MappedWater, setWaterFlow));
+        waterFlowBox->pack(waterFlow);
+      }
+      this->box->pack(waterFlowBox);
+
+      OrxGui::GLGuiBox* shineSizeBox = new OrxGui::GLGuiBox(OrxGui::Horizontal);
+      {
+        OrxGui::GLGuiInputLine* shineSizeText = new OrxGui::GLGuiInputLine();
+        shineSizeText->setText("ShineSize");
+        shineSizeBox->pack(shineSizeText);
+
+        OrxGui::GLGuiSlider* shineSize = new OrxGui::GLGuiSlider();
+        shineSize->setRange(1, 128);
+        shineSize->setValue(this->shineSize);
+        shineSize->setStep(1);
+        shineSize->connect(SIGNAL(shineSize, valueChanged), this, SLOT(MappedWater, resetShineSize));
+        shineSizeBox->pack(shineSize);
+      }
+      this->box->pack(shineSizeBox);
+
+      OrxGui::GLGuiBox* shineStrengthBox = new OrxGui::GLGuiBox(OrxGui::Horizontal);
+      {
+        OrxGui::GLGuiInputLine* shineStrengthText = new OrxGui::GLGuiInputLine();
+        shineStrengthText->setText("ShineStrength");
+        shineStrengthBox->pack(shineStrengthText);
+
+        OrxGui::GLGuiSlider* shineStrength = new OrxGui::GLGuiSlider();
+        shineStrength->setRange(0, 1);
+        shineStrength->setValue(this->shineStrength);
+        shineStrength->setStep(0.1f);
+        shineStrength->connect(SIGNAL(shineStrength, valueChanged), this, SLOT(MappedWater, resetShineStrength));
+        shineStrengthBox->pack(shineStrength);
+      }
+      this->box->pack(shineStrengthBox);
+
+      OrxGui::GLGuiBox* reflStrengthBox = new OrxGui::GLGuiBox(OrxGui::Horizontal);
+      {
+        OrxGui::GLGuiInputLine* reflStrengthText = new OrxGui::GLGuiInputLine();
+        reflStrengthText->setText("ReflStrength");
+        reflStrengthBox->pack(reflStrengthText);
+
+        OrxGui::GLGuiSlider* reflStrength = new OrxGui::GLGuiSlider();
+        reflStrength->setRange(0, 1);
+        reflStrength->setValue(this->reflStrength);
+        reflStrength->setStep(0.1f);
+        reflStrength->connect(SIGNAL(reflStrength, valueChanged), this, SLOT(MappedWater, resetReflStrength));
+        reflStrengthBox->pack(reflStrength);
+      }
+      this->box->pack(reflStrengthBox);
+
+      OrxGui::GLGuiBox* refractionBox = new OrxGui::GLGuiBox(OrxGui::Horizontal);
+      {
+        OrxGui::GLGuiInputLine* refractionText = new OrxGui::GLGuiInputLine();
+        refractionText->setText("Refraction");
+        refractionBox->pack(refractionText);
+
+        OrxGui::GLGuiSlider* refraction = new OrxGui::GLGuiSlider();
+        refraction->setRange(0.001f, 0.1f);
+        refraction->setValue(this->refraction);
+        refraction->setStep(0.004f);
+        refraction->connect(SIGNAL(refraction, valueChanged), this, SLOT(MappedWater, resetRefraction));
+        refractionBox->pack(refraction);
+      }
+      this->box->pack(refractionBox);
+
+      OrxGui::GLGuiBox* lightPosBox = new OrxGui::GLGuiBox(OrxGui::Horizontal);
+      {
+        OrxGui::GLGuiInputLine* lightPosText = new OrxGui::GLGuiInputLine();
+        lightPosText->setText("LightPos");
+        lightPosBox->pack(lightPosText);
+
+        OrxGui::GLGuiSlider* lightPosX = new OrxGui::GLGuiSlider();
+        lightPosX->setRange(-600, 600);
+        lightPosX->setValue(this->lightPos.x);
+        lightPosX->setStep(15);
+        lightPosX->connect(SIGNAL(lightPosX, valueChanged), this, SLOT(MappedWater, resetLightPosX));
+        lightPosBox->pack(lightPosX);
+
+        OrxGui::GLGuiSlider* lightPosY = new OrxGui::GLGuiSlider();
+        lightPosY->setRange(-600, 600);
+        lightPosY->setStep(15);
+        lightPosY->setValue(this->lightPos.y);
+        lightPosY->connect(SIGNAL(lightPosY, valueChanged), this, SLOT(MappedWater, resetLightPosY));
+        lightPosBox->pack(lightPosY);
+
+        OrxGui::GLGuiSlider* lightPosZ = new OrxGui::GLGuiSlider();
+        lightPosZ->setRange(-600, 600);
+        lightPosZ->setStep(15);
+        lightPosZ->setValue(this->lightPos.z);
+        lightPosZ->connect(SIGNAL(lightPosZ, valueChanged), this, SLOT(MappedWater, resetLightPosZ));
+        lightPosBox->pack(lightPosZ);
+      }
+      this->box->pack(lightPosBox);
+
+      OrxGui::GLGuiBox* waterHeightBox = new OrxGui::GLGuiBox(OrxGui::Horizontal);
+      {
+        OrxGui::GLGuiInputLine* waterHeightText = new OrxGui::GLGuiInputLine();
+        waterHeightText->setText("WaterHeight");
+        waterHeightBox->pack(waterHeightText);
+
+        OrxGui::GLGuiSlider* waterHeight = new OrxGui::GLGuiSlider();
+        waterHeight->setRange(-500, 500);
+        waterHeight->setValue(this->waterHeight);
+        waterHeight->setStep(10);
+        waterHeight->connect(SIGNAL(waterHeight, valueChanged), this, SLOT(MappedWater, setWaterHeight));
+        waterHeightBox->pack(waterHeight);
+      }
+      this->box->pack(waterHeightBox);
+    }
+
+    this->box->showAll();
+    this->box->setAbsCoor2D(300, 40);
+    OrxGui::GLGuiHandler::getInstance()->activate();
+    OrxGui::GLGuiHandler::getInstance()->activateCursor();
+  }
+}
+
+/**
+ * @brief closes the water gui
+ */
+void MappedWater::closeGui()
+{
+  delete this->box;
+  this->box = NULL;
 }
 
@@ -230,8 +535,7 @@
 {
   glMatrixMode(GL_MODELVIEW);
-
   glPushMatrix();
-  // don't use a glTranslate here, the reflection point won't be at the right place anymore
-  glRotatef(this->waterAngle, 0, 1, 0);
+
+  // don't use glRotate or glTranslate here... the shader won't work anymore
 
   mat.select();
@@ -247,30 +551,30 @@
   glBegin(GL_QUADS);
   // The back left vertice for the water
-  glMultiTexCoord2f(GL_TEXTURE0, 0, waterUV);            // Reflection texture
-  glMultiTexCoord2f(GL_TEXTURE1, 0, waterUV - move);        // Refraction texture
-  glMultiTexCoord2f(GL_TEXTURE2, 0, normalUV + move2);     // Normal map texture
-  glMultiTexCoord2f(GL_TEXTURE3, 0, 0);                       // DUDV map texture
-  glVertex3f(this->waterPos.x, this->waterPos.y, this->waterPos.z);
+  glMultiTexCoord2f(GL_TEXTURE0, 0, waterUV);                   // Reflection texture
+  glMultiTexCoord2f(GL_TEXTURE1, 0, waterUV - move);            // Refraction texture
+  glMultiTexCoord2f(GL_TEXTURE2, 0, normalUV + move2);          // Normal map texture
+  glMultiTexCoord2f(GL_TEXTURE3, 0, 0);                         // DUDV map texture
+  glVertex3f(this->waterVerts[0], this->waterHeight, this->waterVerts[1]);
 
   // The front left vertice for the water
-  glMultiTexCoord2f(GL_TEXTURE0, 0, 0);                  // Reflection texture
-  glMultiTexCoord2f(GL_TEXTURE1, 0, -move);           // Refraction texture
-  glMultiTexCoord2f(GL_TEXTURE2, 0, move2);          // Normal map texture
-  glMultiTexCoord2f(GL_TEXTURE3, 0, 0);                        // DUDV map texture
-  glVertex3f(this->waterPos.x, this->waterPos.y, this->waterPos.z + this->zWidth);
+  glMultiTexCoord2f(GL_TEXTURE0, 0, 0);                         // Reflection texture
+  glMultiTexCoord2f(GL_TEXTURE1, 0, -move);                     // Refraction texture
+  glMultiTexCoord2f(GL_TEXTURE2, 0, move2);                     // Normal map texture
+  glMultiTexCoord2f(GL_TEXTURE3, 0, 0);                         // DUDV map texture
+  glVertex3f(this->waterVerts[2], this->waterHeight, this->waterVerts[3]);
 
   // The front right vertice for the water
-  glMultiTexCoord2f(GL_TEXTURE0, waterUV, 0);             // Reflection texture
-  glMultiTexCoord2f(GL_TEXTURE1, waterUV, -move);         // Refraction texture
-  glMultiTexCoord2f(GL_TEXTURE2, normalUV, move2);      // Normal map texture
-  glMultiTexCoord2f(GL_TEXTURE3, 0, 0);                        // DUDV map texture
-  glVertex3f(this->waterPos.x + this->xWidth, this->waterPos.y, this->waterPos.z + this->zWidth);
+  glMultiTexCoord2f(GL_TEXTURE0, waterUV, 0);                   // Reflection texture
+  glMultiTexCoord2f(GL_TEXTURE1, waterUV, -move);               // Refraction texture
+  glMultiTexCoord2f(GL_TEXTURE2, normalUV, move2);              // Normal map texture
+  glMultiTexCoord2f(GL_TEXTURE3, 0, 0);                         // DUDV map texture
+  glVertex3f(this->waterVerts[4], this->waterHeight, this->waterVerts[5]);
 
   // The back right vertice for the water
-  glMultiTexCoord2f(GL_TEXTURE0, waterUV, waterUV);        // Reflection texture
-  glMultiTexCoord2f(GL_TEXTURE1, waterUV, waterUV - move);       // Refraction texture
-  glMultiTexCoord2f(GL_TEXTURE2, normalUV, normalUV + move2);  // Normal map texture
-  glMultiTexCoord2f(GL_TEXTURE3, 0, 0);                        // DUDV map texture
-  glVertex3f(this->waterPos.x + this->xWidth, this->waterPos.y, this->waterPos.z);
+  glMultiTexCoord2f(GL_TEXTURE0, waterUV, waterUV);             // Reflection texture
+  glMultiTexCoord2f(GL_TEXTURE1, waterUV, waterUV - move);      // Refraction texture
+  glMultiTexCoord2f(GL_TEXTURE2, normalUV, normalUV + move2);   // Normal map texture
+  glMultiTexCoord2f(GL_TEXTURE3, 0, 0);                         // DUDV map texture
+  glVertex3f(this->waterVerts[6], this->waterHeight, this->waterVerts[7]);
   glEnd();
 
@@ -290,14 +594,118 @@
   this->move += this->waterFlow * dt;
   this->move2 = this->move * this->kNormalMapScale;
-  
-
-//   if(this->tempcounter == 200) {
-//     this->resetWaterColor(1, 0, 0);
-//     resetShininess(1);
-//     resetLightPos(0, 50, 0);
-//     PRINTF(0)("test waterchangecolor ");
-//     }
-//   tempcounter++;
-    
+
+  // fading TODO fix this so it isnt hacky anymore
+  if(bFadeWaterUV)
+  {
+    this->waterUVFader = new tAnimation<MappedWater>(this, &MappedWater::setWaterUV);
+    this->waterUVFader->setInfinity(ANIM_INF_CONSTANT);
+
+    this->waterUVFader->addKeyFrame(this->waterUV, this->waterUVFadeTime, ANIM_LINEAR);
+    this->waterUVFader->addKeyFrame(this->newWaterUV, 0, ANIM_LINEAR);
+
+    bFadeWaterUV = false;
+    this->waterUVFader->replay();
+  }
+
+  if(bFadeWaterFlow)
+  {
+    this->waterFlowFader = new tAnimation<MappedWater>(this, &MappedWater::setWaterFlow);
+    this->waterFlowFader->setInfinity(ANIM_INF_CONSTANT);
+
+    this->waterFlowFader->addKeyFrame(this->waterFlow, this->waterFlowFadeTime, ANIM_LINEAR);
+    this->waterFlowFader->addKeyFrame(this->newWaterFlow, 0, ANIM_LINEAR);
+
+    bFadeWaterFlow = false;
+    this->waterFlowFader->replay();
+  }
+
+  if(bFadeShineSize)
+  {
+    this->shineSizeFader = new tAnimation<MappedWater>(this, &MappedWater::resetShineSize);
+    this->shineSizeFader->setInfinity(ANIM_INF_CONSTANT);
+
+    this->shineSizeFader->addKeyFrame(this->shineSize, this->shineSizeFadeTime, ANIM_LINEAR);
+    this->shineSizeFader->addKeyFrame(this->newShineSize, 0, ANIM_LINEAR);
+
+    bFadeShineSize = false;
+    this->shineSizeFader->replay();
+  }
+
+  if(bFadeShineStrength)
+  {
+    this->shineStrengthFader = new tAnimation<MappedWater>(this, &MappedWater::resetShineStrength);
+    this->shineStrengthFader->setInfinity(ANIM_INF_CONSTANT);
+
+    this->shineStrengthFader->addKeyFrame(this->shineStrength, this->shineStrengthFadeTime, ANIM_LINEAR);
+    this->shineStrengthFader->addKeyFrame(this->newShineStrength, 0, ANIM_LINEAR);
+
+    bFadeShineStrength = false;
+    this->shineStrengthFader->replay();
+  }
+
+  if(bFadeReflStrength)
+  {
+    this->reflStrengthFader = new tAnimation<MappedWater>(this, &MappedWater::resetReflStrength);
+    this->reflStrengthFader->setInfinity(ANIM_INF_CONSTANT);
+
+    this->reflStrengthFader->addKeyFrame(this->reflStrength, this->reflStrengthFadeTime, ANIM_LINEAR);
+    this->reflStrengthFader->addKeyFrame(this->newReflStrength, 0, ANIM_LINEAR);
+
+    bFadeReflStrength = false;
+    this->reflStrengthFader->replay();
+  }
+
+  if(bFadeRefraction)
+  {
+    this->refractionFader = new tAnimation<MappedWater>(this, &MappedWater::resetRefraction);
+    this->refractionFader->setInfinity(ANIM_INF_CONSTANT);
+
+    this->refractionFader->addKeyFrame(this->refraction, this->refractionFadeTime, ANIM_LINEAR);
+    this->refractionFader->addKeyFrame(this->newRefraction, 0, ANIM_LINEAR);
+
+    bFadeRefraction = false;
+    this->refractionFader->replay();
+  }
+
+  if(bFadeWaterHeight)
+  {
+    this->waterHeightFader = new tAnimation<MappedWater>(this, &MappedWater::setWaterHeight);
+    this->waterHeightFader->setInfinity(ANIM_INF_CONSTANT);
+
+    this->waterHeightFader->addKeyFrame(this->waterHeight, this->waterHeightFadeTime, ANIM_LINEAR);
+    this->waterHeightFader->addKeyFrame(this->newWaterHeight, 0, ANIM_LINEAR);
+
+    bFadeWaterHeight = false;
+    this->waterHeightFader->replay();
+  }
+
+  if(bFadeWaterColor)
+  {
+    this->waterColorRFader = new tAnimation<MappedWater>(this, &MappedWater::resetWaterColorR);
+    this->waterColorRFader->setInfinity(ANIM_INF_CONSTANT);
+
+    this->waterColorRFader->addKeyFrame(this->waterColor.x, this->waterColorFadeTime, ANIM_LINEAR);
+    this->waterColorRFader->addKeyFrame(this->newWaterColor.x, 0, ANIM_LINEAR);
+
+    this->waterColorRFader->replay();
+
+    this->waterColorGFader = new tAnimation<MappedWater>(this, &MappedWater::resetWaterColorG);
+    this->waterColorGFader->setInfinity(ANIM_INF_CONSTANT);
+
+    this->waterColorGFader->addKeyFrame(this->waterColor.y, this->waterColorFadeTime, ANIM_LINEAR);
+    this->waterColorGFader->addKeyFrame(this->newWaterColor.y, 0, ANIM_LINEAR);
+
+    this->waterColorGFader->replay();
+
+    this->waterColorBFader = new tAnimation<MappedWater>(this, &MappedWater::resetWaterColorB);
+    this->waterColorBFader->setInfinity(ANIM_INF_CONSTANT);
+
+    this->waterColorBFader->addKeyFrame(this->waterColor.z, this->waterColorFadeTime, ANIM_LINEAR);
+    this->waterColorBFader->addKeyFrame(this->newWaterColor.z, 0, ANIM_LINEAR);
+
+    this->waterColorBFader->replay();
+
+    bFadeWaterColor = false;
+  }
 }
 
@@ -330,8 +738,8 @@
   Vector pos = State::getCameraNode()->getAbsCoor();
 
-  if(pos.y > waterPos.y)
+  if(pos.y > waterHeight)
   {
     // Translate the world, then flip it upside down
-    glTranslatef(0, waterPos.y*2, 0);
+    glTranslatef(0, waterHeight * 2, 0);
     glScalef(1, -1, 1);
 
@@ -340,5 +748,5 @@
 
     // Set our plane equation and turn clipping on
-    double plane[4] = {0, 1, 0, -waterPos.y};
+    double plane[4] = {0, 1, 0, -waterHeight};
     glClipPlane(GL_CLIP_PLANE0, plane);
   }
@@ -347,5 +755,5 @@
     // If the camera is below the water we don't want to flip the world,
     // but just render it clipped so only the top is drawn.
-    double plane[4] = {0, 1, 0, waterPos.y};
+    double plane[4] = {0, 1, 0, waterHeight};
     glClipPlane(GL_CLIP_PLANE0, plane);
   }
@@ -392,7 +800,7 @@
   glEnable(GL_CLIP_PLANE0);
   Vector pos = State::getCameraNode()->getAbsCoor();
-  if(pos.y > waterPos.y)
-  {
-    double plane[4] = {0, -1, 0, waterPos.y};
+  if(pos.y > waterHeight)
+  {
+    double plane[4] = {0, -1, 0, waterHeight};
     glClipPlane(GL_CLIP_PLANE0, plane);
   }
@@ -401,5 +809,5 @@
   {
     glCullFace(GL_FRONT);
-    double plane[4] = {0, 1, 0, -waterPos.y};
+    double plane[4] = {0, 1, 0, -waterHeight};
     glClipPlane(GL_CLIP_PLANE0, plane);
   }
Index: trunk/src/world_entities/environments/mapped_water.h
===================================================================
--- trunk/src/world_entities/environments/mapped_water.h	(revision 8792)
+++ trunk/src/world_entities/environments/mapped_water.h	(revision 9006)
@@ -1,3 +1,3 @@
-/*!
+ /*!
  * @file mapped_water.h
  *  worldentity for flat, cool looking, mapped water
@@ -12,5 +12,8 @@
   <waterangle>0</waterangle>
   <normalmapscale>0.25</normalmapscale><!-- you won't see a big differnce if you change that -->
-  <shininess>128</shininess><!-- the bigger the value, the smaller the specular reflection point -->
+  <shinesize>128</shinesize><!-- the bigger the value, the smaller the specular reflection point -->
+  <shinestrength>0.7</shinestrength>
+  <reflstrength>1</reflstrength>
+  <refraction>0.009</refraction>
   <watercolor>0.1, 0.2, 0.4</watercolor>
 </MappedWater>
@@ -25,4 +28,8 @@
 #include "shader.h"
 
+namespace OrxGui { class GLGuiBox; };
+
+// forward declaration
+template <class T> class tAnimation;
 
 class MappedWater : public WorldEntity
@@ -32,6 +39,7 @@
   virtual ~MappedWater();
 
+  // worldentity functions
   void loadParams(const TiXmlElement* root);
-
+  void saveParams();
   void draw() const;
   void tick(float dt);
@@ -43,25 +51,51 @@
   void deactivateRefraction();
 
+  // slider gui to edit water params during gameplay
+  void openGui();
+  void closeGui();
+
   // functions to set parameters for the water, usually they're called through loadparam
-  void setLightPos(float x, float y, float z) { this->lightPos = Vector(x,y,z); };
-  void setWaterPos(float x, float y, float z) { this->waterPos = Vector(x,y,z); };
-  void setWaterSize(float x, float z) { this->xWidth = x; this->zWidth = z; };
-  void setWaterAngle(float angle) { this->waterAngle = angle; };
-  void setWaterUV(float uv) { this->waterUV = uv; };
-  void setWaterFlow(float flow) { this->waterFlow = flow; };
-  void setNormalMapScale(float scale) { this->kNormalMapScale = scale; };
-  void setShininess(float shine) { this->shininess = shine; };
-  void setWaterColor(float r, float g, float b) { this->waterColor = Vector(r,g,b); };
+  void setLightPos(float x, float y, float z) { this->lightPos = Vector(x,y,z); }
+  void setWaterPos(float x, float y, float z) { this->waterHeight = y; this->waterVerts[0] = x; this->waterVerts[1] = z; }
+  void setWaterHeight(float y) { this->waterHeight = y;  }
+  void setWaterSize(float x, float z) { this->xWidth = x; this->zWidth = z; }
+  void setWaterAngle(float angle) { this->waterAngle = angle; }
+  void setWaterColor(float r, float g, float b) { this->waterColor = Vector(r,g,b); }
+  void setWaterUV(float uv) { this->waterUV = uv; }
+  void setWaterFlow(float flow) { this->waterFlow = flow; }
+  void setNormalMapScale(float scale) { this->kNormalMapScale = scale; }
+  void setShineSize(float shine) { this->shineSize = shine; }
+  void setShineStrength(float strength) { this->shineStrength = strength; }
+  void setReflStrength(float strength) { this->reflStrength = strength; }
+  void setRefraction(float refraction) { this->refraction = refraction; }
 
   // functions to change water parameters during runtime
   // to reset waterUV and waterFlow just use the normal set functions
+  // don't reset kNormalMapScale (because it won't change anything)
+  void resetLightPos(float x, float y, float z);
+  void resetLightPosX(float x) { this->resetLightPos(x, this->lightPos.y, this->lightPos.z); }
+  void resetLightPosY(float y) { this->resetLightPos(this->lightPos.x, y, this->lightPos.z); }
+  void resetLightPosZ(float z) { this->resetLightPos(this->lightPos.x, this->lightPos.y, z); }
+  void resetWaterPos(float x, float y, float z) { this->setWaterPos(x, y, z); this->calcVerts(); }
+  void resetWaterSize(float x, float z) { this->setWaterSize(x, z); this->calcVerts(); }
+  void resetWaterAngle(float angle) { this->setWaterAngle(angle); this->calcVerts(); }
   void resetWaterColor(float r, float g, float b);
-  void resetShininess(float shine);
-  void resetLightPos(float x, float y, float z);
+  void resetWaterColorR(float r) { this->resetWaterColor(r, this->waterColor.y, this->waterColor.z); }
+  void resetWaterColorG(float g) { this->resetWaterColor(this->waterColor.x, g, this->waterColor.z); }
+  void resetWaterColorB(float b) { this->resetWaterColor(this->waterColor.x, this->waterColor.y, b); }
+  void resetShineSize(float shine);
+  void resetShineStrength(float strength);
+  void resetReflStrength(float strength);
+  void resetRefraction(float refraction);
 
-  // fade functions
-  void fadeWaterColor(float r, float g, float b, float time);
-  void fadeShininess(float shine, float time);
-  void fadeLightPos(float x, float y, float z, float time);
+  // fading functions
+  void fadeWaterUV(float uv, float time) { this->newWaterUV = uv; this->waterUVFadeTime = time; this->bFadeWaterUV = true; }
+  void fadeWaterFlow(float flow, float time) { this->newWaterFlow = flow; this->waterFlowFadeTime = time; this->bFadeWaterFlow = true; }
+  void fadeShineSize(float shine, float time) { this->newShineSize = shine; this->shineSizeFadeTime = time; this->bFadeShineSize = true; }
+  void fadeShineStrength(float strength, float time) { this->newShineStrength = strength; this->shineStrengthFadeTime = time; this->bFadeShineStrength = true; }
+  void fadeReflStrength(float strength, float time) { this->newReflStrength = strength; this->reflStrengthFadeTime = time; this->bFadeReflStrength = true; }
+  void fadeRefraction(float refraction, float time) { this->newRefraction = refraction; this->refractionFadeTime = time; this->bFadeRefraction = true; }
+  void fadeWaterHeight(float y, float time) { this->newWaterHeight = y; this->waterHeightFadeTime = time; this->bFadeWaterHeight = true; }
+  void fadeWaterColor(float r, float g, float b, float time) { this->newWaterColor = Vector(r, g, b); this->waterColorFadeTime = time; this->bFadeWaterColor = true; }
 
 private:
@@ -69,29 +103,78 @@
   void initTextures();
   void initShaders();
+  void calcVerts();
 
 private:
-  Vector              waterPos;               //!< position of the water
-  float               xWidth, zWidth;         //!< size of the water quad
-  Vector              lightPos;               //!< position of the light that is used to render the reflection
-  float               waterAngle;             //!< defines how much the water will be turned around the point waterPos
-  Vector              waterColor;             //!< color of the water
-  float               move;                   //!< textures coords, speeds, positions for the shaded textures....
-  float               move2;
-  float               waterUV;                //!< size of the waves
-  float               waterFlow;              //!< speed of the water
-  float               normalUV;
-  float               kNormalMapScale;
-  float               shininess;              //!< the bigger the value, the smaller the specular reflection point
+  Material                  mat;
+  Shader*                   shader;
+  OrxGui::GLGuiBox*         box;
 
-  int                 textureSize;            //!< height and width of the texture
-  Material            mat;
-  Shader*             shader;
-  Shader::Uniform*    cam_uni;                //!< uniform that is used for the camera position
-  Shader::Uniform*    light_uni;              //!< uniform that is used for the light position
-  Shader::Uniform*    color_uni;              //!< uniform that is used for the watercolor
-  Shader::Uniform*    shine_uni;              //!< uniform that is used for the specular shininessd of the water
-  
-  
-  int tempcounter;
+  // water size and position
+  float                     waterHeight;            //!< position of the water
+  float                     waterVerts[8];          //!< coords of the 4 vertexes of the water quad
+  float                     xWidth, zWidth;         //!< size of the water quad
+  float                     waterAngle;             //!< defines how much the water will be turned around the point waterPos
+
+  // values for texture size, scale, texture coords
+  float                     move;
+  float                     move2;
+  float                     waterUV;                //!< size of the waves
+  float                     waterFlow;              //!< speed of the water
+  float                     normalUV;
+  float                     kNormalMapScale;
+  int                       textureSize;            //!< height and width of the texture
+
+  // values for the uniforms
+  Vector                    waterColor;             //!< color of the water
+  Vector                    lightPos;               //!< position of the light that is used to render the reflection
+  float                     shineSize;              //!< the bigger the value, the smaller the specular reflection point
+  float                     shineStrength;
+  float                     reflStrength;
+  float                     refraction;
+
+  // uniforms
+  Shader::Uniform*          cam_uni;                //!< uniform that is used for the camera position
+  Shader::Uniform*          light_uni;              //!< uniform that is used for the light position
+  Shader::Uniform*          color_uni;              //!< uniform that is used for the watercolor
+  Shader::Uniform*          shineSize_uni;          //!< uniform that is used for the specular shininessd of the water
+  Shader::Uniform*          shineStrength_uni;      //!< uniform that is used for the strenght of the specular reflection
+  Shader::Uniform*          reflStrength_uni;       //!< uniform that is used for the strength of the reflection
+  Shader::Uniform*          refr_uni;               //!< uniform that is used for the strength of the refraction
+
+  // fading TODO fix this so it isnt so hacky anymore
+  tAnimation<MappedWater>*  waterUVFader;
+  float                     newWaterUV;
+  float                     waterUVFadeTime;
+  bool                      bFadeWaterUV ;
+  tAnimation<MappedWater>*  waterFlowFader;
+  float                     newWaterFlow;
+  float                     waterFlowFadeTime;
+  bool                      bFadeWaterFlow;
+  tAnimation<MappedWater>*  shineSizeFader;
+  float                     newShineSize;
+  float                     shineSizeFadeTime;
+  bool                      bFadeShineSize;
+  tAnimation<MappedWater>*  shineStrengthFader;
+  float                     newShineStrength;
+  float                     shineStrengthFadeTime;
+  bool                      bFadeShineStrength;
+  tAnimation<MappedWater>*  reflStrengthFader;
+  float                     newReflStrength;
+  float                     reflStrengthFadeTime;
+  bool                      bFadeReflStrength;
+  tAnimation<MappedWater>*  refractionFader;
+  float                     newRefraction;
+  float                     refractionFadeTime;
+  bool                      bFadeRefraction;
+  tAnimation<MappedWater>*  waterHeightFader;
+  float                     newWaterHeight;
+  float                     waterHeightFadeTime;
+  bool                      bFadeWaterHeight;
+  tAnimation<MappedWater>*  waterColorRFader;
+  tAnimation<MappedWater>*  waterColorGFader;
+  tAnimation<MappedWater>*  waterColorBFader;
+  Vector                    newWaterColor;
+  float                     waterColorFadeTime;
+  bool                      bFadeWaterColor;
 };
 
