Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/branches/atmospheric_engine/src/lib/graphics/effects/fog_effect.cc @ 8327

Last change on this file since 8327 was 8327, checked in by amaechler, 18 years ago

branches/atmospheric_engine: better default values

File size: 3.6 KB
RevLine 
[6741]1/*
[7810]2        orxonox - the future of 3D-vertical-scrollers
[6741]3
[7810]4        Copyright (C) 2004 orx
[6741]5
[7810]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.
[6741]10
11### File Specific:
[7810]12        main-programmer: hdavid, amaechler
[6741]13*/
14
15#include "fog_effect.h"
16
[7193]17#include "util/loading/load_param.h"
18#include "util/loading/factory.h"
[6741]19
[6772]20#include "glincl.h"
[6741]21
[8255]22#include "shell_command.h"
[6772]23
[8255]24SHELL_COMMAND(activate, FogEffect, activateFog);
25SHELL_COMMAND(deactivate, FogEffect, deactivateFog);
26SHELL_COMMAND(startfogging, FogEffect, startFogging);
27
[6741]28using namespace std;
29
[6772]30CREATE_FACTORY(FogEffect, CL_FOG_EFFECT);
[6741]31
[7810]32FogEffect::FogEffect(const TiXmlElement* root)
[6741]33{
[7810]34        this->setClassID(CL_FOG_EFFECT, "FogEffect");
[6741]35
[7810]36        this->init();
[6772]37
[7810]38        if (root != NULL)
39                this->loadParams(root);
[7107]40
[8255]41        if (this->fogActivate)
42                this->activate();
[6741]43}
44
45
46FogEffect::~FogEffect()
[6980]47{
[7810]48        this->deactivate();
[6980]49}
[6741]50
51
52void FogEffect::loadParams(const TiXmlElement* root)
53{
[7810]54        WeatherEffect::loadParams(root);
[6741]55
[7810]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);
[8267]60        LoadParam(root, "fadeinduration", this, FogEffect, setFogFadeIn);
61        LoadParam(root, "fadeoutduration", this, FogEffect, setFogFadeOut);
[8255]62
63        LOAD_PARAM_START_CYCLE(root, element);
64        {
65                LoadParam_CYCLE(element, "option", this, FogEffect, setFogOption);
66        }
67        LOAD_PARAM_END_CYCLE(element);
[7810]68}
[6772]69
[7810]70bool FogEffect::init()
71{
72        //default values
[8255]73        this->fogActivate = false;
[8267]74        this->fogFadeInDuration = 0;
75        this->fogFadeOutDuration = 0;
[8255]76        this->localTimer = 0;
77       
[8327]78        this->fogMode = GL_LINEAR;
79        this->fogDensity = 0.05;
[7810]80        this->fogStart = 0;
[8327]81        this->fogEnd = 500;
82        this->colorVector = Vector(0.3, 0.3, 0.3);
[8255]83
[8267]84        return 0;
[6741]85}
86
87
88bool FogEffect::activate()
[6752]89{
[7810]90        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);
[6772]91
[8255]92        this->fogActivate = true;
93       
94        GLfloat fogColor[4] = { colorVector.x, colorVector.y, colorVector.z, 1.0};
95        glFogi(GL_FOG_MODE, this->fogMode);
96        glFogfv(GL_FOG_COLOR, fogColor);
97        glFogf(GL_FOG_DENSITY, this->fogDensity);
98        glHint(GL_FOG_HINT, GL_DONT_CARE);
99        glFogf(GL_FOG_START, this->fogStart);
100        glFogf(GL_FOG_END, this->fogEnd);
101       
[7810]102        glEnable(GL_FOG);
[8255]103        // glClearColor(0.5, 0.5, 0.5, 1.0);
[8267]104
105        return 0;
[6752]106}
107
108
[6741]109bool FogEffect::deactivate()
[6772]110{
[7810]111        PRINTF(0)("Deactivating FogEffect\n");
[8255]112
113        this->fogActivate = false;
114       
[7810]115        glDisable(GL_FOG);
[8267]116
117        return 0;
[6772]118}
119
[8255]120void FogEffect::draw() const {
[6772]121
[8267]122        if (this->fogFadeInDuration > 0 && this->localTimer < this->fogFadeInDuration)
[8255]123                glFogf(GL_FOG_DENSITY, this->fogFadeDensity);
124        //else
125        //      glFogf(GL_FOG_DENSITY, this->fogDensity);
126
127}
128void FogEffect::tick(float dt)
129{
130        if (!this->fogActivate)
131                return;
132               
133
[8267]134        if (this->fogFadeInDuration > 0 && this->localTimer < this->fogFadeInDuration) {
[8255]135                this->localTimer += dt;
[8267]136                float progress = this->localTimer / this->fogFadeInDuration;
[8255]137                this->fogFadeDensity = progress * this->fogDensity;
138        }
139}
140
141void FogEffect::startFogging() {
142
143        if (this->fogActivate)
144                this->deactivate();
145
[8267]146        if (!this->fogFadeInDuration > 0)
147                this->fogFadeInDuration = 20;
148
[8255]149        this->localTimer = 0;
150        this->activate();
151
152}
153
154
[7221]155GLint FogEffect::stringToFogMode(const std::string& mode)
[6772]156{
[7810]157        if(mode == "GL_LINEAR")
158                return GL_LINEAR;
159        else if(mode == "GL_EXP")
160                return GL_EXP;
161        else if(mode == "GL_EXP2" )
162                return GL_EXP2;
163        else
164                return -1;
[6772]165}
166
[7810]167
Note: See TracBrowser for help on using the repository browser.