Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Jun 8, 2006, 3:44:12 PM (19 years ago)
Author:
bensch
Message:

merged the atmos back with command: https://svn.orxonox.net/orxonox/branches/atmospheric_engine

File:
1 edited

Legend:

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

    r7810 r8255  
    11/*
    2    orxonox - the future of 3D-vertical-scrollers
    3 
    4    Copyright (C) 2004 orx
    5 
    6    This program is free software; you can redistribute it and/or modify
    7    it under the terms of the GNU General Public License as published by
    8    the Free Software Foundation; either version 2, or (at your option)
    9    any later version.
     2orxonox - the future of 3D-vertical-scrollers
     3
     4Copyright (C) 2004 orx
     5
     6This program is free software; you can redistribute it and/or modify
     7it under the terms of the GNU General Public License as published by
     8the Free Software Foundation; either version 2, or (at your option)
     9any later version.
    1010
    1111### File Specific:
    12    main-programmer: hdavid, amaechler
     12main-programmer: hdavid, amaechler
    1313*/
    1414
     
    2525#include "plane_emitter.h"
    2626#include "shell_command.h"
     27#include "light.h"
    2728
    2829#include "parser/tinyxml/tinyxml.h"
     
    3132SHELL_COMMAND(deactivate, RainEffect, deactivateRain);
    3233
     34SHELL_COMMAND(startRaining, RainEffect, startRaining);
     35
    3336using namespace std;
    3437
    3538CREATE_FACTORY(RainEffect, CL_RAIN_EFFECT);
     39
     40// TODO: Dim Light with Rain, Finish preCaching, check out if multiple rain emitters work,  Think about what happens with building poss. to hang movewithcam off, benchmark, possible to activate lightening, turn off visibility when in a building, variable emitter size depending on playable, also rain velocity
    3641
    3742RainEffect::RainEffect(const TiXmlElement* root)
     
    5055
    5156        //load wind sound
    52         if (this->rainWindForce > 0) {
     57        if (this->rainWindForce != 0) {
    5358                if (this->windBuffer != NULL)
    5459                        ResourceManager::getInstance()->unload(this->windBuffer);
     
    5661        }
    5762
    58         this->activate();
     63        if(rainActivate)
     64                this->activate();
    5965}
    6066
     
    8086        LoadParam(root, "life", this, RainEffect, setRainLife);
    8187        LoadParam(root, "wind", this, RainEffect, setRainWind);
    82         LoadParam(root, "option", this, RainEffect, setRainOption);
     88        LoadParam(root, "startraining", this, RainEffect, setRainStart);
     89
     90        LOAD_PARAM_START_CYCLE(root, element);
     91        {
     92                LoadParam_CYCLE(element, "option", this, RainEffect, setRainOption);
     93        }
     94        LOAD_PARAM_END_CYCLE(element);
     95
    8396}
    8497
     
    87100{
    88101        //Default values
     102        this->rainActivate = false;
     103        this->rainMove = false;
    89104        this->rainCoord = Vector(500, 500, 500);
    90105        this->rainSize = Vector2D(1000, 1000);
     
    94109        this->rainMaxParticles = this->rainRate * this->rainLife;
    95110        this->rainWindForce  = 0;
     111        this->rainStartDuration = 0;
     112        this->localTimer = 0;
     113        this->soundRainVolume = 0.8f;
    96114
    97115        this->emitter = new PlaneEmitter(this->rainSize);
     116
     117        lightMan = LightManager::getInstance();
     118        this->rainAmbient = lightMan->getAmbientColor();
    98119}
    99120
     
    104125{
    105126        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" );
     127
     128        this->rainActivate = true;
    106129
    107130        if (unlikely(RainEffect::rainParticles == NULL))
     
    114137                RainEffect::rainParticles->setRadius(0.2, 0.02);
    115138                RainEffect::rainParticles->setRadius(1, 0.01);
    116                 RainEffect::rainParticles->setColor(0, 0.3, 0.3, 0.5, 0.2); // grey blue 1
    117                 RainEffect::rainParticles->setColor(0.5, 0.4, 0.4, 0.5, 0.2); // grey blue 2
    118                 RainEffect::rainParticles->setColor(1, 0.7, 0.7, 0.7, 0.2); // light grey
     139                RainEffect::rainParticles->setColor(0, 0.3, 0.3, 0.5, 0.2);     // grey blue 1
     140                RainEffect::rainParticles->setColor(0.5, 0.4, 0.4, 0.5, 0.2);   // grey blue 2
     141                RainEffect::rainParticles->setColor(1, 0.7, 0.7, 0.7, 0.2);     // light grey
    119142        }
    120143
     
    128151        this->emitter->setSpread(this->rainWindForce / 50, 0.2);
    129152       
    130         this->soundSource.loop(this->rainBuffer);
    131         if (this->rainWindForce > 0)
    132                 this->soundSource.loop(this->windBuffer);
     153        this->soundSource.loop(this->rainBuffer, this->soundRainVolume);
     154        if (this->rainWindForce != 0) this->soundSource.loop(this->windBuffer, 0.1f * this->rainWindForce);
     155
     156        lightMan->setAmbientColor(.1,.1,.1);
    133157}
    134158
     
    137161{
    138162        PRINTF(0)("Deactivating RainEffect\n");
     163       
     164        this->rainActivate = false;
    139165        this->emitter->setSystem(NULL);
    140166
     167        // Stop Sound
    141168        this->soundSource.stop();
    142 }
    143 
    144 void RainEffect::activateRain()
    145 {
    146         this->activate();
    147 }
    148 
    149 void RainEffect::deactivateRain()
    150 {
    151         this->deactivate();
    152 }
    153 
     169
     170        // Restore Light Ambient
     171        lightMan->setAmbientColor(this->rainAmbient, this->rainAmbient, this->rainAmbient);
     172}
    154173
    155174void RainEffect::tick (float dt)
    156175{
     176        if (!this->rainActivate)
     177                return;
     178               
    157179        if (this->rainMove) {
    158180                this->rainCoord = State::getCameraNode()->getAbsCoor();
    159181                this->emitter->setRelCoor(this->rainCoord.x , this->rainCoord.y+800, this->rainCoord.z);
    160182        }
    161 }
     183
     184        if (this->rainStartDuration != 0 && this->localTimer < this->rainStartDuration) {
     185                this->localTimer += dt;
     186                float progress = this->localTimer / this->rainStartDuration;
     187
     188                // Dim Light
     189                lightMan->setAmbientColor(1.1 - progress, 1.1 - progress, 1.1 - progress);
     190
     191                // use alpha in color to fade in
     192                RainEffect::rainParticles->setColor(0,   0.3, 0.3, 0.5, 0.2 * progress); // grey blue 1
     193                RainEffect::rainParticles->setColor(0.5, 0.4, 0.4, 0.5, 0.2 * progress); // grey blue 2
     194                RainEffect::rainParticles->setColor(1,   0.7, 0.7, 0.7, 0.2 * progress); // light grey
     195
     196                // increase radius for more "heavy" rain
     197                RainEffect::rainParticles->setRadius(0, 0.03 * progress);
     198                RainEffect::rainParticles->setRadius(0.2, 0.02 * progress);
     199                RainEffect::rainParticles->setRadius(1, 0.01 * progress);
     200
     201                // increase sound volume
     202                // this->soundSource.fadein(this->rainBuffer, 10);
     203        }
     204       
     205}
     206
     207void RainEffect::startRaining() {
     208
     209        if (this->rainActivate)
     210                this->deactivate();
     211
     212        this->rainStartDuration = 10;
     213        this->localTimer = 0;
     214        this->activate();
     215
     216}
Note: See TracChangeset for help on using the changeset viewer.