Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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


Ignore:
Timestamp:
Jun 26, 2006, 3:36:16 PM (19 years ago)
Author:
patrick
Message:

trunk: merged the weather engine branche to the trunk

File:
1 edited

Legend:

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

    r8495 r8793  
    2020#include "shell_command.h"
    2121
     22// Define shell commands
    2223SHELL_COMMAND(activate, FogEffect, activateFog);
    2324SHELL_COMMAND(deactivate, FogEffect, deactivateFog);
     
    2526SHELL_COMMAND(fadeout, FogEffect, fadeOutFog);
    2627
    27 // TODO: Fix fades
    28 
    2928using namespace std;
    3029
    3130CREATE_FACTORY(FogEffect, CL_FOG_EFFECT);
    3231
     32/**
     33 * @brief standard constructor
     34 */
    3335FogEffect::FogEffect(const TiXmlElement* root) {
    3436    this->setClassID(CL_FOG_EFFECT, "FogEffect");
    3537
     38    // Initialize values
    3639    this->init();
    3740
     41    // Load XML params
    3842    if (root != NULL)
    3943        this->loadParams(root);
    4044
     45    // Activate fog, if chosen to be activated by default
    4146    if (this->fogActivate)
    4247        this->activate();
    4348}
    4449
    45 
     50/**
     51 * @brief standard destructor
     52 */
    4653FogEffect::~FogEffect() {
    4754    this->deactivate();
    4855}
    4956
    50 
     57/**
     58 * @brief initalizes the fog effect with default values
     59 */
     60void FogEffect::init() {
     61    // default values
     62  this->fogMode = GL_LINEAR;
     63  this->fogDensity = 0.005;
     64  this->fogStart = 0;
     65  this->fogEnd = 300;
     66  this->colorVector = Vector(0.6, 0.0, 0.0);
     67
     68    // init variables
     69  this->fogFadeInDuration = 0;
     70  this->fogFadeOutDuration = 0;
     71  this->fogFadeDensity = 0;
     72  this->fogFadeEnd = 0;
     73
     74  this->localTimer = 0;
     75  this->fogActivate = false;
     76  this->fogFadeInActivate = false;
     77  this->fogFadeOutActivate = false;
     78}
     79
     80/**
     81 * @brief loads the fog effect parameters.
     82 * @param root: the XML-Element to load the data from
     83 */
    5184void FogEffect::loadParams(const TiXmlElement* root) {
    5285    WeatherEffect::loadParams(root);
    5386
    54     LoadParam(root, "mode", this, FogEffect, setFogMode);
    55     LoadParam(root, "density", this, FogEffect, setFogDensity);
    56     LoadParam(root, "range", this, FogEffect, setFogRange);
    57     LoadParam(root, "color", this, FogEffect, setFogColor);
    58     LoadParam(root, "fadeinduration", this, FogEffect, setFogFadeIn);
    59     LoadParam(root, "fadeoutduration", this, FogEffect, setFogFadeOut);
     87    LoadParam(root, "mode", this, FogEffect, setFogMode).describe("fog mode (linear, exponential)");;
     88    LoadParam(root, "density", this, FogEffect, setFogDensity).describe("fog density if exp. fog");;
     89    LoadParam(root, "range", this, FogEffect, setFogRange).describe("fog range: start, end");;
     90    LoadParam(root, "color", this, FogEffect, setFogColor).describe("fog color: r,g,b");;
     91    LoadParam(root, "fadeinduration", this, FogEffect, setFogFadeIn).describe("duration of the fade in");;
     92    LoadParam(root, "fadeoutduration", this, FogEffect, setFogFadeOut).describe("duration of the fade out");;
    6093
    6194    LOAD_PARAM_START_CYCLE(root, element);
    6295    {
    63         LoadParam_CYCLE(element, "option", this, FogEffect, setFogOption);
     96      LoadParam_CYCLE(element, "option", this, FogEffect, setFogOption).describe("sets a fog option: activate");;
    6497    }
    6598    LOAD_PARAM_END_CYCLE(element);
    6699}
    67100
    68 void FogEffect::init() {
    69     // default values
    70     this->fogMode = GL_LINEAR;
    71     this->fogDensity = 0.03;
    72     this->fogStart = 0;
    73     this->fogEnd = 50;
    74     this->colorVector = Vector(0.3, 0.3, 0.3);
    75 
    76     // init variables
    77     this->fogFadeInDuration = 0;
    78     this->fogFadeOutDuration = 0;
    79     this->fogFadeDensity = 0;
    80     this->localTimer = 0;
    81     this->fogActivate = false;
    82     this->fogFadeInActivate = false;
    83     this->fogFadeOutActivate = false;
    84 
    85 }
    86 
    87 
     101/**
     102 * @brief activates the fog effect
     103 */
    88104void FogEffect::activate() {
    89     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);
    90 
    91     this->fogActivate = true;
    92 
     105    PRINTF(0)( "Activating FogEffect\n");
     106
     107    // init fogGL
    93108    GLfloat fogColor[4] = { colorVector.x, colorVector.y, colorVector.z, 1.0};
    94109    glFogi(GL_FOG_MODE, this->fogMode);
     
    99114    glFogf(GL_FOG_END, this->fogEnd);
    100115
     116    this->fogActivate = true;
     117
    101118    glEnable(GL_FOG);
    102 
    103 }
    104 
    105 
     119}
     120
     121/**
     122 * @brief deactivates the fog effect
     123 */
    106124void FogEffect::deactivate() {
    107125    PRINTF(0)("Deactivating FogEffect\n");
     
    112130
    113131    glDisable(GL_FOG);
    114 
    115 }
    116 
     132}
     133
     134/**
     135 * @brief draws the fog effect
     136 */
    117137void FogEffect::draw() const {
    118138
     
    120140        return;
    121141
    122     // If Fog Fade
    123     if ( this->fogFadeInActivate || this->fogFadeOutActivate )
    124         glFogf(GL_FOG_DENSITY, this->fogFadeDensity);
    125 
    126 }
    127 
     142    // If fog is fading
     143    if ( this->fogFadeInActivate || this->fogFadeOutActivate ) {
     144        if ( this->fogMode == GL_LINEAR)
     145            glFogf(GL_FOG_END, this->fogFadeEnd);
     146        else
     147            glFogf(GL_FOG_DENSITY, this->fogFadeDensity);
     148    }
     149}
     150
     151/**
     152 * @brief ticks the fog effect
     153 * @param dt: tick float
     154 */
    128155void FogEffect::tick(float dt) {
     156
    129157    if (!this->fogActivate)
    130158        return;
    131159
     160    // If fog is fading in
    132161    if ( this->fogFadeInActivate ) {
    133162        this->localTimer += dt;
    134         this->fogFadeDensity = ( this->localTimer / this->fogFadeInDuration ) * this->fogDensity;
    135 
    136         if ( this->localTimer >= this->fogFadeOutDuration )
     163
     164        if ( this->fogMode == GL_LINEAR)
     165          this->fogFadeEnd = 2000 * (1 - ( this->localTimer / this->fogFadeInDuration )) + this->fogEnd;
     166        else
     167            this->fogFadeDensity = ( this->localTimer / this->fogFadeInDuration ) * this->fogDensity;
     168
     169        if ( this->localTimer >= this->fogFadeInDuration )
    137170            this->fogFadeInActivate = false;
    138171    }
    139172
     173    // If fog is fading out
    140174    if ( this->fogFadeOutActivate ) {
    141175        this->localTimer += dt;
    142         this->fogFadeDensity = 1 - (( this->localTimer / this->fogFadeInDuration ) * this->fogDensity);
     176
     177        if ( this->fogMode == GL_LINEAR)
     178          this->fogFadeEnd = 2000 * ( this->localTimer / this->fogFadeInDuration ) + this->fogEnd;
     179        else
     180            this->fogFadeDensity = 1 - (( this->localTimer / this->fogFadeInDuration ) * this->fogDensity);
    143181
    144182        if ( this->localTimer >= this->fogFadeOutDuration )
     
    147185}
    148186
     187/**
     188 * @brief fades the fog in
     189 */
    149190void FogEffect::fadeInFog() {
    150191
     
    163204    this->localTimer = 0;
    164205
     206    // Activate Fog
     207    this->activate();
     208
    165209    // set FogFadeIn activate
    166210    this->fogFadeInActivate = true;
    167 
    168     // Activate Fog
    169     this->activate();
    170 
    171 }
    172 
    173 
     211}
     212
     213/**
     214 * @brief fades the fog out
     215 */
    174216void FogEffect::fadeOutFog() {
    175217
     
    190232    // Reset local timer
    191233    this->localTimer = 0;
    192 
    193 }
    194 
    195 
    196 GLint FogEffect::stringToFogMode(const std::string& mode) {
    197     if(mode == "GL_LINEAR")
    198         return GL_LINEAR;
    199     else if(mode == "GL_EXP")
    200         return GL_EXP;
    201     else if(mode == "GL_EXP2" )
    202         return GL_EXP2;
    203     else
    204         return -1;
    205 }
    206 
    207 
     234}
     235
Note: See TracChangeset for help on using the changeset viewer.