Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/trunk/src/lib/graphics/effects/lightening_effect.cc @ 8570

Last change on this file since 8570 was 8495, checked in by bensch, 19 years ago

merged the branche atmos back. no conflicts

File size: 8.6 KB
RevLine 
[7679]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
[7807]17#include "state.h"
[7679]18#include "util/loading/load_param.h"
19#include "util/loading/factory.h"
[8255]20#include "effects/billboard.h"
[7679]21
22#include "glincl.h"
23#include "parser/tinyxml/tinyxml.h"
24
[8255]25#include "shell_command.h"
26#include "light.h"
27
28SHELL_COMMAND(activate, LighteningEffect, activateLightening);
29SHELL_COMMAND(deactivate, LighteningEffect, deactivateLightening);
30
[7679]31using namespace std;
32
33CREATE_FACTORY(LighteningEffect, CL_LIGHTENING_EFFECT);
34
[8495]35// TODO: FIx Lightening with Fog enabled
36
[7679]37LighteningEffect::LighteningEffect(const TiXmlElement* root)
38{
39        this->setClassID(CL_LIGHTENING_EFFECT, "LighteningEffect");
[8316]40
[7679]41        this->init();
42
43        if (root != NULL)
44                this->loadParams(root);
45
[8495]46        if(this->lighteningActivate)
47                this->activate();
[7679]48}
49
50LighteningEffect::~LighteningEffect()
51{
52        this->deactivate();
53}
54
55void LighteningEffect::loadParams(const TiXmlElement* root)
56{
57        WeatherEffect::loadParams(root);
[8316]58
[8495]59        LoadParam(root, "coord", this, LighteningEffect, coord);
60        LoadParam(root, "frequency", this, LighteningEffect, setFlashFrequency);
61        LoadParam(root, "const-time", this, LighteningEffect, setFlashConstTime);
62        LoadParam(root, "rising-time", this, LighteningEffect, setFlashRisingTime);
63        LoadParam(root, "size", this, LighteningEffect, setFlashSize);
64        LoadParam(root, "seed", this, LighteningEffect, setFlashSeed);
65
66        LOAD_PARAM_START_CYCLE(root, element);
67        {
68                LoadParam_CYCLE(element, "option", this, LighteningEffect, setLighteningOption);
69        }
70        LOAD_PARAM_END_CYCLE(element);
[7679]71}
72
73
[8495]74void LighteningEffect::init()
[7679]75{
[8495]76        //default values
77        this->lighteningActivate = false;
[8316]78
[8495]79        this->time = 0.0;
80        this->flashFrequency = 4.0f;
81        this->mainFrequency = 4.0f;
82        this->flashConstTime = 0.1f;
83        this->flashRisingTime = 0.03f;
[8255]84
[8495]85        this->width = 700.0f;
86        this->height = 250.0f;
87        this->seedWidth = 50.0f;
88        this->seedHeight = 50.0f;
89        this->bNewCoordinate = false;
90  this->lighteningMove = false;
[8255]91
[8495]92        this->seedX = 500.f;
93        this->seedZ = 1000.0f;
94        this->seedTime = 2.0f;
[8255]95
[8495]96  this->mainPosX = 3000;
97  this->mainPosY = 900;
98  this->mainPosZ = 0;
[8255]99
[8495]100        // initialize lightening textures
101        this->billboard[0] = new Billboard(NULL);
102        this->billboard[0]->setTexture("maps/lightning_bolt1.png");
103        this->billboard[0]->setSize(this->width, this->height);
104        this->billboard[0]->setVisibiliy(false);
[8255]105
[8495]106        this->billboard[1] = new Billboard(NULL);
107        this->billboard[1]->setTexture("maps/lightning_bolt2.png");
108        this->billboard[1]->setSize(this->width, this->height);
109        this->billboard[1]->setVisibiliy(false);
[8255]110
[8495]111        this->billboard[2] = new Billboard(NULL);
112        this->billboard[2]->setTexture("maps/lightning_bolt3.png");
113        this->billboard[2]->setSize(this->width, this->height);
114        this->billboard[2]->setVisibiliy(false);
[8255]115
[8495]116        this->billboard[3] = new Billboard(NULL);
117        this->billboard[3]->setTexture("maps/lightning_bolt4.png");
118        this->billboard[3]->setSize(this->width, this->height);
119        this->billboard[3]->setVisibiliy(false);
[8255]120
[8495]121        if (this->lighteningMove) {
122                this->cameraCoor = State::getCameraNode()->getAbsCoor();
123                this->billboard[0]->setAbsCoor(this->cameraCoor.x+3000,900,this->cameraCoor.z+0);
124                this->billboard[1]->setAbsCoor(this->cameraCoor.x+3000,900,this->cameraCoor.z+0);
125                this->billboard[2]->setAbsCoor(this->cameraCoor.x+3000,900,this->cameraCoor.z+0);
126                this->billboard[3]->setAbsCoor(this->cameraCoor.x+3000,900,this->cameraCoor.z+0);
127        } else {
128                this->billboard[0]->setAbsCoor(3000,900,0);
129                this->billboard[1]->setAbsCoor(3000,900,0);
130                this->billboard[2]->setAbsCoor(3000,900,0);
131                this->billboard[3]->setAbsCoor(3000,900,0);
132        }
[8316]133
[8495]134        this->flashLight = new Light();
135        this->flashLight->setDiffuseColor(0,0,0);
136        this->flashLight->setSpecularColor(0,0,0);
137
138        /*
139        this->soundSource = NULL;
140        this->thunderBuffer = NULL;
141
142        this->soundSource.setSourceNode(this);
143
144        //load sound
145        if (this->thunderBuffer != NULL)
146        ResourceManager::getInstance()->unload(this->thunderBuffer);
147        this->thunderBuffer = (OrxSound::SoundBuffer*)ResourceManager::getInstance()->load("sound/thunder.wav", WAV);*/
148
[7679]149}
150
[8255]151void LighteningEffect::coord(float x, float y, float z)
152{
[8495]153        if (this->lighteningMove) {
154                this->cameraCoor = State::getCameraNode()->getAbsCoor();
155                this->billboard[0]->setAbsCoor(this->cameraCoor.x+x, y, this->cameraCoor.z+z);
156                this->billboard[1]->setAbsCoor(this->cameraCoor.x+x, y, this->cameraCoor.z+z);
157                this->billboard[2]->setAbsCoor(this->cameraCoor.x+x, y, this->cameraCoor.z+z);
158                this->billboard[3]->setAbsCoor(this->cameraCoor.x+x, y, this->cameraCoor.z+z);
159        } else {
160                this->billboard[0]->setAbsCoor(x, y, z);
161                this->billboard[1]->setAbsCoor(x, y, z);
162                this->billboard[2]->setAbsCoor(x, y, z);
163                this->billboard[3]->setAbsCoor(x, y, z);
164        }
165
166        this->mainPosX = x;
167        this->mainPosY = y;
168        this->mainPosZ = z;
[8255]169}
[7679]170
[8255]171
172void LighteningEffect::setFlashSize(float width, float height, float seedWidth, float seedHeight)
173{
[8495]174        this->width = width;
175        this->height = height;
176        this->seedWidth = seedWidth;
177        this->seedHeight = seedHeight;
178
179        this->billboard[0]->setSize(this->width, this->height);
180        this->billboard[1]->setSize(this->width, this->height);
181        this->billboard[2]->setSize(this->width, this->height);
182        this->billboard[3]->setSize(this->width, this->height);
[8255]183}
184
185
[8495]186void LighteningEffect::activate()
[7679]187{
[7699]188        PRINTF(0)( "Activating LighteningEffect\n" );
[8495]189        this->lighteningActivate = true;
[8316]190
[8495]191        this->time = 0;
[7679]192}
193
194
[8495]195void LighteningEffect::deactivate()
[7679]196{
197        PRINTF(0)("Deactivating LighteningEffect\n");
[8495]198        this->lighteningActivate = false;
[8316]199
[8495]200        this->billboard[0]->setVisibiliy(false);
201        this->billboard[1]->setVisibiliy(false);
202        this->billboard[2]->setVisibiliy(false);
203        this->billboard[3]->setVisibiliy(false);
[7679]204}
205
206void LighteningEffect::tick (float dt)
207{
[8495]208        if(!lighteningActivate)
209                return;
[8316]210
[8495]211        this->time += dt;
[7679]212
[8495]213        // TODO: Make random flashing with short light dingsda:)
[8316]214
[8495]215        if( this->time > this->flashFrequency) {
[8316]216
[8495]217                this->billboard[0]->setVisibiliy(true);
218                this->time = 0.0f;
[8316]219
[8495]220                this->flashLight->setAbsCoor(this->billboard[0]->getAbsCoor().x, this->billboard[0]->getAbsCoor().y, this->billboard[0]->getAbsCoor().z);
[8316]221
[8495]222                // flash environmental lightening
223                this->flashLight->setDiffuseColor(1,1,1);
224                this->flashLight->setSpecularColor(1,1,1);
[8316]225
[8495]226                //this->soundSource.play(this->thunderBuffer);
[8255]227
[8495]228        } else if( this->billboard[3]->isVisible() && this->time > this->flashConstTime) {
[8255]229
[8495]230                this->billboard[3]->setVisibiliy(false);
231                this->time = 0.0f;
232                this->flashLight->setDiffuseColor(0,0,0);
233                this->flashLight->setSpecularColor(0,0,0);
234                this->bNewCoordinate = true;
235
236        }
237
238        if( this->billboard[2]->isVisible() && this->time > this->flashRisingTime) {
239
240                this->billboard[2]->setVisibiliy(false);
241                this->billboard[3]->setVisibiliy(true);
242                // this->flashLight->setDiffuseColor(1,1,1);
243                // this->flashLight->setSpecularColor(1,1,1);
244
245        } else if( this->billboard[1]->isVisible() && this->time > this->flashRisingTime*2/3 ) {
246
247                this->billboard[1]->setVisibiliy(false);
248                this->billboard[2]->setVisibiliy(true);
249                //this->flashLight->setDiffuseColor(0,0,0);
250                //this->flashLight->setSpecularColor(0,0,0);
251
252        } else if( this->billboard[0]->isVisible() && this->time > this->flashRisingTime*1/3 ) {
253
254                this->billboard[0]->setVisibiliy(false);
255                this->billboard[1]->setVisibiliy(true);
256                //this->flashLight->setDiffuseColor(1,1,1);
257                //this->flashLight->setSpecularColor(1,1,1);
258
259        }
260
261        if( this->bNewCoordinate) {
262                float posX, posZ;
263
264                if(this->lighteningMove) {
265
266                        this->cameraCoor = State::getCameraNode()->getAbsCoor();
267                        posX = this->mainPosX - this->seedX * (float)rand()/(float)RAND_MAX + this->cameraCoor.x;
268                        posZ = this->mainPosZ + this->seedZ * (float)rand()/(float)RAND_MAX + this->cameraCoor.z;
269
270                } else {
271
272                        posX = this->mainPosX - this->seedX * (float)rand()/(float)RAND_MAX;
273                        posZ = this->mainPosZ + this->seedZ * (float)rand()/(float)RAND_MAX;
274
275                }
276
277                this->billboard[0]->setAbsCoor(posX, this->mainPosY, posZ);
278                this->billboard[1]->setAbsCoor(posX, this->mainPosY, posZ);
279                this->billboard[2]->setAbsCoor(posX, this->mainPosY, posZ);
280                this->billboard[3]->setAbsCoor(posX, this->mainPosY, posZ);
281
282                this->flashFrequency = this->mainFrequency + this->seedTime * (float)rand()/(float)RAND_MAX;
283
284                float w = this->width + this->seedWidth * (float)rand()/(float)RAND_MAX;
285                float h = this->height + this->seedHeight * (float)rand()/(float)RAND_MAX;
286
287                this->billboard[0]->setSize(w, h);
288                this->billboard[1]->setSize(w, h);
289                this->billboard[2]->setSize(w, h);
290                this->billboard[3]->setSize(w, h);
291
292                this->bNewCoordinate = false;
293        }
[7679]294}
[8255]295
296void LighteningEffect::draw() const
297{
298}
Note: See TracBrowser for help on using the repository browser.