Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

branches/atmospheric_engine: fog activate, cleanups

File size: 2.6 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);
26
27using namespace std;
28
29CREATE_FACTORY(FogEffect, CL_FOG_EFFECT);
30
31FogEffect::FogEffect(const TiXmlElement* root)
32{
33        this->setClassID(CL_FOG_EFFECT, "FogEffect");
34
35        this->init();
36
37        if (root != NULL)
38                this->loadParams(root);
39
40        if (this->fogActivate)
41                this->activate();
42}
43
44
45FogEffect::~FogEffect()
46{
47        this->deactivate();
48}
49
50
51void FogEffect::loadParams(const TiXmlElement* root)
52{
53        WeatherEffect::loadParams(root);
54
55        LoadParam(root, "mode", this, FogEffect, setFogMode);
56        LoadParam(root, "density", this, FogEffect, setFogDensity);
57        LoadParam(root, "range", this, FogEffect, setFogRange);
58        LoadParam(root, "color", this, FogEffect, setFogColor);
59
60        LOAD_PARAM_START_CYCLE(root, element);
61        {
62                LoadParam_CYCLE(element, "option", this, FogEffect, setFogOption);
63        }
64        LOAD_PARAM_END_CYCLE(element);
65}
66
67bool FogEffect::init()
68{
69        //default values
70        this->fogActivate = false;
71        this->fogMode = GL_EXP2;
72        this->fogDensity = 0.001;
73        this->fogStart = 0;
74        this->fogEnd = 5000;
75        this->colorVector = Vector(0.7, 0.7, 0.7);
76}
77
78
79bool FogEffect::activate()
80{
81        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);
82
83        this->fogActivate = true;
84
85        glEnable(GL_FOG);
86        {
87                GLfloat fogColor[4] = { colorVector.x, colorVector.y, colorVector.z, 1.0};
88
89                glFogi(GL_FOG_MODE, this->fogMode);
90                glFogfv(GL_FOG_COLOR, fogColor);
91                glFogf(GL_FOG_DENSITY, this->fogDensity);
92                glHint(GL_FOG_HINT, GL_DONT_CARE);
93                glFogf(GL_FOG_START, this->fogStart);
94                glFogf(GL_FOG_END, this->fogEnd);
95        }
96        glClearColor(0.5, 0.5, 0.5, 1.0);
97}
98
99
100bool FogEffect::deactivate()
101{
102        PRINTF(0)("Deactivating FogEffect\n");
103
104        this->fogActivate = false;
105       
106        glDisable(GL_FOG);
107}
108
109
110GLint FogEffect::stringToFogMode(const std::string& mode)
111{
112        if(mode == "GL_LINEAR")
113                return GL_LINEAR;
114        else if(mode == "GL_EXP")
115                return GL_EXP;
116        else if(mode == "GL_EXP2" )
117                return GL_EXP2;
118        else
119                return -1;
120}
121
122
Note: See TracBrowser for help on using the repository browser.