Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Jun 14, 2006, 11:28:41 AM (18 years ago)
Author:
amaechler
Message:

branches/atmospheric_engine

File:
1 edited

Legend:

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

    r8326 r8373  
    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
     
    5456{
    5557        WeatherEffect::loadParams(root);
    56  
    57   LoadParam(root, "coord", this, LighteningEffect, coord);
    58   LoadParam(root, "frequency", this, LighteningEffect, setFlashFrequency);
    59   LoadParam(root, "const-time", this, LighteningEffect, setFlashConstTime);
    60   LoadParam(root, "rising-time", this, LighteningEffect, setFlashRisingTime);
    61   LoadParam(root, "size", this, LighteningEffect, setFlashSize);
    62   LoadParam(root, "seed", this, LighteningEffect, setFlashSeed);
    63  
    64   LOAD_PARAM_START_CYCLE(root, element);
    65   {
    66     LoadParam_CYCLE(element, "option", this, LighteningEffect, setLighteningOption);
    67   }
    68   LOAD_PARAM_END_CYCLE(element);
     58
     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);
    6971}
    7072
     
    7274bool LighteningEffect::init()
    7375{
    74   lighteningActivate = false;
    75  
    76   this->time = 0.0;
    77   this->flashFrequency = 1.4f;
    78   this->mainFrequency = 1.4f;
    79   this->flashConstTime = 0.5f;
    80   this->flashRisingTime = 0.1f;
    81 
    82   this->width = 400.0f;
    83   this->height = 100.0f;
    84   this->seedWidth = 50;
    85   this->seedHeight = 50;
    86   this->bNewCoordinate = false;
    87 
    88   this->seedX = 500.f;
    89   this->seedZ = 1000.0f;
    90   this->seedTime = 4.0f;
    91 
    92   this->billboard[0] = new Billboard(NULL);
    93   this->billboard[0]->setTexture("maps/lightning_bolt1.png");
    94   this->billboard[0]->setSize(this->width, this->height);
    95   this->billboard[0]->setVisibiliy(false);
    96 
    97   this->billboard[1] = new Billboard(NULL);
    98   this->billboard[1]->setTexture("maps/lightning_bolt2.png");
    99   this->billboard[1]->setSize(this->width, this->height);
    100   this->billboard[1]->setVisibiliy(false);
    101 
    102   this->billboard[2] = new Billboard(NULL);
    103   this->billboard[2]->setTexture("maps/lightning_bolt3.png");
    104   this->billboard[2]->setSize(this->width, this->height);
    105   this->billboard[2]->setVisibiliy(false);
    106 
    107   this->billboard[3] = new Billboard(NULL);
    108   this->billboard[3]->setTexture("maps/lightning_bolt4.png");
    109   this->billboard[3]->setSize(this->width, this->height);
    110   this->billboard[3]->setVisibiliy(false);
    111  
    112   if (this->lighteningMove)
    113   {
    114     this->cameraCoor = State::getCameraNode()->getAbsCoor();
    115     this->billboard[0]->setAbsCoor(this->cameraCoor.x+3000,850,this->cameraCoor.z+0);
    116     this->billboard[1]->setAbsCoor(this->cameraCoor.x+3000,850,this->cameraCoor.z+0);
    117     this->billboard[2]->setAbsCoor(this->cameraCoor.x+3000,850,this->cameraCoor.z+0);
    118     this->billboard[3]->setAbsCoor(this->cameraCoor.x+3000,850,this->cameraCoor.z+0);
    119   }
    120   else
    121   {
    122     this->billboard[0]->setAbsCoor(3000,850,0);
    123     this->billboard[1]->setAbsCoor(3000,850,0);
    124     this->billboard[2]->setAbsCoor(3000,850,0);
    125     this->billboard[3]->setAbsCoor(3000,850,0);
    126   }
    127  
    128   this->flashLight = new Light();
    129   this->flashLight->setDiffuseColor(0,0,0);
    130   this->flashLight->setSpecularColor(0,0,0);
    131  
    132 /*
    133   this->soundSource = NULL;
    134   this->thunderBuffer = NULL;
    135 
    136   this->soundSource.setSourceNode(this);
    137 
    138   //load sound
    139   if (this->thunderBuffer != NULL)
    140     ResourceManager::getInstance()->unload(this->thunderBuffer);
    141   this->thunderBuffer = (OrxSound::SoundBuffer*)ResourceManager::getInstance()->load("sound/thunder.wav", WAV);*/
     76        //default values
     77        this->lighteningActivate = false;
     78       
     79        this->time = 0.0;
     80        this->flashFrequency = 1.4f;
     81        this->mainFrequency = 1.4f;
     82        this->flashConstTime = 0.5f;
     83        this->flashRisingTime = 0.1f;
     84       
     85        this->width = 400.0f;
     86        this->height = 100.0f;
     87        this->seedWidth = 50;
     88        this->seedHeight = 50;
     89        this->bNewCoordinate = false;
     90       
     91        this->seedX = 500.f;
     92        this->seedZ = 1000.0f;
     93        this->seedTime = 4.0f;
     94       
     95        // initialize lightening textures
     96        this->billboard[0] = new Billboard(NULL);
     97        this->billboard[0]->setTexture("maps/lightning_bolt1.png");
     98        this->billboard[0]->setSize(this->width, this->height);
     99        this->billboard[0]->setVisibiliy(false);
     100       
     101        this->billboard[1] = new Billboard(NULL);
     102        this->billboard[1]->setTexture("maps/lightning_bolt2.png");
     103        this->billboard[1]->setSize(this->width, this->height);
     104        this->billboard[1]->setVisibiliy(false);
     105       
     106        this->billboard[2] = new Billboard(NULL);
     107        this->billboard[2]->setTexture("maps/lightning_bolt3.png");
     108        this->billboard[2]->setSize(this->width, this->height);
     109        this->billboard[2]->setVisibiliy(false);
     110       
     111        this->billboard[3] = new Billboard(NULL);
     112        this->billboard[3]->setTexture("maps/lightning_bolt4.png");
     113        this->billboard[3]->setSize(this->width, this->height);
     114        this->billboard[3]->setVisibiliy(false);
     115       
     116        if (this->lighteningMove) {
     117                this->cameraCoor = State::getCameraNode()->getAbsCoor();
     118                this->billboard[0]->setAbsCoor(this->cameraCoor.x+3000,850,this->cameraCoor.z+0);
     119                this->billboard[1]->setAbsCoor(this->cameraCoor.x+3000,850,this->cameraCoor.z+0);
     120                this->billboard[2]->setAbsCoor(this->cameraCoor.x+3000,850,this->cameraCoor.z+0);
     121                this->billboard[3]->setAbsCoor(this->cameraCoor.x+3000,850,this->cameraCoor.z+0);
     122        } else {
     123                this->billboard[0]->setAbsCoor(3000,850,0);
     124                this->billboard[1]->setAbsCoor(3000,850,0);
     125                this->billboard[2]->setAbsCoor(3000,850,0);
     126                this->billboard[3]->setAbsCoor(3000,850,0);
     127        }
     128       
     129        this->flashLight = new Light();
     130        this->flashLight->setDiffuseColor(0,0,0);
     131        this->flashLight->setSpecularColor(0,0,0);
     132       
     133        /*
     134        this->soundSource = NULL;
     135        this->thunderBuffer = NULL;
     136       
     137        this->soundSource.setSourceNode(this);
     138       
     139        //load sound
     140        if (this->thunderBuffer != NULL)
     141        ResourceManager::getInstance()->unload(this->thunderBuffer);
     142        this->thunderBuffer = (OrxSound::SoundBuffer*)ResourceManager::getInstance()->load("sound/thunder.wav", WAV);*/
     143
     144        return 0;
    142145}
    143146
    144147void LighteningEffect::coord(float x, float y, float z)
    145148{
    146   if (this->lighteningMove)
    147   {
    148     this->cameraCoor = State::getCameraNode()->getAbsCoor();
    149     this->billboard[0]->setAbsCoor(this->cameraCoor.x+x, y, this->cameraCoor.z+z);
    150     this->billboard[1]->setAbsCoor(this->cameraCoor.x+x, y, this->cameraCoor.z+z);
    151     this->billboard[2]->setAbsCoor(this->cameraCoor.x+x, y, this->cameraCoor.z+z);
    152     this->billboard[3]->setAbsCoor(this->cameraCoor.x+x, y, this->cameraCoor.z+z);
    153   }
    154   else
    155   {
    156     this->billboard[0]->setAbsCoor(x, y, z);
    157     this->billboard[1]->setAbsCoor(x, y, z);
    158     this->billboard[2]->setAbsCoor(x, y, z);
    159     this->billboard[3]->setAbsCoor(x, y, z);
    160   }
    161   this->mainPosX = x;
    162   this->mainPosY = y;
    163   this->mainPosZ = z;
     149        if (this->lighteningMove) {
     150                this->cameraCoor = State::getCameraNode()->getAbsCoor();
     151                this->billboard[0]->setAbsCoor(this->cameraCoor.x+x, y, this->cameraCoor.z+z);
     152                this->billboard[1]->setAbsCoor(this->cameraCoor.x+x, y, this->cameraCoor.z+z);
     153                this->billboard[2]->setAbsCoor(this->cameraCoor.x+x, y, this->cameraCoor.z+z);
     154                this->billboard[3]->setAbsCoor(this->cameraCoor.x+x, y, this->cameraCoor.z+z);
     155        } else {
     156                this->billboard[0]->setAbsCoor(x, y, z);
     157                this->billboard[1]->setAbsCoor(x, y, z);
     158                this->billboard[2]->setAbsCoor(x, y, z);
     159                this->billboard[3]->setAbsCoor(x, y, z);
     160        }
     161
     162        this->mainPosX = x;
     163        this->mainPosY = y;
     164        this->mainPosZ = z;
    164165}
    165166
     
    167168void LighteningEffect::setFlashSize(float width, float height, float seedWidth, float seedHeight)
    168169{
    169   this->width = width;
    170   this->height = height;
    171   this->seedWidth = seedWidth;
    172   this->seedHeight = seedHeight;
    173   this->billboard[0]->setSize(this->width, this->height);
    174   this->billboard[1]->setSize(this->width, this->height);
    175   this->billboard[2]->setSize(this->width, this->height);
    176   this->billboard[3]->setSize(this->width, this->height);
     170        this->width = width;
     171        this->height = height;
     172        this->seedWidth = seedWidth;
     173        this->seedHeight = seedHeight;
     174
     175        this->billboard[0]->setSize(this->width, this->height);
     176        this->billboard[1]->setSize(this->width, this->height);
     177        this->billboard[2]->setSize(this->width, this->height);
     178        this->billboard[3]->setSize(this->width, this->height);
    177179}
    178180
     
    181183{
    182184        PRINTF(0)( "Activating LighteningEffect\n" );
    183   this->time = 0;
    184   lighteningActivate = true;
     185        this->lighteningActivate = true;
     186
     187        this->time = 0;
     188
     189        return 0;
    185190}
    186191
     
    189194{
    190195        PRINTF(0)("Deactivating LighteningEffect\n");
    191   this->billboard[0]->setVisibiliy(false);
    192   this->billboard[1]->setVisibiliy(false);
    193   this->billboard[2]->setVisibiliy(false);
    194   this->billboard[3]->setVisibiliy(false);
    195   lighteningActivate = false;
     196        this->lighteningActivate = false;
     197
     198        this->billboard[0]->setVisibiliy(false);
     199        this->billboard[1]->setVisibiliy(false);
     200        this->billboard[2]->setVisibiliy(false);
     201        this->billboard[3]->setVisibiliy(false);
     202
     203        return 0;
    196204}
    197205
    198206void LighteningEffect::tick (float dt)
    199207{
    200   if(!lighteningActivate)
    201     return;
    202  
    203   this->time += dt;
    204  
    205   if( this->time > this->flashFrequency)
    206   {
    207     this->billboard[0]->setVisibiliy(true);
    208     this->time = 0.0f;
    209 
    210     this->flashLight->setAbsCoor(this->billboard[0]->getAbsCoor().x, this->billboard[0]->getAbsCoor().y, this->billboard[0]->getAbsCoor().z);
    211     this->flashLight->setDiffuseColor(1,1,1);
    212     this->flashLight->setSpecularColor(1,1,1);
    213    
    214     //this->soundSource.play(this->thunderBuffer);
    215   }
    216   else if( this->billboard[3]->isVisible() && this->time > this->flashConstTime)
    217   {
    218     this->billboard[3]->setVisibiliy(false);
    219     this->time = 0.0f;
    220     this->flashLight->setDiffuseColor(0,0,0);
    221     this->flashLight->setSpecularColor(0,0,0);
    222     this->bNewCoordinate = true;
    223   }
    224 
    225   if( this->billboard[2]->isVisible() && this->time > this->flashRisingTime)
    226   {
    227     this->billboard[2]->setVisibiliy(false);
    228     this->billboard[3]->setVisibiliy(true);
    229    // this->flashLight->setDiffuseColor(1,1,1);
    230    // this->flashLight->setSpecularColor(1,1,1);
    231   }
    232   else if( this->billboard[1]->isVisible() && this->time > this->flashRisingTime*2/3 )
    233   {
    234     this->billboard[1]->setVisibiliy(false);
    235     this->billboard[2]->setVisibiliy(true);
    236     //this->flashLight->setDiffuseColor(0,0,0);
    237     //this->flashLight->setSpecularColor(0,0,0);
    238   }
    239   else if( this->billboard[0]->isVisible() && this->time > this->flashRisingTime*1/3 )
    240   {
    241     this->billboard[0]->setVisibiliy(false);
    242     this->billboard[1]->setVisibiliy(true);
    243     //this->flashLight->setDiffuseColor(1,1,1);
    244     //this->flashLight->setSpecularColor(1,1,1);
    245   }
    246 
    247   if( this->bNewCoordinate)
    248   {
    249     float posX, posZ;
    250     if(this->lighteningMove)
    251     {
    252     this->cameraCoor = State::getCameraNode()->getAbsCoor();
    253     posX = this->mainPosX - this->seedX * (float)rand()/(float)RAND_MAX + this->cameraCoor.x;
    254     posZ = this->mainPosZ + this->seedZ * (float)rand()/(float)RAND_MAX + this->cameraCoor.z;
    255     }
    256     else
    257     {
    258       posX = this->mainPosX - this->seedX * (float)rand()/(float)RAND_MAX;
    259       posZ = this->mainPosZ + this->seedZ * (float)rand()/(float)RAND_MAX;
    260     }
    261    
    262     this->billboard[0]->setAbsCoor(posX, this->mainPosY, posZ);
    263     this->billboard[1]->setAbsCoor(posX, this->mainPosY, posZ);
    264     this->billboard[2]->setAbsCoor(posX, this->mainPosY, posZ);
    265     this->billboard[3]->setAbsCoor(posX, this->mainPosY, posZ);
    266     this->flashFrequency = this->mainFrequency + this->seedTime * (float)rand()/(float)RAND_MAX;
    267     float w = this->width + this->seedWidth * (float)rand()/(float)RAND_MAX;
    268     float h = this->height + this->seedHeight * (float)rand()/(float)RAND_MAX;
    269     this->billboard[0]->setSize(w, h);
    270     this->billboard[1]->setSize(w, h);
    271     this->billboard[2]->setSize(w, h);
    272     this->billboard[3]->setSize(w, h);
    273     this->bNewCoordinate = false;
    274   }
     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        }
    275294}
    276295
Note: See TracChangeset for help on using the changeset viewer.