Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 8457 in orxonox.OLD for branches/atmospheric_engine/src/lib


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

atmospheric: void etc bugfixes

Location:
branches/atmospheric_engine/src/lib
Files:
18 edited

Legend:

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

    r8190 r8457  
    3030 * @param root The XML-element to load the AtmosphericEngine from
    3131 */
    32 AtmosphericEngine::AtmosphericEngine()
    33 {
    34   this->setClassID(CL_ATMOSPHERIC_ENGINE, "AtmosphericEngine");
     32AtmosphericEngine::AtmosphericEngine() {
     33    this->setClassID(CL_ATMOSPHERIC_ENGINE, "AtmosphericEngine");
    3534}
    3635
     
    4443 *  destroys a AtmosphericEngine
    4544 */
    46 AtmosphericEngine::~AtmosphericEngine()
    47 {
    48   AtmosphericEngine::singletonRef = NULL;
     45AtmosphericEngine::~AtmosphericEngine() {
     46    AtmosphericEngine::singletonRef = NULL;
    4947
    50   const std::list<BaseObject*>* weatherEffects = ClassList::getList( CL_WEATHER_EFFECT);
     48    const std::list<BaseObject*>* weatherEffects = ClassList::getList( CL_WEATHER_EFFECT);
    5149
    52   if (weatherEffects != NULL)
    53   {
    54       while(!weatherEffects->empty())
    55         delete weatherEffects->front();
    56   }
     50    if (weatherEffects != NULL) {
     51        while(!weatherEffects->empty())
     52            delete weatherEffects->front();
     53    }
    5754}
    5855
     
    6057 * @param root The XML-element to load the AtmosphericEngine from
    6158 */
    62 void AtmosphericEngine::loadParams(const TiXmlElement* root)
    63 {
    64   LoadParamXML(root, "WeatherEffect", this, AtmosphericEngine, loadWeatherEffect);
    65   LoadParamXML(root, "SunEffect", this, AtmosphericEngine, loadSunEffect);
     59void AtmosphericEngine::loadParams(const TiXmlElement* root) {
     60    LoadParamXML(root, "WeatherEffect", this, AtmosphericEngine, loadWeatherEffect);
     61    LoadParamXML(root, "SunEffect", this, AtmosphericEngine, loadSunEffect);
    6662}
    6763
     
    6965 * @param root The XML-element to load WeatherEffects from
    7066 */
    71 void AtmosphericEngine::loadWeatherEffect(const TiXmlElement* root)
    72 {
    73   LOAD_PARAM_START_CYCLE(root, element);
    74   {
    75     PRINTF(4)("element is: %s\n", element->Value());
    76     // Factory::fabricate(element);
     67void AtmosphericEngine::loadWeatherEffect(const TiXmlElement* root) {
     68    LOAD_PARAM_START_CYCLE(root, element);
     69    {
     70        PRINTF(4)("element is: %s\n", element->Value());
     71        // Factory::fabricate(element);
    7772
    78     BaseObject* bo = Factory::fabricate(element);
    79     if( bo == NULL)
    80       PRINTF(0)(" Could not create Element %s\n", element->Value());
    81   }
    82   LOAD_PARAM_END_CYCLE(element);
     73        BaseObject* bo = Factory::fabricate(element);
     74        if( bo == NULL)
     75            PRINTF(0)(" Could not create Element %s\n", element->Value());
     76    }
     77    LOAD_PARAM_END_CYCLE(element);
    8378}
    8479
     
    8681 * @param root The XML-element to load SunEffects from
    8782 */
    88 void AtmosphericEngine::loadSunEffect(const TiXmlElement* root)
    89 {
    90   LOAD_PARAM_START_CYCLE(root, element);
    91   {
    92     PRINTF(4)("element is: %s\n", element->Value());
    93   }
    94   LOAD_PARAM_END_CYCLE(element);
     83void AtmosphericEngine::loadSunEffect(const TiXmlElement* root) {
     84    LOAD_PARAM_START_CYCLE(root, element);
     85    {
     86        PRINTF(4)("element is: %s\n", element->Value());
     87    }
     88    LOAD_PARAM_END_CYCLE(element);
    9589}
    9690
     
    9993 * draws the effect, if needed
    10094 */
    101 void AtmosphericEngine::draw() const
    102 {
    103   const std::list<BaseObject*>* weatherEffects = ClassList::getList( CL_WEATHER_EFFECT);
     95void AtmosphericEngine::draw() const {
     96    const std::list<BaseObject*>* weatherEffects = ClassList::getList( CL_WEATHER_EFFECT);
    10497
    105   // draw the weather effects
    106   if (weatherEffects != NULL)
    107   {
    108     std::list<BaseObject*>::const_iterator it;
    109     for (it = weatherEffects->begin(); it != weatherEffects->end(); it++)
    110       dynamic_cast<WeatherEffect*>(*it)->draw();
    111   }
     98    // draw the weather effects
     99    if (weatherEffects != NULL) {
     100        std::list<BaseObject*>::const_iterator it;
     101        for (it = weatherEffects->begin(); it != weatherEffects->end(); it++)
     102            dynamic_cast<WeatherEffect*>(*it)->draw();
     103    }
    112104}
    113105
     
    117109 * ticks the effect if there is any time dependancy
    118110 */
    119 void AtmosphericEngine::tick(float dt)
    120 {
    121   const std::list<BaseObject*>* weatherEffects = ClassList::getList( CL_WEATHER_EFFECT);
     111void AtmosphericEngine::tick(float dt) {
     112    const std::list<BaseObject*>* weatherEffects = ClassList::getList( CL_WEATHER_EFFECT);
    122113
    123   // tick the weather effects
    124   if (weatherEffects != NULL)
    125   {
    126     std::list<BaseObject*>::const_iterator it;
    127     for (it = weatherEffects->begin(); it != weatherEffects->end(); it++)
    128     {
    129 /*      printf("%s::%s \n", (*it)->getClassName(), (*it)->getName());*/
    130       dynamic_cast<WeatherEffect*>(*it)->tick(dt);
     114    // tick the weather effects
     115    if (weatherEffects != NULL) {
     116        std::list<BaseObject*>::const_iterator it;
     117        for (it = weatherEffects->begin(); it != weatherEffects->end(); it++) {
     118            /*      printf("%s::%s \n", (*it)->getClassName(), (*it)->getName());*/
     119            dynamic_cast<WeatherEffect*>(*it)->tick(dt);
     120        }
    131121    }
    132   }
    133122}
  • branches/atmospheric_engine/src/lib/graphics/effects/cloud_effect.h

    r8455 r8457  
    2020class Vector;
    2121
    22 class CloudEffect : public WeatherEffect
    23 {
    24         public:
    25                 CloudEffect(const TiXmlElement* root = NULL);
    26                 virtual ~CloudEffect();
     22class CloudEffect : public WeatherEffect {
     23public:
     24    CloudEffect(const TiXmlElement* root = NULL);
     25    virtual ~CloudEffect();
    2726
    28                 virtual void loadParams(const TiXmlElement* root);
     27    virtual void loadParams(const TiXmlElement* root);
    2928
    30                 virtual void init();
     29    virtual void init();
    3130
    32                 virtual void activate();
    33                 virtual void deactivate();
     31    virtual void activate();
     32    virtual void deactivate();
    3433
    35                 inline void activateCloud() { this->activate(); }
    36                 inline void deactivateCloud() { this->deactivate(); }
    37                
    38                 virtual void draw() const;
    39                 virtual void tick(float dt);
     34    inline void activateCloud() {
     35        this->activate();
     36    }
     37    inline void deactivateCloud() {
     38        this->deactivate();
     39    }
    4040
    41                 inline void setCloudOption(const std::string& option) {
    42                         if (option == "activate") this->cloudActivate = true;
    43                 }
     41    virtual void draw() const;
     42    virtual void tick(float dt);
     43
     44    inline void setCloudOption(const std::string& option) {
     45        if (option == "activate")
     46            this->cloudActivate = true;
     47    }
    4448
    4549
    46         private:
    47                 void initialize(char* fileName);
     50private:
     51    void initialize(char* fileName);
    4852
    49                 bool                            cloudActivate;
     53    bool        cloudActivate;
    5054
    51                 Material*                       cloudMaterial;          // A Material for the Sphere.
     55    Material*     cloudMaterial;    // A Material for the Sphere.
    5256
    53                 std::string                     cloudTexture;
     57    std::string     cloudTexture;
    5458
    55                 Sglmodel_sgl                    cloudModel;
    56                 Shader*                         cloudShader;
     59    Sglmodel_sgl      cloudModel;
     60    Shader*       cloudShader;
    5761
    58                 GLfloat                         cloudTint[4];
    59                 GLfloat                         cloudScroll;
     62    GLfloat       cloudTint[4];
     63    GLfloat       cloudScroll;
    6064
    61                 float                           time;
     65    float       time;
    6266
    6367};
  • 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
  • branches/atmospheric_engine/src/lib/graphics/effects/fog_effect.h

    r8455 r8457  
    1010#include "weather_effect.h"
    1111
    12 class FogEffect : public WeatherEffect
    13 {
    14         public:
    15                 FogEffect(const TiXmlElement* root = NULL);
    16                 virtual ~FogEffect();
     12class FogEffect : public WeatherEffect {
     13public:
     14    FogEffect(const TiXmlElement* root = NULL);
     15    virtual ~FogEffect();
    1716
    18                 virtual void loadParams(const TiXmlElement* root);
     17    virtual void loadParams(const TiXmlElement* root);
    1918
    20                 virtual void init();
     19    virtual void init();
    2120
    22                 virtual void activate();
    23                 virtual void deactivate();
     21    virtual void activate();
     22    virtual void deactivate();
    2423
    25                 void activateFog() { this->activate(); }
    26                 void deactivateFog() { this->deactivate(); }
     24    void activateFog() {
     25        this->activate();
     26    }
     27    void deactivateFog() {
     28        this->deactivate();
     29    }
    2730
    28                 virtual void draw() const;
    29                 virtual void tick(float dt);
     31    virtual void draw() const;
     32    virtual void tick(float dt);
    3033
    31                 inline void setFogMode(const std::string& mode) { this->fogMode = this->stringToFogMode(mode); }
    32                 inline void setFogDensity(float density) { this->fogDensity = density; }
    33                 inline void setFogRange(float start, float end) { this->fogStart = start; this->fogEnd = end; }
    34                 inline void setFogColor(float r, float g, float b) { this->colorVector = Vector(r, g, b); }
    35                 inline void setFogFadeIn(float fadein) { this->fogFadeInDuration = fadein; }
    36                 inline void setFogFadeOut(float fadeout) { this->fogFadeOutDuration = fadeout; }
     34    inline void setFogMode(const std::string& mode) {
     35        this->fogMode = this->stringToFogMode(mode);
     36    }
     37    inline void setFogDensity(float density) {
     38        this->fogDensity = density;
     39    }
     40    inline void setFogRange(float start, float end) {
     41        this->fogStart = start;
     42        this->fogEnd = end;
     43    }
     44    inline void setFogColor(float r, float g, float b) {
     45        this->colorVector = Vector(r, g, b);
     46    }
     47    inline void setFogFadeIn(float fadein) {
     48        this->fogFadeInDuration = fadein;
     49    }
     50    inline void setFogFadeOut(float fadeout) {
     51        this->fogFadeOutDuration = fadeout;
     52    }
    3753
    38                 inline void setFogOption(const std::string& option) { if (option == "activate") this->fogActivate = true; }
     54    inline void setFogOption(const std::string& option) {
     55        if (option == "activate")
     56            this->fogActivate = true;
     57    }
    3958
    40                 void fadeInFog();
    41                 void fadeOutFog();
     59    void fadeInFog();
     60    void fadeOutFog();
    4261
    4362
    44         private:
    45                 GLint stringToFogMode(const std::string& mode);
     63private:
     64    GLint stringToFogMode(const std::string& mode);
    4665
    47                 bool                            fogActivate;
     66    bool        fogActivate;
    4867
    49                 bool                            fogFadeInActivate;
    50                 bool                            fogFadeOutActivate;
     68    bool        fogFadeInActivate;
     69    bool        fogFadeOutActivate;
    5170
    52                 GLfloat                         fogFadeInDuration;
    53                 GLfloat                         fogFadeOutDuration;
     71    GLfloat       fogFadeInDuration;
     72    GLfloat       fogFadeOutDuration;
    5473
    55                 float                           localTimer;
    56                
    57                 GLint                           fogMode;
    58                 GLfloat                         fogDensity;
    59                 GLfloat                         fogFadeInDensity;
    60                 GLfloat                         fogFadeOutDensity;
     74    float       localTimer;
    6175
    62                 GLfloat                         fogStart;
    63                 GLfloat                         fogEnd;
    64                 Vector                          colorVector;
     76    GLint       fogMode;
     77    GLfloat       fogDensity;
     78    GLfloat       fogFadeInDensity;
     79    GLfloat       fogFadeOutDensity;
     80
     81    GLfloat       fogStart;
     82    GLfloat       fogEnd;
     83    Vector        colorVector;
    6584};
    6685
  • branches/atmospheric_engine/src/lib/graphics/effects/graphics_effect.cc

    r7193 r8457  
    3232  @todo what to do, if no GraphicsEffect-Slots are open anymore ???
    3333 */
    34 GraphicsEffect::GraphicsEffect(const TiXmlElement* root)
    35 {
    36   this->setClassID(CL_GRAPHICS_EFFECT, "GraphicsEffect");
    37   this->bActivated = false;
     34GraphicsEffect::GraphicsEffect(const TiXmlElement* root) {
     35    this->setClassID(CL_GRAPHICS_EFFECT, "GraphicsEffect");
     36    this->bActivated = false;
    3837}
    3938
     
    4241 *  destroys a GraphicsEffect
    4342 */
    44 GraphicsEffect::~GraphicsEffect()
    45 {
    46 
     43GraphicsEffect::~GraphicsEffect() {
    4744}
    4845
     
    5148 * @param root The XML-element to load the GraphicsEffect from
    5249 */
    53 void GraphicsEffect::loadParams(const TiXmlElement* root)
    54 {
    55   BaseObject::loadParams(root);
     50void GraphicsEffect::loadParams(const TiXmlElement* root) {
     51    BaseObject::loadParams(root);
    5652}
    5753
     
    6056 *  initializes the graphics effect
    6157 */
    62 bool GraphicsEffect::init()
    63 {}
     58void GraphicsEffect::init() {}
    6459
    6560
     
    6863 * draws the effect, if needed
    6964 */
    70 void GraphicsEffect::draw() const
    71 {}
     65void GraphicsEffect::draw() const {}
    7266
    7367
     
    7670 * ticks the effect if there is any time dependancy
    7771 */
    78 void GraphicsEffect::tick(float dt)
    79 {}
     72void GraphicsEffect::tick(float dt) {}
  • branches/atmospheric_engine/src/lib/graphics/effects/graphics_effect.h

    r6815 r8457  
    1212
    1313//! A class that handles GraphicsEffects. The GraphicsEffectManager operates on this.
    14 class GraphicsEffect : public BaseObject
    15 {
    16   public:
     14class GraphicsEffect : public BaseObject {
     15public:
    1716    GraphicsEffect(const TiXmlElement* root = NULL);
    1817    virtual ~GraphicsEffect();
     
    2019    virtual void loadParams(const TiXmlElement* root);
    2120
    22     virtual bool init();
     21    virtual void init();
    2322
    24     virtual bool activate() = 0;
    25     virtual bool deactivate() = 0;
     23    virtual void activate() = 0;
     24    virtual void deactivate() = 0;
    2625
    2726    virtual void draw() const;
    2827    virtual void tick(float dt);
    2928
    30     inline bool isActivated() const { return this->bActivated; }
     29    inline bool isActivated() const {
     30        return this->bActivated;
     31    }
    3132
    3233
    33   protected:
     34protected:
    3435    bool              bActivated;
    3536};
  • branches/atmospheric_engine/src/lib/graphics/effects/lense_flare.cc

    r7844 r8457  
    4444 * @param root The XML-element to load the LenseFlare from
    4545 */
    46  LenseFlare::LenseFlare(const TiXmlElement* root)
    47 {
    48   this->setClassID(CL_LENSE_FLARE, "LenseFlare");
    49 
    50   this->flareMatrix = new float[14];
    51   /*          length                      image scale */
    52   this->flareMatrix[0] = 1.0f; this->flareMatrix[1] = 1.0f;
    53   this->flareMatrix[2] = 0.5f; this->flareMatrix[3] = 0.5f;
    54   this->flareMatrix[4] = 0.33f; this->flareMatrix[5] = 0.25f;
    55   this->flareMatrix[6] = 0.125f; this->flareMatrix[7] = 1.0f;
    56   this->flareMatrix[8] = -0.5f; this->flareMatrix[9] = 0.5f;
    57   this->flareMatrix[10] = -0.25f; this->flareMatrix[11] = 0.15f;
    58   this->flareMatrix[12] = -1.82f; this->flareMatrix[13] = 0.25f;
    59 
    60   this->lightSource = (LightManager::getInstance())->getLight(0);
    61   PRINTF(0)("light is: %p\n", this->lightSource);
    62 
    63   if (root != NULL)
    64   {
    65     this->loadParams(root);
    66     this->activate();
    67   }
    68 
    69   this->bVisible = true;
    70   this->setSourceVisibility(false);
     46LenseFlare::LenseFlare(const TiXmlElement* root) {
     47    this->setClassID(CL_LENSE_FLARE, "LenseFlare");
     48
     49    this->flareMatrix = new float[14];
     50    /*          length                      image scale */
     51    this->flareMatrix[0] = 1.0f;
     52    this->flareMatrix[1] = 1.0f;
     53    this->flareMatrix[2] = 0.5f;
     54    this->flareMatrix[3] = 0.5f;
     55    this->flareMatrix[4] = 0.33f;
     56    this->flareMatrix[5] = 0.25f;
     57    this->flareMatrix[6] = 0.125f;
     58    this->flareMatrix[7] = 1.0f;
     59    this->flareMatrix[8] = -0.5f;
     60    this->flareMatrix[9] = 0.5f;
     61    this->flareMatrix[10] = -0.25f;
     62    this->flareMatrix[11] = 0.15f;
     63    this->flareMatrix[12] = -1.82f;
     64    this->flareMatrix[13] = 0.25f;
     65
     66    this->lightSource = (LightManager::getInstance())->getLight(0);
     67    PRINTF(0)("light is: %p\n", this->lightSource);
     68
     69    if (root != NULL) {
     70        this->loadParams(root);
     71        this->activate();
     72    }
     73
     74    this->bVisible = true;
     75    this->setSourceVisibility(false);
    7176
    7277}
     
    7681 *  destroys a LenseFlare
    7782 */
    78 LenseFlare::~LenseFlare()
    79 {
    80   std::vector<ImagePlane*>::iterator it;
    81   for( it = flares.begin(); it != flares.end(); it++)
    82     delete (*it);
     83LenseFlare::~LenseFlare() {
     84    std::vector<ImagePlane*>::iterator it;
     85    for( it = flares.begin(); it != flares.end(); it++)
     86        delete (*it);
    8387}
    8488
     
    8791 * @param root The XML-element to load the LenseFlare from
    8892 */
    89 void LenseFlare::loadParams(const TiXmlElement* root)
    90 {
    91   GraphicsEffect::loadParams(root);
    92 
    93   LOAD_PARAM_START_CYCLE(root, element);
    94   {
    95     LoadParam_CYCLE(element, "add-flare-texture", this, LenseFlare, addFlare)
     93void LenseFlare::loadParams(const TiXmlElement* root) {
     94    GraphicsEffect::loadParams(root);
     95
     96    LOAD_PARAM_START_CYCLE(root, element);
     97    {
     98        LoadParam_CYCLE(element, "add-flare-texture", this, LenseFlare, addFlare)
    9699        .describe("adds a lensflare texture to the engine");
    97   }
    98   LOAD_PARAM_END_CYCLE(element);
     100    }
     101    LOAD_PARAM_END_CYCLE(element);
    99102}
    100103
     
    103106 * initializes the fog effect
    104107 */
    105 bool LenseFlare::init()
    106 {}
     108void LenseFlare::init() {}
    107109
    108110
     
    110112 * activates the fog effect
    111113 */
    112 bool LenseFlare::activate()
    113 {
    114   this->bActivated = true;
     114void LenseFlare::activate() {
     115    this->bActivated = true;
    115116}
    116117
     
    119120 * deactivates the fog effect
    120121 */
    121 bool LenseFlare::deactivate()
    122 {
    123   this->bActivated = false;
     122void LenseFlare::deactivate() {
     123    this->bActivated = false;
    124124}
    125125
     
    129129 * @param mode the mode character
    130130 */
    131 GLint LenseFlare::stringToFogMode(const std::string& mode)
    132 {}
     131GLint LenseFlare::stringToFogMode(const std::string& mode) {
     132    return 0;
     133}
    133134
    134135
     
    145146 *  7th: Texture of the third burst
    146147 */
    147 void LenseFlare::addFlare(const std::string& textureName)
    148 {
    149   if( this->flares.size() > LF_MAX_FLARES)
    150   {
    151     PRINTF(2)("You tried to add more than %i lense flares, ignoring\n", LF_MAX_FLARES);
    152     return;
    153   }
    154 
    155   ImagePlane* bb = new ImagePlane(NULL);
    156   if (this->flares.empty())
    157     bb->setLayer(E2D_LAYER_BELOW_ALL);
    158   bb->setTexture(textureName);
    159   bb->setSize(50, 50);
    160   this->flares.push_back(bb);
    161   bb->setVisibility(true);
    162 
    163   PRINTF(4)("Added a Lenseflare ImagePlane with texture %s\n", textureName.c_str());
    164 
    165   // the first flare belongs to the light source
    166   if( this->flares.size() == 1 && this->lightSource != NULL)
    167   {
    168     bb->setBindNode(static_cast<PNode*>(this->lightSource));
    169   }
    170 
    171   PRINTF(4)("Finished adding\n");
    172 }
    173 
    174 
    175 void LenseFlare::setSourceVisibility(bool visibility)
    176 {
    177    if (this->bVisible == visibility)
    178      return;
    179 
    180   std::vector<ImagePlane*>::const_iterator it;
     148void LenseFlare::addFlare(const std::string& textureName) {
     149    if( this->flares.size() > LF_MAX_FLARES) {
     150        PRINTF(2)("You tried to add more than %i lense flares, ignoring\n", LF_MAX_FLARES);
     151        return;
     152    }
     153
     154    ImagePlane* bb = new ImagePlane(NULL);
     155    if (this->flares.empty())
     156        bb->setLayer(E2D_LAYER_BELOW_ALL);
     157    bb->setTexture(textureName);
     158    bb->setSize(50, 50);
     159    this->flares.push_back(bb);
     160    bb->setVisibility(true);
     161
     162    PRINTF(4)("Added a Lenseflare ImagePlane with texture %s\n", textureName.c_str());
     163
     164    // the first flare belongs to the light source
     165    if( this->flares.size() == 1 && this->lightSource != NULL) {
     166        bb->setBindNode(static_cast<PNode*>(this->lightSource));
     167    }
     168
     169    PRINTF(4)("Finished adding\n");
     170}
     171
     172
     173void LenseFlare::setSourceVisibility(bool visibility) {
     174    if (this->bVisible == visibility)
     175        return;
     176
     177    std::vector<ImagePlane*>::const_iterator it;
    181178    for(it = ++flares.begin(); it != flares.end(); it++)
    182       (*it)->setVisibility(visibility);
    183   this->bVisible = visibility;
     179        (*it)->setVisibility(visibility);
     180    this->bVisible = visibility;
    184181}
    185182
     
    188185 * tick the effect
    189186 */
    190 void LenseFlare::tick(float dt)
    191 {
    192   if( unlikely(!this->bActivated || this->flares.size() == 0))
    193     return;
    194 
    195   // refetch light source information if needed
    196   if( unlikely( this->lightSource == NULL))
    197   {
    198     this->lightSource = (LightManager::getInstance())->getLight(0);
    199     if( this->flares.size() > 0)
    200       this->flares[0]->setBindNode(static_cast<PNode*>(this->lightSource));
    201   }
     187void LenseFlare::tick(float dt) {
     188    if( unlikely(!this->bActivated || this->flares.size() == 0))
     189        return;
     190
     191    // refetch light source information if needed
     192    if( unlikely( this->lightSource == NULL)) {
     193        this->lightSource = (LightManager::getInstance())->getLight(0);
     194        if( this->flares.size() > 0)
     195            this->flares[0]->setBindNode(static_cast<PNode*>(this->lightSource));
     196    }
    202197
    203198    //set the frustum plane
    204   if (!flares.empty())
    205     this->setSourceVisibility(this->flares[0]->isVisible());
    206 
    207 
    208   // always update the screen center, it could be, that the window is resized
    209   this->screenCenter = Vector2D(State::getResX()/2.0f, State::getResY()/2.0f);
    210 
    211   // flare vector is the direction from the center to the light source
    212   this->flareVector = this->flares[0]->getAbsCoor2D() - this->screenCenter;
    213   this->distance = this->flareVector.len();
    214   this->flareVector.normalize();
    215 
    216   // now calculate the new coordinates of the billboards
    217   std::vector<ImagePlane*>::iterator it;
    218   int i;
    219   for( it = flares.begin(), i = 0; it != flares.end(); it++, i++)
    220   {
    221     // set the new position
    222     if( i == 0)
    223       continue;
    224 
    225     (*it)->setAbsCoor2D( this->screenCenter + this->flareVector * this->flareMatrix[i * 2] * this->distance);
    226     (*it)->setSize2D(50.0f * this->flareMatrix[i * 2 + 1], 50.0f * this->flareMatrix[i * 2 + 1]);
    227     PRINTF(5)("Tick flare %i @ (%f, %f)\n", i, (*it)->getAbsCoor2D().x, (*it)->getAbsCoor2D().y);
    228   }
     199    if (!flares.empty())
     200        this->setSourceVisibility(this->flares[0]->isVisible());
     201
     202
     203    // always update the screen center, it could be, that the window is resized
     204    this->screenCenter = Vector2D(State::getResX()/2.0f, State::getResY()/2.0f);
     205
     206    // flare vector is the direction from the center to the light source
     207    this->flareVector = this->flares[0]->getAbsCoor2D() - this->screenCenter;
     208    this->distance = this->flareVector.len();
     209    this->flareVector.normalize();
     210
     211    // now calculate the new coordinates of the billboards
     212    std::vector<ImagePlane*>::iterator it;
     213    int i;
     214    for( it = flares.begin(), i = 0; it != flares.end(); it++, i++) {
     215        // set the new position
     216        if( i == 0)
     217            continue;
     218
     219        (*it)->setAbsCoor2D( this->screenCenter + this->flareVector * this->flareMatrix[i * 2] * this->distance);
     220        (*it)->setSize2D(50.0f * this->flareMatrix[i * 2 + 1], 50.0f * this->flareMatrix[i * 2 + 1]);
     221        PRINTF(5)("Tick flare %i @ (%f, %f)\n", i, (*it)->getAbsCoor2D().x, (*it)->getAbsCoor2D().y);
     222    }
    229223}
    230224
     
    233227 * draws the LenseFlares
    234228 */
    235 void LenseFlare::draw() const
    236 {
    237   if( !this->bActivated)
    238     return;
    239 }
     229void LenseFlare::draw() const {
     230    if( !this->bActivated)
     231        return;
     232}
  • branches/atmospheric_engine/src/lib/graphics/effects/lense_flare.h

    r7844 r8457  
    3131    virtual void loadParams(const TiXmlElement* root);
    3232
    33     virtual bool init();
     33    virtual void init();
    3434
    35     virtual bool activate();
    36     virtual bool deactivate();
     35    virtual void activate();
     36    virtual void deactivate();
    3737
    3838    virtual void draw() const;
  • branches/atmospheric_engine/src/lib/graphics/effects/rain_effect.cc

    r8455 r8457  
    3939
    4040/* TODO:
    41         - preCaching
    42         - test multiple rain emitters
    43         - Think about what happens with building poss. to hang movewithcam off
    44         - Possible to activate lightening
    45         - turn off visibility when in a building
    46         - variable emitter size depending on playable
     41  - preCaching
     42  - test multiple rain emitters
     43  - Think about what happens with building poss. to hang movewithcam off
     44  - Possible to activate lightening
     45  - turn off visibility when in a building
     46  - variable emitter size depending on playable
    4747*/
    4848
    49 RainEffect::RainEffect(const TiXmlElement* root)
    50 {
    51         this->setClassID(CL_RAIN_EFFECT, "RainEffect");
    52 
    53         this->init();
    54 
    55         if (root != NULL)
    56                 this->loadParams(root);
    57 
    58         //load rain sound
    59         if (this->rainBuffer != NULL)
    60                 ResourceManager::getInstance()->unload(this->rainBuffer);
    61         this->rainBuffer = (OrxSound::SoundBuffer*)ResourceManager::getInstance()->load("sound/atmosphere/rain.wav", WAV);
    62 
    63         //load wind sound
    64         if (this->rainWindForce != 0) {
    65                 if (this->windBuffer != NULL)
    66                         ResourceManager::getInstance()->unload(this->windBuffer);
    67                 this->windBuffer = (OrxSound::SoundBuffer*)ResourceManager::getInstance()->load("sound/atmosphere/wind.wav", WAV);
    68         }
    69 
    70         if(rainActivate)
    71                 this->activate();
    72 }
    73 
    74 RainEffect::~RainEffect()
    75 {
    76         this->deactivate();
    77 
    78         if (this->rainBuffer != NULL)
    79                 ResourceManager::getInstance()->unload(this->rainBuffer);
    80 
    81         if (this->windBuffer != NULL)
    82                 ResourceManager::getInstance()->unload(this->windBuffer);
    83 }
    84 
    85 void RainEffect::loadParams(const TiXmlElement* root)
    86 {
    87         WeatherEffect::loadParams(root);
    88 
    89         LoadParam(root, "coord", this, RainEffect, setRainCoord);
    90         LoadParam(root, "size", this, RainEffect, setRainSize);
    91         LoadParam(root, "rate", this, RainEffect, setRainRate);
    92         LoadParam(root, "velocity", this, RainEffect, setRainVelocity);
    93         LoadParam(root, "life", this, RainEffect, setRainLife);
    94         LoadParam(root, "wind", this, RainEffect, setRainWind);
    95         LoadParam(root, "fadeinduration", this, RainEffect, setRainFadeIn);
    96         LoadParam(root, "fadeoutduration", this, RainEffect, setRainFadeOut);
    97 
    98         LOAD_PARAM_START_CYCLE(root, element);
    99         {
    100                 LoadParam_CYCLE(element, "option", this, RainEffect, setRainOption);
    101         }
    102         LOAD_PARAM_END_CYCLE(element);
    103 
    104 }
    105 
    106 
    107 void RainEffect::init()
    108 {
    109         //Default values
    110         this->rainActivate = false;
    111         this->rainMove = false;
    112         this->rainCoord = Vector(500, 500, 500);
    113         this->rainSize = Vector2D(1000, 1000);
    114         this->rainRate = 4000;
    115         this->rainVelocity = -300;
    116         this->rainLife = 4;
    117         this->rainMaxParticles = this->rainRate * this->rainLife;
    118         this->rainWindForce  = 0;
    119         this->rainFadeInDuration = 0;
    120         this->rainFadeOutDuration = 0;
    121         this->localTimer = 0;
    122         this->soundRainVolume = 0.8f;
    123 
    124         this->emitter = new PlaneEmitter(this->rainSize);
    125 
    126         lightMan = LightManager::getInstance();
    127         this->rainAmbient = lightMan->getAmbientColor();
     49RainEffect::RainEffect(const TiXmlElement* root) {
     50    this->setClassID(CL_RAIN_EFFECT, "RainEffect");
     51
     52    this->init();
     53
     54    if (root != NULL)
     55        this->loadParams(root);
     56
     57    //load rain sound
     58    if (this->rainBuffer != NULL)
     59        ResourceManager::getInstance()->unload(this->rainBuffer);
     60    this->rainBuffer = (OrxSound::SoundBuffer*)ResourceManager::getInstance()->load("sound/atmosphere/rain.wav", WAV);
     61
     62    //load wind sound
     63    if (this->rainWindForce != 0) {
     64        if (this->windBuffer != NULL)
     65            ResourceManager::getInstance()->unload(this->windBuffer);
     66        this->windBuffer = (OrxSound::SoundBuffer*)ResourceManager::getInstance()->load("sound/atmosphere/wind.wav", WAV);
     67    }
     68
     69    if(rainActivate)
     70        this->activate();
     71}
     72
     73RainEffect::~RainEffect() {
     74    this->deactivate();
     75
     76    if (this->rainBuffer != NULL)
     77        ResourceManager::getInstance()->unload(this->rainBuffer);
     78
     79    if (this->windBuffer != NULL)
     80        ResourceManager::getInstance()->unload(this->windBuffer);
     81}
     82
     83void RainEffect::loadParams(const TiXmlElement* root) {
     84    WeatherEffect::loadParams(root);
     85
     86    LoadParam(root, "coord", this, RainEffect, setRainCoord);
     87    LoadParam(root, "size", this, RainEffect, setRainSize);
     88    LoadParam(root, "rate", this, RainEffect, setRainRate);
     89    LoadParam(root, "velocity", this, RainEffect, setRainVelocity);
     90    LoadParam(root, "life", this, RainEffect, setRainLife);
     91    LoadParam(root, "wind", this, RainEffect, setRainWind);
     92    LoadParam(root, "fadeinduration", this, RainEffect, setRainFadeIn);
     93    LoadParam(root, "fadeoutduration", this, RainEffect, setRainFadeOut);
     94
     95    LOAD_PARAM_START_CYCLE(root, element);
     96    {
     97        LoadParam_CYCLE(element, "option", this, RainEffect, setRainOption);
     98    }
     99    LOAD_PARAM_END_CYCLE(element);
     100
     101}
     102
     103
     104void RainEffect::init() {
     105    //Default values
     106    this->rainActivate = false;
     107    this->rainMove = false;
     108    this->rainCoord = Vector(500, 500, 500);
     109    this->rainSize = Vector2D(1000, 1000);
     110    this->rainRate = 4000;
     111    this->rainVelocity = -300;
     112    this->rainLife = 4;
     113    this->rainMaxParticles = this->rainRate * this->rainLife;
     114    this->rainWindForce  = 0;
     115    this->rainFadeInDuration = 0;
     116    this->rainFadeOutDuration = 0;
     117    this->localTimer = 0;
     118    this->soundRainVolume = 0.8f;
     119
     120    this->emitter = new PlaneEmitter(this->rainSize);
     121
     122    lightMan = LightManager::getInstance();
     123    this->rainAmbient = lightMan->getAmbientColor();
    128124}
    129125
     
    131127SparkParticles* RainEffect::rainParticles = NULL;
    132128
    133 void RainEffect::activate()
    134 {
    135         PRINTF(0)( "Activating RainEffect, coord: %f, %f, %f, size: %f, %f, rate: %f, velocity: %f, moveRain: %s\n", this->rainCoord.x, this->rainCoord.y, this->rainCoord.z, this->rainSize.x, this-> rainSize.y, this->rainRate, this->rainVelocity, this->rainMove ? "true" : "false" );
    136 
    137         this->rainActivate = true;
    138 
    139         if (unlikely(RainEffect::rainParticles == NULL))
    140         {
    141                 RainEffect::rainParticles = new SparkParticles((int) this->rainMaxParticles);
    142                 RainEffect::rainParticles->setName("RainParticles");
    143                 RainEffect::rainParticles->precache((int)this->rainLife, 30); // TODO: Why doesnt this work??
    144                 RainEffect::rainParticles->setLifeSpan(this->rainLife, 2);
    145                 RainEffect::rainParticles->setRadius(0, 0.03);
    146                 RainEffect::rainParticles->setRadius(0.2, 0.02);
    147                 RainEffect::rainParticles->setRadius(1, 0.01);
    148                 RainEffect::rainParticles->setColor(0, 0.3, 0.3, 0.5, 0.2);     // grey blue 1
    149                 RainEffect::rainParticles->setColor(0.5, 0.4, 0.4, 0.5, 0.2);   // grey blue 2
    150                 RainEffect::rainParticles->setColor(1, 0.7, 0.7, 0.7, 0.2);     // light grey
    151         }
    152 
    153         this->emitter->setSystem(RainEffect::rainParticles);
    154 
    155         this->emitter->setRelCoor(this->rainCoord);
    156 
    157         this->emitter->setEmissionRate(this->rainRate);
    158         this->emitter->setEmissionVelocity(this->rainVelocity);
    159 
    160         this->emitter->setSpread(this->rainWindForce / 50, 0.2);
    161        
    162         this->soundSource.loop(this->rainBuffer, this->soundRainVolume);
    163         if (this->rainWindForce != 0) this->soundSource.loop(this->windBuffer, 0.1f * this->rainWindForce);
    164 
    165         if (this->rainFadeInDuration == 0)
    166                 lightMan->setAmbientColor(.1,.1,.1);
    167 
    168 }
    169 
    170 
    171 void RainEffect::deactivate()
    172 {
    173         PRINTF(0)("Deactivating RainEffect\n");
    174        
    175         this->rainActivate = false;
    176         this->emitter->setSystem(NULL);
    177 
    178         // Stop Sound
    179         this->soundSource.stop();
    180 
    181         // Restore Light Ambient
    182         lightMan->setAmbientColor(this->rainAmbient, this->rainAmbient, this->rainAmbient);
    183 
    184 }
    185 
    186 void RainEffect::tick (float dt)
    187 {
    188         if (!this->rainActivate)
    189                 return;
    190                
    191         if (this->rainMove) {
    192                 this->rainCoord = State::getCameraNode()->getAbsCoor();
    193                 this->emitter->setRelCoor(this->rainCoord.x , this->rainCoord.y+800, this->rainCoord.z);
    194         }
    195 
    196         if (this->rainFadeInDuration != 0 && this->localTimer < this->rainFadeInDuration) {
    197                 this->localTimer += dt;
    198                 float progress = this->localTimer / this->rainFadeInDuration;
    199 
    200                 // Dim Light
    201                 lightMan->setAmbientColor(1 - progress * 0.9, 1 - progress * 0.9, 1 - progress * 0.9);
    202 
    203                 // use alpha in color to fade in
    204                 RainEffect::rainParticles->setColor(0,   0.3, 0.3, 0.5, 0.2 * progress); // grey blue 1
    205                 RainEffect::rainParticles->setColor(0.5, 0.4, 0.4, 0.5, 0.2 * progress); // grey blue 2
    206                 RainEffect::rainParticles->setColor(1,   0.7, 0.7, 0.7, 0.2 * progress); // light grey
    207 
    208                 // increase radius for more "heavy" rain
    209                 RainEffect::rainParticles->setRadius(0, 0.03 * progress);
    210                 RainEffect::rainParticles->setRadius(0.2, 0.02 * progress);
    211                 RainEffect::rainParticles->setRadius(1, 0.01 * progress);
    212 
    213                 // increase sound volume
    214                 // this->soundSource.fadein(this->rainBuffer, 10);
    215         }
    216         else if ( this->rainFadeOutDuration != 0 ) {
    217                 if ( this->localTimer < this->rainFadeOutDuration ) {
    218                         this->localTimer += dt;
    219                         float progress = 1 - (this->localTimer / this->rainFadeOutDuration);
    220        
    221                         // Fade In Light
    222                         lightMan->setAmbientColor(1 - progress * 0.9, 1 - progress * 0.9, 1 - progress * 0.9);
    223 
    224                         // use alpha in color to fade out
    225                         RainEffect::rainParticles->setColor(0,   0.3, 0.3, 0.5, 0.2 * progress); // grey blue 1
    226                         RainEffect::rainParticles->setColor(0.5, 0.4, 0.4, 0.5, 0.2 * progress); // grey blue 2
    227                         RainEffect::rainParticles->setColor(1,   0.7, 0.7, 0.7, 0.2 * progress); // light grey
    228        
    229                         // decrease radius
    230                         RainEffect::rainParticles->setRadius(0, 0.03 * progress);
    231                         RainEffect::rainParticles->setRadius(0.2, 0.02 * progress);
    232                         RainEffect::rainParticles->setRadius(1, 0.01 * progress);
    233        
    234                         // decrease sound volume
    235                         // this->soundSource.fadeout(this->rainBuffer, 10);
    236                 }
    237                 else
    238                         this->deactivate();
    239         }
    240        
     129void RainEffect::activate() {
     130    PRINTF(0)( "Activating RainEffect, coord: %f, %f, %f, size: %f, %f, rate: %f, velocity: %f, moveRain: %s\n", this->rainCoord.x, this->rainCoord.y, this->rainCoord.z, this->rainSize.x, this-> rainSize.y, this->rainRate, this->rainVelocity, this->rainMove ? "true" : "false" );
     131
     132    this->rainActivate = true;
     133
     134    if (unlikely(RainEffect::rainParticles == NULL)) {
     135        RainEffect::rainParticles = new SparkParticles((int) this->rainMaxParticles);
     136        RainEffect::rainParticles->setName("RainParticles");
     137        RainEffect::rainParticles->setLifeSpan(this->rainLife, 2);
     138        RainEffect::rainParticles->setRadius(0, 0.03);
     139        RainEffect::rainParticles->setRadius(0.2, 0.02);
     140        RainEffect::rainParticles->setRadius(1, 0.01);
     141        RainEffect::rainParticles->setColor(0, 0.3, 0.3, 0.5, 0.2); // grey blue 1
     142        RainEffect::rainParticles->setColor(0.5, 0.4, 0.4, 0.5, 0.2); // grey blue 2
     143        RainEffect::rainParticles->setColor(1, 0.7, 0.7, 0.7, 0.2); // light grey
     144    }
     145
     146    this->emitter->setSystem(RainEffect::rainParticles);
     147
     148    this->emitter->setRelCoor(this->rainCoord);
     149
     150    this->emitter->setEmissionRate(this->rainRate);
     151    this->emitter->setEmissionVelocity(this->rainVelocity);
     152
     153    this->emitter->setSpread(this->rainWindForce / 50, 0.2);
     154
     155    RainEffect::rainParticles->precache((int)this->rainLife);
     156
     157    this->soundSource.loop(this->rainBuffer, this->soundRainVolume);
     158    if (this->rainWindForce != 0)
     159        this->soundSource.loop(this->windBuffer, 0.1f * this->rainWindForce);
     160
     161    if (this->rainFadeInDuration == 0)
     162        lightMan->setAmbientColor(.1,.1,.1);
     163
     164}
     165
     166
     167void RainEffect::deactivate() {
     168    PRINTF(0)("Deactivating RainEffect\n");
     169
     170    this->rainActivate = false;
     171    this->emitter->setSystem(NULL);
     172
     173    // Stop Sound
     174    this->soundSource.stop();
     175
     176    // Restore Light Ambient
     177    lightMan->setAmbientColor(this->rainAmbient, this->rainAmbient, this->rainAmbient);
     178
     179}
     180
     181void RainEffect::tick (float dt) {
     182    if (!this->rainActivate)
     183        return;
     184
     185    if (this->rainMove) {
     186        this->rainCoord = State::getCameraNode()->getAbsCoor();
     187        this->emitter->setRelCoor(this->rainCoord.x , this->rainCoord.y+800, this->rainCoord.z);
     188    }
     189
     190    if (this->rainFadeInDuration != 0 && this->localTimer < this->rainFadeInDuration) {
     191        this->localTimer += dt;
     192        float progress = this->localTimer / this->rainFadeInDuration;
     193
     194        // Dim Light
     195        lightMan->setAmbientColor(1 - progress * 0.9, 1 - progress * 0.9, 1 - progress * 0.9);
     196
     197        // use alpha in color to fade in
     198        RainEffect::rainParticles->setColor(0,   0.3, 0.3, 0.5, 0.2 * progress); // grey blue 1
     199        RainEffect::rainParticles->setColor(0.5, 0.4, 0.4, 0.5, 0.2 * progress); // grey blue 2
     200        RainEffect::rainParticles->setColor(1,   0.7, 0.7, 0.7, 0.2 * progress); // light grey
     201
     202        // increase radius for more "heavy" rain
     203        RainEffect::rainParticles->setRadius(0, 0.03 * progress);
     204        RainEffect::rainParticles->setRadius(0.2, 0.02 * progress);
     205        RainEffect::rainParticles->setRadius(1, 0.01 * progress);
     206
     207        // increase sound volume
     208        // this->soundSource.fadein(this->rainBuffer, 10);
     209    } else if ( this->rainFadeOutDuration != 0 ) {
     210        if ( this->localTimer < this->rainFadeOutDuration ) {
     211            this->localTimer += dt;
     212            float progress = 1 - (this->localTimer / this->rainFadeOutDuration);
     213
     214            // Fade In Light
     215            lightMan->setAmbientColor(1 - progress * 0.9, 1 - progress * 0.9, 1 - progress * 0.9);
     216
     217            // use alpha in color to fade out
     218            RainEffect::rainParticles->setColor(0,   0.3, 0.3, 0.5, 0.2 * progress); // grey blue 1
     219            RainEffect::rainParticles->setColor(0.5, 0.4, 0.4, 0.5, 0.2 * progress); // grey blue 2
     220            RainEffect::rainParticles->setColor(1,   0.7, 0.7, 0.7, 0.2 * progress); // light grey
     221
     222            // decrease radius
     223            RainEffect::rainParticles->setRadius(0, 0.03 * progress);
     224            RainEffect::rainParticles->setRadius(0.2, 0.02 * progress);
     225            RainEffect::rainParticles->setRadius(1, 0.01 * progress);
     226
     227            // decrease sound volume
     228            // this->soundSource.fadeout(this->rainBuffer, 10);
     229        } else
     230            this->deactivate();
     231    }
     232
    241233}
    242234
    243235void RainEffect::startRaining() {
    244236
    245         if (this->rainActivate)
    246                 this->deactivate();
    247 
    248         if (!this->rainFadeInDuration > 0)
    249                 this->rainFadeInDuration = 20;
    250 
    251         this->localTimer = 0;
    252 
    253         this->activate();
     237    if (this->rainActivate)
     238        this->deactivate();
     239
     240    if (!this->rainFadeInDuration > 0)
     241        this->rainFadeInDuration = 20;
     242
     243    this->localTimer = 0;
     244
     245    this->activate();
    254246
    255247}
     
    257249void RainEffect::stopRaining() {
    258250
    259         if (!this->rainActivate)
    260                 this->activate();
    261 
    262         if (!this->rainFadeOutDuration > 0)
    263                 this->rainFadeOutDuration = 20;
    264 
    265         this->localTimer = 0;
    266 
    267 }
     251    if (!this->rainActivate)
     252        this->activate();
     253
     254    if (!this->rainFadeOutDuration > 0)
     255        this->rainFadeOutDuration = 20;
     256
     257    this->localTimer = 0;
     258
     259}
  • branches/atmospheric_engine/src/lib/graphics/effects/rain_effect.h

    r8455 r8457  
    2222
    2323
    24 class RainEffect : public WeatherEffect
    25 {
    26         public:
    27                 RainEffect(const TiXmlElement* root = NULL);
    28                 virtual ~RainEffect();
     24class RainEffect : public WeatherEffect {
     25public:
     26    RainEffect(const TiXmlElement* root = NULL);
     27    virtual ~RainEffect();
    2928
    30                 virtual void loadParams(const TiXmlElement* root);
     29    virtual void loadParams(const TiXmlElement* root);
    3130
    32                 virtual void init();
     31    virtual void init();
    3332
    34                 virtual void activate();
    35                 virtual void deactivate();
     33    virtual void activate();
     34    virtual void deactivate();
    3635
    37                 inline void activateRain() { this->activate(); }
    38                 inline void deactivateRain() { this->deactivate(); }
     36    inline void activateRain() {
     37        this->activate();
     38    }
     39    inline void deactivateRain() {
     40        this->deactivate();
     41    }
    3942
    40                 virtual void tick(float dt);
     43    virtual void tick(float dt);
    4144
    42                 void startRaining();
    43                 void stopRaining();
     45    void startRaining();
     46    void stopRaining();
    4447
    45                 inline void setRainCoord(float x, float y, float z) { this->rainCoord = Vector(x, y, z); }
    46                 inline void setRainSize(float x, float y) { this->rainSize = Vector2D(x, y); }
    47                 inline void setRainRate(float rate) { this->rainRate = rate;}
    48                 inline void setRainVelocity(float velocity) { this->rainVelocity = -velocity; }
    49                 inline void setRainLife(float life) { this->rainLife = life; }
    50                 inline void setRainWind(int force) { this->rainWindForce = force; }
     48    inline void setRainCoord(float x, float y, float z) {
     49        this->rainCoord = Vector(x, y, z);
     50    }
     51    inline void setRainSize(float x, float y) {
     52        this->rainSize = Vector2D(x, y);
     53    }
     54    inline void setRainRate(float rate) {
     55        this->rainRate = rate;
     56    }
     57    inline void setRainVelocity(float velocity) {
     58        this->rainVelocity = -velocity;
     59    }
     60    inline void setRainLife(float life) {
     61        this->rainLife = life;
     62    }
     63    inline void setRainWind(int force) {
     64        this->rainWindForce = force;
     65    }
    5166
    52                 inline void setRainFadeIn(float fadein) { this->rainFadeInDuration = fadein; }
    53                 inline void setRainFadeOut(float fadeout) { this->rainFadeOutDuration = fadeout; }
     67    inline void setRainFadeIn(float fadein) {
     68        this->rainFadeInDuration = fadein;
     69    }
     70    inline void setRainFadeOut(float fadeout) {
     71        this->rainFadeOutDuration = fadeout;
     72    }
    5473
    55                 inline void setRainOption(const std::string& option) {
    56                         if (option == "moverain") this->rainMove = true;
    57                         if (option == "activate") this->rainActivate = true;
    58                 }
     74    inline void setRainOption(const std::string& option) {
     75        if (option == "moverain")
     76            this->rainMove = true;
     77        if (option == "activate")
     78            this->rainActivate = true;
     79    }
    5980
    6081
    61         private:
    62                 static SparkParticles*                  rainParticles;
    63                 ParticleEmitter*                        emitter;
     82private:
     83    static SparkParticles*      rainParticles;
     84    ParticleEmitter*      emitter;
    6485
    65                 GLfloat                                 rainFadeInDuration;
    66                 GLfloat                                 rainFadeOutDuration;
    67                 float                                   localTimer;
     86    GLfloat         rainFadeInDuration;
     87    GLfloat         rainFadeOutDuration;
     88    float         localTimer;
    6889
    69                 Vector                                  rainCoord;
    70                 Vector2D                                rainSize;
    71                 GLfloat                                 rainRate;
    72                 GLfloat                                 rainVelocity;
    73                 GLfloat                                 rainLife;
    74                 GLfloat                                 rainMaxParticles;
    75                 int                                     rainWindForce;
    76                 bool                                    rainMove;
    77                 bool                                    rainActivate;
     90    Vector          rainCoord;
     91    Vector2D        rainSize;
     92    GLfloat         rainRate;
     93    GLfloat         rainVelocity;
     94    GLfloat         rainLife;
     95    GLfloat         rainMaxParticles;
     96    int         rainWindForce;
     97    bool          rainMove;
     98    bool          rainActivate;
    7899
    79                 OrxSound::SoundSource                   soundSource;
    80                 OrxSound::SoundBuffer*                  rainBuffer;
    81                 OrxSound::SoundBuffer*                  windBuffer;
     100    OrxSound::SoundSource     soundSource;
     101    OrxSound::SoundBuffer*      rainBuffer;
     102    OrxSound::SoundBuffer*      windBuffer;
    82103
    83                 float                                   soundRainVolume;
     104    float         soundRainVolume;
    84105
    85                 LightManager*                           lightMan;
    86                 GLfloat                                 rainAmbient;
     106    LightManager*       lightMan;
     107    GLfloat         rainAmbient;
    87108
    88109};
  • branches/atmospheric_engine/src/lib/graphics/effects/snow_effect.cc

    r8455 r8457  
    9696        this->particles = 12000;
    9797        this->texture = "maps/snow_flake_01_32x32.png";
    98         this->life = 8;
     98        this->snowLife = 8;
    9999        this->randomLife = 2;
    100100        this->snowRadius = 3.5;
     
    122122        SnowEffect::snowParticles->setName("SnowEffectTrailParticles");
    123123        SnowEffect::snowParticles->setMaterialTexture(texture);
    124         SnowEffect::snowParticles->setLifeSpan(life, randomLife);
     124        SnowEffect::snowParticles->setLifeSpan(snowLife, randomLife);
    125125        SnowEffect::snowParticles->setRadius(0.0, snowRadius, randomRadius);
    126126        SnowEffect::snowParticles->setRadius(0.2, snowRadius, randomRadius*0.8);
     
    139139        this->emitter->setSize(snowSize);
    140140
    141         // SnowEffect::snowParticles->precache(8);
     141  SnowEffect::snowParticles->precache((int) this->snowLife);
    142142
    143143        if (this->snowWindForce > 1)
  • branches/atmospheric_engine/src/lib/graphics/effects/snow_effect.h

    r8455 r8457  
    2020#include "sound_buffer.h"
    2121
    22 class SnowEffect : public WeatherEffect
    23 {
    24         public:
    25                 SnowEffect(const TiXmlElement* root = NULL);
    26                 virtual ~SnowEffect();
     22class SnowEffect : public WeatherEffect {
     23public:
     24    SnowEffect(const TiXmlElement* root = NULL);
     25    virtual ~SnowEffect();
    2726
    28                 virtual void loadParams(const TiXmlElement* root);
     27    virtual void loadParams(const TiXmlElement* root);
    2928
    30                 virtual void init();
     29    virtual void init();
    3130
    32                 virtual void activate();
    33                 virtual void deactivate();
     31    virtual void activate();
     32    virtual void deactivate();
    3433
    35                 inline void activateSnow() { this->activate(); }
    36                 inline void deactivateSnow() { this->deactivate(); }
    37                
    38                 virtual void draw() const;
    39                 virtual void tick(float dt);
     34    inline void activateSnow() {
     35        this->activate();
     36    }
     37    inline void deactivateSnow() {
     38        this->deactivate();
     39    }
     40
     41    virtual void draw() const;
     42    virtual void tick(float dt);
    4043
    4144
    42                 inline void numParticles(int n) { this->particles = n; }
    43                 inline void materialTexture(const std::string& texture) { this->texture = texture; }
    44                 inline void lifeSpan(float lifeSpan, float randomLifeSpan) { this->life = lifeSpan; this->randomLife = randomLifeSpan; }
    45                 inline void radius(float radius, float randomRadius) { this->snowRadius = radius; this->randomRadius = randomRadius; }
    46                 inline void mass(float mass, float randomMass) { this->snowMass = mass; this->randomMass = randomMass; }
    47                 inline void emissionRate(float emissionRate){ this->rate = emissionRate; }
    48                 inline void emissionVelocity(float velocity, float randomVelocity){ this->velocity = velocity; this->randomVelocity = randomVelocity; }
    49                 inline void size(float sizeX, float sizeY) { this->snowSize = Vector2D(sizeX, sizeY); }
    50                 inline void coord(float x, float y, float z) { this->snowCoord = Vector(x, y, z); }
    51                 inline void wind(int force) { this->snowWindForce = force; }
     45    inline void numParticles(int n) {
     46        this->particles = n;
     47    }
     48    inline void materialTexture(const std::string& texture) {
     49        this->texture = texture;
     50    }
     51    inline void lifeSpan(float lifeSpan, float randomLifeSpan) {
     52        this->snowLife = lifeSpan;
     53        this->randomLife = randomLifeSpan;
     54    }
     55    inline void radius(float radius, float randomRadius) {
     56        this->snowRadius = radius;
     57        this->randomRadius = randomRadius;
     58    }
     59    inline void mass(float mass, float randomMass) {
     60        this->snowMass = mass;
     61        this->randomMass = randomMass;
     62    }
     63    inline void emissionRate(float emissionRate) {
     64        this->rate = emissionRate;
     65    }
     66    inline void emissionVelocity(float velocity, float randomVelocity) {
     67        this->velocity = velocity;
     68        this->randomVelocity = randomVelocity;
     69    }
     70    inline void size(float sizeX, float sizeY) {
     71        this->snowSize = Vector2D(sizeX, sizeY);
     72    }
     73    inline void coord(float x, float y, float z) {
     74        this->snowCoord = Vector(x, y, z);
     75    }
     76    inline void wind(int force) {
     77        this->snowWindForce = force;
     78    }
    5279
    53                 inline void setSnowOption(const std::string& option) {
    54                         /*if (option == "fade") this->snowFade = true;*/
    55                         if (option == "movesnow") this->snowMove = true;
    56                         if (option == "activate") this->snowActivate = true;
    57                 }
     80    inline void setSnowOption(const std::string& option) {
     81        /*if (option == "fade") this->snowFade = true;*/
     82        if (option == "movesnow")
     83            this->snowMove = true;
     84        if (option == "activate")
     85            this->snowActivate = true;
     86    }
    5887
    5988
    60         private:
    61                 int                             particles;
    62                 std::string                     texture;
    63                 float                           life, randomLife;
    64                 float                           snowRadius, randomRadius;
    65                 float                           snowMass, randomMass;
    66                 float                           rate;
    67                 float                           velocity, randomVelocity;
    68                 float                           angle, randomAngle;
    69                 float                           alpha;
    70                 Vector                          snowCoord;
    71                 Vector2D                        snowSize;
    72                 int                             snowWindForce;
     89private:
     90    int         particles;
     91    std::string       texture;
     92    float       snowLife, randomLife;
     93    float       snowRadius, randomRadius;
     94    float       snowMass, randomMass;
     95    float         rate;
     96    float         velocity, randomVelocity;
     97    float         angle, randomAngle;
     98    float         alpha;
     99    Vector        snowCoord;
     100    Vector2D      snowSize;
     101    int       snowWindForce;
    73102
    74                 bool                            snowMove;
    75                 bool                            snowActivate;
     103    bool        snowMove;
     104    bool        snowActivate;
    76105
    77                 PlaneEmitter*                   emitter;
     106    PlaneEmitter*     emitter;
    78107
    79                 static SpriteParticles*         snowParticles;
    80                 OrxSound::SoundSource           soundSource;
    81                 OrxSound::SoundBuffer*          windBuffer;
     108    static SpriteParticles*   snowParticles;
     109    OrxSound::SoundSource   soundSource;
     110    OrxSound::SoundBuffer*    windBuffer;
    82111
    83112};
  • branches/atmospheric_engine/src/lib/graphics/effects/volfog_effect.cc

    r8455 r8457  
    11/*
    2         orxonox - the future of 3D-vertical-scrollers
     2  orxonox - the future of 3D-vertical-scrollers
    33
    4         Copyright (C) 2004 orx
     4  Copyright (C) 2004 orx
    55
    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.
     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
     
    5151CREATE_FACTORY(VolFogEffect, CL_VOLFOG_EFFECT);
    5252
    53 VolFogEffect::VolFogEffect(const TiXmlElement* root)
    54 {
    55         this->setClassID(CL_VOLFOG_EFFECT, "VolFogEffect");
     53VolFogEffect::VolFogEffect(const TiXmlElement* root) {
     54    this->setClassID(CL_VOLFOG_EFFECT, "VolFogEffect");
    5655
    57         if (root != NULL)
    58                 this->loadParams(root);
     56    if (root != NULL)
     57        this->loadParams(root);
    5958
    60         // Initialize Effect
    61         this->init();
     59    // Initialize Effect
     60    this->init();
    6261
    63         // Activate Effect
    64         this->activate();
     62    // Activate Effect
     63    this->activate();
    6564}
    6665
    6766
    68 VolFogEffect::~VolFogEffect()
    69 {
    70         this->deactivate();
     67VolFogEffect::~VolFogEffect() {
     68    this->deactivate();
    7169}
    7270
    73 void VolFogEffect::loadParams(const TiXmlElement* root)
    74 {
    75         WeatherEffect::loadParams(root);
     71void VolFogEffect::loadParams(const TiXmlElement* root) {
     72    WeatherEffect::loadParams(root);
    7673}
    7774
    78 void VolFogEffect::init()
    79 {
    80         PRINTF(0)("Initalize VolFogEffect\n");
     75void VolFogEffect::init() {
     76    PRINTF(0)("Initalize VolFogEffect\n");
    8177
    82         // set fog mode
    83         GLenum fogMode  = GL_EXP;
     78    // set fog mode
     79    GLenum fogMode  = GL_EXP;
    8480
    85         // set fog density
    86         float  fogDensity  = 0.001f;
     81    // set fog density
     82    float  fogDensity  = 0.001f;
    8783
    88         // set fog near & far distance
    89         float fogStart = 0.0f;
    90         float fogEnd   = 1000.0f;
     84    // set fog near & far distance
     85    float fogStart = 0.0f;
     86    float fogEnd   = 1000.0f;
    9187
    92         // Set fog color
    93         float fogColor[4] = {0.6f,0.58f,0.79f,0.0f};
     88    // Set fog color
     89    float fogColor[4] = {0.6f,0.58f,0.79f,0.0f};
    9490
    9591
    96         glFogCoordfEXT       = (PFNGLFOGCOORDFEXTPROC)glXGetProcAddressARB((const GLubyte*)"glFogCoordfEXT");
    97         glFogCoordfvEXT      = (PFNGLFOGCOORDFVEXTPROC)glXGetProcAddressARB((const GLubyte*)"glFogCoordfvEXT");
    98         glFogCoorddEXT       = (PFNGLFOGCOORDDEXTPROC)glXGetProcAddressARB((const GLubyte*)"glFogCoorddEXT");
    99         glFogCoorddvEXT      = (PFNGLFOGCOORDDVEXTPROC)glXGetProcAddressARB((const GLubyte*)"glFogCoorddvEXT");
    100         glFogCoordPointerEXT = (PFNGLFOGCOORDPOINTEREXTPROC)glXGetProcAddressARB((const GLubyte*)"glFogCoordPointerEXT");
     92    glFogCoordfEXT       = (PFNGLFOGCOORDFEXTPROC)glXGetProcAddressARB((const GLubyte*)"glFogCoordfEXT");
     93    glFogCoordfvEXT      = (PFNGLFOGCOORDFVEXTPROC)glXGetProcAddressARB((const GLubyte*)"glFogCoordfvEXT");
     94    glFogCoorddEXT       = (PFNGLFOGCOORDDEXTPROC)glXGetProcAddressARB((const GLubyte*)"glFogCoorddEXT");
     95    glFogCoorddvEXT      = (PFNGLFOGCOORDDVEXTPROC)glXGetProcAddressARB((const GLubyte*)"glFogCoorddvEXT");
     96    glFogCoordPointerEXT = (PFNGLFOGCOORDPOINTEREXTPROC)glXGetProcAddressARB((const GLubyte*)"glFogCoordPointerEXT");
    10197
    102         // set the fog attributes
    103         glFogf (GL_FOG_START,  fogStart);
    104         glFogf (GL_FOG_END,    fogEnd);
    105         glFogfv(GL_FOG_COLOR,  fogColor);
    106         glFogi (GL_FOG_MODE,   fogMode);
    107         glFogf (GL_FOG_DENSITY,fogDensity);
    108         glFogi (GL_FOG_COORDINATE_SOURCE_EXT,GL_FOG_COORDINATE_EXT);
     98    // set the fog attributes
     99    glFogf (GL_FOG_START,  fogStart);
     100    glFogf (GL_FOG_END,    fogEnd);
     101    glFogfv(GL_FOG_COLOR,  fogColor);
     102    glFogi (GL_FOG_MODE,   fogMode);
     103    glFogf (GL_FOG_DENSITY,fogDensity);
     104    glFogi (GL_FOG_COORDINATE_SOURCE_EXT,GL_FOG_COORDINATE_EXT);
    109105
    110         // enable the fog
    111         glEnable(GL_FOG);
     106    // enable the fog
     107    glEnable(GL_FOG);
    112108
    113         if (glewInit() == GLEW_OK)
    114                 PRINTF(0)("glewInit OK\n");
    115         else
    116                 PRINTF(0)("glewInit failed\n");
     109    if (glewInit() == GLEW_OK)
     110        PRINTF(0)("glewInit OK\n");
     111    else
     112        PRINTF(0)("glewInit failed\n");
    117113
    118         if (glewGetExtension("GL_EXT_fog_coord"))
    119                 PRINTF(0)("GL_EXT_fog_coord extension found\n");
     114    if (glewGetExtension("GL_EXT_fog_coord"))
     115        PRINTF(0)("GL_EXT_fog_coord extension found\n");
    120116}
    121117
    122118
    123 void VolFogEffect::activate()
    124 {
    125         PRINTF(0)("Activating VolFogEffect\n");
     119void VolFogEffect::activate() {
     120    PRINTF(0)("Activating VolFogEffect\n");
    126121}
    127122
    128 void VolFogEffect::deactivate()
    129 {
    130         PRINTF(0)("Deactivating VolFogEffect\n");
     123void VolFogEffect::deactivate() {
     124    PRINTF(0)("Deactivating VolFogEffect\n");
    131125
    132         glDisable(GL_FOG);
     126    glDisable(GL_FOG);
    133127}
    134128
     
    137131* draws the effect, if needed
    138132*/
    139 void VolFogEffect::draw() const
    140 {
    141   glPushAttrib(GL_ENABLE_BIT);
    142   glClearColor(fogColor[0],fogColor[1],fogColor[2],0.0f);
    143         glShadeModel(GL_SMOOTH);
    144         glEnable(GL_DEPTH_TEST);
    145         glEnable(GL_CULL_FACE);
    146         glCullFace(GL_BACK);
     133void VolFogEffect::draw() const {
     134    glPushAttrib(GL_ENABLE_BIT);
     135    glClearColor(fogColor[0],fogColor[1],fogColor[2],0.0f);
     136    glShadeModel(GL_SMOOTH);
     137    glEnable(GL_DEPTH_TEST);
     138    glEnable(GL_CULL_FACE);
     139    glCullFace(GL_BACK);
    147140
    148         /* clear all pixels in colour buffer */
    149         glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
     141    /* clear all pixels in colour buffer */
     142    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    150143
    151         /* Enable blending */
    152         //glEnable(GL_BLEND);
    153         //glBlendFunc(GL_SRC_ALPHA, GL_DST_ALPHA);
     144    /* Enable blending */
     145    //glEnable(GL_BLEND);
     146    //glBlendFunc(GL_SRC_ALPHA, GL_DST_ALPHA);
    154147
    155         int i;
    156         glLoadIdentity();
     148    int i;
     149    glLoadIdentity();
    157150
    158151
    159         glBegin( GL_LINES );
    160                 glNormal3f(0,1,0);
    161                 for(i=-20;i<=20;i+=2)
    162                 {
    163                         float fog_c;
    164                         float diff[3];
     152    glBegin( GL_LINES );
     153    glNormal3f(0,1,0);
     154    for(i=-20;i<=20;i+=2) {
     155        float fog_c;
     156        float diff[3];
    165157
    166                         diff[0] = State::getCameraNode()->getAbsCoor().x - i;
    167                         diff[2] = State::getCameraNode()->getAbsCoor().z + 20;
    168                         diff[1] = State::getCameraNode()->getAbsCoor().y;
    169                         fog_c = 1.3f*sqrt(diff[0]*diff[0]+diff[1]*diff[1]+diff[2]*diff[2]);
    170                         glFogCoordfEXT(fog_c*2);
    171                         glVertex3f(i,0,-20);
     158        diff[0] = State::getCameraNode()->getAbsCoor().x - i;
     159        diff[2] = State::getCameraNode()->getAbsCoor().z + 20;
     160        diff[1] = State::getCameraNode()->getAbsCoor().y;
     161        fog_c = 1.3f*sqrt(diff[0]*diff[0]+diff[1]*diff[1]+diff[2]*diff[2]);
     162        glFogCoordfEXT(fog_c*2);
     163        glVertex3f(i,0,-20);
    172164
    173                         diff[0] = State::getCameraNode()->getAbsCoor().x - i;
    174                         diff[2] = State::getCameraNode()->getAbsCoor().z + 20;
    175                         diff[1] = State::getCameraNode()->getAbsCoor().y;
    176                         fog_c = 1.3f*sqrt(diff[0]*diff[0]+diff[1]*diff[1]+diff[2]*diff[2]);
    177                         glFogCoordfEXT(fog_c*2);
    178                         glVertex3f(i,0,20);
     165        diff[0] = State::getCameraNode()->getAbsCoor().x - i;
     166        diff[2] = State::getCameraNode()->getAbsCoor().z + 20;
     167        diff[1] = State::getCameraNode()->getAbsCoor().y;
     168        fog_c = 1.3f*sqrt(diff[0]*diff[0]+diff[1]*diff[1]+diff[2]*diff[2]);
     169        glFogCoordfEXT(fog_c*2);
     170        glVertex3f(i,0,20);
    179171
    180                         diff[0] = State::getCameraNode()->getAbsCoor().x - i;
    181                         diff[2] = State::getCameraNode()->getAbsCoor().z + 20;
    182                         diff[1] = State::getCameraNode()->getAbsCoor().y;
    183                         fog_c = 1.3f*sqrt(diff[0]*diff[0]+diff[1]*diff[1]+diff[2]*diff[2]);
    184                         glFogCoordfEXT(fog_c*2);
    185                         glVertex3f(-20,0,i);
     172        diff[0] = State::getCameraNode()->getAbsCoor().x - i;
     173        diff[2] = State::getCameraNode()->getAbsCoor().z + 20;
     174        diff[1] = State::getCameraNode()->getAbsCoor().y;
     175        fog_c = 1.3f*sqrt(diff[0]*diff[0]+diff[1]*diff[1]+diff[2]*diff[2]);
     176        glFogCoordfEXT(fog_c*2);
     177        glVertex3f(-20,0,i);
    186178
    187                         diff[0] = State::getCameraNode()->getAbsCoor().x - i;
    188                         diff[2] = State::getCameraNode()->getAbsCoor().z + 20;
    189                         diff[1] = State::getCameraNode()->getAbsCoor().y;
    190                         fog_c = 1.3f*sqrt(diff[0]*diff[0]+diff[1]*diff[1]+diff[2]*diff[2]);
    191                         glFogCoordfEXT(fog_c*2);
    192                         glVertex3f(20,0,i);
    193                 }
    194         glEnd();
     179        diff[0] = State::getCameraNode()->getAbsCoor().x - i;
     180        diff[2] = State::getCameraNode()->getAbsCoor().z + 20;
     181        diff[1] = State::getCameraNode()->getAbsCoor().y;
     182        fog_c = 1.3f*sqrt(diff[0]*diff[0]+diff[1]*diff[1]+diff[2]*diff[2]);
     183        glFogCoordfEXT(fog_c*2);
     184        glVertex3f(20,0,i);
     185    }
     186    glEnd();
    195187
    196   glPopAttrib();
     188    glPopAttrib();
    197189
    198190}
     
    202194* ticks the effect if there is any time dependancy
    203195*/
    204 void VolFogEffect::tick(float dt)
    205 {
    206 }
     196void VolFogEffect::tick(float dt) {}
  • branches/atmospheric_engine/src/lib/graphics/effects/volfog_effect.h

    r8455 r8457  
    1010#include "weather_effect.h"
    1111
    12 class VolFogEffect : public WeatherEffect
    13 {
    14         public:
    15                 VolFogEffect(const TiXmlElement* root = NULL);
    16                 virtual ~VolFogEffect();
     12class VolFogEffect : public WeatherEffect {
     13public:
     14    VolFogEffect(const TiXmlElement* root = NULL);
     15    virtual ~VolFogEffect();
    1716
    18                 virtual void loadParams(const TiXmlElement* root);
     17    virtual void loadParams(const TiXmlElement* root);
    1918
    20                 virtual void init();
     19    virtual void init();
    2120
    22                 virtual void activate();
    23                 virtual void deactivate();
     21    virtual void activate();
     22    virtual void deactivate();
    2423
    25                 virtual void draw() const;
    26                 virtual void tick(float dt);
     24    virtual void draw() const;
     25    virtual void tick(float dt);
    2726
    28         private:
    29                 GLfloat fogColor[4];
     27private:
     28    GLfloat fogColor[4];
    3029
    3130};
  • branches/atmospheric_engine/src/lib/graphics/effects/weather_effect.h

    r8455 r8457  
    11/*!
    22 * @file weather_effect.h
    3  * 
     3 *
    44 */
    55
     
    2020    virtual void init();
    2121
    22     virtual void activate();
    23     virtual void deactivate();
     22    virtual void activate() = 0;
     23    virtual void deactivate() = 0;
    2424
    2525    virtual void draw() const;
  • branches/atmospheric_engine/src/lib/graphics/shader.cc

    r8255 r8457  
    153153      glAttachObjectARB(this->shaderProgram, shader);
    154154  }
     155
     156  return true;
    155157}
    156158
  • branches/atmospheric_engine/src/lib/gui/gl/glmenu/glmenu_imagescreen.cc

    r8145 r8457  
    269269    glEnd();
    270270
    271     /* draw black border
     271    // draw black border
    272272    glBegin(GL_QUADS);
    273273    glColor3f(0.0, 0.0, 0.0);
  • branches/atmospheric_engine/src/lib/gui/qt/gui_control.cc

    r8145 r8457  
    285285        return -1;
    286286    }
     287
     288    return 0;
     289
    287290  }
    288291
Note: See TracChangeset for help on using the changeset viewer.