Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

Last change on this file since 8284 was 8281, checked in by hdavid, 19 years ago

branches/atmospheric_engine: lightening effect

File size: 7.2 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, "option", this, LighteningEffect, setLighteningOption);
59  LoadParam(root, "frequency", this, LighteningEffect, setFlashFrequency);
60  LoadParam(root, "const-time", this, LighteningEffect, setFlashConstTime);
61  LoadParam(root, "rising-time", this, LighteningEffect, setFlashRisingTime);
62  LoadParam(root, "size", this, LighteningEffect, setFlashSize);
63  LoadParam(root, "seed", this, LighteningEffect, setFlashSeed);
64}
65
66
67bool LighteningEffect::init()
68{
69  lighteningActivate = false;
70 
71  this->time = 0.0;
72  this->flashFrequency = 1.4f;
73  this->mainFrequency = 1.4f;
74  this->flashConstTime = 0.5f;
75  this->flashRisingTime = 0.1f;
76
77  this->width = 400.0f;
78  this->height = 100.0f;
79  this->seedWidth = 50;
80  this->seedHeight = 50;
81  this->bNewCoordinate = false;
82
83  this->seedX = 500.f;
84  this->seedZ = 1000.0f;
85  this->seedTime = 4.0f;
86
87  this->billboard[0] = new Billboard(NULL);
88  this->billboard[0]->setTexture("maps/lightning_bolt1.png");
89  this->billboard[0]->setSize(this->width, this->height);
90  this->billboard[0]->setAbsCoor(3000,850,0);
91  this->billboard[0]->setVisibiliy(false);
92
93  this->billboard[1] = new Billboard(NULL);
94  this->billboard[1]->setTexture("maps/lightning_bolt2.png");
95  this->billboard[1]->setSize(this->width, this->height);
96  this->billboard[1]->setAbsCoor(3000,850,0);
97  this->billboard[1]->setVisibiliy(false);
98
99  this->billboard[2] = new Billboard(NULL);
100  this->billboard[2]->setTexture("maps/lightning_bolt3.png");
101  this->billboard[2]->setSize(this->width, this->height);
102  this->billboard[2]->setAbsCoor(3000,850,0);
103  this->billboard[2]->setVisibiliy(false);
104
105  this->billboard[3] = new Billboard(NULL);
106  this->billboard[3]->setTexture("maps/lightning_bolt4.png");
107  this->billboard[3]->setSize(this->width, this->height);
108  this->billboard[3]->setAbsCoor(3000,850,0);
109  this->billboard[3]->setVisibiliy(false);
110 
111  this->flashLight = new Light();
112  this->flashLight->setDiffuseColor(0,0,0);
113  this->flashLight->setSpecularColor(0,0,0);
114 
115/*
116  this->soundSource = NULL;
117  this->thunderBuffer = NULL;
118
119  this->soundSource.setSourceNode(this);
120
121  //load sound
122  if (this->thunderBuffer != NULL)
123    ResourceManager::getInstance()->unload(this->thunderBuffer);
124  this->thunderBuffer = (OrxSound::SoundBuffer*)ResourceManager::getInstance()->load("sound/thunder.wav", WAV);*/
125}
126
127void LighteningEffect::coord(float x, float y, float z)
128{
129  this->billboard[0]->setAbsCoor(x, y, z);
130  this->billboard[1]->setAbsCoor(x, y, z);
131  this->billboard[2]->setAbsCoor(x, y, z);
132  this->billboard[3]->setAbsCoor(x, y, z);
133  this->mainPosX = x;
134  this->mainPosY = y;
135  this->mainPosZ = z;
136}
137
138
139void LighteningEffect::setFlashSize(float width, float height, float seedWidth, float seedHeight)
140{
141  this->width = width;
142  this->height = height;
143  this->seedWidth = seedWidth;
144  this->seedHeight = seedHeight;
145  this->billboard[0]->setSize(this->width, this->height);
146  this->billboard[1]->setSize(this->width, this->height);
147  this->billboard[2]->setSize(this->width, this->height);
148  this->billboard[3]->setSize(this->width, this->height);
149}
150
151
152bool LighteningEffect::activate()
153{
154        PRINTF(0)( "Activating LighteningEffect\n" );
155  this->time = 0;
156  lighteningActivate = true;
157}
158
159
160bool LighteningEffect::deactivate()
161{
162        PRINTF(0)("Deactivating LighteningEffect\n");
163  this->billboard[0]->setVisibiliy(false);
164  this->billboard[1]->setVisibiliy(false);
165  this->billboard[2]->setVisibiliy(false);
166  this->billboard[3]->setVisibiliy(false);
167  lighteningActivate = false;
168}
169
170void LighteningEffect::tick (float dt)
171{
172  if(!lighteningActivate)
173    return;
174 
175  this->time += dt;
176 
177  if( this->time > this->flashFrequency)
178  {
179    this->billboard[0]->setVisibiliy(true);
180    this->time = 0.0f;
181
182    this->flashLight->setAbsCoor(this->billboard[0]->getAbsCoor().x, this->billboard[0]->getAbsCoor().y, this->billboard[0]->getAbsCoor().z);
183    this->flashLight->setDiffuseColor(1,1,1);
184    this->flashLight->setSpecularColor(1,1,1);
185   
186    //this->soundSource.play(this->thunderBuffer);
187  }
188  else if( this->billboard[3]->isVisible() && this->time > this->flashConstTime)
189  {
190    this->billboard[3]->setVisibiliy(false);
191    this->time = 0.0f;
192    this->flashLight->setDiffuseColor(0,0,0);
193    this->flashLight->setSpecularColor(0,0,0);
194    this->bNewCoordinate = true;
195  }
196
197  if( this->billboard[2]->isVisible() && this->time > this->flashRisingTime)
198  {
199    this->billboard[2]->setVisibiliy(false);
200    this->billboard[3]->setVisibiliy(true);
201   // this->flashLight->setDiffuseColor(1,1,1);
202   // this->flashLight->setSpecularColor(1,1,1);
203  }
204  else if( this->billboard[1]->isVisible() && this->time > this->flashRisingTime*2/3 )
205  {
206    this->billboard[1]->setVisibiliy(false);
207    this->billboard[2]->setVisibiliy(true);
208    //this->flashLight->setDiffuseColor(0,0,0);
209    //this->flashLight->setSpecularColor(0,0,0);
210  }
211  else if( this->billboard[0]->isVisible() && this->time > this->flashRisingTime*1/3 )
212  {
213    this->billboard[0]->setVisibiliy(false);
214    this->billboard[1]->setVisibiliy(true);
215    //this->flashLight->setDiffuseColor(1,1,1);
216    //this->flashLight->setSpecularColor(1,1,1);
217  }
218
219  if( this->bNewCoordinate)
220  {
221    float posX = this->mainPosX - this->seedX * (float)rand()/(float)RAND_MAX;
222    float posZ = this->mainPosZ + this->seedZ * (float)rand()/(float)RAND_MAX;
223    this->billboard[0]->setAbsCoor(posX, this->mainPosY, posZ);
224    this->billboard[1]->setAbsCoor(posX, this->mainPosY, posZ);
225    this->billboard[2]->setAbsCoor(posX, this->mainPosY, posZ);
226    this->billboard[3]->setAbsCoor(posX, this->mainPosY, posZ);
227    this->flashFrequency = this->mainFrequency + this->seedTime * (float)rand()/(float)RAND_MAX;
228    float w = this->width + this->seedWidth * (float)rand()/(float)RAND_MAX;
229    float h = this->height + this->seedHeight * (float)rand()/(float)RAND_MAX;
230    this->billboard[0]->setSize(w, h);
231    this->billboard[1]->setSize(w, h);
232    this->billboard[2]->setSize(w, h);
233    this->billboard[3]->setSize(w, h);
234    this->bNewCoordinate = false;
235  }
236}
237
238void LighteningEffect::draw() const
239{
240}
Note: See TracBrowser for help on using the repository browser.