Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 8253 in orxonox.OLD


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

branches/atmospheric_engine: fog fade

Location:
branches/atmospheric_engine/src/lib/graphics/effects
Files:
2 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
  • branches/atmospheric_engine/src/lib/graphics/effects/fog_effect.h

    r8247 r8253  
    2626                void deactivateFog() { this->deactivate(); }
    2727
     28                virtual void draw() const;
     29                virtual void tick(float dt);
     30
    2831                inline void setFogMode(const std::string& mode) { this->fogMode = this->stringToFogMode(mode); }
    2932                inline void setFogDensity(float density) { this->fogDensity = density; }
     
    3235                inline void setFogOption(const std::string& option) { if (option == "activate") this->fogActivate = true; }
    3336
     37                void startFogging();
     38
    3439        private:
    3540                GLint stringToFogMode(const std::string& mode);
    3641
    3742                bool                            fogActivate;
    38 
     43                GLfloat                         fogFadeDuration;
     44                float                           localTimer;
     45               
    3946                GLint                           fogMode;
    4047                GLfloat                         fogDensity;
     48                GLfloat                         fogFadeDensity;
     49
    4150                GLfloat                         fogStart;
    4251                GLfloat                         fogEnd;
Note: See TracChangeset for help on using the changeset viewer.