Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/branches/terrain/src/lib/graphics/effects/fog_effect.cc @ 8548

Last change on this file since 8548 was 8255, checked in by bensch, 19 years ago

merged the atmos back with command: https://svn.orxonox.net/orxonox/branches/atmospheric_engine

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