Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/branches/atmospheric_engine/src/world_entities/effects/billboard.cc @ 7913

Last change on this file since 7913 was 7810, checked in by bensch, 19 years ago

orxonox/trunk: merged the Weather effects back here

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