Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

branches/atmospheric_engine: raising lightening effect

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