Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 6623 in orxonox.OLD for trunk/src/lib/particles/spark_particles.cc


Ignore:
Timestamp:
Jan 20, 2006, 12:54:20 AM (18 years ago)
Author:
bensch
Message:

orxonox/trunk: particle Systems and Emitters are loaded and cleaned up nicely

File:
1 copied

Legend:

Unmodified
Added
Removed
  • trunk/src/lib/particles/spark_particles.cc

    r6622 r6623  
    1616#define DEBUG_SPECIAL_MODULE DEBUG_MODULE_GRAPHICS
    1717
    18 #include "sprite_particles.h"
     18#include "spark_particles.h"
    1919
    2020#include "load_param.h"
     
    2828
    2929
    30 CREATE_FACTORY(SpriteParticles, CL_SPRITE_PARTICLES);
    31 
    32 SHELL_COMMAND(texture, SpriteParticles, setMaterialTexture)
    33     ->defaultValues(1, "maps/evil-flower.png");
     30CREATE_FACTORY(SparkParticles, CL_SPARK_PARTICLES);
    3431
    3532using namespace std;
     
    3835 *  standard constructor
    3936 * @param maxCount the Count of particles in the System
    40  * @param type The Type of the SpriteParticles
     37 * @param type The Type of the SparkParticles
    4138*/
    42 SpriteParticles::SpriteParticles (unsigned int maxCount)
    43   : ParticleSystem(maxCount)
     39SparkParticles::SparkParticles (unsigned int maxCount)
     40    : ParticleSystem(maxCount)
    4441{
    4542  this->init();
     
    5047 * @param root: the XML-element to load from
    5148 */
    52 SpriteParticles::SpriteParticles(const TiXmlElement* root)
     49SparkParticles::SparkParticles(const TiXmlElement* root)
    5350{
    5451  this->init();
    5552
    56   this->loadParams(root);
     53  if (root != NULL)
     54    this->loadParams(root);
    5755}
    5856
     
    6058 *  standard deconstructor
    6159*/
    62 SpriteParticles::~SpriteParticles()
     60SparkParticles::~SparkParticles()
    6361{
    6462  // deleting all the living Particles
     
    8078
    8179/**
    82  * @brief initializes the SpriteParticles with default values
     80 * @brief initializes the SparkParticles with default values
    8381*/
    84 void SpriteParticles::init()
     82void SparkParticles::init()
    8583{
    86   this->setClassID(CL_SPRITE_PARTICLES, "SpriteParticles");
     84  this->setClassID(CL_SPARK_PARTICLES, "SparkParticles");
    8785
    8886  this->material = NULL;
     
    9492 * @param root the XML-element to load from.
    9593 */
    96 void SpriteParticles::loadParams(const TiXmlElement* root)
     94void SparkParticles::loadParams(const TiXmlElement* root)
    9795{
    98   SpriteParticles::loadParams(root);
    99 
    100   LoadParam(root, "texture", this, SpriteParticles, setMaterialTexture);
    101 }
    102 
    103 // setting properties
    104 /**
    105  * @brief sets the material to an external material
    106  * @param material: the material to set this material to.
    107  *
    108  * !! important if the extern material gets deleted it MUST be unregistered here or segfault !!
    109 */
    110 void SpriteParticles::setMaterial(Material* material)
    111 {
    112   this->material = *material;
    113 }
    114 
    115 void SpriteParticles::setMaterialTexture(const char* textureFile)
    116 {
    117   this->material.setDiffuseMap(textureFile);
     96  ParticleSystem::loadParams(root);
    11897}
    11998
     
    125104 * This is just the fastest Way to do this, but will most likely be changed in the future.
    126105 */
    127 void SpriteParticles::draw() const
     106void SparkParticles::draw() const
    128107{
    129108  glPushAttrib(GL_ENABLE_BIT);
     
    131110  Particle* drawPart = particles;
    132111
    133   glDisable(GL_LIGHTING);
    134   glMatrixMode(GL_MODELVIEW);
    135112  glDepthMask(GL_FALSE);
    136113
    137   material.select();
    138   glBlendFunc(GL_SRC_ALPHA, GL_DST_ALPHA);
     114  glDisable(GL_LIGHTING);
     115  glEnable(GL_LINE_SMOOTH);
     116  glEnable(GL_BLEND);
    139117
    140   //glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_ENV_MODE, GL_MODULATE);
    141 
    142 
     118  glBegin(GL_LINES);
    143119  while (likely(drawPart != NULL))
    144120  {
    145121    glColor4fv(drawPart->color);
    146     //! @todo implement a faster code for the look-at Camera algorithm.
    147 
    148     const PNode* camera = State::getCamera();  //!< @todo MUST be different
    149     Vector cameraPos = camera->getAbsCoor();
    150     Vector cameraTargetPos = State::getCameraTarget()->getAbsCoor();
    151     Vector view = cameraTargetPos - cameraPos;
    152     Vector up = Vector(0, 1, 0);
    153     up = camera->getAbsDir().apply(up);
    154     Vector h = up.cross(view);
    155     Vector v = h.cross(view);
    156     h.normalize();
    157     v.normalize();
    158     v *= .5 * drawPart->radius;
    159     h *= .5 * drawPart->radius;
    160 
    161     glBegin(GL_TRIANGLE_STRIP);
    162     glTexCoord2i(1, 1);
    163     glVertex3f(drawPart->position.x - h.x - v.x,
    164                drawPart->position.y - h.y - v.y,
    165                drawPart->position.z - h.z - v.z);
    166     glTexCoord2i(0, 1);
    167     glVertex3f(drawPart->position.x - h.x + v.x,
    168                drawPart->position.y - h.y + v.y,
    169                drawPart->position.z - h.z + v.z);
    170     glTexCoord2i(1, 0);
    171     glVertex3f(drawPart->position.x + h.x - v.x,
    172                drawPart->position.y + h.y - v.y,
    173                drawPart->position.z + h.z - v.z);
    174     glTexCoord2i(0, 0);
    175     glVertex3f(drawPart->position.x + h.x + v.x,
    176                drawPart->position.y + h.y + v.y,
    177                drawPart->position.z + h.z + v.z);
    178 
    179     glEnd();
    180 
     122    glVertex3f(drawPart->position.x, drawPart->position.y, drawPart->position.z);
     123    glVertex3f(drawPart->position.x - drawPart->velocity.x * drawPart->radius,
     124               drawPart->position.y - drawPart->velocity.y * drawPart->radius,
     125               drawPart->position.z - drawPart->velocity.z * drawPart->radius);
    181126    drawPart = drawPart->next;
    182127  }
     128  glEnd();
     129
    183130  glDepthMask(GL_TRUE);
    184131  glPopAttrib();
Note: See TracChangeset for help on using the changeset viewer.