Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

branches/atmospheric_engine: lightening effect

File size: 4.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, "size", this, LighteningEffect, setFlashSize);
62  LoadParam(root, "seed", this, LighteningEffect, setFlashSeed);
63}
64
65
66bool LighteningEffect::init()
67{
68  lighteningActivate = false;
69 
70  this->time = 0.0;
71  this->flashFrequency = 0.6f;
72  this->flashConstTime = 0.07f;
73
74  this->width = 40.0f;
75  this->height = 10.0f;
76  this->bNewCoordinate = false;
77
78  this->seedX = 10.f;
79  this->seedZ = 10.0f;
80  this->seedTime = 4.0f;
81
82  this->billboard = new Billboard(NULL);
83  this->billboard->setTexture("maps/lightning_bolt.png");
84  this->billboard->setSize(this->width, this->height);
85  this->billboard->setAbsCoor(0.0f, 50.0f, 0.0f);
86  this->billboard->setVisibiliy(false);
87
88/*
89  this->soundSource = NULL;
90  this->thunderBuffer = NULL;
91
92  this->soundSource.setSourceNode(this);
93
94  //load sound
95  if (this->thunderBuffer != NULL)
96    ResourceManager::getInstance()->unload(this->thunderBuffer);
97  this->thunderBuffer = (OrxSound::SoundBuffer*)ResourceManager::getInstance()->load("sound/thunder.wav", WAV);*/
98}
99
100void LighteningEffect::coord(float x, float y, float z)
101{
102  this->billboard->setAbsCoor(x, y, z);
103  this->mainPosX = x;
104  this->mainPosY = y;
105  this->mainPosZ = z;
106 
107}
108
109bool LighteningEffect::activate()
110{
111        PRINTF(0)( "Activating LighteningEffect\n" );
112  this->billboard->setVisibiliy(true);
113  lighteningActivate = true;
114}
115
116
117bool LighteningEffect::deactivate()
118{
119        PRINTF(0)("Deactivating LighteningEffect\n");
120  this->billboard->setVisibiliy(false);
121  lighteningActivate = false;
122}
123
124void LighteningEffect::tick (float dt)
125{
126  if(!lighteningActivate)
127    return;
128 
129  this->time += dt;
130
131  if( this->time > this->flashFrequency)
132  {
133    this->billboard->setVisibiliy(true);
134    this->time = 0.0f;
135    //this->soundSource.play(this->thunderBuffer);
136  }
137  else if( this->billboard->isVisible() && this->time > this->flashConstTime)
138  {
139    this->billboard->setVisibiliy(false);
140    this->time = 0.0f;
141    this->bNewCoordinate = true;
142  }
143
144  if( this->bNewCoordinate)
145  {
146    this->flashFrequency = this->seedTime * (float)rand()/(float)RAND_MAX + 0.1;
147    this->billboard->setAbsCoor(this->mainPosX - this->seedX * (float)rand()/(float)RAND_MAX, this->mainPosY, this->mainPosZ + this->seedZ * (float)rand()/(float)RAND_MAX);
148    this->bNewCoordinate = false;
149  }
150}
151
152void LighteningEffect::draw() const
153{
154  /*if(!this->billboard->isVisible())
155    return;
156 
157  LightManager* lightMan = LightManager::getInstance();
158 
159  (new Light())->setAbsCoor(this->billboard->getAbsCoor().x, this->billboard->getAbsCoor().y, this->billboard->getAbsCoor().z);
160  (new Light())->setDiffuseColor(1,1,1);
161  LightManager::getInstance()->draw();
162 
163  delete lightMan;*/
164}
Note: See TracBrowser for help on using the repository browser.