Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/trunk/src/world_entities/effects/lightning_bolt.cc @ 10331

Last change on this file since 10331 was 10317, checked in by patrick, 18 years ago

merged branche data-fix back to trunk. this breaks compatibility with the old data/trunk data repository! be sure to update your data trunk

File size: 3.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: 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 "sound/resource_sound_buffer.h"
23
24
25
26
27
28ObjectListDefinition(LightningBolt);
29CREATE_FACTORY(LightningBolt);
30
31/**
32 *  standard constructor
33*/
34LightningBolt::LightningBolt (const TiXmlElement* root)
35{
36  this->registerObject(this, LightningBolt::_objectList);
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("textures/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.setSourceNode(this);
59
60  this->thunderBuffer = OrxSound::ResourceSoundBuffer("sounds/atmosphere/thunder.wav");
61}
62
63
64/**
65 *  standard deconstructor
66*/
67LightningBolt::~LightningBolt ()
68{
69}
70
71void LightningBolt::activate()
72{
73}
74
75
76void LightningBolt::deactivate()
77{
78
79}
80
81
82/**
83 *  signal tick, time dependent things will be handled here
84 * @param time since last tick
85*/
86void LightningBolt::tick (float dt)
87{
88  this->time += dt;
89
90  if( this->time > this->flashFrequency)
91  {
92    this->bRender = true;
93    this->time = 0.0f;
94    this->soundSource.play(this->thunderBuffer);
95  }
96  else if( this->bRender && this->time > this->flashConstTime)
97  {
98    this->bRender = false;
99    this->time = 0.0f;
100    this->bNewCoordinate = true;
101  }
102
103  if( this->bNewCoordinate)
104  {
105    this->flashFrequency = this->seedTime * (float)rand()/(float)RAND_MAX + 0.1;
106    this->setAbsCoor( - 800.0f - this->seedX * (float)rand()/(float)RAND_MAX, 250.00, -200.0f + this->seedZ * (float)rand()/(float)RAND_MAX);
107    this->bNewCoordinate = false;
108  }
109}
110
111
112void LightningBolt::draw() const
113{
114  if( this->bRender)
115  {
116
117    glPushMatrix();
118    glTranslatef (this->getAbsCoor ().x,
119                  this->getAbsCoor ().y,
120                  this->getAbsCoor ().z);
121
122    glRotatef(90, 0.0f,1.0f,0.0f);
123
124//     Vector tmpRot = drawPart->orientation.getSpacialAxis();
125//     glRotatef (drawPart->orientation.getSpacialAxisAngle(), tmpRot.x, tmpRot.y, tmpRot.z );
126
127//     glPushAttrib(GL_ENABLE_BIT);
128//     glDisable(GL_LIGHTING);
129//     glDisable(GL_BLEND);
130
131    this->material->select();
132
133    glBegin(GL_QUADS);
134    glTexCoord2f(1.0f, 1.0f); glVertex3f(-width/2, -height/2,  0.0f);
135    glTexCoord2f(0.0f, 1.0f); glVertex3f( width/2, -height/2,  0.0f);
136    glTexCoord2f(0.0f, 0.0f); glVertex3f( width/2,  height/2,  0.0f);
137    glTexCoord2f(1.0f, 0.0f); glVertex3f(-width/2,  height/2,  0.0f);
138    glEnd();
139
140//     glPopAttrib();
141
142    glPopMatrix();
143  }
144}
145
146
Note: See TracBrowser for help on using the repository browser.