Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Jun 15, 2006, 1:43:24 PM (18 years ago)
Author:
amaechler
Message:

atmospheric: void etc bugfixes

File:
1 edited

Legend:

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

    r8455 r8457  
    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.
     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.
    1010
    1111### File Specific:
    12         main-programmer: hdavid, amaechler
     12  main-programmer: hdavid, amaechler
    1313*/
    1414
     
    3333CREATE_FACTORY(FogEffect, CL_FOG_EFFECT);
    3434
    35 FogEffect::FogEffect(const TiXmlElement* root)
    36 {
    37         this->setClassID(CL_FOG_EFFECT, "FogEffect");
    38 
    39         this->init();
    40 
    41         if (root != NULL)
    42                 this->loadParams(root);
    43 
    44         if (this->fogActivate)
    45                 this->activate();
    46 }
    47 
    48 
    49 FogEffect::~FogEffect()
    50 {
    51         this->deactivate();
    52 }
    53 
    54 
    55 void FogEffect::loadParams(const TiXmlElement* root)
    56 {
    57         WeatherEffect::loadParams(root);
    58 
    59         LoadParam(root, "mode", this, FogEffect, setFogMode);
    60         LoadParam(root, "density", this, FogEffect, setFogDensity);
    61         LoadParam(root, "range", this, FogEffect, setFogRange);
    62         LoadParam(root, "color", this, FogEffect, setFogColor);
    63         LoadParam(root, "fadeinduration", this, FogEffect, setFogFadeIn);
    64         LoadParam(root, "fadeoutduration", this, FogEffect, setFogFadeOut);
    65 
    66         LOAD_PARAM_START_CYCLE(root, element);
    67         {
    68                 LoadParam_CYCLE(element, "option", this, FogEffect, setFogOption);
    69         }
    70         LOAD_PARAM_END_CYCLE(element);
    71 }
    72 
    73 void FogEffect::init()
    74 {
    75         // default values
    76         this->fogMode = GL_LINEAR;
    77         this->fogDensity = 0.03;
    78         this->fogStart = 0;
    79         this->fogEnd = 50;
    80         this->colorVector = Vector(0.3, 0.3, 0.3);
    81 
    82         // init variables
    83         this->fogFadeInDuration = 0;
    84         this->fogFadeOutDuration = 0;
    85         this->fogFadeInDensity = 0;
    86         this->fogFadeOutDensity = 0;
    87         this->localTimer = 0;
    88         this->fogActivate = false;
    89         this->fogFadeInActivate = false;
    90         this->fogFadeOutActivate = false;
    91 
    92 }
    93 
    94 
    95 void FogEffect::activate()
    96 {
    97         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);
    98 
    99         this->fogActivate = true;
    100        
    101         GLfloat fogColor[4] = { colorVector.x, colorVector.y, colorVector.z, 1.0};
    102         glFogi(GL_FOG_MODE, this->fogMode);
    103         glFogfv(GL_FOG_COLOR, fogColor);
    104         glHint(GL_FOG_HINT, GL_DONT_CARE);
    105         glFogf(GL_FOG_START, this->fogStart);
    106         glFogf(GL_FOG_END, this->fogEnd);
    107 
    108         if ( this->fogFadeInActivate )
    109                 glFogf(GL_FOG_DENSITY, this->fogFadeInDensity);
    110         else if ( this->fogFadeOutActivate )
    111                 glFogf(GL_FOG_DENSITY, this->fogFadeOutDensity);
    112         else
    113                 glFogf(GL_FOG_DENSITY, this->fogDensity);
    114                
    115         glEnable(GL_FOG);
    116 
    117 }
    118 
    119 
    120 void FogEffect::deactivate()
    121 {
    122         PRINTF(0)("Deactivating FogEffect\n");
    123 
    124         this->fogFadeInActivate = false;
    125         this->fogFadeOutActivate = false;
    126         this->fogActivate = false;
    127        
    128         glDisable(GL_FOG);
     35FogEffect::FogEffect(const TiXmlElement* root) {
     36    this->setClassID(CL_FOG_EFFECT, "FogEffect");
     37
     38    this->init();
     39
     40    if (root != NULL)
     41        this->loadParams(root);
     42
     43    if (this->fogActivate)
     44        this->activate();
     45}
     46
     47
     48FogEffect::~FogEffect() {
     49    this->deactivate();
     50}
     51
     52
     53void FogEffect::loadParams(const TiXmlElement* root) {
     54    WeatherEffect::loadParams(root);
     55
     56    LoadParam(root, "mode", this, FogEffect, setFogMode);
     57    LoadParam(root, "density", this, FogEffect, setFogDensity);
     58    LoadParam(root, "range", this, FogEffect, setFogRange);
     59    LoadParam(root, "color", this, FogEffect, setFogColor);
     60    LoadParam(root, "fadeinduration", this, FogEffect, setFogFadeIn);
     61    LoadParam(root, "fadeoutduration", this, FogEffect, setFogFadeOut);
     62
     63    LOAD_PARAM_START_CYCLE(root, element);
     64    {
     65        LoadParam_CYCLE(element, "option", this, FogEffect, setFogOption);
     66    }
     67    LOAD_PARAM_END_CYCLE(element);
     68}
     69
     70void FogEffect::init() {
     71    // default values
     72    this->fogMode = GL_LINEAR;
     73    this->fogDensity = 0.03;
     74    this->fogStart = 0;
     75    this->fogEnd = 50;
     76    this->colorVector = Vector(0.3, 0.3, 0.3);
     77
     78    // init variables
     79    this->fogFadeInDuration = 0;
     80    this->fogFadeOutDuration = 0;
     81    this->fogFadeInDensity = 0;
     82    this->fogFadeOutDensity = 0;
     83    this->localTimer = 0;
     84    this->fogActivate = false;
     85    this->fogFadeInActivate = false;
     86    this->fogFadeOutActivate = false;
     87
     88}
     89
     90
     91void FogEffect::activate() {
     92    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);
     93
     94    this->fogActivate = true;
     95
     96    GLfloat fogColor[4] = { colorVector.x, colorVector.y, colorVector.z, 1.0};
     97    glFogi(GL_FOG_MODE, this->fogMode);
     98    glFogfv(GL_FOG_COLOR, fogColor);
     99    glHint(GL_FOG_HINT, GL_DONT_CARE);
     100    glFogf(GL_FOG_START, this->fogStart);
     101    glFogf(GL_FOG_END, this->fogEnd);
     102
     103    if ( this->fogFadeInActivate )
     104        glFogf(GL_FOG_DENSITY, this->fogFadeInDensity);
     105    else if ( this->fogFadeOutActivate )
     106        glFogf(GL_FOG_DENSITY, this->fogFadeOutDensity);
     107    else
     108        glFogf(GL_FOG_DENSITY, this->fogDensity);
     109
     110    glEnable(GL_FOG);
     111
     112}
     113
     114
     115void FogEffect::deactivate() {
     116    PRINTF(0)("Deactivating FogEffect\n");
     117
     118    this->fogFadeInActivate = false;
     119    this->fogFadeOutActivate = false;
     120    this->fogActivate = false;
     121
     122    glDisable(GL_FOG);
    129123
    130124}
     
    132126void FogEffect::draw() const {
    133127
    134         if (!this->fogActivate)
    135                 return;
    136 
    137         // If Fog Fade In
    138         if ( this->fogFadeInActivate )
    139                 glFogf(GL_FOG_DENSITY, this->fogFadeInDensity);
    140 
    141         // If Fog Fade Out
    142         if ( this->fogFadeOutActivate )
    143                 glFogf(GL_FOG_DENSITY, this->fogFadeOutDensity);
    144 
    145 }
    146 
    147 void FogEffect::tick(float dt)
    148 {
    149         if (!this->fogActivate)
    150                 return;
    151                
    152         if ( this->fogFadeInActivate ) {
    153                 this->localTimer += dt;
    154                 this->fogFadeInDensity = ( this->localTimer / this->fogFadeInDuration ) * this->fogDensity;
    155 
    156                 if ( this->localTimer >= this->fogFadeOutDuration )
    157                         this->fogFadeInActivate = false;
    158         }
    159 
    160         if ( this->fogFadeOutActivate ) {
    161                 this->localTimer += dt;
    162                 this->fogFadeOutDensity = 1 - (( this->localTimer / this->fogFadeInDuration ) * this->fogDensity);
    163 
    164                 if ( this->localTimer >= this->fogFadeOutDuration )
    165                         this->deactivate();
    166         }
     128    if (!this->fogActivate)
     129        return;
     130
     131    // If Fog Fade In
     132    if ( this->fogFadeInActivate )
     133        glFogf(GL_FOG_DENSITY, this->fogFadeInDensity);
     134
     135    // If Fog Fade Out
     136    if ( this->fogFadeOutActivate )
     137        glFogf(GL_FOG_DENSITY, this->fogFadeOutDensity);
     138
     139}
     140
     141void FogEffect::tick(float dt) {
     142    if (!this->fogActivate)
     143        return;
     144
     145    if ( this->fogFadeInActivate ) {
     146        this->localTimer += dt;
     147        this->fogFadeInDensity = ( this->localTimer / this->fogFadeInDuration ) * this->fogDensity;
     148
     149        if ( this->localTimer >= this->fogFadeOutDuration )
     150            this->fogFadeInActivate = false;
     151    }
     152
     153    if ( this->fogFadeOutActivate ) {
     154        this->localTimer += dt;
     155        this->fogFadeOutDensity = 1 - (( this->localTimer / this->fogFadeInDuration ) * this->fogDensity);
     156
     157        if ( this->localTimer >= this->fogFadeOutDuration )
     158            this->deactivate();
     159    }
    167160}
    168161
    169162void FogEffect::fadeInFog() {
    170163
    171         // If Fog is already fading out, stop it
    172         this->fogFadeOutActivate = false;
    173 
    174         // If Fog is already on, turn it off first
    175         if (this->fogActivate)
    176                 this->deactivate();
    177 
    178         // If no manual FadeIn value was set, set a default value
    179         if (!this->fogFadeInDuration > 0)
    180                 this->fogFadeInDuration = 20;
    181 
    182         // Reset local timer
    183         this->localTimer = 0;
    184 
    185         // set FogFadeIn activate
    186         this->fogFadeInActivate = true;
    187 
    188         // Activate Fog
    189         this->activate();
     164    // If Fog is already fading out, stop it
     165    this->fogFadeOutActivate = false;
     166
     167    // If Fog is already on, turn it off first
     168    if (this->fogActivate)
     169        this->deactivate();
     170
     171    // If no manual FadeIn value was set, set a default value
     172    if (!this->fogFadeInDuration > 0)
     173        this->fogFadeInDuration = 20;
     174
     175    // Reset local timer
     176    this->localTimer = 0;
     177
     178    // set FogFadeIn activate
     179    this->fogFadeInActivate = true;
     180
     181    // Activate Fog
     182    this->activate();
    190183
    191184}
     
    194187void FogEffect::fadeOutFog() {
    195188
    196         // If Fog is already fading in, stop it
    197         this->fogFadeInActivate = false;
    198 
    199         // If Fog is off, turn it on first
    200         if (!this->fogActivate)
    201                 this->activate();
    202 
    203         // If no manual FadeOut value was set, set a default value
    204         if (!this->fogFadeOutDuration > 0)
    205                 this->fogFadeOutDuration = 20;
    206 
    207         // set FogFadeOut activate
    208         this->fogFadeOutActivate = true;
    209 
    210         // Reset local timer
    211         this->localTimer = 0;
    212 
    213 }
    214 
    215 
    216 GLint FogEffect::stringToFogMode(const std::string& mode)
    217 {
    218         if(mode == "GL_LINEAR")
    219                 return GL_LINEAR;
    220         else if(mode == "GL_EXP")
    221                 return GL_EXP;
    222         else if(mode == "GL_EXP2" )
    223                 return GL_EXP2;
    224         else
    225                 return -1;
    226 }
    227 
    228 
     189    // If Fog is already fading in, stop it
     190    this->fogFadeInActivate = false;
     191
     192    // If Fog is off, turn it on first
     193    if (!this->fogActivate)
     194        this->activate();
     195
     196    // If no manual FadeOut value was set, set a default value
     197    if (!this->fogFadeOutDuration > 0)
     198        this->fogFadeOutDuration = 20;
     199
     200    // set FogFadeOut activate
     201    this->fogFadeOutActivate = true;
     202
     203    // Reset local timer
     204    this->localTimer = 0;
     205
     206}
     207
     208
     209GLint FogEffect::stringToFogMode(const std::string& mode) {
     210    if(mode == "GL_LINEAR")
     211        return GL_LINEAR;
     212    else if(mode == "GL_EXP")
     213        return GL_EXP;
     214    else if(mode == "GL_EXP2" )
     215        return GL_EXP2;
     216    else
     217        return -1;
     218}
     219
     220
Note: See TracChangeset for help on using the changeset viewer.