Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

Last change on this file since 8247 was 8223, checked in by hdavid, 18 years ago

branches/atmospheric_enc_engine: starting implementation of random raising for the lightening

File size: 6.1 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.8f;
74  this->flashRisingTime = 0.5f;
75
76  this->width = 40.0f;
77  this->height = 10.0f;
78  this->bNewCoordinate = false;
79
80  this->seedX = 10.f;
81  this->seedZ = 10.0f;
82  this->seedTime = 4.0f;
83 
84  lightening1 = 1;
85  lightening2 = 2;
86  lightening3 = 3;
87
88  this->billboard[0] = new Billboard(NULL);
89  this->billboard[0]->setTexture("maps/lightning_bolt1.png");
90  this->billboard[0]->setSize(this->width, this->height);
91  this->billboard[0]->setAbsCoor(0.0f, 50.0f, 0.0f);
92  this->billboard[0]->setVisibiliy(false);
93
94  this->billboard[1] = new Billboard(NULL);
95  this->billboard[1]->setTexture("maps/lightning_bolt2.png");
96  this->billboard[1]->setSize(this->width, this->height);
97  this->billboard[1]->setAbsCoor(0.0f, 50.0f, 0.0f);
98  this->billboard[1]->setVisibiliy(false);
99
100  this->billboard[2] = new Billboard(NULL);
101  this->billboard[2]->setTexture("maps/lightning_bolt3.png");
102  this->billboard[2]->setSize(this->width, this->height);
103  this->billboard[2]->setAbsCoor(0.0f, 50.0f, 0.0f);
104  this->billboard[2]->setVisibiliy(false);
105
106  this->billboard[3] = new Billboard(NULL);
107  this->billboard[3]->setTexture("maps/lightning_bolt4.png");
108  this->billboard[3]->setSize(this->width, this->height);
109  this->billboard[3]->setAbsCoor(0.0f, 50.0f, 0.0f);
110  this->billboard[3]->setVisibiliy(false);
111/*
112  this->soundSource = NULL;
113  this->thunderBuffer = NULL;
114
115  this->soundSource.setSourceNode(this);
116
117  //load sound
118  if (this->thunderBuffer != NULL)
119    ResourceManager::getInstance()->unload(this->thunderBuffer);
120  this->thunderBuffer = (OrxSound::SoundBuffer*)ResourceManager::getInstance()->load("sound/thunder.wav", WAV);*/
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
135bool LighteningEffect::activate()
136{
137        PRINTF(0)( "Activating LighteningEffect\n" );
138  this->time = 0;
139  lighteningActivate = true;
140}
141
142
143bool LighteningEffect::deactivate()
144{
145        PRINTF(0)("Deactivating LighteningEffect\n");
146  this->billboard[0]->setVisibiliy(false);
147  this->billboard[1]->setVisibiliy(false);
148  this->billboard[2]->setVisibiliy(false);
149  this->billboard[3]->setVisibiliy(false);
150  lighteningActivate = false;
151}
152
153void LighteningEffect::tick (float dt)
154{
155  if(!lighteningActivate)
156    return;
157 
158  this->time += dt;
159
160  if( this->time > this->flashFrequency)
161  {
162    this->billboard[0]->setVisibiliy(true);
163    this->time = 0.0f;
164    //this->soundSource.play(this->thunderBuffer);
165  }
166  else if( this->billboard[lightening3]->isVisible() && this->time > this->flashConstTime)
167  {
168    this->billboard[lightening3]->setVisibiliy(false);
169    this->time = 0.0f;
170    this->bNewCoordinate = true;
171  }
172
173  if( this->billboard[lightening2]->isVisible() && this->time > this->flashRisingTime)
174  {
175    this->billboard[lightening2]->setVisibiliy(false);
176    this->billboard[lightening3]->setVisibiliy(true);
177  }
178  else if( this->billboard[lightening1]->isVisible() && this->time > this->flashRisingTime*2/3 )
179  {
180    this->billboard[lightening1]->setVisibiliy(false);
181    this->billboard[lightening2]->setVisibiliy(true);
182  }
183  else if( this->billboard[0]->isVisible() && this->time > this->flashRisingTime*1/3 )
184  {
185    this->billboard[0]->setVisibiliy(false);
186    this->billboard[lightening1]->setVisibiliy(true);
187  }
188
189  if( this->bNewCoordinate)
190  {
191    float posX = this->mainPosX - this->seedX * (float)rand()/(float)RAND_MAX;
192    float posZ = this->mainPosZ + this->seedZ * (float)rand()/(float)RAND_MAX;
193    this->billboard[0]->setAbsCoor(posX, this->mainPosY, posZ);
194    this->billboard[1]->setAbsCoor(posX, this->mainPosY, posZ);
195    this->billboard[2]->setAbsCoor(posX, this->mainPosY, posZ);
196    this->billboard[3]->setAbsCoor(posX, this->mainPosY, posZ);   
197    this->bNewCoordinate = false;
198  }
199}
200
201void LighteningEffect::draw() const
202{
203  /*if(!this->billboard->isVisible())
204    return;
205 
206  LightManager* lightMan = LightManager::getInstance();
207 
208  (new Light())->setAbsCoor(this->billboard->getAbsCoor().x, this->billboard->getAbsCoor().y, this->billboard->getAbsCoor().z);
209  (new Light())->setDiffuseColor(1,1,1);
210  LightManager::getInstance()->draw();
211 
212  delete lightMan;*/
213}
Note: See TracBrowser for help on using the repository browser.