Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Jun 15, 2006, 9:50:56 PM (18 years ago)
Author:
bensch
Message:

merged the branche atmos back. no conflicts

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/lib/graphics/effects/lightening_effect.cc

    r8316 r8495  
    3333CREATE_FACTORY(LighteningEffect, CL_LIGHTENING_EFFECT);
    3434
     35// TODO: FIx Lightening with Fog enabled
     36
    3537LighteningEffect::LighteningEffect(const TiXmlElement* root)
    3638{
     
    4244                this->loadParams(root);
    4345
    44   if(this->lighteningActivate)
    45          this->activate();
     46        if(this->lighteningActivate)
     47                this->activate();
    4648}
    4749
     
    5557        WeatherEffect::loadParams(root);
    5658
    57   LoadParam(root, "coord", this, LighteningEffect, coord);
    58   LoadParam(root, "option", this, LighteningEffect, setLighteningOption);
    59   LoadParam(root, "frequency", this, LighteningEffect, setFlashFrequency);
    60   LoadParam(root, "const-time", this, LighteningEffect, setFlashConstTime);
    61   LoadParam(root, "rising-time", this, LighteningEffect, setFlashRisingTime);
    62   LoadParam(root, "size", this, LighteningEffect, setFlashSize);
    63   LoadParam(root, "seed", this, LighteningEffect, setFlashSeed);
    64 }
    65 
    66 
    67 bool LighteningEffect::init()
    68 {
    69   lighteningActivate = false;
    70 
    71   this->time = 0.0;
    72   this->flashFrequency = 1.4f;
    73   this->flashConstTime = 0.5f;
    74   this->flashRisingTime = 0.1f;
    75 
    76   this->width = 400.0f;
    77   this->height = 100.0f;
    78   this->seedWidth = 50;
    79   this->seedHeight = 50;
    80   this->bNewCoordinate = false;
    81 
    82   this->seedX = 500.f;
    83   this->seedZ = 1000.0f;
    84   this->seedTime = 4.0f;
    85 
    86   this->billboard[0] = new Billboard(NULL);
    87   this->billboard[0]->setTexture("maps/lightning_bolt1.png");
    88   this->billboard[0]->setSize(this->width, this->height);
    89   this->billboard[0]->setAbsCoor(3000,850,0);
    90   this->billboard[0]->setVisibiliy(false);
    91 
    92   this->billboard[1] = new Billboard(NULL);
    93   this->billboard[1]->setTexture("maps/lightning_bolt2.png");
    94   this->billboard[1]->setSize(this->width, this->height);
    95   this->billboard[1]->setAbsCoor(3000,850,0);
    96   this->billboard[1]->setVisibiliy(false);
    97 
    98   this->billboard[2] = new Billboard(NULL);
    99   this->billboard[2]->setTexture("maps/lightning_bolt3.png");
    100   this->billboard[2]->setSize(this->width, this->height);
    101   this->billboard[2]->setAbsCoor(3000,850,0);
    102   this->billboard[2]->setVisibiliy(false);
    103 
    104   this->billboard[3] = new Billboard(NULL);
    105   this->billboard[3]->setTexture("maps/lightning_bolt4.png");
    106   this->billboard[3]->setSize(this->width, this->height);
    107   this->billboard[3]->setAbsCoor(0.0f, 50.0f, 0.0f);
    108   this->billboard[3]->setVisibiliy(false);
    109 /*
    110   this->soundSource = NULL;
    111   this->thunderBuffer = NULL;
    112 
    113   this->soundSource.setSourceNode(this);
    114 
    115   //load sound
    116   if (this->thunderBuffer != NULL)
    117     ResourceManager::getInstance()->unload(this->thunderBuffer);
    118   this->thunderBuffer = (OrxSound::SoundBuffer*)ResourceManager::getInstance()->load("sound/thunder.wav", WAV);*/
    119 
    120   return true;
     59        LoadParam(root, "coord", this, LighteningEffect, coord);
     60        LoadParam(root, "frequency", this, LighteningEffect, setFlashFrequency);
     61        LoadParam(root, "const-time", this, LighteningEffect, setFlashConstTime);
     62        LoadParam(root, "rising-time", this, LighteningEffect, setFlashRisingTime);
     63        LoadParam(root, "size", this, LighteningEffect, setFlashSize);
     64        LoadParam(root, "seed", this, LighteningEffect, setFlashSeed);
     65
     66        LOAD_PARAM_START_CYCLE(root, element);
     67        {
     68                LoadParam_CYCLE(element, "option", this, LighteningEffect, setLighteningOption);
     69        }
     70        LOAD_PARAM_END_CYCLE(element);
     71}
     72
     73
     74void LighteningEffect::init()
     75{
     76        //default values
     77        this->lighteningActivate = false;
     78
     79        this->time = 0.0;
     80        this->flashFrequency = 4.0f;
     81        this->mainFrequency = 4.0f;
     82        this->flashConstTime = 0.1f;
     83        this->flashRisingTime = 0.03f;
     84
     85        this->width = 700.0f;
     86        this->height = 250.0f;
     87        this->seedWidth = 50.0f;
     88        this->seedHeight = 50.0f;
     89        this->bNewCoordinate = false;
     90  this->lighteningMove = false;
     91
     92        this->seedX = 500.f;
     93        this->seedZ = 1000.0f;
     94        this->seedTime = 2.0f;
     95
     96  this->mainPosX = 3000;
     97  this->mainPosY = 900;
     98  this->mainPosZ = 0;
     99
     100        // initialize lightening textures
     101        this->billboard[0] = new Billboard(NULL);
     102        this->billboard[0]->setTexture("maps/lightning_bolt1.png");
     103        this->billboard[0]->setSize(this->width, this->height);
     104        this->billboard[0]->setVisibiliy(false);
     105
     106        this->billboard[1] = new Billboard(NULL);
     107        this->billboard[1]->setTexture("maps/lightning_bolt2.png");
     108        this->billboard[1]->setSize(this->width, this->height);
     109        this->billboard[1]->setVisibiliy(false);
     110
     111        this->billboard[2] = new Billboard(NULL);
     112        this->billboard[2]->setTexture("maps/lightning_bolt3.png");
     113        this->billboard[2]->setSize(this->width, this->height);
     114        this->billboard[2]->setVisibiliy(false);
     115
     116        this->billboard[3] = new Billboard(NULL);
     117        this->billboard[3]->setTexture("maps/lightning_bolt4.png");
     118        this->billboard[3]->setSize(this->width, this->height);
     119        this->billboard[3]->setVisibiliy(false);
     120
     121        if (this->lighteningMove) {
     122                this->cameraCoor = State::getCameraNode()->getAbsCoor();
     123                this->billboard[0]->setAbsCoor(this->cameraCoor.x+3000,900,this->cameraCoor.z+0);
     124                this->billboard[1]->setAbsCoor(this->cameraCoor.x+3000,900,this->cameraCoor.z+0);
     125                this->billboard[2]->setAbsCoor(this->cameraCoor.x+3000,900,this->cameraCoor.z+0);
     126                this->billboard[3]->setAbsCoor(this->cameraCoor.x+3000,900,this->cameraCoor.z+0);
     127        } else {
     128                this->billboard[0]->setAbsCoor(3000,900,0);
     129                this->billboard[1]->setAbsCoor(3000,900,0);
     130                this->billboard[2]->setAbsCoor(3000,900,0);
     131                this->billboard[3]->setAbsCoor(3000,900,0);
     132        }
     133
     134        this->flashLight = new Light();
     135        this->flashLight->setDiffuseColor(0,0,0);
     136        this->flashLight->setSpecularColor(0,0,0);
     137
     138        /*
     139        this->soundSource = NULL;
     140        this->thunderBuffer = NULL;
     141
     142        this->soundSource.setSourceNode(this);
     143
     144        //load sound
     145        if (this->thunderBuffer != NULL)
     146        ResourceManager::getInstance()->unload(this->thunderBuffer);
     147        this->thunderBuffer = (OrxSound::SoundBuffer*)ResourceManager::getInstance()->load("sound/thunder.wav", WAV);*/
     148
    121149}
    122150
    123151void LighteningEffect::coord(float x, float y, float z)
    124152{
    125   this->billboard[0]->setAbsCoor(x, y, z);
    126   this->billboard[1]->setAbsCoor(x, y, z);
    127   this->billboard[2]->setAbsCoor(x, y, z);
    128   this->billboard[3]->setAbsCoor(x, y, z);
    129   this->mainPosX = x;
    130   this->mainPosY = y;
    131   this->mainPosZ = z;
     153        if (this->lighteningMove) {
     154                this->cameraCoor = State::getCameraNode()->getAbsCoor();
     155                this->billboard[0]->setAbsCoor(this->cameraCoor.x+x, y, this->cameraCoor.z+z);
     156                this->billboard[1]->setAbsCoor(this->cameraCoor.x+x, y, this->cameraCoor.z+z);
     157                this->billboard[2]->setAbsCoor(this->cameraCoor.x+x, y, this->cameraCoor.z+z);
     158                this->billboard[3]->setAbsCoor(this->cameraCoor.x+x, y, this->cameraCoor.z+z);
     159        } else {
     160                this->billboard[0]->setAbsCoor(x, y, z);
     161                this->billboard[1]->setAbsCoor(x, y, z);
     162                this->billboard[2]->setAbsCoor(x, y, z);
     163                this->billboard[3]->setAbsCoor(x, y, z);
     164        }
     165
     166        this->mainPosX = x;
     167        this->mainPosY = y;
     168        this->mainPosZ = z;
    132169}
    133170
     
    135172void LighteningEffect::setFlashSize(float width, float height, float seedWidth, float seedHeight)
    136173{
    137   this->width = width;
    138   this->height = height;
    139   this->seedWidth = seedWidth;
    140   this->seedHeight = seedHeight;
    141   this->billboard[0]->setSize(this->width, this->height);
    142   this->billboard[1]->setSize(this->width, this->height);
    143   this->billboard[2]->setSize(this->width, this->height);
    144   this->billboard[3]->setSize(this->width, this->height);
    145 }
    146 
    147 
    148 bool LighteningEffect::activate()
     174        this->width = width;
     175        this->height = height;
     176        this->seedWidth = seedWidth;
     177        this->seedHeight = seedHeight;
     178
     179        this->billboard[0]->setSize(this->width, this->height);
     180        this->billboard[1]->setSize(this->width, this->height);
     181        this->billboard[2]->setSize(this->width, this->height);
     182        this->billboard[3]->setSize(this->width, this->height);
     183}
     184
     185
     186void LighteningEffect::activate()
    149187{
    150188        PRINTF(0)( "Activating LighteningEffect\n" );
    151   this->time = 0;
    152   lighteningActivate = true;
    153 
    154   return true;
    155 }
    156 
    157 
    158 bool LighteningEffect::deactivate()
     189        this->lighteningActivate = true;
     190
     191        this->time = 0;
     192}
     193
     194
     195void LighteningEffect::deactivate()
    159196{
    160197        PRINTF(0)("Deactivating LighteningEffect\n");
    161   this->billboard[0]->setVisibiliy(false);
    162   this->billboard[1]->setVisibiliy(false);
    163   this->billboard[2]->setVisibiliy(false);
    164   this->billboard[3]->setVisibiliy(false);
    165   lighteningActivate = false;
    166 
    167 
    168   return true;
     198        this->lighteningActivate = false;
     199
     200        this->billboard[0]->setVisibiliy(false);
     201        this->billboard[1]->setVisibiliy(false);
     202        this->billboard[2]->setVisibiliy(false);
     203        this->billboard[3]->setVisibiliy(false);
    169204}
    170205
    171206void LighteningEffect::tick (float dt)
    172207{
    173   if(!lighteningActivate)
    174     return;
    175 
    176   this->time += dt;
    177 
    178   /*if( flashLight != NULL)
    179   {
    180     if((int)(100*time)%2)
    181       this->flashLight->setDiffuseColor(0,0,0);
    182     else
    183       this->flashLight->setDiffuseColor(100,100,100);
    184 
    185     //PRINTF(0)("100*time: %f %i\n", 100*time, (int)(100*time));
    186 }*/
    187 
    188   if( this->time > this->flashFrequency)
    189   {
    190     this->billboard[0]->setVisibiliy(true);
    191     this->time = 0.0f;
    192 
    193     this->flashLight = new Light();
    194     this->flashLight->setAbsCoor(this->billboard[0]->getAbsCoor().x, this->billboard[0]->getAbsCoor().y, this->billboard[0]->getAbsCoor().z);
    195     this->flashLight->setDiffuseColor(100,100,100);
    196 
    197     //this->soundSource.play(this->thunderBuffer);
    198   }
    199   else if( this->billboard[3]->isVisible() && this->time > this->flashConstTime)
    200   {
    201     this->billboard[3]->setVisibiliy(false);
    202     this->time = 0.0f;
    203     this->bNewCoordinate = true;
    204 
    205     if(flashLight != NULL)
    206     {
    207       delete this->flashLight;
    208       flashLight = NULL;
    209     }
    210   }
    211 
    212   if( this->billboard[2]->isVisible() && this->time > this->flashRisingTime)
    213   {
    214     this->billboard[2]->setVisibiliy(false);
    215     this->billboard[3]->setVisibiliy(true);
    216     this->flashLight->setDiffuseColor(100,100,100);
    217   }
    218   else if( this->billboard[1]->isVisible() && this->time > this->flashRisingTime*2/3 )
    219   {
    220     this->billboard[1]->setVisibiliy(false);
    221     this->billboard[2]->setVisibiliy(true);
    222     this->flashLight->setDiffuseColor(0,0,0);
    223   }
    224   else if( this->billboard[0]->isVisible() && this->time > this->flashRisingTime*1/3 )
    225   {
    226     this->billboard[0]->setVisibiliy(false);
    227     this->billboard[1]->setVisibiliy(true);
    228     this->flashLight->setDiffuseColor(100,100,100);
    229   }
    230 
    231   if( this->bNewCoordinate)
    232   {
    233     float posX = this->mainPosX - this->seedX * (float)rand()/(float)RAND_MAX;
    234     float posZ = this->mainPosZ + this->seedZ * (float)rand()/(float)RAND_MAX;
    235     this->billboard[0]->setAbsCoor(posX, this->mainPosY, posZ);
    236     this->billboard[1]->setAbsCoor(posX, this->mainPosY, posZ);
    237     this->billboard[2]->setAbsCoor(posX, this->mainPosY, posZ);
    238     this->billboard[3]->setAbsCoor(posX, this->mainPosY, posZ);
    239     this->bNewCoordinate = false;
    240   }
     208        if(!lighteningActivate)
     209                return;
     210
     211        this->time += dt;
     212
     213        // TODO: Make random flashing with short light dingsda:)
     214
     215        if( this->time > this->flashFrequency) {
     216
     217                this->billboard[0]->setVisibiliy(true);
     218                this->time = 0.0f;
     219
     220                this->flashLight->setAbsCoor(this->billboard[0]->getAbsCoor().x, this->billboard[0]->getAbsCoor().y, this->billboard[0]->getAbsCoor().z);
     221
     222                // flash environmental lightening
     223                this->flashLight->setDiffuseColor(1,1,1);
     224                this->flashLight->setSpecularColor(1,1,1);
     225
     226                //this->soundSource.play(this->thunderBuffer);
     227
     228        } else if( this->billboard[3]->isVisible() && this->time > this->flashConstTime) {
     229
     230                this->billboard[3]->setVisibiliy(false);
     231                this->time = 0.0f;
     232                this->flashLight->setDiffuseColor(0,0,0);
     233                this->flashLight->setSpecularColor(0,0,0);
     234                this->bNewCoordinate = true;
     235
     236        }
     237
     238        if( this->billboard[2]->isVisible() && this->time > this->flashRisingTime) {
     239
     240                this->billboard[2]->setVisibiliy(false);
     241                this->billboard[3]->setVisibiliy(true);
     242                // this->flashLight->setDiffuseColor(1,1,1);
     243                // this->flashLight->setSpecularColor(1,1,1);
     244
     245        } else if( this->billboard[1]->isVisible() && this->time > this->flashRisingTime*2/3 ) {
     246
     247                this->billboard[1]->setVisibiliy(false);
     248                this->billboard[2]->setVisibiliy(true);
     249                //this->flashLight->setDiffuseColor(0,0,0);
     250                //this->flashLight->setSpecularColor(0,0,0);
     251
     252        } else if( this->billboard[0]->isVisible() && this->time > this->flashRisingTime*1/3 ) {
     253
     254                this->billboard[0]->setVisibiliy(false);
     255                this->billboard[1]->setVisibiliy(true);
     256                //this->flashLight->setDiffuseColor(1,1,1);
     257                //this->flashLight->setSpecularColor(1,1,1);
     258
     259        }
     260
     261        if( this->bNewCoordinate) {
     262                float posX, posZ;
     263
     264                if(this->lighteningMove) {
     265
     266                        this->cameraCoor = State::getCameraNode()->getAbsCoor();
     267                        posX = this->mainPosX - this->seedX * (float)rand()/(float)RAND_MAX + this->cameraCoor.x;
     268                        posZ = this->mainPosZ + this->seedZ * (float)rand()/(float)RAND_MAX + this->cameraCoor.z;
     269
     270                } else {
     271
     272                        posX = this->mainPosX - this->seedX * (float)rand()/(float)RAND_MAX;
     273                        posZ = this->mainPosZ + this->seedZ * (float)rand()/(float)RAND_MAX;
     274
     275                }
     276
     277                this->billboard[0]->setAbsCoor(posX, this->mainPosY, posZ);
     278                this->billboard[1]->setAbsCoor(posX, this->mainPosY, posZ);
     279                this->billboard[2]->setAbsCoor(posX, this->mainPosY, posZ);
     280                this->billboard[3]->setAbsCoor(posX, this->mainPosY, posZ);
     281
     282                this->flashFrequency = this->mainFrequency + this->seedTime * (float)rand()/(float)RAND_MAX;
     283
     284                float w = this->width + this->seedWidth * (float)rand()/(float)RAND_MAX;
     285                float h = this->height + this->seedHeight * (float)rand()/(float)RAND_MAX;
     286
     287                this->billboard[0]->setSize(w, h);
     288                this->billboard[1]->setSize(w, h);
     289                this->billboard[2]->setSize(w, h);
     290                this->billboard[3]->setSize(w, h);
     291
     292                this->bNewCoordinate = false;
     293        }
    241294}
    242295
Note: See TracChangeset for help on using the changeset viewer.