Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 8255 in orxonox.OLD for trunk/src/lib/graphics/effects/fog_effect.cc


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/fog_effect.cc

    r7810 r8255  
    2020#include "glincl.h"
    2121
    22 /*#include "shell_command.h"
    23 SHELL_COMMAND(activateFog, FogEffect, FogEffect::activate)
    24         ->setAlias("aFog");
    25 SHELL_COMMAND(deactivateFog, FogEffect, FogEffect::deactivate)
    26         ->setAlias("dFog");*/
     22#include "shell_command.h"
     23
     24SHELL_COMMAND(activate, FogEffect, activateFog);
     25SHELL_COMMAND(deactivate, FogEffect, deactivateFog);
     26SHELL_COMMAND(startfogging, FogEffect, startFogging);
    2727
    2828using namespace std;
     
    3939                this->loadParams(root);
    4040
    41         this->activate();
     41        if (this->fogActivate)
     42                this->activate();
    4243}
    4344
     
    5758        LoadParam(root, "range", this, FogEffect, setFogRange);
    5859        LoadParam(root, "color", this, FogEffect, setFogColor);
     60
     61        LOAD_PARAM_START_CYCLE(root, element);
     62        {
     63                LoadParam_CYCLE(element, "option", this, FogEffect, setFogOption);
     64        }
     65        LOAD_PARAM_END_CYCLE(element);
    5966}
    6067
     
    6269{
    6370        //default values
     71        this->fogActivate = false;
     72        this->fogFadeDuration = 0;
     73        this->localTimer = 0;
     74       
    6475        this->fogMode = GL_EXP2;
    6576        this->fogDensity = 0.001;
    6677        this->fogStart = 0;
    6778        this->fogEnd = 5000;
    68   this->colorVector = Vector(0.7, 0.7, 0.7);
     79        this->colorVector = Vector(0.7, 0.7, 0.7);
     80
    6981}
    70 
    7182
    7283
     
    7586        PRINTF(0)( "Enabling FogEffect, mode: %i, density: %f, start: %f, end: %f, color %f, %f, %f\n", this->fogMode, this->fogDensity, this->fogStart, this->fogEnd, this->colorVector.x, this->colorVector.y, this->colorVector.z);
    7687
     88        this->fogActivate = true;
     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       
    7798        glEnable(GL_FOG);
    78         {
    79                 GLfloat fogColor[4] = { colorVector.x, colorVector.y, colorVector.z, 1.0};
    80 
    81                 glFogi(GL_FOG_MODE, this->fogMode);
    82                 glFogfv(GL_FOG_COLOR, fogColor);
    83                 glFogf(GL_FOG_DENSITY, this->fogDensity);
    84                 glHint(GL_FOG_HINT, GL_DONT_CARE);
    85                 glFogf(GL_FOG_START, this->fogStart);
    86                 glFogf(GL_FOG_END, this->fogEnd);
    87         }
    88         glClearColor(0.5, 0.5, 0.5, 1.0);
     99        // glClearColor(0.5, 0.5, 0.5, 1.0);
    89100}
    90101
     
    93104{
    94105        PRINTF(0)("Deactivating FogEffect\n");
     106
     107        this->fogActivate = false;
     108       
    95109        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
    96142}
    97143
Note: See TracChangeset for help on using the changeset viewer.