Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/trunk/src/lib/graphics/effects/fog_effect.cc @ 8453

Last change on this file since 8453 was 8362, checked in by bensch, 18 years ago

orxonox/trunk: removed stupid included in base_object.h
this should lead to faster compile-times

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