Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/trunk/src/lib/graphics/effects/lightening_effect.cc @ 8734

Last change on this file since 8734 was 8495, checked in by bensch, 18 years ago

merged the branche atmos back. no conflicts

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
74void LighteningEffect::init()
75{
76        //default values
77        this->lighteningActivate = false;
78
79        this->time = 0.0;
80        this->flashFrequency = 4.0f;
81        this->mainFrequency = 4.0f;
82        this->flashConstTime = 0.1f;
83        this->flashRisingTime = 0.03f;
84
85        this->width = 700.0f;
86        this->height = 250.0f;
87        this->seedWidth = 50.0f;
88        this->seedHeight = 50.0f;
89        this->bNewCoordinate = false;
90  this->lighteningMove = false;
91
92        this->seedX = 500.f;
93        this->seedZ = 1000.0f;
94        this->seedTime = 2.0f;
95
96  this->mainPosX = 3000;
97  this->mainPosY = 900;
98  this->mainPosZ = 0;
99
100        // initialize lightening textures
101        this->billboard[0] = new Billboard(NULL);
102        this->billboard[0]->setTexture("maps/lightning_bolt1.png");
103        this->billboard[0]->setSize(this->width, this->height);
104        this->billboard[0]->setVisibiliy(false);
105
106        this->billboard[1] = new Billboard(NULL);
107        this->billboard[1]->setTexture("maps/lightning_bolt2.png");
108        this->billboard[1]->setSize(this->width, this->height);
109        this->billboard[1]->setVisibiliy(false);
110
111        this->billboard[2] = new Billboard(NULL);
112        this->billboard[2]->setTexture("maps/lightning_bolt3.png");
113        this->billboard[2]->setSize(this->width, this->height);
114        this->billboard[2]->setVisibiliy(false);
115
116        this->billboard[3] = new Billboard(NULL);
117        this->billboard[3]->setTexture("maps/lightning_bolt4.png");
118        this->billboard[3]->setSize(this->width, this->height);
119        this->billboard[3]->setVisibiliy(false);
120
121        if (this->lighteningMove) {
122                this->cameraCoor = State::getCameraNode()->getAbsCoor();
123                this->billboard[0]->setAbsCoor(this->cameraCoor.x+3000,900,this->cameraCoor.z+0);
124                this->billboard[1]->setAbsCoor(this->cameraCoor.x+3000,900,this->cameraCoor.z+0);
125                this->billboard[2]->setAbsCoor(this->cameraCoor.x+3000,900,this->cameraCoor.z+0);
126                this->billboard[3]->setAbsCoor(this->cameraCoor.x+3000,900,this->cameraCoor.z+0);
127        } else {
128                this->billboard[0]->setAbsCoor(3000,900,0);
129                this->billboard[1]->setAbsCoor(3000,900,0);
130                this->billboard[2]->setAbsCoor(3000,900,0);
131                this->billboard[3]->setAbsCoor(3000,900,0);
132        }
133
134        this->flashLight = new Light();
135        this->flashLight->setDiffuseColor(0,0,0);
136        this->flashLight->setSpecularColor(0,0,0);
137
138        /*
139        this->soundSource = NULL;
140        this->thunderBuffer = NULL;
141
142        this->soundSource.setSourceNode(this);
143
144        //load sound
145        if (this->thunderBuffer != NULL)
146        ResourceManager::getInstance()->unload(this->thunderBuffer);
147        this->thunderBuffer = (OrxSound::SoundBuffer*)ResourceManager::getInstance()->load("sound/thunder.wav", WAV);*/
148
149}
150
151void LighteningEffect::coord(float x, float y, float z)
152{
153        if (this->lighteningMove) {
154                this->cameraCoor = State::getCameraNode()->getAbsCoor();
155                this->billboard[0]->setAbsCoor(this->cameraCoor.x+x, y, this->cameraCoor.z+z);
156                this->billboard[1]->setAbsCoor(this->cameraCoor.x+x, y, this->cameraCoor.z+z);
157                this->billboard[2]->setAbsCoor(this->cameraCoor.x+x, y, this->cameraCoor.z+z);
158                this->billboard[3]->setAbsCoor(this->cameraCoor.x+x, y, this->cameraCoor.z+z);
159        } else {
160                this->billboard[0]->setAbsCoor(x, y, z);
161                this->billboard[1]->setAbsCoor(x, y, z);
162                this->billboard[2]->setAbsCoor(x, y, z);
163                this->billboard[3]->setAbsCoor(x, y, z);
164        }
165
166        this->mainPosX = x;
167        this->mainPosY = y;
168        this->mainPosZ = z;
169}
170
171
172void LighteningEffect::setFlashSize(float width, float height, float seedWidth, float seedHeight)
173{
174        this->width = width;
175        this->height = height;
176        this->seedWidth = seedWidth;
177        this->seedHeight = seedHeight;
178
179        this->billboard[0]->setSize(this->width, this->height);
180        this->billboard[1]->setSize(this->width, this->height);
181        this->billboard[2]->setSize(this->width, this->height);
182        this->billboard[3]->setSize(this->width, this->height);
183}
184
185
186void LighteningEffect::activate()
187{
188        PRINTF(0)( "Activating LighteningEffect\n" );
189        this->lighteningActivate = true;
190
191        this->time = 0;
192}
193
194
195void LighteningEffect::deactivate()
196{
197        PRINTF(0)("Deactivating LighteningEffect\n");
198        this->lighteningActivate = false;
199
200        this->billboard[0]->setVisibiliy(false);
201        this->billboard[1]->setVisibiliy(false);
202        this->billboard[2]->setVisibiliy(false);
203        this->billboard[3]->setVisibiliy(false);
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.