Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 7810 in orxonox.OLD for trunk/src/lib/graphics/effects/fog_effect.cc


Ignore:
Timestamp:
May 24, 2006, 3:57:04 PM (18 years ago)
Author:
bensch
Message:

orxonox/trunk: merged the Weather effects back here

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/lib/graphics/effects/fog_effect.cc

    r7221 r7810  
     1/*
     2        orxonox - the future of 3D-vertical-scrollers
    13
     4        Copyright (C) 2004 orx
    25
    3 /*
    4    orxonox - the future of 3D-vertical-scrollers
    5 
    6    Copyright (C) 2004 orx
    7 
    8    This program is free software; you can redistribute it and/or modify
    9    it under the terms of the GNU General Public License as published by
    10    the Free Software Foundation; either version 2, or (at your option)
    11    any later version.
     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.
    1210
    1311### File Specific:
    14    main-programmer: Patrick Boenzli
     12        main-programmer: hdavid, amaechler
    1513*/
    16 
    17 #define DEBUG_SPECIAL_MODULE DEBUG_MODULE_GRAPHICS
    1814
    1915#include "fog_effect.h"
     
    2420#include "glincl.h"
    2521
    26 
     22/*#include "shell_command.h"
     23SHELL_COMMAND(activateFog, FogEffect, FogEffect::activate)
     24        ->setAlias("aFog");
     25SHELL_COMMAND(deactivateFog, FogEffect, FogEffect::deactivate)
     26        ->setAlias("dFog");*/
    2727
    2828using namespace std;
     
    3030CREATE_FACTORY(FogEffect, CL_FOG_EFFECT);
    3131
     32FogEffect::FogEffect(const TiXmlElement* root)
     33{
     34        this->setClassID(CL_FOG_EFFECT, "FogEffect");
    3235
    33 /**
    34  *  default constructor
    35  * @param root The XML-element to load the FogEffect from
    36  */
    37  FogEffect::FogEffect(const TiXmlElement* root)
    38 {
    39   this->setClassID(CL_FOG_EFFECT, "FogEffect");
     36        this->init();
    4037
    41   this->fogMode = GL_LINEAR;
    42   this->fogDensity = 0.001f;
    43   this->fogStart = 10.0f;
    44   this->fogEnd = 1000.0f;
     38        if (root != NULL)
     39                this->loadParams(root);
    4540
    46   if (root != NULL)
    47     this->loadParams(root);
    48 
    49   this->activate();
     41        this->activate();
    5042}
    5143
    5244
    53 /**
    54  *  destroys a FogEffect
    55  */
    5645FogEffect::~FogEffect()
    5746{
    58   this->deactivate();
     47        this->deactivate();
    5948}
    6049
    6150
    62 /**
    63  * @param root The XML-element to load the FogEffect from
    64  */
    6551void FogEffect::loadParams(const TiXmlElement* root)
    6652{
    67   GraphicsEffect::loadParams(root);
     53        WeatherEffect::loadParams(root);
    6854
     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}
    6960
    70   LoadParam(root, "fog-mode", this, FogEffect, setFogMode)
    71       .describe("sets the the fog mode {GL_LINEAR, GL_EXP, GL_EXP2}");
    72 
    73   LoadParam(root, "fog-density", this, FogEffect, setFogDensity)
    74       .describe("sets the the fog density of the exponentionl functions");
    75 
    76   LoadParam(root, "fog-color", this, FogEffect, setFogColor)
    77       .describe("sets the fog color");
    78 
     61bool FogEffect::init()
     62{
     63        //default values
     64        this->fogMode = GL_EXP2;
     65        this->fogDensity = 0.001;
     66        this->fogStart = 0;
     67        this->fogEnd = 5000;
     68  this->colorVector = Vector(0.7, 0.7, 0.7);
    7969}
    8070
    8171
    82 /**
    83  * initializes the fog effect
    84  */
    85 bool FogEffect::init()
    86 {}
    8772
    88 
    89 /**
    90  * activates the fog effect
    91  */
    9273bool FogEffect::activate()
    9374{
    94   PRINTF(0)( "Enabling Fog Effect, mode: %i, density: %f, start: %f, end: %f, color %f, %f, %f\n", this->fogMode, this->fogDensity,
    95              this->fogStart, this->fogEnd, this->colorVector.x, this->colorVector.y, this->colorVector.z);
     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);
    9676
    97   glEnable(GL_FOG);
    98   {
    99 //     GLfloat fogColor[4] = {0.7, 0.6, 0.6, 1.0};
    100     GLfloat fogColor[4] = { colorVector.x, colorVector.y, colorVector.z, 1.0};
     77        glEnable(GL_FOG);
     78        {
     79                GLfloat fogColor[4] = { colorVector.x, colorVector.y, colorVector.z, 1.0};
    10180
    102     glFogi(GL_FOG_MODE, this->fogMode);
    103     glFogfv(GL_FOG_COLOR, fogColor);
    104     glFogf(GL_FOG_DENSITY, this->fogDensity);
    105     glHint(GL_FOG_HINT, GL_DONT_CARE);
    106     glFogf(GL_FOG_START, this->fogStart);
    107     glFogf(GL_FOG_END, this->fogEnd);
    108 
    109     //glFogi(GL_FOG_COORDINATE_SOURCE, GL_FOG_COORDINATE);
    110   }
    111   glClearColor(0.5, 0.5, 0.5, 1.0);
     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);
    11289}
    11390
    11491
    115 /**
    116  * deactivates the fog effect
    117  */
    11892bool FogEffect::deactivate()
    11993{
    120   glDisable(GL_FOG);
     94        PRINTF(0)("Deactivating FogEffect\n");
     95        glDisable(GL_FOG);
    12196}
    12297
    12398
    124 /**
    125  * converts a gl mode char to a GLint
    126  * @param mode the mode character
    127  */
    12899GLint FogEffect::stringToFogMode(const std::string& mode)
    129100{
    130   if(mode == "GL_LINEAR")
    131     return GL_LINEAR;
    132   else if(mode == "GL_EXP")
    133     return GL_EXP;
    134   else if(mode == "GL_EXP2" )
    135     return GL_EXP2;
    136   else
    137     return -1;
     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;
    138109}
    139110
     111
Note: See TracChangeset for help on using the changeset viewer.