Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

branches/atmosphere_engine: fog

File size: 2.4 KB
RevLine 
[6741]1/*
[7652]2        orxonox - the future of 3D-vertical-scrollers
[6741]3
[7652]4        Copyright (C) 2004 orx
[6741]5
[7652]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:
[7652]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
[7523]22/*#include "shell_command.h"
23SHELL_COMMAND(activateFog, FogEffect, FogEffect::activate)
[7652]24        ->setAlias("aFog");
[7392]25SHELL_COMMAND(deactivateFog, FogEffect, FogEffect::deactivate)
[7652]26        ->setAlias("dFog");*/
[6772]27
[6741]28using namespace std;
29
[6772]30CREATE_FACTORY(FogEffect, CL_FOG_EFFECT);
[6741]31
[7379]32FogEffect::FogEffect(const TiXmlElement* root)
[6741]33{
[7652]34        this->setClassID(CL_FOG_EFFECT, "FogEffect");
[7392]35
[7689]36        this->init();
37
[7652]38        if (root != NULL)
39                this->loadParams(root);
[7107]40
[7652]41        this->activate();
[6741]42}
43
44
45FogEffect::~FogEffect()
[6980]46{
[7652]47        this->deactivate();
[6980]48}
[6741]49
50
51void FogEffect::loadParams(const TiXmlElement* root)
52{
[7652]53        WeatherEffect::loadParams(root);
[6741]54
[7691]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);
[6741]59}
60
61bool FogEffect::init()
[7689]62{
63        //default values
64        this->fogMode = GL_LINEAR;
65        this->fogDensity = 0.1;
66        this->fogStart = 0;
67        this->fogEnd = 5000;
68  this->colorVector = Vector(0.7, 0.7, 0.7);
69}
[6741]70
71
[7379]72
[6741]73bool FogEffect::activate()
[7392]74{
[7652]75        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]76
[7652]77        glEnable(GL_FOG);
78        {
79                GLfloat fogColor[4] = { colorVector.x, colorVector.y, colorVector.z, 1.0};
[6741]80
[7652]81                glFogi(GL_FOG_MODE, this->fogMode);
82                glFogfv(GL_FOG_COLOR, fogColor);
83                glFogf(GL_FOG_DENSITY, this->fogDensity);
84                glHint(GL_FOG_HINT, GL_DONT_CARE);
85                glFogf(GL_FOG_START, this->fogStart);
86                glFogf(GL_FOG_END, this->fogEnd);
87        }
88        glClearColor(0.5, 0.5, 0.5, 1.0);
[6752]89}
90
91
[6741]92bool FogEffect::deactivate()
[6772]93{
[7652]94        PRINTF(0)("Deactivating FogEffect\n");
[7392]95        glDisable(GL_FOG);
[6772]96}
97
98
[7221]99GLint FogEffect::stringToFogMode(const std::string& mode)
[6772]100{
[7652]101        if(mode == "GL_LINEAR")
102                return GL_LINEAR;
103        else if(mode == "GL_EXP")
104                return GL_EXP;
105        else if(mode == "GL_EXP2" )
106                return GL_EXP2;
107        else
108                return -1;
[6772]109}
110
[7392]111
Note: See TracBrowser for help on using the repository browser.