Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

Last change on this file since 8355 was 8316, checked in by bensch, 18 years ago

trunk: fixed most -Wall warnings… but there are still many missing :/

File size: 3.4 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);
[8255]60
61        LOAD_PARAM_START_CYCLE(root, element);
62        {
63                LoadParam_CYCLE(element, "option", this, FogEffect, setFogOption);
64        }
65        LOAD_PARAM_END_CYCLE(element);
[7810]66}
[6772]67
[7810]68bool FogEffect::init()
69{
70        //default values
[8255]71        this->fogActivate = false;
72        this->fogFadeDuration = 0;
73        this->localTimer = 0;
[8316]74
[7810]75        this->fogMode = GL_EXP2;
76        this->fogDensity = 0.001;
77        this->fogStart = 0;
78        this->fogEnd = 5000;
[8255]79        this->colorVector = Vector(0.7, 0.7, 0.7);
80
[8316]81        return true;
[6741]82}
83
84
85bool FogEffect::activate()
[6752]86{
[7810]87        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]88
[8255]89        this->fogActivate = true;
[8316]90
[8255]91        GLfloat fogColor[4] = { colorVector.x, colorVector.y, colorVector.z, 1.0};
92        glFogi(GL_FOG_MODE, this->fogMode);
93        glFogfv(GL_FOG_COLOR, fogColor);
94        glFogf(GL_FOG_DENSITY, this->fogDensity);
95        glHint(GL_FOG_HINT, GL_DONT_CARE);
96        glFogf(GL_FOG_START, this->fogStart);
97        glFogf(GL_FOG_END, this->fogEnd);
[8316]98
[7810]99        glEnable(GL_FOG);
[8255]100        // glClearColor(0.5, 0.5, 0.5, 1.0);
[8316]101        return true;
[6752]102}
103
104
[6741]105bool FogEffect::deactivate()
[6772]106{
[7810]107        PRINTF(0)("Deactivating FogEffect\n");
[8255]108
109        this->fogActivate = false;
[8316]110
[7810]111        glDisable(GL_FOG);
[8316]112
113        return true;
[6772]114}
115
[8255]116void FogEffect::draw() const {
[6772]117
[8255]118        if (this->fogFadeDuration != 0 && this->localTimer < this->fogFadeDuration)
119                glFogf(GL_FOG_DENSITY, this->fogFadeDensity);
120        //else
121        //      glFogf(GL_FOG_DENSITY, this->fogDensity);
122
123}
124void FogEffect::tick(float dt)
125{
126        if (!this->fogActivate)
127                return;
128
[8316]129
[8255]130        if (this->fogFadeDuration != 0 && this->localTimer < this->fogFadeDuration) {
131                this->localTimer += dt;
132                float progress = this->localTimer / this->fogFadeDuration;
133                this->fogFadeDensity = progress * this->fogDensity;
134        }
135}
136
137void FogEffect::startFogging() {
138
139        if (this->fogActivate)
140                this->deactivate();
141
142        this->fogFadeDuration = 10;
143        this->localTimer = 0;
144        this->activate();
145
146}
147
148
[7221]149GLint FogEffect::stringToFogMode(const std::string& mode)
[6772]150{
[7810]151        if(mode == "GL_LINEAR")
152                return GL_LINEAR;
153        else if(mode == "GL_EXP")
154                return GL_EXP;
155        else if(mode == "GL_EXP2" )
156                return GL_EXP2;
157        else
158                return -1;
[6772]159}
160
[7810]161
Note: See TracBrowser for help on using the repository browser.