| 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; |
|---|
| 25 | |
|---|
| 26 | typedef struct |
|---|
| 27 | { |
|---|
| 28 | float x; |
|---|
| 29 | float y; |
|---|
| 30 | float z; |
|---|
| 31 | } world_vector; |
|---|
| 32 | |
|---|
| 33 | world_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 | |
|---|
| 42 | using namespace std; |
|---|
| 43 | |
|---|
| 44 | CREATE_FACTORY(VolFogEffect, CL_VOLFOG_EFFECT); |
|---|
| 45 | |
|---|
| 46 | VolFogEffect::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 | |
|---|
| 57 | VolFogEffect::~VolFogEffect() |
|---|
| 58 | { |
|---|
| 59 | this->deactivate(); |
|---|
| 60 | } |
|---|
| 61 | |
|---|
| 62 | |
|---|
| 63 | void 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 | LoadParam(root, "test", this, VolFogEffect, test); |
|---|
| 70 | } |
|---|
| 71 | |
|---|
| 72 | void VolFogEffect::test(int t) |
|---|
| 73 | { |
|---|
| 74 | PRINTF(0)("Test: %i\n", t); |
|---|
| 75 | } |
|---|
| 76 | |
|---|
| 77 | bool VolFogEffect::init() |
|---|
| 78 | { |
|---|
| 79 | PRINTF(0)("Initalize VolFogEffect\n"); |
|---|
| 80 | }; |
|---|
| 81 | |
|---|
| 82 | |
|---|
| 83 | |
|---|
| 84 | bool VolFogEffect::activate() |
|---|
| 85 | { |
|---|
| 86 | //PRINTF(0)( "Enabling Volumetric Fog Effect, altitude: %i, color %f, %f, %f\n", this->fogAltitude, this->colorVector.x, this->colorVector.y, this->colorVector.z); |
|---|
| 87 | |
|---|
| 88 | PRINTF(0)("Activate VolFogEffect\n"); |
|---|
| 89 | } |
|---|
| 90 | |
|---|
| 91 | bool VolFogEffect::deactivate() |
|---|
| 92 | { |
|---|
| 93 | PRINTF(0)("Deactivate VolFogEffect\n"); |
|---|
| 94 | } |
|---|
| 95 | |
|---|
| 96 | /* |
|---|
| 97 | void VolFogEffect::setFogColor(int v) |
|---|
| 98 | { |
|---|
| 99 | float z; |
|---|
| 100 | float f; |
|---|
| 101 | |
|---|
| 102 | z = 0.0 - vertices[v].y; |
|---|
| 103 | f = (60.0 - z) / (60.0 - 0.0); |
|---|
| 104 | glColor4f(this->colorVector.x, this->colorVector.y, this->colorVector.z, f); |
|---|
| 105 | } |
|---|
| 106 | */ |
|---|
| 107 | |
|---|
| 108 | /** |
|---|
| 109 | * draws the effect, if needed |
|---|
| 110 | */ |
|---|
| 111 | void VolFogEffect::draw() const |
|---|
| 112 | { |
|---|
| 113 | |
|---|
| 114 | /*int v; // store of next vertex ref |
|---|
| 115 | int ref; |
|---|
| 116 | |
|---|
| 117 | PRINTF(0)("DRAW VolFogEffect\n"); |
|---|
| 118 | |
|---|
| 119 | for (ref=0; ref<NUM_PANELS; ref++) { |
|---|
| 120 | |
|---|
| 121 | // disable writes to z buffer (if fog area) |
|---|
| 122 | glDepthMask(GL_FALSE); |
|---|
| 123 | |
|---|
| 124 | // restore z buffer writes, set blend params & disable texturing |
|---|
| 125 | |
|---|
| 126 | glDepthMask(GL_TRUE); |
|---|
| 127 | glEnable(GL_BLEND); |
|---|
| 128 | glBlendFunc(GL_ONE_MINUS_SRC_ALPHA, GL_SRC_ALPHA); |
|---|
| 129 | glDisable(GL_TEXTURE_2D); |
|---|
| 130 | |
|---|
| 131 | // draw the fog panel |
|---|
| 132 | |
|---|
| 133 | v = ref * 4; |
|---|
| 134 | glBegin(GL_QUADS); |
|---|
| 135 | //this->setFogColor(v); |
|---|
| 136 | glVertex3f(vertices[v].x, vertices[v].y, vertices[v].z); v++; |
|---|
| 137 | //this->setFogColor(v); |
|---|
| 138 | glVertex3f(vertices[v].x, vertices[v].y, vertices[v].z); v++; |
|---|
| 139 | //this->setFogColor(v); |
|---|
| 140 | glVertex3f(vertices[v].x, vertices[v].y, vertices[v].z); v++; |
|---|
| 141 | //this->setFogColor(v); |
|---|
| 142 | glVertex3f(vertices[v].x, vertices[v].y, vertices[v].z); |
|---|
| 143 | glEnd(); |
|---|
| 144 | |
|---|
| 145 | // restore rendering state |
|---|
| 146 | |
|---|
| 147 | glEnable(GL_TEXTURE_2D); |
|---|
| 148 | glDisable(GL_BLEND); |
|---|
| 149 | }*/ |
|---|
| 150 | } |
|---|
| 151 | |
|---|
| 152 | |
|---|
| 153 | |
|---|
| 154 | /** |
|---|
| 155 | * ticks the effect if there is any time dependancy |
|---|
| 156 | */ |
|---|
| 157 | void VolFogEffect::tick(float dt) |
|---|
| 158 | { |
|---|
| 159 | } |
|---|