Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/branches/gui/src/lib/graphics/effects/lightening_effect.cc @ 8493

Last change on this file since 8493 was 8316, checked in by bensch, 18 years ago

trunk: fixed most -Wall warnings… but there are still many missing :/

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