Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Jun 8, 2006, 3:21:15 PM (18 years ago)
Author:
amaechler
Message:

branches/atmospheric_engine: fog fade

File:
1 edited

Legend:

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

    r8247 r8253  
    2424SHELL_COMMAND(activate, FogEffect, activateFog);
    2525SHELL_COMMAND(deactivate, FogEffect, deactivateFog);
     26SHELL_COMMAND(startfogging, FogEffect, startFogging);
    2627
    2728using namespace std;
     
    6970        //default values
    7071        this->fogActivate = false;
     72        this->fogFadeDuration = 0;
     73        this->localTimer = 0;
     74       
    7175        this->fogMode = GL_EXP2;
    7276        this->fogDensity = 0.001;
     
    7478        this->fogEnd = 5000;
    7579        this->colorVector = Vector(0.7, 0.7, 0.7);
     80
    7681}
    7782
     
    8287
    8388        this->fogActivate = true;
    84 
     89       
     90        GLfloat fogColor[4] = { colorVector.x, colorVector.y, colorVector.z, 1.0};
     91        glFogi(GL_FOG_MODE, this->fogMode);
     92        glFogfv(GL_FOG_COLOR, fogColor);
     93        glFogf(GL_FOG_DENSITY, this->fogDensity);
     94        glHint(GL_FOG_HINT, GL_DONT_CARE);
     95        glFogf(GL_FOG_START, this->fogStart);
     96        glFogf(GL_FOG_END, this->fogEnd);
     97       
    8598        glEnable(GL_FOG);
    86         {
    87                 GLfloat fogColor[4] = { colorVector.x, colorVector.y, colorVector.z, 1.0};
    88 
    89                 glFogi(GL_FOG_MODE, this->fogMode);
    90                 glFogfv(GL_FOG_COLOR, fogColor);
    91                 glFogf(GL_FOG_DENSITY, this->fogDensity);
    92                 glHint(GL_FOG_HINT, GL_DONT_CARE);
    93                 glFogf(GL_FOG_START, this->fogStart);
    94                 glFogf(GL_FOG_END, this->fogEnd);
    95         }
    96         glClearColor(0.5, 0.5, 0.5, 1.0);
     99        // glClearColor(0.5, 0.5, 0.5, 1.0);
    97100}
    98101
     
    105108       
    106109        glDisable(GL_FOG);
     110}
     111
     112void FogEffect::draw() const {
     113
     114        if (this->fogFadeDuration != 0 && this->localTimer < this->fogFadeDuration)
     115                glFogf(GL_FOG_DENSITY, this->fogFadeDensity);
     116        //else
     117        //      glFogf(GL_FOG_DENSITY, this->fogDensity);
     118
     119}
     120void FogEffect::tick(float dt)
     121{
     122        if (!this->fogActivate)
     123                return;
     124               
     125
     126        if (this->fogFadeDuration != 0 && this->localTimer < this->fogFadeDuration) {
     127                this->localTimer += dt;
     128                float progress = this->localTimer / this->fogFadeDuration;
     129                this->fogFadeDensity = progress * this->fogDensity;
     130        }
     131}
     132
     133void FogEffect::startFogging() {
     134
     135        if (this->fogActivate)
     136                this->deactivate();
     137
     138        this->fogFadeDuration = 10;
     139        this->localTimer = 0;
     140        this->activate();
     141
    107142}
    108143
Note: See TracChangeset for help on using the changeset viewer.