/* orxonox - the future of 3D-vertical-scrollers Copyright (C) 2004 orx This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2, or (at your option) any later version. ### File Specific: main-programmer: hdavid, amaechler */ #include "volfog_effect.h" #include "util/loading/load_param.h" #include "util/loading/factory.h" #include "glincl.h" #include "shell_command.h" #define NUM_PANELS 6 /* number of panels in scene */ typedef struct { float x; float y; float z; } world_vector; /* vertex data */ world_vector vertices[NUM_PANELS*4] = { {-50.0, -60.0, 0.0},{50.0, -60.0, 0.0},{50.0, 0.0, 0.0},{-50.0, 0.0, 0.0}, {-50.0, -60.0, 60.0},{-50.0, -60.0, 0.0},{-50.0, 0.0, 0.0},{-50.0, 0.0, 60.0}, {-50.0, -60.0, 20.0},{-50.0, -60.0, 60.0},{-50.0, 0.0, 60.0},{-50.0, 0.0, 20.0}, {50.0, -60.0, 0.0},{50.0, -60.0, 60.0},{50.0, 0.0, 60.0},{50.0, 0.0, 0.0}, {50.0, -60.0, 60.0},{50.0, -60.0, 20.0},{50.0, 0.0, 20.0},{50.0, 0.0, 60.0}, {-50.0, -60.0, 60.0},{50.0, -60.0, 60.0},{50.0, -60.0, 0.0},{-50.0, -60.0, 0.0} }; using namespace std; CREATE_FACTORY(VolFogEffect, CL_VOLFOG_EFFECT); VolFogEffect::VolFogEffect(const TiXmlElement* root) { this->setClassID(CL_VOLFOG_EFFECT, "VolFogEffect"); if (root != NULL) this->loadParams(root); this->activate(); } VolFogEffect::~VolFogEffect() { this->deactivate(); } void VolFogEffect::loadParams(const TiXmlElement* root) { WeatherEffect::loadParams(root); LoadParam(root, "fog-altitude", this, VolFogEffect, setFogAltitude); LoadParam(root, "fog-color", this, VolFogEffect, startFogColor); } bool VolFogEffect::init() { PRINTF(0)("Initalize VolFogEffect\n"); }; bool VolFogEffect::activate() { PRINTF(0)( "Enabling Volumetric Fog Effect, altitude: %i, color %f, %f, %f\n", this->fogAltitude, this->colorVector.x, this->colorVector.y, this->colorVector.z); } bool VolFogEffect::deactivate() { PRINTF(0)("Deactivate VolFogEffect\n"); } void VolFogEffect::setFogColor(int v) { float z; /* distance of vertex from edge of fog volume */ float f; /* fog factor */ z = 0.0 - vertices[v].y; f = (60.0 - z) / (60.0 - 0.0); /* linear fog: f = (end - z)/(end - start) */ glColor4f(this->colorVector.x, this->colorVector.y, this->colorVector.z, f); } // int v; /* store of next vertex ref */ /** * draws the effect, if needed */ void VolFogEffect::draw() const { int v; /* store of next vertex ref */ int ref; PRINTF(0)("DRAW VolFogEffect\n"); for (ref=0; refsetFogColor(v); glVertex3f(vertices[v].x, vertices[v].y, vertices[v].z); v++; //this->setFogColor(v); glVertex3f(vertices[v].x, vertices[v].y, vertices[v].z); v++; //this->setFogColor(v); glVertex3f(vertices[v].x, vertices[v].y, vertices[v].z); v++; //this->setFogColor(v); glVertex3f(vertices[v].x, vertices[v].y, vertices[v].z); glEnd(); /* restore rendering state */ glEnable(GL_TEXTURE_2D); glDisable(GL_BLEND); } } /** * ticks the effect if there is any time dependancy */ void VolFogEffect::tick(float dt) { PRINTF(0)("TICK VolFogEffect\n"); }