Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/trunk/src/lib/particles/spark_particles.cc @ 6623

Last change on this file since 6623 was 6623, checked in by bensch, 18 years ago

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

File size: 2.9 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: Benjamin Grauer
13   co-programmer: ...
14*/
15
16#define DEBUG_SPECIAL_MODULE DEBUG_MODULE_GRAPHICS
17
18#include "spark_particles.h"
19
20#include "load_param.h"
21#include "factory.h"
22#include "material.h"
23#include "state.h"
24#include "shell_command.h"
25
26#include "parser/tinyxml/tinyxml.h"
27#include <algorithm>
28
29
30CREATE_FACTORY(SparkParticles, CL_SPARK_PARTICLES);
31
32using namespace std;
33
34/**
35 *  standard constructor
36 * @param maxCount the Count of particles in the System
37 * @param type The Type of the SparkParticles
38*/
39SparkParticles::SparkParticles (unsigned int maxCount)
40    : ParticleSystem(maxCount)
41{
42  this->init();
43}
44
45/**
46 * @brief creates a Particle System out of a XML-element
47 * @param root: the XML-element to load from
48 */
49SparkParticles::SparkParticles(const TiXmlElement* root)
50{
51  this->init();
52
53  if (root != NULL)
54    this->loadParams(root);
55}
56
57/**
58 *  standard deconstructor
59*/
60SparkParticles::~SparkParticles()
61{
62  // deleting all the living Particles
63  while (this->particles)
64  {
65    Particle* tmpDelPart = this->particles;
66    this->particles = this->particles->next;
67    delete tmpDelPart;
68  }
69
70  // deleting all the dead particles
71  while (this->deadList)
72  {
73    Particle* tmpDelPart = this->deadList;
74    this->deadList = this->deadList->next;
75    delete tmpDelPart;
76  }
77}
78
79/**
80 * @brief initializes the SparkParticles with default values
81*/
82void SparkParticles::init()
83{
84  this->setClassID(CL_SPARK_PARTICLES, "SparkParticles");
85
86  this->material = NULL;
87}
88
89
90/**
91 * loads Parameters from a TiXmlElement
92 * @param root the XML-element to load from.
93 */
94void SparkParticles::loadParams(const TiXmlElement* root)
95{
96  ParticleSystem::loadParams(root);
97}
98
99/**
100 * @brief draws all the Particles of this System
101 *
102 * The Cases in this Function all do the same:
103 * Drawing all the particles with the appropriate Type.
104 * This is just the fastest Way to do this, but will most likely be changed in the future.
105 */
106void SparkParticles::draw() const
107{
108  glPushAttrib(GL_ENABLE_BIT);
109
110  Particle* drawPart = particles;
111
112  glDepthMask(GL_FALSE);
113
114  glDisable(GL_LIGHTING);
115  glEnable(GL_LINE_SMOOTH);
116  glEnable(GL_BLEND);
117
118  glBegin(GL_LINES);
119  while (likely(drawPart != NULL))
120  {
121    glColor4fv(drawPart->color);
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);
126    drawPart = drawPart->next;
127  }
128  glEnd();
129
130  glDepthMask(GL_TRUE);
131  glPopAttrib();
132}
Note: See TracBrowser for help on using the repository browser.