Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 9006 in orxonox.OLD for trunk/src/world_entities/environments


Ignore:
Timestamp:
Jul 2, 2006, 2:11:59 PM (18 years ago)
Author:
bensch
Message:

orxonox/trunk: merged the mountain_lake branche back to the trunk
merged with command:
svn merge -r8799:HEAD https://svn.orxonox.net/orxonox/branches/mountain_lake .

conflicts in script taken from the branche, since they are indentation-problems.

also fixed the delete-bug for the lightning-effect

Location:
trunk/src/world_entities/environments
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/world_entities/environments/mapped_water.cc

    r8792 r9006  
    1919#include "util/loading/resource_manager.h"
    2020#include "state.h"
     21#include "t_animation.h"
    2122#include "math.h"
    22 
     23#include "glgui.h"
     24#include "shell_command.h"
     25#include "script_class.h"
    2326
    2427CREATE_FACTORY(MappedWater, CL_MAPPED_WATER);
     28
     29SHELL_COMMAND(gui, MappedWater, openGui);
     30SHELL_COMMAND(output, MappedWater, saveParams);
     31
     32CREATE_SCRIPTABLE_CLASS(MappedWater, CL_MAPPED_WATER,
     33                        addMethod("waterUV", ExecutorLua2<MappedWater, float, float>(&MappedWater::fadeWaterUV))
     34                      ->addMethod("waterFlow", ExecutorLua2<MappedWater, float, float>(&MappedWater::fadeWaterFlow))
     35                      ->addMethod("shineSize", ExecutorLua2<MappedWater, float, float>(&MappedWater::fadeShineSize))
     36                      ->addMethod("shineStrength", ExecutorLua2<MappedWater, float, float>(&MappedWater::fadeShineStrength))
     37                      ->addMethod("reflStrength", ExecutorLua2<MappedWater, float, float>(&MappedWater::fadeReflStrength))
     38                      ->addMethod("refraction", ExecutorLua2<MappedWater, float, float>(&MappedWater::fadeRefraction))
     39                      ->addMethod("waterHeight", ExecutorLua2<MappedWater, float, float>(&MappedWater::fadeWaterHeight))
     40                      ->addMethod("waterColor", ExecutorLua4<MappedWater, float, float, float, float>(&MappedWater::fadeWaterColor)));
     41
    2542
    2643/**
     
    4562  /// initialization of the shaders
    4663  this->initShaders();
    47  
    48   tempcounter = 0;
     64
     65  /// calculation of the 4 verts of the water quad
     66  this->calcVerts();
     67
     68  // init gui
     69  this->box = NULL;
    4970}
    5071
     
    5879  delete color_uni;
    5980  delete light_uni;
    60   delete shine_uni;
     81  delete shineSize_uni;
     82  delete shineStrength_uni;
     83  delete reflStrength_uni;
     84  delete refr_uni;
    6185}
    6286
     
    7094  this->setWaterSize(100, 100);
    7195  this->setWaterUV(9);
    72   this->setWaterFlow(0.08);
     96  this->setWaterFlow(0.08f);
    7397  this->setLightPos(0, 10, 0);
    7498  this->setWaterAngle(0);
    7599  this->setNormalMapScale(0.25f);
    76100  this->setWaterColor(0.1f, 0.2f, 0.4f);
    77   this->setShininess(128);
     101  this->setShineSize(128);
     102  this->setShineStrength(0.7f);
     103  this->setReflStrength(1.0f);
     104  this->setRefraction(0.009f);
    78105
    79106  // initialization of the texture coords, speeds etc...
     
    84111  this->move2 = this->move * this->kNormalMapScale;
    85112
    86 
     113  // initalize fading bools
     114  this->bFadeWaterHeight = false;
     115  this->bFadeWaterUV = false;
     116  this->bFadeWaterFlow = false;
     117  this->bFadeShineSize = false;
     118  this->bFadeShineStrength = false;
     119  this->bFadeReflStrength = false;
     120  this->bFadeRefraction = false;
     121  this->bFadeWaterColor = false;
    87122}
    88123
     
    104139  mat.setDiffuseMap(refrTex, 1);
    105140  // load normal map
    106   mat.setDiffuseMap("pictures/normalmap.bmp", GL_TEXTURE_2D, 2);
     141  mat.setDiffuseMap("pictures/water_normalmap.bmp", GL_TEXTURE_2D, 2);
    107142  // load dudv map
    108   mat.setDiffuseMap("pictures/dudvmap.bmp", GL_TEXTURE_2D, 3);
     143  mat.setDiffuseMap("pictures/water_dudvmap.bmp", GL_TEXTURE_2D, 3);
    109144
    110145  // sets texture parameters for reflection texture
     
    140175  Shader::Uniform(shader, "dudvMap").set(3);
    141176  // Set the variable "depthMap" to correspond to the fifth texture unit
    142   Shader::Uniform(shader, "depthMap").set(2);
     177  Shader::Uniform(shader, "depthMap").set(1);
    143178  // Give the variable "waterColor" a blue color
    144179  color_uni = new Shader::Uniform(shader, "waterColor");
     
    148183  light_uni->set(lightPos.x, lightPos.y, lightPos.z, 1.0f);
    149184  // Set the variable "shine"
    150   shine_uni = new Shader::Uniform(shader, "kShine");
    151   shine_uni->set(this->shininess);
     185  shineSize_uni = new Shader::Uniform(shader, "kShine");
     186  shineSize_uni->set(this->shineSize);
     187  // Set the variable "shineStrength"
     188  shineStrength_uni = new Shader::Uniform(shader, "shineStrength");
     189  shineStrength_uni->set(this->shineStrength);
     190  // Set the variable "reflStrength"
     191  reflStrength_uni = new Shader::Uniform(shader, "reflStrength");
     192  reflStrength_uni->set(this->reflStrength);
     193  // Set the variable "refraction"
     194  refr_uni = new Shader::Uniform(shader, "kRefraction");
     195  refr_uni->set(this->refraction);
    152196  // uniform for the camera position
    153197  cam_uni = new Shader::Uniform(shader, "cameraPos");
    154198
    155199  this->shader->deactivateShader();
     200}
     201
     202/**
     203 * @brief calculates the 4 verts of the water quad
     204 */
     205void MappedWater::calcVerts()
     206{
     207  float deg2radtemp = this->waterAngle / 180 * PI;
     208
     209  this->waterVerts[2] = this->waterVerts[0] + cos(deg2radtemp) * this->xWidth;
     210  this->waterVerts[3] = this->waterVerts[1] + sin(deg2radtemp) * this->xWidth;
     211  this->waterVerts[4] = this->waterVerts[0] + cos(deg2radtemp) * this->xWidth - sin(deg2radtemp) * this->zWidth;
     212  this->waterVerts[5] = this->waterVerts[1] + sin(deg2radtemp) * this->xWidth + cos(deg2radtemp) * this->zWidth;
     213  this->waterVerts[6] = this->waterVerts[0] - sin(deg2radtemp) * this->zWidth;
     214  this->waterVerts[7] = this->waterVerts[1] + cos(deg2radtemp) * this->zWidth;
    156215}
    157216
     
    171230
    172231  this->shader->deactivateShader();
    173 };
     232}
    174233
    175234/**
     
    177236 * @param shine new value for the shininess
    178237 */
    179 void MappedWater::resetShininess(float shine)
     238void MappedWater::resetShineSize(float shine)
    180239{
    181240  this->shader->activateShader();
    182   this->shininess = shine;
     241  this->shineSize = shine;
    183242
    184243  // Set the variable "shine"
    185   shine_uni->set(this->shininess);
     244  shineSize_uni->set(this->shineSize);
    186245
    187246  this->shader->deactivateShader();
    188 };
     247}
     248
     249/**
     250 * @brief resets the strength of the specular reflection in the Shader
     251 * @param strength new value for the strength of the specular reflection
     252 */
     253void MappedWater::resetShineStrength(float strength)
     254{
     255  this->shader->activateShader();
     256  this->shineStrength = strength;
     257
     258  // Set the variable "shine"
     259  shineStrength_uni->set(this->shineStrength);
     260
     261  this->shader->deactivateShader();
     262}
     263
     264/**
     265 * @brief resets the strength of the reflection in the Shader
     266 * @param strength new value for the strength of the reflection
     267 */
     268void MappedWater::resetReflStrength(float strength)
     269{
     270  this->shader->activateShader();
     271  this->reflStrength = strength;
     272
     273  // Set the variable "shine"
     274  reflStrength_uni->set(this->reflStrength);
     275
     276  this->shader->deactivateShader();
     277}
     278
     279/**
     280 * @brief resets the refraction in the Shader
     281 * @param refraction new value for the refraction
     282 */
     283void MappedWater::resetRefraction(float refraction)
     284{
     285  this->shader->activateShader();
     286  this->refraction = refraction;
     287
     288  // Set the variable "shine"
     289  refr_uni->set(this->refraction);
     290
     291  this->shader->deactivateShader();
     292}
    189293
    190294/**
     
    203307
    204308  this->shader->deactivateShader();
    205 };
     309}
    206310
    207311/**
     
    215319  LoadParam(root, "waterpos", this, MappedWater, setWaterPos);
    216320  LoadParam(root, "watersize", this, MappedWater, setWaterSize);
    217   LoadParam(root, "lightpos", this, MappedWater, setLightPos);
    218321  LoadParam(root, "wateruv", this, MappedWater, setWaterUV);
    219322  LoadParam(root, "waterflow", this, MappedWater, setWaterFlow);
     323  LoadParam(root, "lightpos", this, MappedWater, setLightPos);
     324  LoadParam(root, "waterangle", this, MappedWater, setWaterAngle);
    220325  LoadParam(root, "normalmapscale", this, MappedWater, setNormalMapScale);
    221   LoadParam(root, "waterangle", this, MappedWater, setWaterAngle);
     326  LoadParam(root, "shinesize", this, MappedWater, setShineSize);
     327  LoadParam(root, "shinestrength", this, MappedWater, setShineStrength);
     328  LoadParam(root, "reflstrength", this, MappedWater, setReflStrength);
     329  LoadParam(root, "refraction", this, MappedWater, setRefraction);
    222330  LoadParam(root, "watercolor", this, MappedWater, setWaterColor);
    223   LoadParam(root, "shininess", this, MappedWater, setShininess);
     331}
     332
     333/**
     334 * @brief prints the xml code of the water params
     335 */
     336void MappedWater::saveParams()
     337{
     338  // it's not too nice, but it works fine
     339  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);
     340}
     341
     342/**
     343 * @brief starts the slider gui that lets you edit all water parameters
     344 */
     345void MappedWater::openGui()
     346{
     347  if (this->box == NULL)
     348  {
     349    this->box = new OrxGui::GLGuiBox(OrxGui::Vertical);
     350    {
     351      OrxGui::GLGuiBox* waterColorBox = new OrxGui::GLGuiBox(OrxGui::Horizontal);
     352      {
     353        OrxGui::GLGuiInputLine* waterColorText = new OrxGui::GLGuiInputLine();
     354        waterColorText->setText("WaterColor");
     355        waterColorBox->pack(waterColorText);
     356
     357        OrxGui::GLGuiSlider* waterColorR = new OrxGui::GLGuiSlider();
     358        waterColorR->setRange(0, 1.0f);
     359        waterColorR->setValue(this->waterColor.x);
     360        waterColorR->setStep(0.1f);
     361        waterColorR->connect(SIGNAL(waterColorR, valueChanged), this, SLOT(MappedWater, resetWaterColorR));
     362        waterColorBox->pack(waterColorR);
     363
     364        OrxGui::GLGuiSlider* waterColorG = new OrxGui::GLGuiSlider();
     365        waterColorG->setRange(0, 1.0f);
     366        waterColorG->setStep(0.1f);
     367        waterColorG->setValue(this->waterColor.y);
     368        waterColorG->connect(SIGNAL(waterColorG, valueChanged), this, SLOT(MappedWater, resetWaterColorG));
     369        waterColorBox->pack(waterColorG);
     370
     371        OrxGui::GLGuiSlider* waterColorB = new OrxGui::GLGuiSlider();
     372        waterColorB->setRange(0, 1.0f);
     373        waterColorB->setStep(0.1f);
     374        waterColorB->setValue(this->waterColor.z);
     375        waterColorB->connect(SIGNAL(waterColorB, valueChanged), this, SLOT(MappedWater, resetWaterColorB));
     376        waterColorBox->pack(waterColorB);
     377      }
     378      this->box->pack(waterColorBox);
     379
     380      OrxGui::GLGuiBox* waterUVBox = new OrxGui::GLGuiBox(OrxGui::Horizontal);
     381      {
     382        OrxGui::GLGuiInputLine* waterUVText = new OrxGui::GLGuiInputLine();
     383        waterUVText->setText("WaterUV");
     384        waterUVBox->pack(waterUVText);
     385
     386        OrxGui::GLGuiSlider* waterUV = new OrxGui::GLGuiSlider();
     387        waterUV->setRange(1, 20);
     388        waterUV->setValue(this->waterUV);
     389        waterUV->setStep(1);
     390        waterUV->connect(SIGNAL(waterUV, valueChanged), this, SLOT(MappedWater, setWaterUV));
     391        waterUVBox->pack(waterUV);
     392      }
     393      this->box->pack(waterUVBox);
     394
     395      OrxGui::GLGuiBox* waterFlowBox = new OrxGui::GLGuiBox(OrxGui::Horizontal);
     396      {
     397        OrxGui::GLGuiInputLine* waterFlowText = new OrxGui::GLGuiInputLine();
     398        waterFlowText->setText("WaterFlow");
     399        waterFlowBox->pack(waterFlowText);
     400
     401        OrxGui::GLGuiSlider* waterFlow = new OrxGui::GLGuiSlider();
     402        waterFlow->setRange(0.01f, 2);
     403        waterFlow->setValue(this->waterFlow);
     404        waterFlow->setStep(0.02f);
     405        waterFlow->connect(SIGNAL(waterFlow, valueChanged), this, SLOT(MappedWater, setWaterFlow));
     406        waterFlowBox->pack(waterFlow);
     407      }
     408      this->box->pack(waterFlowBox);
     409
     410      OrxGui::GLGuiBox* shineSizeBox = new OrxGui::GLGuiBox(OrxGui::Horizontal);
     411      {
     412        OrxGui::GLGuiInputLine* shineSizeText = new OrxGui::GLGuiInputLine();
     413        shineSizeText->setText("ShineSize");
     414        shineSizeBox->pack(shineSizeText);
     415
     416        OrxGui::GLGuiSlider* shineSize = new OrxGui::GLGuiSlider();
     417        shineSize->setRange(1, 128);
     418        shineSize->setValue(this->shineSize);
     419        shineSize->setStep(1);
     420        shineSize->connect(SIGNAL(shineSize, valueChanged), this, SLOT(MappedWater, resetShineSize));
     421        shineSizeBox->pack(shineSize);
     422      }
     423      this->box->pack(shineSizeBox);
     424
     425      OrxGui::GLGuiBox* shineStrengthBox = new OrxGui::GLGuiBox(OrxGui::Horizontal);
     426      {
     427        OrxGui::GLGuiInputLine* shineStrengthText = new OrxGui::GLGuiInputLine();
     428        shineStrengthText->setText("ShineStrength");
     429        shineStrengthBox->pack(shineStrengthText);
     430
     431        OrxGui::GLGuiSlider* shineStrength = new OrxGui::GLGuiSlider();
     432        shineStrength->setRange(0, 1);
     433        shineStrength->setValue(this->shineStrength);
     434        shineStrength->setStep(0.1f);
     435        shineStrength->connect(SIGNAL(shineStrength, valueChanged), this, SLOT(MappedWater, resetShineStrength));
     436        shineStrengthBox->pack(shineStrength);
     437      }
     438      this->box->pack(shineStrengthBox);
     439
     440      OrxGui::GLGuiBox* reflStrengthBox = new OrxGui::GLGuiBox(OrxGui::Horizontal);
     441      {
     442        OrxGui::GLGuiInputLine* reflStrengthText = new OrxGui::GLGuiInputLine();
     443        reflStrengthText->setText("ReflStrength");
     444        reflStrengthBox->pack(reflStrengthText);
     445
     446        OrxGui::GLGuiSlider* reflStrength = new OrxGui::GLGuiSlider();
     447        reflStrength->setRange(0, 1);
     448        reflStrength->setValue(this->reflStrength);
     449        reflStrength->setStep(0.1f);
     450        reflStrength->connect(SIGNAL(reflStrength, valueChanged), this, SLOT(MappedWater, resetReflStrength));
     451        reflStrengthBox->pack(reflStrength);
     452      }
     453      this->box->pack(reflStrengthBox);
     454
     455      OrxGui::GLGuiBox* refractionBox = new OrxGui::GLGuiBox(OrxGui::Horizontal);
     456      {
     457        OrxGui::GLGuiInputLine* refractionText = new OrxGui::GLGuiInputLine();
     458        refractionText->setText("Refraction");
     459        refractionBox->pack(refractionText);
     460
     461        OrxGui::GLGuiSlider* refraction = new OrxGui::GLGuiSlider();
     462        refraction->setRange(0.001f, 0.1f);
     463        refraction->setValue(this->refraction);
     464        refraction->setStep(0.004f);
     465        refraction->connect(SIGNAL(refraction, valueChanged), this, SLOT(MappedWater, resetRefraction));
     466        refractionBox->pack(refraction);
     467      }
     468      this->box->pack(refractionBox);
     469
     470      OrxGui::GLGuiBox* lightPosBox = new OrxGui::GLGuiBox(OrxGui::Horizontal);
     471      {
     472        OrxGui::GLGuiInputLine* lightPosText = new OrxGui::GLGuiInputLine();
     473        lightPosText->setText("LightPos");
     474        lightPosBox->pack(lightPosText);
     475
     476        OrxGui::GLGuiSlider* lightPosX = new OrxGui::GLGuiSlider();
     477        lightPosX->setRange(-600, 600);
     478        lightPosX->setValue(this->lightPos.x);
     479        lightPosX->setStep(15);
     480        lightPosX->connect(SIGNAL(lightPosX, valueChanged), this, SLOT(MappedWater, resetLightPosX));
     481        lightPosBox->pack(lightPosX);
     482
     483        OrxGui::GLGuiSlider* lightPosY = new OrxGui::GLGuiSlider();
     484        lightPosY->setRange(-600, 600);
     485        lightPosY->setStep(15);
     486        lightPosY->setValue(this->lightPos.y);
     487        lightPosY->connect(SIGNAL(lightPosY, valueChanged), this, SLOT(MappedWater, resetLightPosY));
     488        lightPosBox->pack(lightPosY);
     489
     490        OrxGui::GLGuiSlider* lightPosZ = new OrxGui::GLGuiSlider();
     491        lightPosZ->setRange(-600, 600);
     492        lightPosZ->setStep(15);
     493        lightPosZ->setValue(this->lightPos.z);
     494        lightPosZ->connect(SIGNAL(lightPosZ, valueChanged), this, SLOT(MappedWater, resetLightPosZ));
     495        lightPosBox->pack(lightPosZ);
     496      }
     497      this->box->pack(lightPosBox);
     498
     499      OrxGui::GLGuiBox* waterHeightBox = new OrxGui::GLGuiBox(OrxGui::Horizontal);
     500      {
     501        OrxGui::GLGuiInputLine* waterHeightText = new OrxGui::GLGuiInputLine();
     502        waterHeightText->setText("WaterHeight");
     503        waterHeightBox->pack(waterHeightText);
     504
     505        OrxGui::GLGuiSlider* waterHeight = new OrxGui::GLGuiSlider();
     506        waterHeight->setRange(-500, 500);
     507        waterHeight->setValue(this->waterHeight);
     508        waterHeight->setStep(10);
     509        waterHeight->connect(SIGNAL(waterHeight, valueChanged), this, SLOT(MappedWater, setWaterHeight));
     510        waterHeightBox->pack(waterHeight);
     511      }
     512      this->box->pack(waterHeightBox);
     513    }
     514
     515    this->box->showAll();
     516    this->box->setAbsCoor2D(300, 40);
     517    OrxGui::GLGuiHandler::getInstance()->activate();
     518    OrxGui::GLGuiHandler::getInstance()->activateCursor();
     519  }
     520}
     521
     522/**
     523 * @brief closes the water gui
     524 */
     525void MappedWater::closeGui()
     526{
     527  delete this->box;
     528  this->box = NULL;
    224529}
    225530
     
    230535{
    231536  glMatrixMode(GL_MODELVIEW);
    232 
    233537  glPushMatrix();
    234   // don't use a glTranslate here, the reflection point won't be at the right place anymore
    235   glRotatef(this->waterAngle, 0, 1, 0);
     538
     539  // don't use glRotate or glTranslate here... the shader won't work anymore
    236540
    237541  mat.select();
     
    247551  glBegin(GL_QUADS);
    248552  // The back left vertice for the water
    249   glMultiTexCoord2f(GL_TEXTURE0, 0, waterUV);            // Reflection texture
    250   glMultiTexCoord2f(GL_TEXTURE1, 0, waterUV - move);        // Refraction texture
    251   glMultiTexCoord2f(GL_TEXTURE2, 0, normalUV + move2);     // Normal map texture
    252   glMultiTexCoord2f(GL_TEXTURE3, 0, 0);                       // DUDV map texture
    253   glVertex3f(this->waterPos.x, this->waterPos.y, this->waterPos.z);
     553  glMultiTexCoord2f(GL_TEXTURE0, 0, waterUV);                   // Reflection texture
     554  glMultiTexCoord2f(GL_TEXTURE1, 0, waterUV - move);            // Refraction texture
     555  glMultiTexCoord2f(GL_TEXTURE2, 0, normalUV + move2);          // Normal map texture
     556  glMultiTexCoord2f(GL_TEXTURE3, 0, 0);                         // DUDV map texture
     557  glVertex3f(this->waterVerts[0], this->waterHeight, this->waterVerts[1]);
    254558
    255559  // The front left vertice for the water
    256   glMultiTexCoord2f(GL_TEXTURE0, 0, 0);                  // Reflection texture
    257   glMultiTexCoord2f(GL_TEXTURE1, 0, -move);           // Refraction texture
    258   glMultiTexCoord2f(GL_TEXTURE2, 0, move2);          // Normal map texture
    259   glMultiTexCoord2f(GL_TEXTURE3, 0, 0);                        // DUDV map texture
    260   glVertex3f(this->waterPos.x, this->waterPos.y, this->waterPos.z + this->zWidth);
     560  glMultiTexCoord2f(GL_TEXTURE0, 0, 0);                         // Reflection texture
     561  glMultiTexCoord2f(GL_TEXTURE1, 0, -move);                     // Refraction texture
     562  glMultiTexCoord2f(GL_TEXTURE2, 0, move2);                     // Normal map texture
     563  glMultiTexCoord2f(GL_TEXTURE3, 0, 0);                         // DUDV map texture
     564  glVertex3f(this->waterVerts[2], this->waterHeight, this->waterVerts[3]);
    261565
    262566  // The front right vertice for the water
    263   glMultiTexCoord2f(GL_TEXTURE0, waterUV, 0);             // Reflection texture
    264   glMultiTexCoord2f(GL_TEXTURE1, waterUV, -move);         // Refraction texture
    265   glMultiTexCoord2f(GL_TEXTURE2, normalUV, move2);      // Normal map texture
    266   glMultiTexCoord2f(GL_TEXTURE3, 0, 0);                        // DUDV map texture
    267   glVertex3f(this->waterPos.x + this->xWidth, this->waterPos.y, this->waterPos.z + this->zWidth);
     567  glMultiTexCoord2f(GL_TEXTURE0, waterUV, 0);                   // Reflection texture
     568  glMultiTexCoord2f(GL_TEXTURE1, waterUV, -move);               // Refraction texture
     569  glMultiTexCoord2f(GL_TEXTURE2, normalUV, move2);              // Normal map texture
     570  glMultiTexCoord2f(GL_TEXTURE3, 0, 0);                         // DUDV map texture
     571  glVertex3f(this->waterVerts[4], this->waterHeight, this->waterVerts[5]);
    268572
    269573  // The back right vertice for the water
    270   glMultiTexCoord2f(GL_TEXTURE0, waterUV, waterUV);        // Reflection texture
    271   glMultiTexCoord2f(GL_TEXTURE1, waterUV, waterUV - move);       // Refraction texture
    272   glMultiTexCoord2f(GL_TEXTURE2, normalUV, normalUV + move2);  // Normal map texture
    273   glMultiTexCoord2f(GL_TEXTURE3, 0, 0);                        // DUDV map texture
    274   glVertex3f(this->waterPos.x + this->xWidth, this->waterPos.y, this->waterPos.z);
     574  glMultiTexCoord2f(GL_TEXTURE0, waterUV, waterUV);             // Reflection texture
     575  glMultiTexCoord2f(GL_TEXTURE1, waterUV, waterUV - move);      // Refraction texture
     576  glMultiTexCoord2f(GL_TEXTURE2, normalUV, normalUV + move2);   // Normal map texture
     577  glMultiTexCoord2f(GL_TEXTURE3, 0, 0);                         // DUDV map texture
     578  glVertex3f(this->waterVerts[6], this->waterHeight, this->waterVerts[7]);
    275579  glEnd();
    276580
     
    290594  this->move += this->waterFlow * dt;
    291595  this->move2 = this->move * this->kNormalMapScale;
    292  
    293 
    294 //   if(this->tempcounter == 200) {
    295 //     this->resetWaterColor(1, 0, 0);
    296 //     resetShininess(1);
    297 //     resetLightPos(0, 50, 0);
    298 //     PRINTF(0)("test waterchangecolor ");
    299 //     }
    300 //   tempcounter++;
    301    
     596
     597  // fading TODO fix this so it isnt hacky anymore
     598  if(bFadeWaterUV)
     599  {
     600    this->waterUVFader = new tAnimation<MappedWater>(this, &MappedWater::setWaterUV);
     601    this->waterUVFader->setInfinity(ANIM_INF_CONSTANT);
     602
     603    this->waterUVFader->addKeyFrame(this->waterUV, this->waterUVFadeTime, ANIM_LINEAR);
     604    this->waterUVFader->addKeyFrame(this->newWaterUV, 0, ANIM_LINEAR);
     605
     606    bFadeWaterUV = false;
     607    this->waterUVFader->replay();
     608  }
     609
     610  if(bFadeWaterFlow)
     611  {
     612    this->waterFlowFader = new tAnimation<MappedWater>(this, &MappedWater::setWaterFlow);
     613    this->waterFlowFader->setInfinity(ANIM_INF_CONSTANT);
     614
     615    this->waterFlowFader->addKeyFrame(this->waterFlow, this->waterFlowFadeTime, ANIM_LINEAR);
     616    this->waterFlowFader->addKeyFrame(this->newWaterFlow, 0, ANIM_LINEAR);
     617
     618    bFadeWaterFlow = false;
     619    this->waterFlowFader->replay();
     620  }
     621
     622  if(bFadeShineSize)
     623  {
     624    this->shineSizeFader = new tAnimation<MappedWater>(this, &MappedWater::resetShineSize);
     625    this->shineSizeFader->setInfinity(ANIM_INF_CONSTANT);
     626
     627    this->shineSizeFader->addKeyFrame(this->shineSize, this->shineSizeFadeTime, ANIM_LINEAR);
     628    this->shineSizeFader->addKeyFrame(this->newShineSize, 0, ANIM_LINEAR);
     629
     630    bFadeShineSize = false;
     631    this->shineSizeFader->replay();
     632  }
     633
     634  if(bFadeShineStrength)
     635  {
     636    this->shineStrengthFader = new tAnimation<MappedWater>(this, &MappedWater::resetShineStrength);
     637    this->shineStrengthFader->setInfinity(ANIM_INF_CONSTANT);
     638
     639    this->shineStrengthFader->addKeyFrame(this->shineStrength, this->shineStrengthFadeTime, ANIM_LINEAR);
     640    this->shineStrengthFader->addKeyFrame(this->newShineStrength, 0, ANIM_LINEAR);
     641
     642    bFadeShineStrength = false;
     643    this->shineStrengthFader->replay();
     644  }
     645
     646  if(bFadeReflStrength)
     647  {
     648    this->reflStrengthFader = new tAnimation<MappedWater>(this, &MappedWater::resetReflStrength);
     649    this->reflStrengthFader->setInfinity(ANIM_INF_CONSTANT);
     650
     651    this->reflStrengthFader->addKeyFrame(this->reflStrength, this->reflStrengthFadeTime, ANIM_LINEAR);
     652    this->reflStrengthFader->addKeyFrame(this->newReflStrength, 0, ANIM_LINEAR);
     653
     654    bFadeReflStrength = false;
     655    this->reflStrengthFader->replay();
     656  }
     657
     658  if(bFadeRefraction)
     659  {
     660    this->refractionFader = new tAnimation<MappedWater>(this, &MappedWater::resetRefraction);
     661    this->refractionFader->setInfinity(ANIM_INF_CONSTANT);
     662
     663    this->refractionFader->addKeyFrame(this->refraction, this->refractionFadeTime, ANIM_LINEAR);
     664    this->refractionFader->addKeyFrame(this->newRefraction, 0, ANIM_LINEAR);
     665
     666    bFadeRefraction = false;
     667    this->refractionFader->replay();
     668  }
     669
     670  if(bFadeWaterHeight)
     671  {
     672    this->waterHeightFader = new tAnimation<MappedWater>(this, &MappedWater::setWaterHeight);
     673    this->waterHeightFader->setInfinity(ANIM_INF_CONSTANT);
     674
     675    this->waterHeightFader->addKeyFrame(this->waterHeight, this->waterHeightFadeTime, ANIM_LINEAR);
     676    this->waterHeightFader->addKeyFrame(this->newWaterHeight, 0, ANIM_LINEAR);
     677
     678    bFadeWaterHeight = false;
     679    this->waterHeightFader->replay();
     680  }
     681
     682  if(bFadeWaterColor)
     683  {
     684    this->waterColorRFader = new tAnimation<MappedWater>(this, &MappedWater::resetWaterColorR);
     685    this->waterColorRFader->setInfinity(ANIM_INF_CONSTANT);
     686
     687    this->waterColorRFader->addKeyFrame(this->waterColor.x, this->waterColorFadeTime, ANIM_LINEAR);
     688    this->waterColorRFader->addKeyFrame(this->newWaterColor.x, 0, ANIM_LINEAR);
     689
     690    this->waterColorRFader->replay();
     691
     692    this->waterColorGFader = new tAnimation<MappedWater>(this, &MappedWater::resetWaterColorG);
     693    this->waterColorGFader->setInfinity(ANIM_INF_CONSTANT);
     694
     695    this->waterColorGFader->addKeyFrame(this->waterColor.y, this->waterColorFadeTime, ANIM_LINEAR);
     696    this->waterColorGFader->addKeyFrame(this->newWaterColor.y, 0, ANIM_LINEAR);
     697
     698    this->waterColorGFader->replay();
     699
     700    this->waterColorBFader = new tAnimation<MappedWater>(this, &MappedWater::resetWaterColorB);
     701    this->waterColorBFader->setInfinity(ANIM_INF_CONSTANT);
     702
     703    this->waterColorBFader->addKeyFrame(this->waterColor.z, this->waterColorFadeTime, ANIM_LINEAR);
     704    this->waterColorBFader->addKeyFrame(this->newWaterColor.z, 0, ANIM_LINEAR);
     705
     706    this->waterColorBFader->replay();
     707
     708    bFadeWaterColor = false;
     709  }
    302710}
    303711
     
    330738  Vector pos = State::getCameraNode()->getAbsCoor();
    331739
    332   if(pos.y > waterPos.y)
     740  if(pos.y > waterHeight)
    333741  {
    334742    // Translate the world, then flip it upside down
    335     glTranslatef(0, waterPos.y*2, 0);
     743    glTranslatef(0, waterHeight * 2, 0);
    336744    glScalef(1, -1, 1);
    337745
     
    340748
    341749    // Set our plane equation and turn clipping on
    342     double plane[4] = {0, 1, 0, -waterPos.y};
     750    double plane[4] = {0, 1, 0, -waterHeight};
    343751    glClipPlane(GL_CLIP_PLANE0, plane);
    344752  }
     
    347755    // If the camera is below the water we don't want to flip the world,
    348756    // but just render it clipped so only the top is drawn.
    349     double plane[4] = {0, 1, 0, waterPos.y};
     757    double plane[4] = {0, 1, 0, waterHeight};
    350758    glClipPlane(GL_CLIP_PLANE0, plane);
    351759  }
     
    392800  glEnable(GL_CLIP_PLANE0);
    393801  Vector pos = State::getCameraNode()->getAbsCoor();
    394   if(pos.y > waterPos.y)
    395   {
    396     double plane[4] = {0, -1, 0, waterPos.y};
     802  if(pos.y > waterHeight)
     803  {
     804    double plane[4] = {0, -1, 0, waterHeight};
    397805    glClipPlane(GL_CLIP_PLANE0, plane);
    398806  }
     
    401809  {
    402810    glCullFace(GL_FRONT);
    403     double plane[4] = {0, 1, 0, -waterPos.y};
     811    double plane[4] = {0, 1, 0, -waterHeight};
    404812    glClipPlane(GL_CLIP_PLANE0, plane);
    405813  }
  • trunk/src/world_entities/environments/mapped_water.h

    r8792 r9006  
    1 /*!
     1 /*!
    22 * @file mapped_water.h
    33 *  worldentity for flat, cool looking, mapped water
     
    1212  <waterangle>0</waterangle>
    1313  <normalmapscale>0.25</normalmapscale><!-- you won't see a big differnce if you change that -->
    14   <shininess>128</shininess><!-- the bigger the value, the smaller the specular reflection point -->
     14  <shinesize>128</shinesize><!-- the bigger the value, the smaller the specular reflection point -->
     15  <shinestrength>0.7</shinestrength>
     16  <reflstrength>1</reflstrength>
     17  <refraction>0.009</refraction>
    1518  <watercolor>0.1, 0.2, 0.4</watercolor>
    1619</MappedWater>
     
    2528#include "shader.h"
    2629
     30namespace OrxGui { class GLGuiBox; };
     31
     32// forward declaration
     33template <class T> class tAnimation;
    2734
    2835class MappedWater : public WorldEntity
     
    3239  virtual ~MappedWater();
    3340
     41  // worldentity functions
    3442  void loadParams(const TiXmlElement* root);
    35 
     43  void saveParams();
    3644  void draw() const;
    3745  void tick(float dt);
     
    4351  void deactivateRefraction();
    4452
     53  // slider gui to edit water params during gameplay
     54  void openGui();
     55  void closeGui();
     56
    4557  // functions to set parameters for the water, usually they're called through loadparam
    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->waterPos = Vector(x,y,z); };
    48   void setWaterSize(float x, float z) { this->xWidth = x; this->zWidth = z; };
    49   void setWaterAngle(float angle) { this->waterAngle = angle; };
    50   void setWaterUV(float uv) { this->waterUV = uv; };
    51   void setWaterFlow(float flow) { this->waterFlow = flow; };
    52   void setNormalMapScale(float scale) { this->kNormalMapScale = scale; };
    53   void setShininess(float shine) { this->shininess = shine; };
    54   void setWaterColor(float r, float g, float b) { this->waterColor = Vector(r,g,b); };
     58  void setLightPos(float x, float y, float z) { this->lightPos = Vector(x,y,z); }
     59  void setWaterPos(float x, float y, float z) { this->waterHeight = y; this->waterVerts[0] = x; this->waterVerts[1] = z; }
     60  void setWaterHeight(float y) { this->waterHeight = y;  }
     61  void setWaterSize(float x, float z) { this->xWidth = x; this->zWidth = z; }
     62  void setWaterAngle(float angle) { this->waterAngle = angle; }
     63  void setWaterColor(float r, float g, float b) { this->waterColor = Vector(r,g,b); }
     64  void setWaterUV(float uv) { this->waterUV = uv; }
     65  void setWaterFlow(float flow) { this->waterFlow = flow; }
     66  void setNormalMapScale(float scale) { this->kNormalMapScale = scale; }
     67  void setShineSize(float shine) { this->shineSize = shine; }
     68  void setShineStrength(float strength) { this->shineStrength = strength; }
     69  void setReflStrength(float strength) { this->reflStrength = strength; }
     70  void setRefraction(float refraction) { this->refraction = refraction; }
    5571
    5672  // functions to change water parameters during runtime
    5773  // to reset waterUV and waterFlow just use the normal set functions
     74  // don't reset kNormalMapScale (because it won't change anything)
     75  void resetLightPos(float x, float y, float z);
     76  void resetLightPosX(float x) { this->resetLightPos(x, this->lightPos.y, this->lightPos.z); }
     77  void resetLightPosY(float y) { this->resetLightPos(this->lightPos.x, y, this->lightPos.z); }
     78  void resetLightPosZ(float z) { this->resetLightPos(this->lightPos.x, this->lightPos.y, z); }
     79  void resetWaterPos(float x, float y, float z) { this->setWaterPos(x, y, z); this->calcVerts(); }
     80  void resetWaterSize(float x, float z) { this->setWaterSize(x, z); this->calcVerts(); }
     81  void resetWaterAngle(float angle) { this->setWaterAngle(angle); this->calcVerts(); }
    5882  void resetWaterColor(float r, float g, float b);
    59   void resetShininess(float shine);
    60   void resetLightPos(float x, float y, float z);
     83  void resetWaterColorR(float r) { this->resetWaterColor(r, this->waterColor.y, this->waterColor.z); }
     84  void resetWaterColorG(float g) { this->resetWaterColor(this->waterColor.x, g, this->waterColor.z); }
     85  void resetWaterColorB(float b) { this->resetWaterColor(this->waterColor.x, this->waterColor.y, b); }
     86  void resetShineSize(float shine);
     87  void resetShineStrength(float strength);
     88  void resetReflStrength(float strength);
     89  void resetRefraction(float refraction);
    6190
    62   // fade functions
    63   void fadeWaterColor(float r, float g, float b, float time);
    64   void fadeShininess(float shine, float time);
    65   void fadeLightPos(float x, float y, float z, float time);
     91  // fading functions
     92  void fadeWaterUV(float uv, float time) { this->newWaterUV = uv; this->waterUVFadeTime = time; this->bFadeWaterUV = true; }
     93  void fadeWaterFlow(float flow, float time) { this->newWaterFlow = flow; this->waterFlowFadeTime = time; this->bFadeWaterFlow = true; }
     94  void fadeShineSize(float shine, float time) { this->newShineSize = shine; this->shineSizeFadeTime = time; this->bFadeShineSize = true; }
     95  void fadeShineStrength(float strength, float time) { this->newShineStrength = strength; this->shineStrengthFadeTime = time; this->bFadeShineStrength = true; }
     96  void fadeReflStrength(float strength, float time) { this->newReflStrength = strength; this->reflStrengthFadeTime = time; this->bFadeReflStrength = true; }
     97  void fadeRefraction(float refraction, float time) { this->newRefraction = refraction; this->refractionFadeTime = time; this->bFadeRefraction = true; }
     98  void fadeWaterHeight(float y, float time) { this->newWaterHeight = y; this->waterHeightFadeTime = time; this->bFadeWaterHeight = true; }
     99  void fadeWaterColor(float r, float g, float b, float time) { this->newWaterColor = Vector(r, g, b); this->waterColorFadeTime = time; this->bFadeWaterColor = true; }
    66100
    67101private:
     
    69103  void initTextures();
    70104  void initShaders();
     105  void calcVerts();
    71106
    72107private:
    73   Vector              waterPos;               //!< position of the water
    74   float               xWidth, zWidth;         //!< size of the water quad
    75   Vector              lightPos;               //!< position of the light that is used to render the reflection
    76   float               waterAngle;             //!< defines how much the water will be turned around the point waterPos
    77   Vector              waterColor;             //!< color of the water
    78   float               move;                   //!< textures coords, speeds, positions for the shaded textures....
    79   float               move2;
    80   float               waterUV;                //!< size of the waves
    81   float               waterFlow;              //!< speed of the water
    82   float               normalUV;
    83   float               kNormalMapScale;
    84   float               shininess;              //!< the bigger the value, the smaller the specular reflection point
     108  Material                  mat;
     109  Shader*                   shader;
     110  OrxGui::GLGuiBox*         box;
    85111
    86   int                 textureSize;            //!< height and width of the texture
    87   Material            mat;
    88   Shader*             shader;
    89   Shader::Uniform*    cam_uni;                //!< uniform that is used for the camera position
    90   Shader::Uniform*    light_uni;              //!< uniform that is used for the light position
    91   Shader::Uniform*    color_uni;              //!< uniform that is used for the watercolor
    92   Shader::Uniform*    shine_uni;              //!< uniform that is used for the specular shininessd of the water
    93  
    94  
    95   int tempcounter;
     112  // water size and position
     113  float                     waterHeight;            //!< position of the water
     114  float                     waterVerts[8];          //!< coords of the 4 vertexes of the water quad
     115  float                     xWidth, zWidth;         //!< size of the water quad
     116  float                     waterAngle;             //!< defines how much the water will be turned around the point waterPos
     117
     118  // values for texture size, scale, texture coords
     119  float                     move;
     120  float                     move2;
     121  float                     waterUV;                //!< size of the waves
     122  float                     waterFlow;              //!< speed of the water
     123  float                     normalUV;
     124  float                     kNormalMapScale;
     125  int                       textureSize;            //!< height and width of the texture
     126
     127  // values for the uniforms
     128  Vector                    waterColor;             //!< color of the water
     129  Vector                    lightPos;               //!< position of the light that is used to render the reflection
     130  float                     shineSize;              //!< the bigger the value, the smaller the specular reflection point
     131  float                     shineStrength;
     132  float                     reflStrength;
     133  float                     refraction;
     134
     135  // uniforms
     136  Shader::Uniform*          cam_uni;                //!< uniform that is used for the camera position
     137  Shader::Uniform*          light_uni;              //!< uniform that is used for the light position
     138  Shader::Uniform*          color_uni;              //!< uniform that is used for the watercolor
     139  Shader::Uniform*          shineSize_uni;          //!< uniform that is used for the specular shininessd of the water
     140  Shader::Uniform*          shineStrength_uni;      //!< uniform that is used for the strenght of the specular reflection
     141  Shader::Uniform*          reflStrength_uni;       //!< uniform that is used for the strength of the reflection
     142  Shader::Uniform*          refr_uni;               //!< uniform that is used for the strength of the refraction
     143
     144  // fading TODO fix this so it isnt so hacky anymore
     145  tAnimation<MappedWater>*  waterUVFader;
     146  float                     newWaterUV;
     147  float                     waterUVFadeTime;
     148  bool                      bFadeWaterUV ;
     149  tAnimation<MappedWater>*  waterFlowFader;
     150  float                     newWaterFlow;
     151  float                     waterFlowFadeTime;
     152  bool                      bFadeWaterFlow;
     153  tAnimation<MappedWater>*  shineSizeFader;
     154  float                     newShineSize;
     155  float                     shineSizeFadeTime;
     156  bool                      bFadeShineSize;
     157  tAnimation<MappedWater>*  shineStrengthFader;
     158  float                     newShineStrength;
     159  float                     shineStrengthFadeTime;
     160  bool                      bFadeShineStrength;
     161  tAnimation<MappedWater>*  reflStrengthFader;
     162  float                     newReflStrength;
     163  float                     reflStrengthFadeTime;
     164  bool                      bFadeReflStrength;
     165  tAnimation<MappedWater>*  refractionFader;
     166  float                     newRefraction;
     167  float                     refractionFadeTime;
     168  bool                      bFadeRefraction;
     169  tAnimation<MappedWater>*  waterHeightFader;
     170  float                     newWaterHeight;
     171  float                     waterHeightFadeTime;
     172  bool                      bFadeWaterHeight;
     173  tAnimation<MappedWater>*  waterColorRFader;
     174  tAnimation<MappedWater>*  waterColorGFader;
     175  tAnimation<MappedWater>*  waterColorBFader;
     176  Vector                    newWaterColor;
     177  float                     waterColorFadeTime;
     178  bool                      bFadeWaterColor;
    96179};
    97180
Note: See TracChangeset for help on using the changeset viewer.