| [7111] | 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 | |
|---|
| [7193] | 19 | #include "util/loading/factory.h" |
|---|
| [7111] | 20 | #include "material.h" |
|---|
| 21 | |
|---|
| [9869] | 22 | #include "sound/resource_sound_buffer.h" |
|---|
| [7112] | 23 | |
|---|
| 24 | |
|---|
| 25 | |
|---|
| [7111] | 26 | |
|---|
| [10114] | 27 | |
|---|
| 28 | ObjectListDefinition(LightningBolt); |
|---|
| [9869] | 29 | CREATE_FACTORY(LightningBolt); |
|---|
| [9406] | 30 | |
|---|
| [7111] | 31 | /** |
|---|
| 32 | * standard constructor |
|---|
| 33 | */ |
|---|
| 34 | LightningBolt::LightningBolt (const TiXmlElement* root) |
|---|
| 35 | { |
|---|
| [9869] | 36 | this->registerObject(this, LightningBolt::_objectList); |
|---|
| [7111] | 37 | |
|---|
| 38 | this->toList(OM_COMMON); |
|---|
| 39 | |
|---|
| 40 | this->bRender = false; |
|---|
| 41 | this->time = 0.0; |
|---|
| 42 | this->flashFrequency = 0.6f; |
|---|
| [7112] | 43 | this->flashConstTime = 0.07f; |
|---|
| [7111] | 44 | |
|---|
| 45 | this->material = new Material(); |
|---|
| [10317] | 46 | this->material->setDiffuseMap("textures/lightning_bolt.png"); |
|---|
| [7112] | 47 | //this->offset = Vector(-1440.00, 100.00, 280.00); |
|---|
| [7111] | 48 | |
|---|
| 49 | this->setAbsCoor(offset); |
|---|
| 50 | this->width = 100.0f; |
|---|
| 51 | this->height = 300.0f; |
|---|
| [7112] | 52 | this->bNewCoordinate = false; |
|---|
| 53 | |
|---|
| 54 | this->seedX = 200.f; |
|---|
| 55 | this->seedZ = 500.0f; |
|---|
| [7113] | 56 | this->seedTime = 4.0f; |
|---|
| [7112] | 57 | |
|---|
| 58 | this->soundSource.setSourceNode(this); |
|---|
| 59 | |
|---|
| [10317] | 60 | this->thunderBuffer = OrxSound::ResourceSoundBuffer("sounds/atmosphere/thunder.wav"); |
|---|
| [7111] | 61 | } |
|---|
| 62 | |
|---|
| 63 | |
|---|
| 64 | /** |
|---|
| 65 | * standard deconstructor |
|---|
| 66 | */ |
|---|
| 67 | LightningBolt::~LightningBolt () |
|---|
| 68 | { |
|---|
| 69 | } |
|---|
| 70 | |
|---|
| 71 | void LightningBolt::activate() |
|---|
| 72 | { |
|---|
| 73 | } |
|---|
| 74 | |
|---|
| 75 | |
|---|
| 76 | void 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 | */ |
|---|
| 86 | void 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; |
|---|
| [7112] | 94 | this->soundSource.play(this->thunderBuffer); |
|---|
| [7111] | 95 | } |
|---|
| 96 | else if( this->bRender && this->time > this->flashConstTime) |
|---|
| 97 | { |
|---|
| 98 | this->bRender = false; |
|---|
| [7112] | 99 | this->time = 0.0f; |
|---|
| 100 | this->bNewCoordinate = true; |
|---|
| [7111] | 101 | } |
|---|
| [7112] | 102 | |
|---|
| 103 | if( this->bNewCoordinate) |
|---|
| [7111] | 104 | { |
|---|
| [7112] | 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; |
|---|
| [7111] | 108 | } |
|---|
| 109 | } |
|---|
| 110 | |
|---|
| 111 | |
|---|
| 112 | void 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 | |
|---|
| [7112] | 122 | glRotatef(90, 0.0f,1.0f,0.0f); |
|---|
| [7111] | 123 | |
|---|
| [7112] | 124 | // Vector tmpRot = drawPart->orientation.getSpacialAxis(); |
|---|
| 125 | // glRotatef (drawPart->orientation.getSpacialAxisAngle(), tmpRot.x, tmpRot.y, tmpRot.z ); |
|---|
| 126 | |
|---|
| [7111] | 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 | |
|---|