Changeset 8255 in orxonox.OLD for trunk/src/world_entities/effects
- Timestamp:
- Jun 8, 2006, 3:44:12 PM (18 years ago)
- Location:
- trunk/src/world_entities/effects
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/world_entities/effects/billboard.cc
r7810 r8255 2 2 orxonox - the future of 3D-vertical-scrollers 3 3 4 Copyright (C) 200 4orx4 Copyright (C) 2006 orx 5 5 6 6 This program is free software; you can redistribute it and/or modify … … 9 9 any later version. 10 10 11 ### File Specific 12 main-programmer: Patrick Boenzli11 ### File Specific: 12 main-programmer: David Hasenfratz 13 13 */ 14 #define DEBUG_SPECIAL_MODULE DEBUG_MODULE_WEAPON15 14 15 #include "billboard.h" 16 16 17 #include "lightning_bolt.h" 17 #include "util/loading/load_param.h" 18 #include "util/loading/factory.h" 18 19 19 #include " util/loading/factory.h"20 #include "graphics_engine.h" 20 21 #include "material.h" 21 22 #include "util/loading/resource_manager.h" 23 22 #include "glincl.h" 23 #include "state.h" 24 24 25 25 26 26 using namespace std; 27 27 28 CREATE_FACTORY(LightningBolt, CL_LIGHTNING_BOLT); 28 29 CREATE_FACTORY(Billboard, CL_BILLBOARD); 29 30 30 31 31 32 /** 32 * standardconstructor33 */34 LightningBolt::LightningBolt(const TiXmlElement* root)33 * standart constructor 34 */ 35 Billboard::Billboard (const TiXmlElement* root) 35 36 { 36 this-> setClassID(CL_LIGHTNING_BOLT, "LightningBolt");37 this->init(); 37 38 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); 39 if( root) 40 this->loadParams(root); 64 41 } 65 42 66 43 67 44 /** 68 * standard deconstructor69 */70 LightningBolt::~LightningBolt()45 * destroys a Billboard 46 */ 47 Billboard::~Billboard () 71 48 { 49 if (this->material) 50 delete this->material; 72 51 } 73 52 74 void LightningBolt::activate() 53 54 /** 55 * initializes the Billboard 56 */ 57 void Billboard::init() 58 { 59 this->setClassID(CL_BILLBOARD, "Billboard"); 60 this->setName("Billboard"); 61 62 this->toList(OM_COMMON); 63 64 this->material = new Material(); 65 this->setAbsCoor(0, 0, 0); 66 //this->setVisibiliy(true); 67 this->setSize(5, 5); 68 } 69 70 71 /** 72 * load params 73 * @param root TiXmlElement object 74 */ 75 void Billboard::loadParams(const TiXmlElement* root) 76 { 77 /*LoadParam(root, "texture", this->material, Material, setDiffuseMap) 78 .describe("the texture-file to load onto the Billboard"); 79 80 LoadParam(root, "size", this, Billboard, setSize) 81 .describe("the size of the Billboard in Pixels");*/ 82 } 83 84 85 /** 86 * sets the size of the Billboard. 87 * @param size the size in pixels 88 */ 89 void Billboard::setSize(float sizeX, float sizeY) 90 { 91 this->sizeX = sizeX; 92 this->sizeY = sizeY; 93 } 94 95 96 /** 97 * sets the material to load 98 * @param textureFile The texture-file to load 99 */ 100 void Billboard::setTexture(const std::string& textureFile) 101 { 102 this->material->setDiffuseMap(textureFile); 103 } 104 105 106 /** 107 * ticks the Billboard 108 * @param dt the time to ticks 109 */ 110 void Billboard::tick(float dt) 75 111 { 76 112 } 77 113 78 114 79 void LightningBolt::deactivate() 115 /** 116 * draws the billboard 117 */ 118 void Billboard::draw() const 80 119 { 120 if( !this->isVisible()) 121 return; 81 122 123 glPushMatrix(); 124 125 //glTranslatef(this->getAbsCoor().x, this->getAbsCoor().y, this->getAbsCoor().z); 126 //glTranslatef(0,0,0); 127 this->material->select(); 128 129 const PNode* camera = State::getCameraNode(); //!< @todo MUST be different 130 Vector cameraPos = camera->getAbsCoor(); 131 Vector cameraTargetPos = State::getCameraTargetNode()->getAbsCoor(); 132 Vector view = cameraTargetPos - cameraPos; 133 Vector up = Vector(0, 1, 0); 134 up = camera->getAbsDir().apply(up); 135 Vector h = up.cross(view); 136 Vector v = h.cross(view); 137 h.normalize(); 138 v.normalize(); 139 140 v *= sizeX; 141 h *= sizeY; 142 143 //v += this->getAbsCoor(); 144 //PRINTF(0)("sizeX: %f sizeY: %f\n", sizeX, sizeY); 145 glBegin(GL_QUADS); 146 glTexCoord2f(0.0f, 0.0f); 147 glVertex3f(this->getAbsCoor().x - h.x - v.x, 148 this->getAbsCoor().y - h.y - v.y, 149 this->getAbsCoor().z - h.z - v.z); 150 glTexCoord2f(1.0f, 0.0f); 151 glVertex3f( this->getAbsCoor().x + h.x - v.x, 152 this->getAbsCoor().y + h.y - v.y, 153 this->getAbsCoor().z + h.z - v.z); 154 glTexCoord2f(1.0f, 1.0f); 155 glVertex3f(this->getAbsCoor().x + h.x + v.x, 156 this->getAbsCoor().y + h.y + v.y, 157 this->getAbsCoor().z + h.z + v.z); 158 glTexCoord2f(0.0f, 1.0f); 159 glVertex3f(this->getAbsCoor().x - h.x + v.x, 160 this->getAbsCoor().y - h.y + v.y, 161 this->getAbsCoor().z - h.z + v.z); 162 glEnd(); 163 164 165 glPopMatrix(); 82 166 } 83 84 85 /**86 * signal tick, time dependent things will be handled here87 * @param time since last tick88 */89 void 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 115 void LightningBolt::draw() const116 {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 -
trunk/src/world_entities/effects/billboard.h
r7810 r8255 1 1 /*! 2 * @file lightning_bolt.h 3 * @brief a LightningBolt Projectile 2 * @file billboard.h 4 3 */ 5 4 6 #ifndef _ LIGHTNING_BOLT_H7 #define _ LIGHTNING_BOLT_H5 #ifndef _BILLBOARD_H 6 #define _BILLBOARD_H 8 7 9 8 #include "world_entity.h" 10 9 11 #include "sound_buffer.h" 12 #include "sound_source.h" 10 class Material; 11 class TiXmlElement; 13 12 14 class Material; 15 16 class LightningBolt : public WorldEntity 13 class Billboard : public WorldEntity 17 14 { 18 15 public: 19 LightningBolt(const TiXmlElement* root = NULL);20 virtual ~ LightningBolt();16 Billboard(const TiXmlElement* root = NULL); 17 virtual ~Billboard(); 21 18 22 v irtual void activate();23 v irtual void deactivate();19 void init(); 20 void loadParams(const TiXmlElement* root); 24 21 25 virtual void tick(float time); 22 void setSize(float sizeX, float sizeY); 23 void setTexture(const std::string& textureFile); 24 25 virtual void tick(float dt); 26 26 virtual void draw() const; 27 27 28 28 private: 29 float flashFrequency; //!< frequency to activate itself 30 float flashRisingTime; //!< time to rise 31 float flashConstTime; //!< time to be drawn 32 float flashFallTime; //!< time to fall 33 34 float time; //!< time 35 36 bool bRender; 37 bool bNewCoordinate; 38 Material* material; 39 Vector offset; 40 float width; 41 float height; 42 43 float seedX; 44 float seedZ; 45 float seedTime; 46 47 SoundSource soundSource; 48 SoundBuffer* thunderBuffer; 29 Material* material; 30 float sizeX; 31 float sizeY; 49 32 }; 50 33 51 #endif /* _ LIGHTNING_BOLT_H */34 #endif /* _BILLBOARD_H */
Note: See TracChangeset
for help on using the changeset viewer.