Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 8255 in orxonox.OLD for trunk/src/world_entities/effects


Ignore:
Timestamp:
Jun 8, 2006, 3:44:12 PM (18 years ago)
Author:
bensch
Message:

merged the atmos back with command: https://svn.orxonox.net/orxonox/branches/atmospheric_engine

Location:
trunk/src/world_entities/effects
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/world_entities/effects/billboard.cc

    r7810 r8255  
    22   orxonox - the future of 3D-vertical-scrollers
    33
    4    Copyright (C) 2004 orx
     4   Copyright (C) 2006 orx
    55
    66   This program is free software; you can redistribute it and/or modify
     
    99   any later version.
    1010
    11    ### File Specific
    12    main-programmer: Patrick Boenzli
     11### File Specific:
     12   main-programmer: David Hasenfratz
    1313*/
    14 #define DEBUG_SPECIAL_MODULE DEBUG_MODULE_WEAPON
    1514
     15#include "billboard.h"
    1616
    17 #include "lightning_bolt.h"
     17#include "util/loading/load_param.h"
     18#include "util/loading/factory.h"
    1819
    19 #include "util/loading/factory.h"
     20#include "graphics_engine.h"
    2021#include "material.h"
    21 
    22 #include "util/loading/resource_manager.h"
    23 
     22#include "glincl.h"
     23#include "state.h"
    2424
    2525
    2626using namespace std;
    2727
    28 CREATE_FACTORY(LightningBolt, CL_LIGHTNING_BOLT);
     28
     29CREATE_FACTORY(Billboard, CL_BILLBOARD);
    2930
    3031
    3132/**
    32  *  standard constructor
    33 */
    34 LightningBolt::LightningBolt (const TiXmlElement* root)
     33 * standart constructor
     34 */
     35Billboard::Billboard (const TiXmlElement* root)
    3536{
    36   this->setClassID(CL_LIGHTNING_BOLT, "LightningBolt");
     37  this->init();
    3738
    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);
    6441}
    6542
    6643
    6744/**
    68  *  standard deconstructor
    69 */
    70 LightningBolt::~LightningBolt ()
     45 * destroys a Billboard
     46 */
     47Billboard::~Billboard ()
    7148{
     49  if (this->material)
     50    delete this->material;
    7251}
    7352
    74 void LightningBolt::activate()
     53
     54/**
     55 * initializes the Billboard
     56 */
     57void 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 */
     75void 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 */
     89void 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 */
     100void 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 */
     110void Billboard::tick(float dt)
    75111{
    76112}
    77113
    78114
    79 void LightningBolt::deactivate()
     115/**
     116 * draws the billboard
     117 */
     118void Billboard::draw() const
    80119{
     120  if( !this->isVisible())
     121    return;
    81122
     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();
    82166}
    83 
    84 
    85 /**
    86  *  signal tick, time dependent things will be handled here
    87  * @param time since last tick
    88 */
    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() 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 
  • trunk/src/world_entities/effects/billboard.h

    r7810 r8255  
    11/*!
    2  * @file lightning_bolt.h
    3  * @brief a LightningBolt Projectile
     2 * @file billboard.h
    43 */
    54
    6 #ifndef _LIGHTNING_BOLT_H
    7 #define _LIGHTNING_BOLT_H
     5#ifndef _BILLBOARD_H
     6#define _BILLBOARD_H
    87
    98#include "world_entity.h"
    109
    11 #include "sound_buffer.h"
    12 #include "sound_source.h"
     10class Material;
     11class TiXmlElement;
    1312
    14 class Material;
    15 
    16 class LightningBolt : public WorldEntity
     13class Billboard : public WorldEntity
    1714{
    1815  public:
    19     LightningBolt(const TiXmlElement* root = NULL);
    20     virtual ~LightningBolt ();
     16    Billboard(const TiXmlElement* root = NULL);
     17    virtual ~Billboard();
    2118
    22     virtual void activate();
    23     virtual void deactivate();
     19    void init();
     20    void loadParams(const TiXmlElement* root);
    2421
    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);
    2626    virtual void draw() const;
    2727
    2828  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;
    4932};
    5033
    51 #endif /* _LIGHTNING_BOLT_H */
     34#endif /* _BILLBOARD_H */
Note: See TracChangeset for help on using the changeset viewer.