Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/branches/terrain/src/world_entities/effects/lightning_bolt.cc @ 9611

Last change on this file since 9611 was 9406, checked in by bensch, 18 years ago

orxonox/trunk: merged the proxy back

merged with commandsvn merge -r9346:HEAD https://svn.orxonox.net/orxonox/branches/proxy .

no conflicts

File size: 3.3 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: Patrick Boenzli
13*/
14#define DEBUG_SPECIAL_MODULE DEBUG_MODULE_WEAPON
15
16
17#include "lightning_bolt.h"
18
19#include "util/loading/factory.h"
20#include "material.h"
21
22#include "util/loading/resource_manager.h"
23
24
25
26
27
28CREATE_FACTORY(LightningBolt, CL_LIGHTNING_BOLT);
29
30
31/**
32 *  standard constructor
33*/
34LightningBolt::LightningBolt (const TiXmlElement* root)
35{
36  this->setClassID(CL_LIGHTNING_BOLT, "LightningBolt");
37
38  this->toList(OM_COMMON);
39
40  this->bRender = false;
41  this->time = 0.0;
42  this->flashFrequency = 0.6f;
43  this->flashConstTime = 0.07f;
44
45  this->material = new Material();
46  this->material->setDiffuseMap("maps/lightning_bolt.png");
47  //this->offset = Vector(-1440.00, 100.00, 280.00);
48
49  this->setAbsCoor(offset);
50  this->width = 100.0f;
51  this->height = 300.0f;
52  this->bNewCoordinate = false;
53
54  this->seedX = 200.f;
55  this->seedZ = 500.0f;
56  this->seedTime = 4.0f;
57
58  this->soundSource = NULL;
59  this->thunderBuffer = NULL;
60
61  this->soundSource.setSourceNode(this);
62
63  //load sound
64  if (this->thunderBuffer != NULL)
65    ResourceManager::getInstance()->unload(this->thunderBuffer);
66  this->thunderBuffer = (OrxSound::SoundBuffer*)ResourceManager::getInstance()->load("sound/atmosphere/thunder.wav", WAV);
67}
68
69
70/**
71 *  standard deconstructor
72*/
73LightningBolt::~LightningBolt ()
74{
75}
76
77void LightningBolt::activate()
78{
79}
80
81
82void LightningBolt::deactivate()
83{
84
85}
86
87
88/**
89 *  signal tick, time dependent things will be handled here
90 * @param time since last tick
91*/
92void LightningBolt::tick (float dt)
93{
94  this->time += dt;
95
96  if( this->time > this->flashFrequency)
97  {
98    this->bRender = true;
99    this->time = 0.0f;
100    this->soundSource.play(this->thunderBuffer);
101  }
102  else if( this->bRender && this->time > this->flashConstTime)
103  {
104    this->bRender = false;
105    this->time = 0.0f;
106    this->bNewCoordinate = true;
107  }
108
109  if( this->bNewCoordinate)
110  {
111    this->flashFrequency = this->seedTime * (float)rand()/(float)RAND_MAX + 0.1;
112    this->setAbsCoor( - 800.0f - this->seedX * (float)rand()/(float)RAND_MAX, 250.00, -200.0f + this->seedZ * (float)rand()/(float)RAND_MAX);
113    this->bNewCoordinate = false;
114  }
115}
116
117
118void LightningBolt::draw() const
119{
120  if( this->bRender)
121  {
122
123    glPushMatrix();
124    glTranslatef (this->getAbsCoor ().x,
125                  this->getAbsCoor ().y,
126                  this->getAbsCoor ().z);
127
128    glRotatef(90, 0.0f,1.0f,0.0f);
129
130//     Vector tmpRot = drawPart->orientation.getSpacialAxis();
131//     glRotatef (drawPart->orientation.getSpacialAxisAngle(), tmpRot.x, tmpRot.y, tmpRot.z );
132
133//     glPushAttrib(GL_ENABLE_BIT);
134//     glDisable(GL_LIGHTING);
135//     glDisable(GL_BLEND);
136
137    this->material->select();
138
139    glBegin(GL_QUADS);
140    glTexCoord2f(1.0f, 1.0f); glVertex3f(-width/2, -height/2,  0.0f);
141    glTexCoord2f(0.0f, 1.0f); glVertex3f( width/2, -height/2,  0.0f);
142    glTexCoord2f(0.0f, 0.0f); glVertex3f( width/2,  height/2,  0.0f);
143    glTexCoord2f(1.0f, 0.0f); glVertex3f(-width/2,  height/2,  0.0f);
144    glEnd();
145
146//     glPopAttrib();
147
148    glPopMatrix();
149  }
150}
151
152
Note: See TracBrowser for help on using the repository browser.