Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 9006 in orxonox.OLD for trunk


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
Files:
2 deleted
19 edited
2 copied

Legend:

Unmodified
Added
Removed
  • trunk/src/Makefile.am

    r8271 r9006  
    4646                lib/graphics/effects/snow_effect.cc \
    4747                lib/graphics/effects/cloud_effect.cc \
    48                 lib/graphics/effects/lightening_effect.cc \
     48                lib/graphics/effects/lightning_effect.cc \
    4949                lib/graphics/effects/lense_flare.cc \
    5050                \
  • trunk/src/defs/class_id.h

    r9003 r9006  
    336336  CL_SNOW_EFFECT                =    0x00000a14,
    337337  CL_CLOUD_EFFECT               =    0x00000a15,
    338   CL_LIGHTENING_EFFECT          =    0x00000a16,
     338  CL_LIGHTNING_EFFECT          =    0x00000a16,
    339339  CL_EXPLOSION                  =    0x00000a20,
    340340  CL_LIGHTNING_BOLT             =    0x00000a21,
  • trunk/src/lib/graphics/Makefile.am

    r8751 r9006  
    2929                effects/snow_effect.cc \
    3030                effects/cloud_effect.cc \
    31                 effects/lightening_effect.cc \
     31                effects/lightning_effect.cc \
    3232                effects/lense_flare.cc
    3333
     
    5858                effects/snow_effect.h \
    5959                effects/cloud_effect.h \
    60                 effects/lightening_effect.h \
     60                effects/lightning_effect.h \
    6161                effects/lense_flare.h
    6262
  • trunk/src/lib/graphics/effects/cloud_effect.cc

    r8793 r9006  
    11/*
    22  orxonox - the future of 3D-vertical-scrollers
    3  
     3
    44  Copyright (C) 2004 orx
    5  
     5
    66  This program is free software; you can redistribute it and/or modify
    77  it under the terms of the GNU General Public License as published by
    88  the Free Software Foundation; either version 2, or (at your option)
    99  any later version.
    10  
     10
    1111### File Specific:
    1212  main-programmer: hdavid, amaechler
    13  
     13
    1414  INSPIRED BY http://www.codesampler.com/usersrc/usersrc_6.htm#oglu_sky_dome_shader
    1515*/
     
    2626#include "shader.h"
    2727#include "shell_command.h"
     28#include "t_animation.h"
     29#include "script_class.h"
    2830
    2931#include "parser/tinyxml/tinyxml.h"
    3032
    31 Vector  CloudEffect::cloudColor;
    32 Vector  CloudEffect::skyColor;
    33 Vector  CloudEffect::newCloudColor;
    34 Vector  CloudEffect::newSkyColor;
     33Vector    CloudEffect::cloudColor;
     34Vector    CloudEffect::skyColor;
     35Vector    CloudEffect::newCloudColor;
     36Vector    CloudEffect::newSkyColor;
     37
     38bool      CloudEffect::fadeSky;
     39bool      CloudEffect::fadeCloud;
     40float     CloudEffect::fadeTime;
     41bool      CloudEffect::flashSkyActivate;
     42float     CloudEffect::localTimer;
     43float     CloudEffect::flashTime;
    3544
    3645using namespace std;
     
    3847SHELL_COMMAND(activate, CloudEffect, activateCloud);
    3948SHELL_COMMAND(deactivate, CloudEffect, deactivateCloud);
     49SHELL_COMMAND(skyColor, CloudEffect, shellSkyColor);
     50SHELL_COMMAND(cloudColor, CloudEffect, shellCloudColor);
     51
     52
     53CREATE_SCRIPTABLE_CLASS(CloudEffect, CL_CLOUD_EFFECT,
     54                        addMethod("skyColor", ExecutorLua4<CloudEffect,float,float,float,float>(&CloudEffect::shellSkyColor))
     55                      ->addMethod("cloudColor", ExecutorLua4<CloudEffect,float,float,float,float>(&CloudEffect::shellCloudColor))
     56                       );
     57
    4058
    4159CREATE_FACTORY(CloudEffect, CL_CLOUD_EFFECT);
    4260
    43 CloudEffect::CloudEffect(const TiXmlElement* root)
    44 {
    45   this->setClassID(CL_CLOUD_EFFECT, "CloudEffect");
    46 
    47   this->init();
    48 
    49   if (root != NULL)
    50     this->loadParams(root);
    51 
    52   if(cloudActivate)
    53     this->activate();
    54 }
    55 
    56 CloudEffect::~CloudEffect()
    57 {
    58   this->deactivate();
    59 
    60   if (glIsTexture(noise3DTexName))
    61     glDeleteTextures(1, &noise3DTexName);
    62 
    63   delete shader;
    64 }
    65 
    66 
    67 void CloudEffect::init()
    68 {
    69   PRINTF(0)("Initializing CloudEffect\n");
    70 
    71   this->offsetZ = 0;
    72   this->animationSpeed = 2;
    73   this->scale = 0.0004f;
    74   this->atmosphericRadius = 4000;
    75   this->planetRadius = 1500;
    76   this->divs = 50;
    77 
    78   skyColor = Vector(0.0f, 0.0f, 0.8f);
    79   cloudColor = Vector(0.8f, 0.8f, 0.8f);
    80   newSkyColor = skyColor;
    81   newCloudColor = cloudColor;
    82   this->fadeTime = 3;
    83 
    84   this->noise3DTexSize = 128;
    85   this->noise3DTexName = 0;
    86 
    87   this->make3DNoiseTexture();
    88 
    89   glGenTextures(1, &noise3DTexName);
    90   glBindTexture(GL_TEXTURE_3D, noise3DTexName);
    91 
    92   glTexParameterf(GL_TEXTURE_3D, GL_TEXTURE_WRAP_S, GL_REPEAT);
    93   glTexParameterf(GL_TEXTURE_3D, GL_TEXTURE_WRAP_T, GL_REPEAT);
    94   glTexParameterf(GL_TEXTURE_3D, GL_TEXTURE_WRAP_R, GL_REPEAT);
    95   glTexParameterf(GL_TEXTURE_3D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
    96   glTexParameterf(GL_TEXTURE_3D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
    97 
    98   glTexImage3D(GL_TEXTURE_3D, 0, GL_RGBA,
    99                noise3DTexSize, noise3DTexSize, noise3DTexSize,
    100                0, GL_RGBA, GL_UNSIGNED_BYTE, noise3DTexPtr);
    101 
    102   this->skydome = new Skydome();
    103   this->skydome->setTexture(noise3DTexName);
    104 
    105   this->shader = new Shader(ResourceManager::getInstance()->getDataDir() + "/shaders/cloud.vert",
    106                             ResourceManager::getInstance()->getDataDir() + "/shaders/cloud.frag");
    107 
    108   this->shader->activateShader();
    109 
    110   Shader::Uniform(shader, "Noise").set(0);
    111 
    112   this->offset = new Shader::Uniform(shader, "Offset");
    113   this->skycolor = new Shader::Uniform(shader, "SkyColor");
    114   this->cloudcolor = new Shader::Uniform(shader, "CloudColor");
    115 
    116   this->shader->deactivateShader();
    117 
    118   this->skydome->setShader(shader);
    119 }
    120 
    121 
    122 void CloudEffect::loadParams(const TiXmlElement* root)
    123 {
    124   WeatherEffect::loadParams(root);
    125 
    126   LoadParam(root, "speed", this, CloudEffect, setAnimationSpeed);
    127   LoadParam(root, "scale", this, CloudEffect, setCloudScale);
    128   LoadParam(root, "cloudcolor", this, CloudEffect, setCloudColor);
    129   LoadParam(root, "skycolor", this, CloudEffect, setSkyColor);
    130 
    131   LoadParam(root, "planetRadius", this, CloudEffect, setPlanetRadius);
    132   LoadParam(root, "atmosphericRadius", this, CloudEffect, setAtmosphericRadius);
    133   LoadParam(root, "divisions", this, CloudEffect, setDivisions);
    134 
    135   LOAD_PARAM_START_CYCLE(root, element);
    136   {
    137     LoadParam_CYCLE(element, "option", this, CloudEffect, setCloudOption);
    138   }
    139   LOAD_PARAM_END_CYCLE(element);
    140 }
    141 
    142 
    143 void CloudEffect::activate()
    144 {
    145   PRINTF(0)( "Activating\n");
    146 
    147   // Can only be set after the loadParams call
    148   this->shader->activateShader();
    149   Shader::Uniform(shader, "Scale").set(this->scale);
    150   this->skycolor->set(skyColor.x, skyColor.y, skyColor.z);
    151   this->cloudcolor->set(cloudColor.x, cloudColor.y, cloudColor.z);
    152   this->shader->deactivateShader();
    153 
    154   this->skydome->generateSkyPlane(this->divs, this->planetRadius, this->atmosphericRadius, 1, 1);
    155 
    156   this->cloudActivate = true;
    157 }
    158 
    159 void CloudEffect::deactivate()
    160 {
    161   PRINTF(0)("Deactivating CloudEffect\n");
    162 
    163   this->cloudActivate = false;
    164 }
    165 
    166 void CloudEffect::draw() const
    167   {}
    168 
    169 void CloudEffect::tick (float dt)
    170 {
    171   if (this->cloudActivate)
    172   {
    173     this->offsetZ += 0.05 * dt * this->animationSpeed;
     61CloudEffect::CloudEffect(const TiXmlElement* root) {
     62    this->setClassID(CL_CLOUD_EFFECT, "CloudEffect");
     63
     64    this->init();
     65
     66    if (root != NULL)
     67        this->loadParams(root);
     68
     69    if(cloudActivate)
     70        this->activate();
     71}
     72
     73CloudEffect::~CloudEffect() {
     74    this->deactivate();
     75
     76    if (glIsTexture(noise3DTexName))
     77        glDeleteTextures(1, &noise3DTexName);
     78
     79    delete shader;
     80}
     81
     82
     83void CloudEffect::init() {
     84    PRINTF(0)("Initializing CloudEffect\n");
     85
     86    // default values
     87    this->offsetZ = 0;
     88    this->animationSpeed = 2;
     89    this->scale = 0.0004f;
     90    this->atmosphericRadius = 4000;
     91    this->planetRadius = 1500;
     92    this->divs = 15;
     93    fadeSky = false;
     94    fadeCloud = false;
     95
     96    flashSkyActivate = false;
     97    localTimer = 0;
     98    flashTime = 0;
     99
     100    skyColor = Vector(0.0f, 0.0f, 0.8f);
     101    cloudColor = Vector(0.8f, 0.8f, 0.8f);
     102    newSkyColor = skyColor;
     103    newCloudColor = cloudColor;
     104
     105    this->noise3DTexSize = 128;
     106    this->noise3DTexName = 0;
     107
     108    this->make3DNoiseTexture();
     109
     110    glGenTextures(1, &noise3DTexName);
     111    glBindTexture(GL_TEXTURE_3D, noise3DTexName);
     112
     113    glTexParameterf(GL_TEXTURE_3D, GL_TEXTURE_WRAP_S, GL_REPEAT);
     114    glTexParameterf(GL_TEXTURE_3D, GL_TEXTURE_WRAP_T, GL_REPEAT);
     115    glTexParameterf(GL_TEXTURE_3D, GL_TEXTURE_WRAP_R, GL_REPEAT);
     116    glTexParameterf(GL_TEXTURE_3D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
     117    glTexParameterf(GL_TEXTURE_3D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
     118
     119    glTexImage3D(GL_TEXTURE_3D, 0, GL_RGBA,
     120                 noise3DTexSize, noise3DTexSize, noise3DTexSize,
     121                 0, GL_RGBA, GL_UNSIGNED_BYTE, noise3DTexPtr);
     122
     123    this->skydome = new Skydome();
     124    this->skydome->setTexture(noise3DTexName);
     125
     126    this->shader = new Shader(ResourceManager::getInstance()->getDataDir() + "/shaders/cloud.vert",
     127                              ResourceManager::getInstance()->getDataDir() + "/shaders/cloud.frag");
    174128
    175129    this->shader->activateShader();
    176     this->offset->set(0.0f, 0.0f, offsetZ);
    177    
    178     //if(cloudColor != newCloudColor)
    179     //{
    180       // TODO: fade from cloudColor to newCloudColor
    181       cloudColor = newCloudColor;
    182       this->cloudcolor->set(this->cloudColor.x, this->cloudColor.y, this->cloudColor.z);
    183     //}
    184     //if(cloudColor != newCloudColor)
    185     //{
    186       // TODO: fade from skyColor to newSkyColor
    187       skyColor = newSkyColor;
    188       this->skycolor->set(this->skyColor.x, this->skyColor.y, this->skyColor.z);
    189     //}
    190    
     130
     131    Shader::Uniform(shader, "Noise").set(0);
     132
     133    this->offset = new Shader::Uniform(shader, "Offset");
     134    this->skycolor = new Shader::Uniform(shader, "SkyColor");
     135    this->cloudcolor = new Shader::Uniform(shader, "CloudColor");
     136
    191137    this->shader->deactivateShader();
    192   }
    193 }
    194 
    195 
    196 void CloudEffect::changeSkyColor(Vector color)
    197 {
    198   newSkyColor = color;
    199 }
    200 
    201 
    202 void CloudEffect::changeCloudColor(Vector color)
    203 {
    204   newCloudColor = color;
    205 }
    206 
    207 
    208 void CloudEffect::make3DNoiseTexture()
    209 {
    210   int f, i, j, k, inc;
    211   int startFrequency = 4;
    212   int numOctaves = 4;
    213   double ni[3];
    214   double inci, incj, inck;
    215   int frequency = startFrequency;
    216   GLubyte *ptr;
    217   double amp = 0.5;
    218 
    219   if ((noise3DTexPtr = (GLubyte *) malloc(noise3DTexSize *
    220                                           noise3DTexSize *
    221                                           noise3DTexSize * 4)) == NULL)
    222     PRINTF(0)("ERROR: Could not allocate 3D noise texture\n");
    223 
    224   for (f=0, inc=0; f < numOctaves;
    225        ++f, frequency *= 2, ++inc, amp *= 0.5)
    226   {
    227     SetNoiseFrequency(frequency);
    228     ptr = noise3DTexPtr;
    229     ni[0] = ni[1] = ni[2] = 0;
    230 
    231     inci = 1.0 / (noise3DTexSize / frequency);
    232     for (i=0; i<noise3DTexSize; ++i, ni[0] += inci)
     138
     139    this->skydome->setShader(shader);
     140}
     141
     142
     143void CloudEffect::loadParams(const TiXmlElement* root) {
     144    WeatherEffect::loadParams(root);
     145
     146    LoadParam(root, "speed", this, CloudEffect, setAnimationSpeed);
     147    LoadParam(root, "scale", this, CloudEffect, setCloudScale);
     148    LoadParam(root, "cloudcolor", this, CloudEffect, setCloudColor);
     149    LoadParam(root, "skycolor", this, CloudEffect, setSkyColor);
     150
     151    LoadParam(root, "planetRadius", this, CloudEffect, setPlanetRadius);
     152    LoadParam(root, "atmosphericRadius", this, CloudEffect, setAtmosphericRadius);
     153    LoadParam(root, "divisions", this, CloudEffect, setDivisions);
     154
     155    LOAD_PARAM_START_CYCLE(root, element);
    233156    {
    234       incj = 1.0 / (noise3DTexSize / frequency);
    235       for (j=0; j<noise3DTexSize; ++j, ni[1] += incj)
    236       {
    237         inck = 1.0 / (noise3DTexSize / frequency);
    238         for (k=0; k<noise3DTexSize; ++k, ni[2] += inck, ptr+= 4)
    239         {
    240           *(ptr+inc) = (GLubyte) (((noise3(ni)+1.0) * amp)*128.0);
     157        LoadParam_CYCLE(element, "option", this, CloudEffect, setCloudOption);
     158    }
     159    LOAD_PARAM_END_CYCLE(element);
     160}
     161
     162
     163void CloudEffect::activate() {
     164    PRINTF(0)( "Activating\n");
     165
     166    // Can only be set after the loadParams call
     167    this->shader->activateShader();
     168    Shader::Uniform(shader, "Scale").set(this->scale);
     169    this->skycolor->set
     170    (skyColor.x, skyColor.y, skyColor.z);
     171    this->cloudcolor->set
     172    (cloudColor.x, cloudColor.y, cloudColor.z);
     173    this->shader->deactivateShader();
     174
     175    this->skydome->generateSkyPlane(this->divs, this->planetRadius, this->atmosphericRadius, 1, 1);
     176    this->skydome->activate();
     177
     178    this->cloudActivate = true;
     179}
     180
     181void CloudEffect::deactivate() {
     182    PRINTF(0)("Deactivating CloudEffect\n");
     183
     184    this->skydome->deactivate();
     185    this->cloudActivate = false;
     186}
     187
     188void CloudEffect::draw() const {}
     189
     190void CloudEffect::tick (float dt) {
     191
     192    if (this->cloudActivate) {
     193
     194        localTimer += dt;
     195
     196        this->offsetZ += 0.05 * dt * this->animationSpeed;
     197
     198        this->shader->activateShader();
     199        this->offset->set(0.0f, 0.0f, offsetZ);
     200
     201        if (flashSkyActivate) {
     202
     203            this->skycolor->set(1, 1, 1);
     204            PRINTF(0)("SkyColor set to white\n");
     205
     206            if (localTimer > flashTime) {
     207                flashSkyActivate = false;
     208                this->skycolor->set(this->skyColor.x, this->skyColor.y, this->skyColor.z);
     209                PRINTF(0)("SkyColor reset\n");
     210            }
     211
     212        } else {
     213
     214            if(cloudColor != newCloudColor) {
     215
     216                if(fadeCloud) {
     217
     218                    this->cloudColorFadeX = new tAnimation<CloudEffect>(this, &CloudEffect::setColorCloudX);
     219                    this->cloudColorFadeX->setInfinity(ANIM_INF_CONSTANT);
     220                    this->cloudColorFadeY = new tAnimation<CloudEffect>(this, &CloudEffect::setColorCloudY);
     221                    this->cloudColorFadeY->setInfinity(ANIM_INF_CONSTANT);
     222                    this->cloudColorFadeZ = new tAnimation<CloudEffect>(this, &CloudEffect::setColorCloudZ);
     223                    this->cloudColorFadeZ->setInfinity(ANIM_INF_CONSTANT);
     224
     225                    this->cloudColorFadeX->addKeyFrame(cloudColor.x, fadeTime, ANIM_LINEAR);
     226                    this->cloudColorFadeX->addKeyFrame(newCloudColor.x, 0, ANIM_LINEAR);
     227
     228                    this->cloudColorFadeY->addKeyFrame(cloudColor.y, fadeTime, ANIM_LINEAR);
     229                    this->cloudColorFadeY->addKeyFrame(newCloudColor.y, 0, ANIM_LINEAR);
     230
     231                    this->cloudColorFadeZ->addKeyFrame(cloudColor.z, fadeTime, ANIM_LINEAR);
     232                    this->cloudColorFadeZ->addKeyFrame(newCloudColor.z, 0, ANIM_LINEAR);
     233
     234                    fadeCloud = false;
     235
     236                    this->cloudColorFadeX->replay();
     237                    this->cloudColorFadeY->replay();
     238                    this->cloudColorFadeZ->replay();
     239                }
     240
     241                this->cloudcolor->set(this->cloudColor.x, this->cloudColor.y, this->cloudColor.z);
     242            }
     243
     244            if(skyColor != newSkyColor) {
     245
     246                if(fadeSky) {
     247
     248                    this->skyColorFadeX = new tAnimation<CloudEffect>(this, &CloudEffect::setColorSkyX);
     249                    this->skyColorFadeX->setInfinity(ANIM_INF_CONSTANT);
     250                    this->skyColorFadeY = new tAnimation<CloudEffect>(this, &CloudEffect::setColorSkyY);
     251                    this->skyColorFadeY->setInfinity(ANIM_INF_CONSTANT);
     252                    this->skyColorFadeZ = new tAnimation<CloudEffect>(this, &CloudEffect::setColorSkyZ);
     253                    this->skyColorFadeZ->setInfinity(ANIM_INF_CONSTANT);
     254
     255                    this->skyColorFadeX->addKeyFrame(skyColor.x, fadeTime, ANIM_LINEAR);
     256                    this->skyColorFadeX->addKeyFrame(newSkyColor.x, 0, ANIM_LINEAR);
     257
     258                    this->skyColorFadeY->addKeyFrame(skyColor.y, fadeTime, ANIM_LINEAR);
     259                    this->skyColorFadeY->addKeyFrame(newSkyColor.y, 0, ANIM_LINEAR);
     260
     261                    this->skyColorFadeZ->addKeyFrame(skyColor.z, fadeTime, ANIM_LINEAR);
     262                    this->skyColorFadeZ->addKeyFrame(newSkyColor.z, 0, ANIM_LINEAR);
     263
     264                    fadeSky = false;
     265
     266                    this->skyColorFadeX->replay();
     267                    this->skyColorFadeY->replay();
     268                    this->skyColorFadeZ->replay();
     269                }
     270
     271                this->skycolor->set(this->skyColor.x, this->skyColor.y, this->skyColor.z);
     272            }
    241273        }
    242       }
    243     }
    244   }
    245 }
    246 
    247 void CloudEffect::initNoise()
    248 {
    249   int i, j, k;
    250 
    251   srand(30757);
    252   for (i = 0 ; i < B ; i++)
    253   {
    254     p[i] = i;
    255     g1[i] = (double)((rand() % (B + B)) - B) / B;
    256 
    257     for (j = 0 ; j < 2 ; j++)
    258       g2[i][j] = (double)((rand() % (B + B)) - B) / B;
    259     normalize2(g2[i]);
    260 
    261     for (j = 0 ; j < 3 ; j++)
    262       g3[i][j] = (double)((rand() % (B + B)) - B) / B;
    263     normalize3(g3[i]);
    264   }
    265 
    266   while (--i)
    267   {
    268     k = p[i];
    269     p[i] = p[j = rand() % B];
    270     p[j] = k;
    271   }
    272 
    273   for (i = 0 ; i < B + 2 ; i++)
    274   {
    275     p[B + i] = p[i];
    276     g1[B + i] = g1[i];
    277     for (j = 0 ; j < 2 ; j++)
    278       g2[B + i][j] = g2[i][j];
    279     for (j = 0 ; j < 3 ; j++)
    280       g3[B + i][j] = g3[i][j];
    281   }
    282 }
    283 
    284 void CloudEffect::SetNoiseFrequency( int frequency)
    285 {
    286   start = 1;
    287   B = frequency;
    288   BM = B-1;
    289 }
    290 
    291 double CloudEffect::noise3( double vec[3])
    292 {
    293   int bx0, bx1, by0, by1, bz0, bz1, b00, b10, b01, b11;
    294   double rx0, rx1, ry0, ry1, rz0, rz1, *q, sy, sz, a, b, c, d, t, u, v;
    295   int i, j;
    296 
    297   if (start)
    298   {
    299     start = 0;
    300     initNoise();
    301   }
    302 
    303   setup(0, bx0,bx1, rx0,rx1);
    304   setup(1, by0,by1, ry0,ry1);
    305   setup(2, bz0,bz1, rz0,rz1);
    306 
    307   i = p[ bx0 ];
    308   j = p[ bx1 ];
    309 
    310   b00 = p[ i + by0 ];
    311   b10 = p[ j + by0 ];
    312   b01 = p[ i + by1 ];
    313   b11 = p[ j + by1 ];
    314 
    315   t  = s_curve(rx0);
    316   sy = s_curve(ry0);
    317   sz = s_curve(rz0);
    318 
    319   q = g3[ b00 + bz0 ] ; u = at3(rx0,ry0,rz0);
    320   q = g3[ b10 + bz0 ] ; v = at3(rx1,ry0,rz0);
    321   a = lerp(t, u, v);
    322 
    323   q = g3[ b01 + bz0 ] ; u = at3(rx0,ry1,rz0);
    324   q = g3[ b11 + bz0 ] ; v = at3(rx1,ry1,rz0);
    325   b = lerp(t, u, v);
    326 
    327   c = lerp(sy, a, b);
    328 
    329   q = g3[ b00 + bz1 ] ; u = at3(rx0,ry0,rz1);
    330   q = g3[ b10 + bz1 ] ; v = at3(rx1,ry0,rz1);
    331   a = lerp(t, u, v);
    332 
    333   q = g3[ b01 + bz1 ] ; u = at3(rx0,ry1,rz1);
    334   q = g3[ b11 + bz1 ] ; v = at3(rx1,ry1,rz1);
    335   b = lerp(t, u, v);
    336 
    337   d = lerp(sy, a, b);
    338 
    339   return lerp(sz, c, d);
    340 }
    341 
    342 void CloudEffect::normalize2( double v[2])
    343 {
    344   double s;
    345 
    346   s = sqrt(v[0] * v[0] + v[1] * v[1]);
    347   v[0] = v[0] / s;
    348   v[1] = v[1] / s;
    349 }
    350 
    351 void CloudEffect::normalize3( double v[3])
    352 {
    353   double s;
    354 
    355   s = sqrt(v[0] * v[0] + v[1] * v[1] + v[2] * v[2]);
    356   v[0] = v[0] / s;
    357   v[1] = v[1] / s;
    358   v[2] = v[2] / s;
    359 }
    360 
     274
     275        this->shader->deactivateShader();
     276    }
     277}
     278
     279
     280void CloudEffect::setColorSkyX(float color) {
     281    skyColor.x = color;
     282}
     283void CloudEffect::setColorSkyY(float color) {
     284    skyColor.y = color;
     285}
     286void CloudEffect::setColorSkyZ(float color) {
     287    skyColor.z = color;
     288}
     289void CloudEffect::setColorCloudX(float color) {
     290    cloudColor.x = color;
     291}
     292void CloudEffect::setColorCloudY(float color) {
     293    cloudColor.y = color;
     294}
     295void CloudEffect::setColorCloudZ(float color) {
     296    cloudColor.z = color;
     297}
     298
     299void CloudEffect::changeSkyColor(Vector color, float time) {
     300    newSkyColor = color;
     301    fadeSky = true;
     302    fadeTime = time;
     303}
     304
     305
     306void CloudEffect::changeCloudColor(Vector color, float time) {
     307    newCloudColor = color;
     308    fadeCloud = true;
     309    fadeTime = time;
     310}
     311
     312void CloudEffect::shellSkyColor(float colorX, float colorY, float colorZ, float time) {
     313    changeSkyColor( Vector(colorX, colorY, colorZ), time);
     314}
     315
     316void CloudEffect::shellCloudColor(float colorX, float colorY, float colorZ, float time) {
     317    changeCloudColor( Vector(colorX, colorY, colorZ), time);
     318}
     319
     320void CloudEffect::flashSky( float time ) {
     321
     322  flashSkyActivate = true;
     323  localTimer = 0;
     324  flashTime = time;
     325
     326}
     327
     328
     329
     330void CloudEffect::make3DNoiseTexture() {
     331    int f, i, j, k, inc;
     332    int startFrequency = 4;
     333    int numOctaves = 4;
     334    double ni[3];
     335    double inci, incj, inck;
     336    int frequency = startFrequency;
     337    GLubyte *ptr;
     338    double amp = 0.5;
     339
     340    if ((noise3DTexPtr = (GLubyte *) malloc(noise3DTexSize *
     341                                            noise3DTexSize *
     342                                            noise3DTexSize * 4)) == NULL)
     343        PRINTF(0)("ERROR: Could not allocate 3D noise texture\n");
     344
     345    for (f=0, inc=0; f < numOctaves;
     346            ++f, frequency *= 2, ++inc, amp *= 0.5) {
     347        SetNoiseFrequency(frequency);
     348        ptr = noise3DTexPtr;
     349        ni[0] = ni[1] = ni[2] = 0;
     350
     351        inci = 1.0 / (noise3DTexSize / frequency);
     352        for (i=0; i<noise3DTexSize; ++i, ni[0] += inci) {
     353            incj = 1.0 / (noise3DTexSize / frequency);
     354            for (j=0; j<noise3DTexSize; ++j, ni[1] += incj) {
     355                inck = 1.0 / (noise3DTexSize / frequency);
     356                for (k=0; k<noise3DTexSize; ++k, ni[2] += inck, ptr+= 4) {
     357                    *(ptr+inc) = (GLubyte) (((noise3(ni)+1.0) * amp)*128.0);
     358                }
     359            }
     360        }
     361    }
     362}
     363
     364void CloudEffect::initNoise() {
     365    int i, j, k;
     366
     367    srand(30757);
     368    for (i = 0 ; i < B ; i++) {
     369        p[i] = i;
     370        g1[i] = (double)((rand() % (B + B)) - B) / B;
     371
     372        for (j = 0 ; j < 2 ; j++)
     373            g2[i][j] = (double)((rand() % (B + B)) - B) / B;
     374        normalize2(g2[i]);
     375
     376        for (j = 0 ; j < 3 ; j++)
     377            g3[i][j] = (double)((rand() % (B + B)) - B) / B;
     378        normalize3(g3[i]);
     379    }
     380
     381    while (--i) {
     382        k = p[i];
     383        p[i] = p[j = rand() % B];
     384        p[j] = k;
     385    }
     386
     387    for (i = 0 ; i < B + 2 ; i++) {
     388        p[B + i] = p[i];
     389        g1[B + i] = g1[i];
     390        for (j = 0 ; j < 2 ; j++)
     391            g2[B + i][j] = g2[i][j];
     392        for (j = 0 ; j < 3 ; j++)
     393            g3[B + i][j] = g3[i][j];
     394    }
     395}
     396
     397void CloudEffect::SetNoiseFrequency( int frequency) {
     398    start = 1;
     399    B = frequency;
     400    BM = B-1;
     401}
     402
     403double CloudEffect::noise3( double vec[3]) {
     404    int bx0, bx1, by0, by1, bz0, bz1, b00, b10, b01, b11;
     405    double rx0, rx1, ry0, ry1, rz0, rz1, *q, sy, sz, a, b, c, d, t, u, v;
     406    int i, j;
     407
     408    if (start) {
     409        start = 0;
     410        initNoise();
     411    }
     412
     413    setup(0, bx0,bx1, rx0,rx1);
     414    setup(1, by0,by1, ry0,ry1);
     415    setup(2, bz0,bz1, rz0,rz1);
     416
     417    i = p[ bx0 ];
     418    j = p[ bx1 ];
     419
     420    b00 = p[ i + by0 ];
     421    b10 = p[ j + by0 ];
     422    b01 = p[ i + by1 ];
     423    b11 = p[ j + by1 ];
     424
     425    t  = s_curve(rx0);
     426    sy = s_curve(ry0);
     427    sz = s_curve(rz0);
     428
     429    q = g3[ b00 + bz0 ] ;
     430    u = at3(rx0,ry0,rz0);
     431    q = g3[ b10 + bz0 ] ;
     432    v = at3(rx1,ry0,rz0);
     433    a = lerp(t, u, v);
     434
     435    q = g3[ b01 + bz0 ] ;
     436    u = at3(rx0,ry1,rz0);
     437    q = g3[ b11 + bz0 ] ;
     438    v = at3(rx1,ry1,rz0);
     439    b = lerp(t, u, v);
     440
     441    c = lerp(sy, a, b);
     442
     443    q = g3[ b00 + bz1 ] ;
     444    u = at3(rx0,ry0,rz1);
     445    q = g3[ b10 + bz1 ] ;
     446    v = at3(rx1,ry0,rz1);
     447    a = lerp(t, u, v);
     448
     449    q = g3[ b01 + bz1 ] ;
     450    u = at3(rx0,ry1,rz1);
     451    q = g3[ b11 + bz1 ] ;
     452    v = at3(rx1,ry1,rz1);
     453    b = lerp(t, u, v);
     454
     455    d = lerp(sy, a, b);
     456
     457    return lerp(sz, c, d);
     458}
     459
     460void CloudEffect::normalize2( double v[2]) {
     461    double s;
     462
     463    s = sqrt(v[0] * v[0] + v[1] * v[1]);
     464    v[0] = v[0] / s;
     465    v[1] = v[1] / s;
     466}
     467
     468void CloudEffect::normalize3( double v[3]) {
     469    double s;
     470
     471    s = sqrt(v[0] * v[0] + v[1] * v[1] + v[2] * v[2]);
     472    v[0] = v[0] / s;
     473    v[1] = v[1] / s;
     474    v[2] = v[2] / s;
     475}
     476
  • trunk/src/lib/graphics/effects/cloud_effect.h

    r8793 r9006  
    11/**
    22 * @file cloud_effect.h
    3  * Creates clouds
     3 * Create clouds
    44*/
    55
     
    3232#define at3(rx,ry,rz) ( rx * q[0] + ry * q[1] + rz * q[2] )
    3333
     34// FORWARD DECLARATION
     35template <class T>
     36class tAnimation;
    3437
    35 class CloudEffect : public WeatherEffect
    36 {
     38class CloudEffect : public WeatherEffect {
     39
    3740public:
    38   CloudEffect(const TiXmlElement* root = NULL);
    39   virtual ~CloudEffect();
    4041
    41   virtual void loadParams(const TiXmlElement* root);
     42    CloudEffect(const TiXmlElement* root = NULL);
     43    virtual ~CloudEffect();
    4244
    43   virtual void init();
     45    virtual void loadParams(const TiXmlElement* root);
    4446
    45   virtual void activate();
    46   virtual void deactivate();
     47    virtual void init();
    4748
    48   inline void activateCloud()
    49   { this->activate(); }
     49    virtual void activate();
     50    virtual void deactivate();
    5051
    51   inline void deactivateCloud()
    52   { this->deactivate(); }
     52    void activateCloud() {
     53        this->activate();
     54    }
     55    void deactivateCloud() {
     56        this->deactivate();
     57    }
    5358
    54   inline void setCloudOption(const std::string& option)
    55   {
    56     if (option == "activate")
    57       this->cloudActivate = true;
    58   }
     59    void setCloudOption(const std::string& option) {
     60        if (option == "activate")
     61            this->cloudActivate = true;
     62    }
    5963
    60   inline void setAnimationSpeed(float speed)
    61 { this->animationSpeed = speed; }
     64    void setAnimationSpeed(float speed) {
     65        this->animationSpeed = speed;
     66    }
    6267
    63   inline void setCloudScale(float scale)
    64   { this->scale = scale; }
     68    void setCloudScale(float scale) {
     69        this->scale = scale;
     70    }
    6571
    66   inline void setCloudColor(float colorX, float colorY, float colorZ)
    67   { this->cloudColor = Vector(colorX, colorY, colorZ); }
     72    void setCloudColor(float colorX, float colorY, float colorZ) {
     73        this->cloudColor = Vector(colorX, colorY, colorZ);
     74    }
    6875
    69   inline void setSkyColor(float colorX, float colorY, float colorZ)
    70   { this->skyColor = Vector(colorX, colorY, colorZ); }
     76    void setSkyColor(float colorX, float colorY, float colorZ) {
     77        this->skyColor = Vector(colorX, colorY, colorZ);
     78    }
    7179
    72   inline void setPlanetRadius(float planetRadius)
    73   { this->planetRadius = planetRadius; }
     80    void setPlanetRadius(float planetRadius) {
     81        this->planetRadius = planetRadius;
     82    }
    7483
    75   inline void setAtmosphericRadius(float atmosphericRadius)
    76   { this->atmosphericRadius = atmosphericRadius; }
     84    void setAtmosphericRadius(float atmosphericRadius) {
     85        this->atmosphericRadius = atmosphericRadius;
     86    }
    7787
    78   inline void setDivisions(int divs)
    79   { this->divs = divs; }
     88    void setDivisions(int divs) {
     89        this->divs = divs;
     90    }
    8091
    81   virtual void draw() const;
    82   virtual void tick(float dt);
     92    virtual void draw() const;
     93    virtual void tick(float dt);
    8394
    84   static void changeSkyColor(Vector color);
    85   static void changeCloudColor(Vector color);
    86  
    87   static Vector    cloudColor;
    88   static Vector    skyColor;
     95    static void changeSkyColor(Vector color, float time);
     96    static void changeCloudColor(Vector color, float time);
    8997
    90   void make3DNoiseTexture();
    91   void initNoise();
    92   void SetNoiseFrequency(int frequency);
    93   double noise3(double vec[3]);
    94   void normalize2(double v[2]);
    95   void normalize3(double v[3]);
     98    void setColorSkyX(float color);
     99    void setColorSkyY(float color);
     100    void setColorSkyZ(float color);
     101    void setColorCloudX(float color);
     102    void setColorCloudY(float color);
     103    void setColorCloudZ(float color);
    96104
    97   void generateSkyPlane(int divisions, float planetRadius, float atmosphereRadius,
    98                         float hTile, float vTile);
     105    static Vector cloudColor;
     106    static Vector skyColor;
     107
     108    void make3DNoiseTexture();
     109    void initNoise();
     110    void SetNoiseFrequency(int frequency);
     111    double noise3(double vec[3]);
     112    void normalize2(double v[2]);
     113    void normalize3(double v[3]);
     114
     115    void generateSkyPlane(int divisions, float planetRadius, float atmosphereRadius,
     116                          float hTile, float vTile);
     117
     118    void shellSkyColor(float colorX, float colorY, float colorZ, float time);
     119    void shellCloudColor(float colorX, float colorY, float colorZ, float time);
     120
     121    static void flashSky(float time);
     122
    99123private:
    100124
    101   bool             cloudActivate;
    102   float            animationSpeed;
    103   float            fadeTime;
    104  
    105   static Vector           newSkyColor;
    106   static Vector           newCloudColor;
     125    bool                    cloudActivate;
     126    float                   animationSpeed;
    107127
    108   // Material                 cloudMaterial;
    109   Skydome*         skydome;
     128    static Vector           newSkyColor;
     129    static Vector           newCloudColor;
    110130
    111   // SHADER STUFF
    112   Shader*          shader;
    113   Shader::Uniform* offset;
    114   Shader::Uniform* skycolor;
    115   Shader::Uniform* cloudcolor;
    116   float            offsetZ;
    117   float            scale;
    118   float            planetRadius;
    119   float            atmosphericRadius;
    120   int              divs;
     131    // Material             cloudMaterial;
     132    Skydome*                 skydome;
    121133
    122   // NOISE STUFF
    123   int              noise3DTexSize;
    124   GLuint           noise3DTexName;
    125   GLubyte          *noise3DTexPtr;
     134    tAnimation<CloudEffect>*  skyColorFadeX;
     135    tAnimation<CloudEffect>*  skyColorFadeY;
     136    tAnimation<CloudEffect>*  skyColorFadeZ;
     137    tAnimation<CloudEffect>*  cloudColorFadeX;
     138    tAnimation<CloudEffect>*  cloudColorFadeY;
     139    tAnimation<CloudEffect>*  cloudColorFadeZ;
     140    static bool fadeSky;
     141    static bool fadeCloud;
     142    static float fadeTime;
    126143
    127   int              p[MAXB + MAXB + 2];
    128   double           g3[MAXB + MAXB + 2][3];
    129   double           g2[MAXB + MAXB + 2][2];
    130   double           g1[MAXB + MAXB + 2];
     144    // SHADER STUFF
     145    Shader*          shader;
     146    Shader::Uniform* offset;
     147    Shader::Uniform* skycolor;
     148    Shader::Uniform* cloudcolor;
     149    float            offsetZ;
     150    float            scale;
     151    float            planetRadius;
     152    float            atmosphericRadius;
     153    int              divs;
    131154
    132   int              start;
    133   int              B;
    134   int              BM;
     155    // NOISE STUFF
     156    int              noise3DTexSize;
     157    GLuint           noise3DTexName;
     158    GLubyte          *noise3DTexPtr;
     159
     160    int              p[MAXB + MAXB + 2];
     161    double           g3[MAXB + MAXB + 2][3];
     162    double           g2[MAXB + MAXB + 2][2];
     163    double           g1[MAXB + MAXB + 2];
     164
     165    int              start;
     166    int              B;
     167    int              BM;
     168
     169    static bool      flashSkyActivate;
     170    static float     localTimer;
     171    static float     flashTime;
     172
    135173};
    136174
  • trunk/src/lib/graphics/effects/fog_effect.cc

    r8793 r9006  
    103103 */
    104104void FogEffect::activate() {
    105     PRINTF(0)( "Activating FogEffect\n");
     105    PRINTF(3)( "Activating FogEffect\n");
    106106
    107107    // init fogGL
     
    123123 */
    124124void FogEffect::deactivate() {
    125     PRINTF(0)("Deactivating FogEffect\n");
     125    PRINTF(3)("Deactivating FogEffect\n");
    126126
    127127    this->fogFadeInActivate = false;
  • trunk/src/lib/graphics/effects/lense_flare.cc

    r8619 r9006  
    6464
    6565    this->lightSource = (LightManager::getInstance())->getLight(0);
    66     PRINTF(0)("light is: %p\n", this->lightSource);
     66    PRINTF(4)("light is: %p\n", this->lightSource);
    6767
    6868    if (root != NULL) {
  • trunk/src/lib/graphics/effects/rain_effect.cc

    r8793 r9006  
    11/*
    22  orxonox - the future of 3D-vertical-scrollers
    3  
     3
    44  Copyright (C) 2004 orx
    5  
     5
    66  This program is free software; you can redistribute it and/or modify
    77  it under the terms of the GNU General Public License as published by
    88  the Free Software Foundation; either version 2, or (at your option)
    99  any later version.
    10  
     10
    1111### File Specific:
    1212  main-programmer: hdavid, amaechler
    1313*/
     14
     15#define DEBUG_SPECIAL_MODULE DEBUG_MODULE_GRAPHICS
    1416
    1517#include "rain_effect.h"
     
    4345 * @brief standard constructor
    4446 */
    45 RainEffect::RainEffect(const TiXmlElement* root)
    46 {
    47   this->setClassID(CL_RAIN_EFFECT, "RainEffect");
    48 
    49   this->init();
    50 
    51   if (root != NULL)
    52     this->loadParams(root);
    53 
    54   //load rain sound
    55   if (this->rainBuffer != NULL)
    56     ResourceManager::getInstance()->unload(this->rainBuffer);
    57   this->rainBuffer = (OrxSound::SoundBuffer*)ResourceManager::getInstance()->load("sound/atmosphere/rain.wav", WAV);
    58 
    59   //load wind sound
    60   if (this->rainWindForce != 0)
    61   {
     47RainEffect::RainEffect(const TiXmlElement* root) {
     48    this->setClassID(CL_RAIN_EFFECT, "RainEffect");
     49
     50    this->init();
     51
     52    if (root != NULL)
     53        this->loadParams(root);
     54
     55    //load rain sound
     56    if (this->rainBuffer != NULL)
     57        ResourceManager::getInstance()->unload(this->rainBuffer);
     58    this->rainBuffer = (OrxSound::SoundBuffer*)ResourceManager::getInstance()->load("sound/atmosphere/rain.wav", WAV);
     59
     60    //load wind sound
     61    if (this->rainWindForce != 0) {
     62        if (this->windBuffer != NULL)
     63            ResourceManager::getInstance()->unload(this->windBuffer);
     64        this->windBuffer = (OrxSound::SoundBuffer*)ResourceManager::getInstance()->load("sound/atmosphere/wind.wav", WAV);
     65    }
     66
     67    if(rainActivate) {
     68        this->activate();
     69        RainEffect::rainParticles->precache((int)this->rainLife * 2);
     70    }
     71}
     72
     73/**
     74 * @brief standard deconstructor
     75 */
     76RainEffect::~RainEffect() {
     77    this->deactivate();
     78
     79    if (this->rainBuffer != NULL)
     80        ResourceManager::getInstance()->unload(this->rainBuffer);
     81
    6282    if (this->windBuffer != NULL)
    63       ResourceManager::getInstance()->unload(this->windBuffer);
    64     this->windBuffer = (OrxSound::SoundBuffer*)ResourceManager::getInstance()->load("sound/atmosphere/wind.wav", WAV);
    65   }
    66 
    67   if(rainActivate)
    68   {
    69     this->activate();
    70     RainEffect::rainParticles->precache((int)this->rainLife * 2);
    71   }
    72 }
    73 
    74 /**
    75  * @brief standard deconstructor
    76  */
    77 RainEffect::~RainEffect()
    78 {
    79   this->deactivate();
    80 
    81   if (this->rainBuffer != NULL)
    82     ResourceManager::getInstance()->unload(this->rainBuffer);
    83 
    84   if (this->windBuffer != NULL)
    85     ResourceManager::getInstance()->unload(this->windBuffer);
     83        ResourceManager::getInstance()->unload(this->windBuffer);
    8684}
    8785
     
    8987 * @brief initalizes the rain effect with default values
    9088 */
    91 void RainEffect::init()
    92 {
    93   //Default values
    94   this->rainActivate = false;
    95   this->rainMove = false;
    96   this->rainCoord = Vector(500, 500, 500);
    97   this->rainSize = Vector2D(1000, 1000);
    98   this->rainRate = 4000;
    99   this->rainVelocity = -300;
    100   this->rainLife = 4;
    101   this->rainWindForce  = 0;
    102   this->rainFadeInDuration = 0;
    103   this->rainFadeOutDuration = 0;
    104  
    105   this->cloudColor = Vector(0.8f, 0.8f, 0.8f);
    106   this->skyColor = Vector(0.0f, 0.0f, 0.0f);
    107 
    108   this->rainMaxParticles = this->rainRate * this->rainLife;
    109   this->localTimer = 0;
    110   this->soundRainVolume = 0.3f;
    111   this->emitter = new PlaneEmitter(this->rainSize);
    112 
    113   lightMan = LightManager::getInstance();
    114   this->rainAmbient = lightMan->getAmbientColor();
     89void RainEffect::init() {
     90    //Default values
     91    this->rainActivate = false;
     92    this->rainFadeInActivate = false;
     93    this->rainFadeOutActivate = false;
     94
     95    this->rainMove = false;
     96    this->rainCoord = Vector(500, 500, 500);
     97    this->rainSize = Vector2D(1000, 1000);
     98    this->rainRate = 4000;
     99    this->rainVelocity = -300;
     100    this->rainLife = 4;
     101    this->rainWindForce = 0;
     102    this->rainFadeInDuration = 10;
     103    this->rainFadeOutDuration = 10;
     104
     105    this->cloudColor = Vector(0.6f, 0.6f, 0.6f);
     106    this->skyColor = Vector(0.0f, 0.0f, 0.0f);
     107
     108    this->rainMaxParticles = this->rainRate * this->rainLife;
     109    this->localTimer = 0;
     110    this->soundRainVolume = 0.3f;
     111    this->emitter = new PlaneEmitter(this->rainSize);
     112
    115113}
    116114
     
    119117 * @param root: the XML-Element to load the data from
    120118 */
    121 void RainEffect::loadParams(const TiXmlElement* root)
    122 {
    123   WeatherEffect::loadParams(root);
    124 
    125   LoadParam(root, "coord", this, RainEffect, setRainCoord);
    126   LoadParam(root, "size", this, RainEffect, setRainSize);
    127   LoadParam(root, "rate", this, RainEffect, setRainRate);
    128   LoadParam(root, "velocity", this, RainEffect, setRainVelocity);
    129   LoadParam(root, "life", this, RainEffect, setRainLife);
    130   LoadParam(root, "wind", this, RainEffect, setRainWind);
    131   LoadParam(root, "fadeinduration", this, RainEffect, setRainFadeIn);
    132   LoadParam(root, "fadeoutduration", this, RainEffect, setRainFadeOut);
    133   LoadParam(root, "cloudcolor", this, RainEffect, setCloudColor);
    134   LoadParam(root, "skycolor", this, RainEffect, setSkyColor);
    135 
    136   LOAD_PARAM_START_CYCLE(root, element);
    137   {
    138     LoadParam_CYCLE(element, "option", this, RainEffect, setRainOption);
    139   }
    140   LOAD_PARAM_END_CYCLE(element);
     119void RainEffect::loadParams(const TiXmlElement* root) {
     120    WeatherEffect::loadParams(root);
     121
     122    LoadParam(root, "coord", this, RainEffect, setRainCoord);
     123    LoadParam(root, "size", this, RainEffect, setRainSize);
     124    LoadParam(root, "rate", this, RainEffect, setRainRate);
     125    LoadParam(root, "velocity", this, RainEffect, setRainVelocity);
     126    LoadParam(root, "life", this, RainEffect, setRainLife);
     127    LoadParam(root, "wind", this, RainEffect, setRainWind);
     128    LoadParam(root, "fadeinduration", this, RainEffect, setRainFadeIn);
     129    LoadParam(root, "fadeoutduration", this, RainEffect, setRainFadeOut);
     130    LoadParam(root, "cloudcolor", this, RainEffect, setCloudColor);
     131    LoadParam(root, "skycolor", this, RainEffect, setSkyColor);
     132
     133    LOAD_PARAM_START_CYCLE(root, element);
     134    {
     135        LoadParam_CYCLE(element, "option", this, RainEffect, setRainOption);
     136    }
     137    LOAD_PARAM_END_CYCLE(element);
    141138}
    142139
     
    146143 * @brief activates the rain effect
    147144 */
    148 void RainEffect::activate()
    149 {
    150   PRINTF(0)( "Activating RainEffect, coord: %f, %f, %f, size: %f, %f, rate: %f, velocity: %f, moveRain: %s\n", this->rainCoord.x, this->rainCoord.y, this->rainCoord.z, this->rainSize.x, this-> rainSize.y, this->rainRate, this->rainVelocity, this->rainMove ? "true" : "false" );
    151 
    152   this->rainActivate = true;
    153 
    154   if (unlikely(RainEffect::rainParticles == NULL))
    155   {
    156     RainEffect::rainParticles = new SparkParticles((int) this->rainMaxParticles);
    157     RainEffect::rainParticles->setName("RainParticles");
    158     RainEffect::rainParticles->setLifeSpan(this->rainLife, 2);
    159     RainEffect::rainParticles->setRadius(0, 0.03);
    160     RainEffect::rainParticles->setRadius(0.2, 0.02);
    161     RainEffect::rainParticles->setRadius(1, 0.01);
    162     RainEffect::rainParticles->setColor(0, 0.3, 0.3, 0.5, 0.2); // grey blue 1
    163     RainEffect::rainParticles->setColor(0.5, 0.4, 0.4, 0.5, 0.2); // grey blue 2
    164     RainEffect::rainParticles->setColor(1, 0.7, 0.7, 0.7, 0.2); // light grey
    165   }
    166 
    167   this->emitter->setSystem(RainEffect::rainParticles);
    168 
    169   this->emitter->setRelCoor(this->rainCoord);
    170 
    171   this->emitter->setEmissionRate(this->rainRate);
    172   this->emitter->setEmissionVelocity(this->rainVelocity);
    173 
    174   this->emitter->setSpread(this->rainWindForce / 50, 0.2);
    175 
    176   // plays the rain sound and loops it
    177   this->soundSource.play(this->rainBuffer, this->soundRainVolume, true);
    178 
    179   // if there is wind, play the wind sound
    180   if (this->rainWindForce != 0)
    181     this->soundSource.play(this->windBuffer, 0.1f * this->rainWindForce, true);
    182 
    183   if (this->rainFadeInDuration == 0)
    184     lightMan->setAmbientColor(.1,.1,.1);
    185  
    186   // Change the cloudcolor,skycolor
    187   this->oldCloudColor = CloudEffect::cloudColor;
    188   this->oldSkyColor = CloudEffect::skyColor;
    189   CloudEffect::changeCloudColor(this->cloudColor);
    190   CloudEffect::changeSkyColor(this->skyColor);
     145void RainEffect::activate() {
     146    PRINTF(3)( "Activating RainEffect, coord: %f, %f, %f, size: %f, %f, rate: %f, velocity: %f, moveRain: %s\n", this->rainCoord.x, this->rainCoord.y, this->rainCoord.z, this->rainSize.x, this-> rainSize.y, this->rainRate, this->rainVelocity, this->rainMove ? "true" : "false" );
     147
     148    this->rainActivate = true;
     149
     150    if (unlikely(RainEffect::rainParticles == NULL)) {
     151        RainEffect::rainParticles = new SparkParticles((int) this->rainMaxParticles);
     152        RainEffect::rainParticles->setName("RainParticles");
     153        RainEffect::rainParticles->setLifeSpan(this->rainLife, 2);
     154        RainEffect::rainParticles->setRadius(0, 0.03);
     155        RainEffect::rainParticles->setRadius(0.2, 0.02);
     156        RainEffect::rainParticles->setRadius(1, 0.01);
     157        RainEffect::rainParticles->setColor(0, 0.3, 0.3, 0.5, 0.2);   // grey blue 1
     158        RainEffect::rainParticles->setColor(0.5, 0.4, 0.4, 0.5, 0.2); // grey blue 2
     159        RainEffect::rainParticles->setColor(1, 0.7, 0.7, 0.7, 0.2);   // light grey
     160    }
     161
     162    this->emitter->setSystem(RainEffect::rainParticles);
     163    this->emitter->setRelCoor(this->rainCoord);
     164    this->emitter->setEmissionRate(this->rainRate);
     165    this->emitter->setEmissionVelocity(this->rainVelocity);
     166    this->emitter->setSpread(this->rainWindForce / 50, 0.2);
     167
     168    // play rain sound and loop it
     169    this->soundSource.play(this->rainBuffer, this->soundRainVolume, true);
     170
     171    // if there's wind, play wind sound
     172    if (this->rainWindForce > 0)
     173        this->soundSource.play(this->windBuffer, 0.1f * this->rainWindForce, true);
     174
     175    // Store cloud- and sky color before the rain;
     176    this->oldCloudColor = CloudEffect::cloudColor;
     177    this->oldSkyColor   = CloudEffect::skyColor;
     178
     179    // If we're not fading, change color immediately
     180    if (!this->rainFadeInActivate || !this->rainFadeOutActivate) {
     181        CloudEffect::changeCloudColor(this->cloudColor, 0);
     182        CloudEffect::changeSkyColor(this->skyColor, 0);
     183    }
    191184}
    192185
     
    194187 * @brief deactivates the rain effect
    195188 */
    196 void RainEffect::deactivate()
    197 {
    198   PRINTF(0)("Deactivating RainEffect\n");
    199 
    200   this->rainActivate = false;
    201   this->emitter->setSystem(NULL);
    202 
    203   // Stop Sound
    204   this->soundSource.stop();
    205 
    206   // Restore Light Ambient
    207   lightMan->setAmbientColor(this->rainAmbient, this->rainAmbient, this->rainAmbient);
    208  
    209   CloudEffect::changeCloudColor(this->oldCloudColor);
    210   CloudEffect::changeSkyColor(this->oldSkyColor);
     189void RainEffect::deactivate() {
     190    PRINTF(3)("Deactivating RainEffect\n");
     191
     192    this->rainActivate = false;
     193    this->rainFadeInActivate = false;
     194    this->rainFadeOutActivate = false;
     195
     196    this->emitter->setSystem(NULL);
     197
     198    // Stop Sound
     199    this->soundSource.stop();
     200
     201    // Restore the old cloud- and sky color
     202    CloudEffect::changeCloudColor(this->oldCloudColor, 0);
     203    CloudEffect::changeSkyColor(this->oldSkyColor, 0);
    211204}
    212205
     
    215208 * @param dt: tick float
    216209 */
    217 void RainEffect::tick (float dt)
    218 {
    219   if (!this->rainActivate)
    220     return;
    221 
    222   if (this->rainMove)
    223   {
    224     this->rainCoord = State::getCameraNode()->getAbsCoor();
    225     this->emitter->setRelCoor(this->rainCoord.x , this->rainCoord.y+800, this->rainCoord.z);
    226   }
    227 
    228   if (this->rainFadeInDuration != 0 && this->localTimer < this->rainFadeInDuration)
    229   {
    230     this->localTimer += dt;
    231     float progress = this->localTimer / this->rainFadeInDuration;
    232 
    233     // Dim Light
    234     lightMan->setAmbientColor(1 - progress * 0.9, 1 - progress * 0.9, 1 - progress * 0.9);
    235 
    236     // use alpha in color to fade in
    237     RainEffect::rainParticles->setColor(0,   0.3, 0.3, 0.5, 0.2 * progress); // grey blue 1
    238     RainEffect::rainParticles->setColor(0.5, 0.4, 0.4, 0.5, 0.2 * progress); // grey blue 2
    239     RainEffect::rainParticles->setColor(1,   0.7, 0.7, 0.7, 0.2 * progress); // light grey
    240 
    241     // increase radius for more "heavy" rain
    242     RainEffect::rainParticles->setRadius(0, 0.03 * progress);
    243     RainEffect::rainParticles->setRadius(0.2, 0.02 * progress);
    244     RainEffect::rainParticles->setRadius(1, 0.01 * progress);
    245 
    246     // increase sound volume
    247     if (!this->soundSource.isPlaying())
    248       this->soundSource.play(this->rainBuffer, this->soundRainVolume, true);
    249 
    250     this->soundSource.gain(this->rainBuffer, this->soundRainVolume * progress);
    251   }
    252   else if ( this->rainFadeOutDuration != 0 )
    253   {
    254     if ( this->localTimer < this->rainFadeOutDuration )
    255     {
    256       this->localTimer += dt;
    257       float progress = 1 - (this->localTimer / this->rainFadeOutDuration);
    258 
    259       // Fade In Light
    260       lightMan->setAmbientColor(1 - progress * 0.9, 1 - progress * 0.9, 1 - progress * 0.9);
    261 
    262       // use alpha in color to fade out
    263       RainEffect::rainParticles->setColor(0,   0.3, 0.3, 0.5, 0.2 * progress); // grey blue 1
    264       RainEffect::rainParticles->setColor(0.5, 0.4, 0.4, 0.5, 0.2 * progress); // grey blue 2
    265       RainEffect::rainParticles->setColor(1,   0.7, 0.7, 0.7, 0.2 * progress); // light grey
    266 
    267       // decrease radius
    268       RainEffect::rainParticles->setRadius(0, 0.03 * progress);
    269       RainEffect::rainParticles->setRadius(0.2, 0.02 * progress);
    270       RainEffect::rainParticles->setRadius(1, 0.01 * progress);
    271 
    272       // decrease sound volume
    273       if (!this->soundSource.isPlaying())
    274         this->soundSource.play(this->rainBuffer, this->soundRainVolume, true);
    275 
    276       this->soundSource.gain(this->rainBuffer, this->soundRainVolume * progress);
    277     }
    278     else
    279       this->deactivate();
    280   }
     210void RainEffect::tick (float dt) {
     211    if (!this->rainActivate)
     212        return;
     213
     214    if (this->rainMove) {
     215        this->rainCoord = State::getCameraNode()->getAbsCoor();
     216        this->emitter->setRelCoor(this->rainCoord.x , this->rainCoord.y+800, this->rainCoord.z);
     217    }
     218
     219    if (this->rainFadeInActivate) {
     220        PRINTF(4)("tick fading IN RainEffect\n");
     221
     222        this->localTimer += dt;
     223        float progress = this->localTimer / this->rainFadeInDuration;
     224
     225        // use alpha in color to fade in rain
     226        RainEffect::rainParticles->setColor(0,   0.3, 0.3, 0.5, 0.2 * progress); // grey blue 1
     227        RainEffect::rainParticles->setColor(0.5, 0.4, 0.4, 0.5, 0.2 * progress); // grey blue 2
     228        RainEffect::rainParticles->setColor(1,   0.7, 0.7, 0.7, 0.2 * progress); // light grey
     229
     230        // increase radius for more "heavy" rain
     231        RainEffect::rainParticles->setRadius(0, 0.03 * progress);
     232        RainEffect::rainParticles->setRadius(0.2, 0.02 * progress);
     233        RainEffect::rainParticles->setRadius(1, 0.01 * progress);
     234
     235        // increase sound volume
     236        if (!this->soundSource.isPlaying())
     237            this->soundSource.play(this->rainBuffer, this->soundRainVolume, true);
     238        this->soundSource.gain(this->rainBuffer, this->soundRainVolume * progress);
     239
     240        if (progress >= 1)
     241            this->rainFadeInActivate = false;
     242    }
     243
     244    if (this->rainFadeOutActivate) {
     245        PRINTF(4)("tick fading OUT RainEffect\n");
     246
     247        this->localTimer += dt;
     248        float progress = 1 - (this->localTimer / this->rainFadeOutDuration);
     249
     250        // use alpha in color to fade out
     251        RainEffect::rainParticles->setColor(0,   0.3, 0.3, 0.5, 0.2 * progress); // grey blue 1
     252        RainEffect::rainParticles->setColor(0.5, 0.4, 0.4, 0.5, 0.2 * progress); // grey blue 2
     253        RainEffect::rainParticles->setColor(1,   0.7, 0.7, 0.7, 0.2 * progress); // light grey
     254
     255        // decrease radius
     256        RainEffect::rainParticles->setRadius(0, 0.03 * progress);
     257        RainEffect::rainParticles->setRadius(0.2, 0.02 * progress);
     258        RainEffect::rainParticles->setRadius(1, 0.01 * progress);
     259
     260        // decrease sound volume
     261        if (!this->soundSource.isPlaying())
     262            this->soundSource.play(this->rainBuffer, this->soundRainVolume, true);
     263        this->soundSource.gain(this->rainBuffer, this->soundRainVolume * progress);
     264
     265        if (progress <= 0) {
     266            PRINTF(4)("tick fading OUT RainEffect COMPLETED! Deactivating...\n");
     267            this->rainFadeOutActivate = false;
     268            this->deactivate();
     269        }
     270    }
    281271}
    282272
     
    284274 * @brief starts raining slowly
    285275*/
    286 void RainEffect::startRaining()
    287 {
    288 
    289   if (this->rainActivate)
    290     this->deactivate();
    291 
    292   if (!this->rainFadeInDuration > 0)
    293     this->rainFadeInDuration = 20;
    294 
    295   this->localTimer = 0;
    296 
    297   this->activate();
     276void RainEffect::startRaining() {
     277    PRINTF(4)("startRaining function;\n");
     278
     279    // If it is already raining, do nothing
     280    if (this->rainActivate)
     281        return;
     282
     283    this->localTimer = 0;
     284    this->rainFadeInActivate = true;
     285
     286    PRINTF(4)("startRaining function complete; fadedur: %f\n", this->rainFadeInDuration);
     287    this->activate();
     288
     289    CloudEffect::changeCloudColor(this->cloudColor, this->rainFadeInDuration);
     290    CloudEffect::changeSkyColor(this->skyColor, this->rainFadeInDuration);
    298291}
    299292
     
    301294 * @brief stops raining slowly
    302295 */
    303 void RainEffect::stopRaining()
    304 {
    305 
    306   if (!this->rainActivate)
    307     this->activate();
    308 
    309   if (!this->rainFadeOutDuration > 0)
    310     this->rainFadeOutDuration = 20;
    311 
    312   this->localTimer = 0;
     296void RainEffect::stopRaining() {
     297    PRINTF(4)("stopRaining function;\n");
     298
     299    // If it is not raining, do nothing
     300    if (!this->rainActivate)
     301        return;
     302
     303    this->localTimer = 0;
     304    this->rainFadeOutActivate = true;
     305
     306    PRINTF(4)("stopRaining function completed; fadedur: %f\n", this->rainFadeOutDuration);
     307
     308    CloudEffect::changeCloudColor(this->oldCloudColor, this->rainFadeOutDuration);
     309    CloudEffect::changeSkyColor(this->oldSkyColor, this->rainFadeOutDuration);
    313310}
    314311
     
    316313 * @brief hides the rain
    317314 */
    318 void RainEffect::hideRain()
    319 {
    320   RainEffect::rainParticles->setColor(0, 0,0,0, 0);
    321   RainEffect::rainParticles->setColor(0, 0,0,0, 0);
    322 }
     315void RainEffect::hideRain() {
     316    RainEffect::rainParticles->setColor(0, 0,0,0, 0);
     317    RainEffect::rainParticles->setColor(0, 0,0,0, 0);
     318}
  • trunk/src/lib/graphics/effects/rain_effect.h

    r8793 r9006  
    8686    this->rainFadeOutDuration = fadeout;
    8787  }
    88  
     88
    8989  inline void setCloudColor(float colorX, float colorY, float colorZ)
    9090  {
     
    113113  GLfloat                     rainFadeInDuration;
    114114  GLfloat                     rainFadeOutDuration;
     115  bool                        rainFadeInActivate;
     116  bool                        rainFadeOutActivate;
    115117
    116118  Vector                      rainCoord;
     
    130132  float                       soundRainVolume;
    131133
    132   LightManager*               lightMan;
    133   GLfloat                     rainAmbient;
    134  
    135134  Vector oldSkyColor;
    136135  Vector oldCloudColor;
  • trunk/src/lib/graphics/effects/snow_effect.cc

    r8793 r9006  
    117117void SnowEffect::activate()
    118118{
    119         PRINTF(0)("Activating SnowEffect\n");
     119        PRINTF(3)("Activating SnowEffect\n");
    120120
    121121        this->snowActivate = true;
     
    149149void SnowEffect::deactivate()
    150150{
    151         PRINTF(0)("Deactivating SnowEffect\n");
     151        PRINTF(3)("Deactivating SnowEffect\n");
    152152
    153153        this->snowActivate = false;
  • trunk/src/lib/graphics/effects/volfog_effect.cc

    r8523 r9006  
    7474
    7575void VolFogEffect::init() {
    76     PRINTF(0)("Initalize VolFogEffect\n");
     76    PRINTF(3)("Initalize VolFogEffect\n");
    7777
    7878    // set fog mode
     
    108108
    109109    if (glewInit() == GLEW_OK)
    110         PRINTF(0)("glewInit OK\n");
     110        PRINTF(4)("glewInit OK\n");
    111111    else
    112         PRINTF(0)("glewInit failed\n");
     112        PRINTF(4)("glewInit failed\n");
    113113
    114114    if (glewGetExtension("GL_EXT_fog_coord"))
    115         PRINTF(0)("GL_EXT_fog_coord extension found\n");
     115        PRINTF(4)("GL_EXT_fog_coord extension found\n");
    116116}
    117117
    118118
    119119void VolFogEffect::activate() {
    120     PRINTF(0)("Activating VolFogEffect\n");
     120    PRINTF(3)("Activating VolFogEffect\n");
    121121}
    122122
    123123void VolFogEffect::deactivate() {
    124     PRINTF(0)("Deactivating VolFogEffect\n");
     124    PRINTF(3)("Deactivating VolFogEffect\n");
    125125
    126126    glDisable(GL_FOG);
  • trunk/src/lib/gui/gl/glgui_handler.cc

    r8743 r9006  
    8888  void GLGuiHandler::activate()
    8989  {
    90     EventHandler::getInstance()->pushState(ES_MENU);
     90    //EventHandler::getInstance()->pushState(ES_MENU);
    9191
    9292
     
    9696  void GLGuiHandler::deactivate()
    9797  {
    98     EventHandler::getInstance()->popState();
     98    //EventHandler::getInstance()->popState();
    9999
    100100
  • trunk/src/lib/util/executor/executor_lua.h

    r8894 r9006  
    4444  public:
    4545    /**
    46      * @brief Constructor of a ExecutorXML
    47      * @param function a Function to call
     46   * @brief Constructor of a ExecutorXML
     47   * @param function a Function to call
    4848     */
    4949    ExecutorLua0(void(T::*function)())
    50         : Executor()
     50  : Executor()
    5151    {
    5252      this->functionPointer = function;
     
    9191  public:
    9292    /**
    93      * @brief Constructor of a ExecutorXML
    94      * @param function a Function to call
     93   * @brief Constructor of a ExecutorXML
     94   * @param function a Function to call
    9595     */
    9696    ExecutorLua1(void(T::*function)(type0))
    97         : Executor(ExecutorParamType<type0>())
    98     {
    99       this->functionPointer = function;
    100       this->functorType = Executor_Objective | Executor_NoLoadString;
    101     }
    102 
    103     /**
    104        * @brief executes the Command on BaseObject
    105        * @param object the BaseObject to execute this Executor on
    106        * @param loadString ignored in this case
     97  : Executor(ExecutorParamType<type0>())
     98    {
     99      this->functionPointer = function;
     100      this->functorType = Executor_Objective | Executor_NoLoadString;
     101    }
     102
     103    /**
     104     * @brief executes the Command on BaseObject
     105     * @param object the BaseObject to execute this Executor on
     106     * @param loadString ignored in this case
    107107     */
    108108    virtual void operator()(BaseObject* object, const SubString& = SubString()) const
     
    120120
    121121    /**
    122        * @returns a _new_ Copy of this Executor
     122     * @returns a _new_ Copy of this Executor
    123123     */
    124124    virtual Executor* clone () const
     
    140140  public:
    141141    /**
    142      * @brief Constructor of a ExecutorXML
    143      * @param function a Function to call
     142   * @brief Constructor of a ExecutorXML
     143   * @param function a Function to call
    144144     */
    145145    ExecutorLua2(void(T::*function)(type0, type1))
    146         : Executor(ExecutorParamType<type0>(), ExecutorParamType<type1>())
     146  : Executor(ExecutorParamType<type0>(), ExecutorParamType<type1>())
    147147    {
    148148      this->functionPointer = function;
     
    166166
    167167      (dynamic_cast<T*>(object)->*(functionPointer))(
    168         fromLua<type0>(state, 1),
    169         fromLua<type1>(state, 2) );
     168          fromLua<type0>(state, 1),
     169      fromLua<type1>(state, 2) );
    170170    }
    171171
     
    217217      (dynamic_cast<T*>(object)->*(functionPointer))(
    218218          fromLua<type0>(state, 1),
    219           fromLua<type1>(state, 2),
    220           fromLua<type2>(state, 3) );
     219      fromLua<type1>(state, 2),
     220      fromLua<type2>(state, 3) );
    221221    }
    222222
     
    268268      (dynamic_cast<T*>(object)->*(functionPointer))(
    269269          fromLua<type0>(state, 1),
    270           fromLua<type1>(state, 2),
    271           fromLua<type2>(state, 3),
    272           fromLua<type3>(state, 4) );
     270      fromLua<type1>(state, 2),
     271      fromLua<type2>(state, 3),
     272      fromLua<type3>(state, 4) );
    273273    }
    274274
     
    300300  public:
    301301    /**
    302      * @brief Constructor of a ExecutorXML
    303      * @param function a Function to call
     302   * @brief Constructor of a ExecutorXML
     303   * @param function a Function to call
    304304     */
    305305    ExecutorLua0ret(ret (T::*function)())
    306         : Executor()
     306  : Executor()
    307307    {
    308308      this->functionPointer = function;
     
    329329
    330330    /**
    331                        * @returns a _new_ Copy of this Executor
     331     * @returns a _new_ Copy of this Executor
    332332     */
    333333    virtual Executor* clone () const
     
    349349  public:
    350350    /**
    351      * @brief Constructor of a ExecutorXML
    352      * @param function a Function to call
     351   * @brief Constructor of a ExecutorXML
     352   * @param function a Function to call
    353353     */
    354354    ExecutorLua1ret(ret (T::*function)(type0))
    355         : Executor(ExecutorParamType<type0>())
     355  : Executor(ExecutorParamType<type0>())
    356356    {
    357357      this->functionPointer = function;
     
    375375
    376376      toLua<ret>(state, (dynamic_cast<T*>(object)->*(functionPointer))(
    377                    fromLua<type0>(state, 1)));
     377          fromLua<type0>(state, 1)));
    378378    }
    379379
     
    397397  public:
    398398    /**
    399      * @brief Constructor of a ExecutorXML
    400      * @param function a Function to call
     399   * @brief Constructor of a ExecutorXML
     400   * @param function a Function to call
    401401     */
    402402    ExecutorLua2ret(ret (T::*function)(type0, type1))
    403         : Executor(ExecutorParamType<type0>(), ExecutorParamType<type1>())
     403  : Executor(ExecutorParamType<type0>(), ExecutorParamType<type1>())
    404404    {
    405405      this->functionPointer = function;
     
    423423
    424424      toLua<ret>(state, (dynamic_cast<T*>(object)->*(functionPointer))(
    425                    fromLua<type0>(state, 1),
    426                    fromLua<type1>(state, 2) ));
     425          fromLua<type0>(state, 1),
     426          fromLua<type1>(state, 2) ));
    427427    }
    428428
     
    608608             ExecutorParamType<type2>(), ExecutorParamType<type3>(),
    609609             ExecutorParamType<type4>(), ExecutorParamType<type5>())
    610     {
    611       this->functionPointer = function;
    612       this->functorType = Executor_Objective | Executor_NoLoadString;
    613     }
    614 
    615     /**
    616      * @brief executes the Command on BaseObject
    617      * @param object the BaseObject to execute this Executor on
    618      * @param loadString ignored in this case
    619      */
    620     virtual void operator()(BaseObject* object, const SubString& = SubString()) const
    621     {
    622       PRINTF(1)("no usefull executor\n");
    623     }
    624 
    625     virtual void operator()(BaseObject* object, int& count, void* values) const
    626     {
    627       lua_State* state = (lua_State*)values;
    628       count = 1;
    629 
    630       toLua<ret>(state, (dynamic_cast<T*>(object)->*(functionPointer))(
    631           fromLua<type0>(state, 1),
    632           fromLua<type1>(state, 2),
    633           fromLua<type2>(state, 3),
    634           fromLua<type3>(state, 4),
    635           fromLua<type4>(state, 5),
    636           fromLua<type5>(state, 6) ));
    637     }
    638 
    639     /**
    640      * @returns a _new_ Copy of this Executor
    641      */
    642     virtual Executor* clone () const
    643     {
    644       return new ExecutorLua6ret<T, ret, type0, type1, type2, type3, type4, type5>(this->functionPointer);
    645     }
     610             {
     611               this->functionPointer = function;
     612               this->functorType = Executor_Objective | Executor_NoLoadString;
     613             }
     614
     615    /**
     616              * @brief executes the Command on BaseObject
     617              * @param object the BaseObject to execute this Executor on
     618              * @param loadString ignored in this case
     619     */
     620             virtual void operator()(BaseObject* object, const SubString& = SubString()) const
     621             {
     622               PRINTF(1)("no usefull executor\n");
     623             }
     624
     625             virtual void operator()(BaseObject* object, int& count, void* values) const
     626             {
     627               lua_State* state = (lua_State*)values;
     628               count = 1;
     629
     630               toLua<ret>(state, (dynamic_cast<T*>(object)->*(functionPointer))(
     631                   fromLua<type0>(state, 1),
     632                   fromLua<type1>(state, 2),
     633                   fromLua<type2>(state, 3),
     634                   fromLua<type3>(state, 4),
     635                   fromLua<type4>(state, 5),
     636                   fromLua<type5>(state, 6) ));
     637             }
     638
     639    /**
     640              * @returns a _new_ Copy of this Executor
     641     */
     642             virtual Executor* clone () const
     643             {
     644               return new ExecutorLua6ret<T, ret, type0, type1, type2, type3, type4, type5>(this->functionPointer);
     645             }
    646646  private:
    647647    ret           (T::*functionPointer)(type0, type1, type2, type3, type4, type5);
  • 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
  • trunk/src/world_entities/script_trigger.cc

    r9003 r9006  
    1414*/
    1515
     16
    1617#include "script_trigger.h"
    1718#include "class_list.h"
     
    2223
    2324CREATE_SCRIPTABLE_CLASS(ScriptTrigger, CL_SCRIPT_TRIGGER,
    24                           //Position
    25                      addMethod("setAbsCoor", ExecutorLua3<PNode,float,float,float>(&PNode::setAbsCoor))
    26                      ->addMethod("getAbsCoorX", ExecutorLua0ret<PNode, float>(&PNode::getAbsCoorX))
    27                      ->addMethod("getAbsCoorY", ExecutorLua0ret<PNode, float>(&PNode::getAbsCoorY))
    28                      ->addMethod("getAbsCoorZ", ExecutorLua0ret<PNode, float>(&PNode::getAbsCoorZ))
    29                      //Set values
    30                     // ->addMethod("setTarget", ExecutorLua1<ScriptTrigger, std::string >(&ScriptTrigger::setTarget))
    31                     // ->addMethod("setTriggerParent", ExecutorLua1<ScriptTrigger, std::string >(&ScriptTrigger::setTriggerParent))
    32                      ->addMethod("setTriggerLasts", ExecutorLua1<ScriptTrigger, bool >(&ScriptTrigger::setTriggerLasts))
    33                      ->addMethod("setInvert", ExecutorLua1<ScriptTrigger, bool >(&ScriptTrigger::setInvert))
    34                      ->addMethod("setRadius", ExecutorLua1<ScriptTrigger, float >(&ScriptTrigger::setRadius))
    35                      //->addMethod("setScript", ExecutorLua1<ScriptTrigger, std::string >(&ScriptTrigger::setScript))
    36                      //->addMethod("setFunction", ExecutorLua1<ScriptTrigger, std::string >(&ScriptTrigger::setFunction))
    37                      ->addMethod("setDebugDraw", ExecutorLua1<ScriptTrigger, bool >(&ScriptTrigger::setInvert))
     25                            addMethod("setAbsCoor", ExecutorLua3<PNode,float,float,float>(&PNode::setAbsCoor))
     26                                ->addMethod("getAbsCoorX", ExecutorLua0ret<PNode, float>(&PNode::getAbsCoorX))
     27                                ->addMethod("getAbsCoorY", ExecutorLua0ret<PNode, float>(&PNode::getAbsCoorY))
     28                                ->addMethod("getAbsCoorZ", ExecutorLua0ret<PNode, float>(&PNode::getAbsCoorZ))
    3829                       );
    3930
     
    6152  {
    6253   
    63   loadParams(root);
    64  
    65   if(addToScript && scriptIsOk)
    66   {
    67     script->addObject( "ScriptTrigger", this->getName());
    68   }
     54    loadParams(root);
     55 
     56    if(addToScript && scriptIsOk)
     57    {
     58      script->addObject( "ScriptTrigger", this->getName());
     59    }
    6960 
    7061  }
     
    8879{
    8980
    90     WorldEntity ::loadParams(root);
    91 
    92     LoadParam(root, "file", this, ScriptTrigger, setScript)
    93         .describe("the fileName of the script, that should be triggered by this script trigger")
    94         .defaultValues("");
    95     LoadParam(root, "function", this, ScriptTrigger, setFunction)
    96         .describe("the function of the script, that should be triggered by this script trigger")
    97         .defaultValues("");
    98     LoadParam(root, "abs-coor", this, ScriptTrigger, setAbsCoor)
    99         .describe("where this script trigger should be located")
    100         .defaultValues("");
    101     LoadParam(root, "radius", this, ScriptTrigger, setRadius)
    102         .describe("the fileName of the script, that should be triggered by this script trigger")
    103         .defaultValues(0);
    104     LoadParam(root, "worldentity", this, ScriptTrigger, setTarget)
    105         .describe("The name of the target as it is in the *.oxw file")
    106         .defaultValues("");
    107     LoadParam(root, "triggerparent", this, ScriptTrigger, setTriggerParent)
    108         .describe("The name of the parent as it is in the *.oxw file")
    109         .defaultValues("");
    110     LoadParam(root, "invert", this, ScriptTrigger, setInvert)
    111         .describe("")
    112         .defaultValues("false");
    113     LoadParam(root, "triggerlasts", this, ScriptTrigger, setTriggerLasts)
    114         .describe("")
    115         .defaultValues("true");
    116     LoadParam(root, "debugdraw", this, ScriptTrigger, setDebugDraw)
    117         .describe("")
    118         .defaultValues("false");
    119     LoadParam(root, "addtoscript", this, ScriptTrigger, setAddToScript)
    120         .describe("True if this scripttrigger should be aviable in the script")
    121         .defaultValues("false");
     81  WorldEntity ::loadParams(root);
     82
     83  LoadParam(root, "file", this, ScriptTrigger, setScript)
     84      .describe("the fileName of the script, that should be triggered by this script trigger")
     85      .defaultValues("");
     86  LoadParam(root, "function", this, ScriptTrigger, setFunction)
     87      .describe("the function of the script, that should be triggered by this script trigger")
     88      .defaultValues("");
     89  LoadParam(root, "abs-coor", this, ScriptTrigger, setAbsCoor)
     90      .describe("where this script trigger should be located")
     91      .defaultValues("");
     92  LoadParam(root, "radius", this, ScriptTrigger, setRadius)
     93      .describe("the fileName of the script, that should be triggered by this script trigger")
     94      .defaultValues(0);
     95  LoadParam(root, "delay", this, ScriptTrigger, setDelay)
     96      .describe("the delay after which the funtion sould be triggered")
     97      .defaultValues(0);
     98  LoadParam(root, "worldentity", this, ScriptTrigger, setTarget)
     99      .describe("The name of the target as it is in the *.oxw file")
     100      .defaultValues("");
     101  LoadParam(root, "triggerparent", this, ScriptTrigger, setTriggerParent)
     102      .describe("The name of the parent as it is in the *.oxw file")
     103      .defaultValues("");
     104  LoadParam(root, "invert", this, ScriptTrigger, setInvert)
     105      .describe("")
     106      .defaultValues("false");
     107  LoadParam(root, "triggerlasts", this, ScriptTrigger, setTriggerLasts)
     108      .describe("")
     109      .defaultValues("true");
     110  LoadParam(root, "debugdraw", this, ScriptTrigger, setDebugDraw)
     111      .describe("")
     112      .defaultValues("false");
     113  LoadParam(root, "addtoscript", this, ScriptTrigger, setAddToScript)
     114      .describe("True if this scripttrigger should be aviable in the script")
     115      .defaultValues("false");
    122116}
    123117
     
    171165 
    172166  if( !invert && this->distance(target) < radius)
    173  {
     167  {
    174168    executeAction(timestep);
    175169    scriptCalled = true;
    176170 
    177  }
    178  else if( invert && this->distance(target) > radius)
    179  {
    180      executeAction(timestep);
    181      scriptCalled = true;
    182  }
     171  }
     172  else if( invert && this->distance(target) > radius)
     173  {
     174    executeAction(timestep);
     175    scriptCalled = true;
     176  }
    183177 //else
    184178   //printf("SCRIPTTRIGGER: target out of range\n");
     
    190184{
    191185 
    192      if(scriptIsOk)
    193      {
     186  if(scriptIsOk)
     187  {
    194188       //testScriptingFramework();
    195      if(!(script->selectFunction(this->functionName,returnCount)) )
    196        printf("Error ScriptTrigger: Selection of %s in %s failed.\n",functionName.c_str(), script->getFileName().c_str());
    197      
    198      script->pushParam( timestep, this->functionName);
    199      
    200      if( !(script->executeFunction()) )
    201        printf("Error ScriptTrigger: Execution of %s in %s failed.\n",functionName.c_str(), script->getFileName().c_str());
    202      
    203      scriptFinished = script->getReturnedBool();
    204      }
     189    if(!(script->selectFunction(this->functionName,returnCount)) )
     190      printf("Error ScriptTrigger: Selection of %s in %s failed.\n",functionName.c_str(), script->getFileName().c_str());
     191     
     192    script->pushParam( timestep, this->functionName);
     193     
     194    if( !(script->executeFunction()) )
     195      printf("Error ScriptTrigger: Execution of %s in %s failed.\n",functionName.c_str(), script->getFileName().c_str());
     196     
     197    scriptFinished = script->getReturnedBool();
     198  }
    205199     
    206200     
     
    225219/*
    226220 void ScriptTrigger::testScriptingFramework()
    227  {
     221{
    228222   std::string file("lunartest2.lua");
    229223   //get script
  • trunk/src/world_entities/script_trigger.h

    r9003 r9006  
    3737    void setTriggerLasts(const bool lasts) { this->triggerLasts = lasts; }
    3838    void setInvert(const bool inv) { this->invert = invert; }
     39    void setDelay(float delay) { this->delay = delay; };
    3940    void setRadius(const float radius) { if(radius>0) this->radius = radius; }
    4041    void setScript(const std::string& file);
  • trunk/src/world_entities/skydome.cc

    r8793 r9006  
    11/*
    22   orxonox - the future of 3D-vertical-scrollers
    3 
     3 
    44   Copyright (C) 2006 orx
    5 
     5 
    66   This program is free software; you can redistribute it and/or modify
    77   it under the terms of the GNU General Public License as published by
    88   the Free Software Foundation; either version 2, or (at your option)
    99   any later version.
    10 
     10 
    1111### File Specific:
    1212   main-programmer: hdavid, amaechler
     
    4343{
    4444  PRINTF(0)("Skydome init\n");
    45  
     45
    4646  this->setClassID(CL_SKYDOME, "Skydome");
    4747  this->toList(OM_BACKGROUND);
    48   this->toReflectionList(); 
     48  this->toReflectionList();
    4949 
     50  activateDome = false;
     51
    5052}
    5153
     
    5759{
    5860  PRINTF(0)("Deleting Skydome\n");
    59  
     61
    6062  if (glIsTexture(texture))
    6163    glDeleteTextures(1, &texture);
     
    7476
    7577
     78void Skydome::activate()
     79{
     80  this->activateDome = true;
     81}
     82
     83void Skydome::deactivate()
     84{
     85  this->activateDome = false;
     86}
     87
     88
    7689void Skydome::draw() const
    7790{
     91  if(!activateDome)
     92    return;
     93 
    7894  glPushAttrib(GL_ENABLE_BIT);
    7995
     
    88104  glPushMatrix();
    89105  glTranslatef(0.0f,pRadius,0.0f);
    90  
     106
    91107
    92108  glBegin(GL_TRIANGLES);
     
    113129{
    114130  PRINTF(0)("Generating a sky plane");
    115  
     131
    116132  // Make sure our vertex array is clear
    117   if (planeVertices) 
     133  if (planeVertices)
    118134  {
    119135    delete planeVertices;
     
    130146  // Set the number of divisions into a valid range
    131147  int divs = divisions;
    132   if (divisions < 1) 
     148  if (divisions < 1)
    133149    divs = 1;
    134150
    135   if (divisions > 256) 
    136     divs = 256; 
     151  if (divisions > 256)
     152    divs = 256;
    137153
    138154  pRadius = planetRadius;
     
    152168  float delta = plane_size/(float)divs;
    153169  float tex_delta = 2.0f/(float)divs;
    154  
     170
    155171  // Variables we'll use during the dome's generation
    156172  float x_dist   = 0.0f;
     
    193209      int startvert = (i*(divs+1) + j);
    194210
    195         // tri 1
     211      // tri 1
    196212      indices[index++] = startvert;
    197213      indices[index++] = startvert+1;
     
    203219      indices[index++] = startvert+divs+1;
    204220    }
    205   } 
    206 }
     221  }
     222}
  • trunk/src/world_entities/skydome.h

    r8793 r9006  
    3434  void setShader(Shader* shader);
    3535  void setTexture(GLuint texture);
     36 
     37  void activate();
     38  void deactivate();
    3639
    3740private:
     
    4447  };
    4548
     49  bool activateDome;
    4650 
    4751  VertexInfo *planeVertices;
Note: See TracChangeset for help on using the changeset viewer.