Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/branches/atmospheric_engine/src/lib/graphics/effects/volfog_effect.cc @ 7523

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

branches/atmospheric_engine:

File size: 3.5 KB
Line 
1/*
2   orxonox - the future of 3D-vertical-scrollers
3
4   Copyright (C) 2004 orx
5
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.
10
11### File Specific:
12   main-programmer: hdavid, amaechler
13*/
14
15#include "volfog_effect.h"
16
17#include "util/loading/load_param.h"
18#include "util/loading/factory.h"
19
20#include "glincl.h"
21
22#include "shell_command.h"
23
24#define NUM_PANELS 6    /* number of panels in scene */
25
26typedef struct
27{
28        float x;
29        float y;
30        float z;
31} world_vector;         /* vertex data */
32
33world_vector vertices[NUM_PANELS*4] = {
34        {-50.0, -60.0, 0.0},{50.0, -60.0, 0.0},{50.0, 0.0, 0.0},{-50.0, 0.0, 0.0},
35        {-50.0, -60.0, 60.0},{-50.0, -60.0, 0.0},{-50.0, 0.0, 0.0},{-50.0, 0.0, 60.0},
36        {-50.0, -60.0, 20.0},{-50.0, -60.0, 60.0},{-50.0, 0.0, 60.0},{-50.0, 0.0, 20.0},
37        {50.0, -60.0, 0.0},{50.0, -60.0, 60.0},{50.0, 0.0, 60.0},{50.0, 0.0, 0.0},
38        {50.0, -60.0, 60.0},{50.0, -60.0, 20.0},{50.0, 0.0, 20.0},{50.0, 0.0, 60.0},
39        {-50.0, -60.0, 60.0},{50.0, -60.0, 60.0},{50.0, -60.0, 0.0},{-50.0, -60.0, 0.0}
40};
41
42using namespace std;
43
44CREATE_FACTORY(VolFogEffect, CL_VOLFOG_EFFECT);
45
46VolFogEffect::VolFogEffect(const TiXmlElement* root)
47{
48  this->setClassID(CL_VOLFOG_EFFECT, "VolFogEffect");
49
50  if (root != NULL)
51    this->loadParams(root);
52 
53  this->activate();
54}
55
56
57VolFogEffect::~VolFogEffect()
58{
59  this->deactivate();
60}
61
62
63void VolFogEffect::loadParams(const TiXmlElement* root)
64{
65  WeatherEffect::loadParams(root);
66
67  LoadParam(root, "fog-altitude", this, VolFogEffect, setFogAltitude);
68  LoadParam(root, "fog-color", this, VolFogEffect, startFogColor);
69}
70
71
72bool VolFogEffect::init()
73{
74  PRINTF(0)("Initalize VolFogEffect\n");
75};
76
77
78
79bool VolFogEffect::activate()
80{
81  PRINTF(0)( "Enabling Volumetric Fog Effect, altitude: %i, color %f, %f, %f\n", this->fogAltitude, this->colorVector.x, this->colorVector.y, this->colorVector.z);
82
83}
84
85bool VolFogEffect::deactivate()
86{
87  PRINTF(0)("Deactivate VolFogEffect\n");
88}
89
90
91void VolFogEffect::setFogColor(int v)
92{
93        float z;        /* distance of vertex from edge of fog volume */
94        float f;        /* fog factor */
95
96        z = 0.0 - vertices[v].y;
97        f = (60.0 - z) / (60.0 - 0.0);  /* linear fog: f = (end - z)/(end - start) */
98        glColor4f(this->colorVector.x, this->colorVector.y, this->colorVector.z, f);
99}
100
101// int v;               /* store of next vertex ref */
102
103/**
104 * draws the effect, if needed
105 */
106void VolFogEffect::draw() const
107{
108        int v;          /* store of next vertex ref */
109        int ref;
110
111        PRINTF(0)("DRAW VolFogEffect\n");
112
113        for (ref=0; ref<NUM_PANELS; ref++) {
114
115                /* disable writes to z buffer (if fog area) */
116                glDepthMask(GL_FALSE);
117       
118                /* restore z buffer writes, set blend params & disable texturing */
119
120                glDepthMask(GL_TRUE);
121                glEnable(GL_BLEND);
122                glBlendFunc(GL_ONE_MINUS_SRC_ALPHA, GL_SRC_ALPHA);
123                glDisable(GL_TEXTURE_2D);
124
125                /* draw the fog panel */
126
127                v = ref * 4;
128                glBegin(GL_QUADS);
129                //this->setFogColor(v);
130                glVertex3f(vertices[v].x, vertices[v].y, vertices[v].z); v++;
131                //this->setFogColor(v);
132                glVertex3f(vertices[v].x, vertices[v].y, vertices[v].z); v++;
133                //this->setFogColor(v);
134                glVertex3f(vertices[v].x, vertices[v].y, vertices[v].z); v++;
135                //this->setFogColor(v);
136                glVertex3f(vertices[v].x, vertices[v].y, vertices[v].z);
137                glEnd();
138
139                /* restore rendering state */
140
141                glEnable(GL_TEXTURE_2D);
142                glDisable(GL_BLEND);
143        }
144
145       
146}
147
148
149
150/**
151 * ticks the effect if there is any time dependancy
152 */
153void VolFogEffect::tick(float dt)       
154{
155  PRINTF(0)("TICK VolFogEffect\n");
156}
Note: See TracBrowser for help on using the repository browser.