Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/branches/atmospheric_engine/src/lib/graphics/effects/lightening_effect.cc @ 8445

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

branches/atmospheric_engine

File size: 8.6 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 "lightening_effect.h"
16
17#include "state.h"
18#include "util/loading/load_param.h"
19#include "util/loading/factory.h"
20#include "effects/billboard.h"
21
22#include "glincl.h"
23#include "parser/tinyxml/tinyxml.h"
24
25#include "shell_command.h"
26#include "light.h"
27
28SHELL_COMMAND(activate, LighteningEffect, activateLightening);
29SHELL_COMMAND(deactivate, LighteningEffect, deactivateLightening);
30
31using namespace std;
32
33CREATE_FACTORY(LighteningEffect, CL_LIGHTENING_EFFECT);
34
35// TODO: FIx Lightening with Fog enabled
36
37LighteningEffect::LighteningEffect(const TiXmlElement* root)
38{
39        this->setClassID(CL_LIGHTENING_EFFECT, "LighteningEffect");
40 
41        this->init();
42
43        if (root != NULL)
44                this->loadParams(root);
45
46        if(this->lighteningActivate)
47                this->activate();
48}
49
50LighteningEffect::~LighteningEffect()
51{
52        this->deactivate();
53}
54
55void LighteningEffect::loadParams(const TiXmlElement* root)
56{
57        WeatherEffect::loadParams(root);
58
59        LoadParam(root, "coord", this, LighteningEffect, coord);
60        LoadParam(root, "frequency", this, LighteningEffect, setFlashFrequency);
61        LoadParam(root, "const-time", this, LighteningEffect, setFlashConstTime);
62        LoadParam(root, "rising-time", this, LighteningEffect, setFlashRisingTime);
63        LoadParam(root, "size", this, LighteningEffect, setFlashSize);
64        LoadParam(root, "seed", this, LighteningEffect, setFlashSeed);
65
66        LOAD_PARAM_START_CYCLE(root, element);
67        {
68                LoadParam_CYCLE(element, "option", this, LighteningEffect, setLighteningOption);
69        }
70        LOAD_PARAM_END_CYCLE(element);
71}
72
73
74bool LighteningEffect::init()
75{
76        //default values
77        this->lighteningActivate = false;
78       
79        this->time = 0.0;
80        this->flashFrequency = 1.4f;
81        this->mainFrequency = 1.4f;
82        this->flashConstTime = 0.5f;
83        this->flashRisingTime = 0.1f;
84       
85        this->width = 400.0f;
86        this->height = 100.0f;
87        this->seedWidth = 50;
88        this->seedHeight = 50;
89        this->bNewCoordinate = false;
90       
91        this->seedX = 500.f;
92        this->seedZ = 1000.0f;
93        this->seedTime = 4.0f;
94       
95        // initialize lightening textures
96        this->billboard[0] = new Billboard(NULL);
97        this->billboard[0]->setTexture("maps/lightning_bolt1.png");
98        this->billboard[0]->setSize(this->width, this->height);
99        this->billboard[0]->setVisibiliy(false);
100       
101        this->billboard[1] = new Billboard(NULL);
102        this->billboard[1]->setTexture("maps/lightning_bolt2.png");
103        this->billboard[1]->setSize(this->width, this->height);
104        this->billboard[1]->setVisibiliy(false);
105       
106        this->billboard[2] = new Billboard(NULL);
107        this->billboard[2]->setTexture("maps/lightning_bolt3.png");
108        this->billboard[2]->setSize(this->width, this->height);
109        this->billboard[2]->setVisibiliy(false);
110       
111        this->billboard[3] = new Billboard(NULL);
112        this->billboard[3]->setTexture("maps/lightning_bolt4.png");
113        this->billboard[3]->setSize(this->width, this->height);
114        this->billboard[3]->setVisibiliy(false);
115       
116        if (this->lighteningMove) {
117                this->cameraCoor = State::getCameraNode()->getAbsCoor();
118                this->billboard[0]->setAbsCoor(this->cameraCoor.x+3000,850,this->cameraCoor.z+0);
119                this->billboard[1]->setAbsCoor(this->cameraCoor.x+3000,850,this->cameraCoor.z+0);
120                this->billboard[2]->setAbsCoor(this->cameraCoor.x+3000,850,this->cameraCoor.z+0);
121                this->billboard[3]->setAbsCoor(this->cameraCoor.x+3000,850,this->cameraCoor.z+0);
122        } else {
123                this->billboard[0]->setAbsCoor(3000,850,0);
124                this->billboard[1]->setAbsCoor(3000,850,0);
125                this->billboard[2]->setAbsCoor(3000,850,0);
126                this->billboard[3]->setAbsCoor(3000,850,0);
127        }
128       
129        this->flashLight = new Light();
130        this->flashLight->setDiffuseColor(0,0,0);
131        this->flashLight->setSpecularColor(0,0,0);
132       
133        /*
134        this->soundSource = NULL;
135        this->thunderBuffer = NULL;
136       
137        this->soundSource.setSourceNode(this);
138       
139        //load sound
140        if (this->thunderBuffer != NULL)
141        ResourceManager::getInstance()->unload(this->thunderBuffer);
142        this->thunderBuffer = (OrxSound::SoundBuffer*)ResourceManager::getInstance()->load("sound/thunder.wav", WAV);*/
143
144        return 0;
145}
146
147void LighteningEffect::coord(float x, float y, float z)
148{
149        if (this->lighteningMove) {
150                this->cameraCoor = State::getCameraNode()->getAbsCoor();
151                this->billboard[0]->setAbsCoor(this->cameraCoor.x+x, y, this->cameraCoor.z+z);
152                this->billboard[1]->setAbsCoor(this->cameraCoor.x+x, y, this->cameraCoor.z+z);
153                this->billboard[2]->setAbsCoor(this->cameraCoor.x+x, y, this->cameraCoor.z+z);
154                this->billboard[3]->setAbsCoor(this->cameraCoor.x+x, y, this->cameraCoor.z+z);
155        } else {
156                this->billboard[0]->setAbsCoor(x, y, z);
157                this->billboard[1]->setAbsCoor(x, y, z);
158                this->billboard[2]->setAbsCoor(x, y, z);
159                this->billboard[3]->setAbsCoor(x, y, z);
160        }
161
162        this->mainPosX = x;
163        this->mainPosY = y;
164        this->mainPosZ = z;
165}
166
167
168void LighteningEffect::setFlashSize(float width, float height, float seedWidth, float seedHeight)
169{
170        this->width = width;
171        this->height = height;
172        this->seedWidth = seedWidth;
173        this->seedHeight = seedHeight;
174
175        this->billboard[0]->setSize(this->width, this->height);
176        this->billboard[1]->setSize(this->width, this->height);
177        this->billboard[2]->setSize(this->width, this->height);
178        this->billboard[3]->setSize(this->width, this->height);
179}
180
181
182bool LighteningEffect::activate()
183{
184        PRINTF(0)( "Activating LighteningEffect\n" );
185        this->lighteningActivate = true;
186
187        this->time = 0;
188
189        return 0;
190}
191
192
193bool LighteningEffect::deactivate()
194{
195        PRINTF(0)("Deactivating LighteningEffect\n");
196        this->lighteningActivate = false;
197
198        this->billboard[0]->setVisibiliy(false);
199        this->billboard[1]->setVisibiliy(false);
200        this->billboard[2]->setVisibiliy(false);
201        this->billboard[3]->setVisibiliy(false);
202
203        return 0;
204}
205
206void LighteningEffect::tick (float dt)
207{
208        if(!lighteningActivate)
209                return;
210       
211        this->time += dt;
212
213        // TODO: Make random flashing with short light dingsda:)
214       
215        if( this->time > this->flashFrequency) {
216       
217                this->billboard[0]->setVisibiliy(true);
218                this->time = 0.0f;
219       
220                this->flashLight->setAbsCoor(this->billboard[0]->getAbsCoor().x, this->billboard[0]->getAbsCoor().y, this->billboard[0]->getAbsCoor().z);
221
222                // flash environmental lightening
223                this->flashLight->setDiffuseColor(1,1,1);
224                this->flashLight->setSpecularColor(1,1,1);
225       
226                //this->soundSource.play(this->thunderBuffer);
227
228        } else if( this->billboard[3]->isVisible() && this->time > this->flashConstTime) {
229       
230                this->billboard[3]->setVisibiliy(false);
231                this->time = 0.0f;
232                this->flashLight->setDiffuseColor(0,0,0);
233                this->flashLight->setSpecularColor(0,0,0);
234                this->bNewCoordinate = true;
235
236        }
237       
238        if( this->billboard[2]->isVisible() && this->time > this->flashRisingTime) {
239       
240                this->billboard[2]->setVisibiliy(false);
241                this->billboard[3]->setVisibiliy(true);
242                // this->flashLight->setDiffuseColor(1,1,1);
243                // this->flashLight->setSpecularColor(1,1,1);
244               
245        } else if( this->billboard[1]->isVisible() && this->time > this->flashRisingTime*2/3 ) {
246       
247                this->billboard[1]->setVisibiliy(false);
248                this->billboard[2]->setVisibiliy(true);
249                //this->flashLight->setDiffuseColor(0,0,0);
250                //this->flashLight->setSpecularColor(0,0,0);
251               
252        } else if( this->billboard[0]->isVisible() && this->time > this->flashRisingTime*1/3 ) {
253       
254                this->billboard[0]->setVisibiliy(false);
255                this->billboard[1]->setVisibiliy(true);
256                //this->flashLight->setDiffuseColor(1,1,1);
257                //this->flashLight->setSpecularColor(1,1,1);
258               
259        }
260       
261        if( this->bNewCoordinate) {
262                float posX, posZ;
263
264                if(this->lighteningMove) {
265               
266                        this->cameraCoor = State::getCameraNode()->getAbsCoor();
267                        posX = this->mainPosX - this->seedX * (float)rand()/(float)RAND_MAX + this->cameraCoor.x;
268                        posZ = this->mainPosZ + this->seedZ * (float)rand()/(float)RAND_MAX + this->cameraCoor.z;
269
270                } else {
271               
272                        posX = this->mainPosX - this->seedX * (float)rand()/(float)RAND_MAX;
273                        posZ = this->mainPosZ + this->seedZ * (float)rand()/(float)RAND_MAX;
274
275                }
276       
277                this->billboard[0]->setAbsCoor(posX, this->mainPosY, posZ);
278                this->billboard[1]->setAbsCoor(posX, this->mainPosY, posZ);
279                this->billboard[2]->setAbsCoor(posX, this->mainPosY, posZ);
280                this->billboard[3]->setAbsCoor(posX, this->mainPosY, posZ);
281               
282                this->flashFrequency = this->mainFrequency + this->seedTime * (float)rand()/(float)RAND_MAX;
283               
284                float w = this->width + this->seedWidth * (float)rand()/(float)RAND_MAX;
285                float h = this->height + this->seedHeight * (float)rand()/(float)RAND_MAX;
286               
287                this->billboard[0]->setSize(w, h);
288                this->billboard[1]->setSize(w, h);
289                this->billboard[2]->setSize(w, h);
290                this->billboard[3]->setSize(w, h);
291               
292                this->bNewCoordinate = false;
293        }
294}
295
296void LighteningEffect::draw() const
297{
298}
Note: See TracBrowser for help on using the repository browser.