Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

Last change on this file since 8327 was 8326, checked in by hdavid, 18 years ago

branches/atmospheric_engine

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