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 "util/loading/load_param.h" |
---|
21 | #include "util/loading/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 | |
---|
30 | |
---|
31 | using namespace std; |
---|
32 | |
---|
33 | CREATE_FACTORY(SparkParticles, CL_SPARK_PARTICLES); |
---|
34 | |
---|
35 | /** |
---|
36 | * standard constructor |
---|
37 | * @param maxCount the Count of particles in the System |
---|
38 | * @param type The Type of the SparkParticles |
---|
39 | */ |
---|
40 | SparkParticles::SparkParticles (unsigned int maxCount) |
---|
41 | : ParticleSystem(maxCount) |
---|
42 | { |
---|
43 | this->init(); |
---|
44 | } |
---|
45 | |
---|
46 | /** |
---|
47 | * @brief creates a Particle System out of a XML-element |
---|
48 | * @param root: the XML-element to load from |
---|
49 | */ |
---|
50 | SparkParticles::SparkParticles(const TiXmlElement* root) |
---|
51 | { |
---|
52 | this->init(); |
---|
53 | |
---|
54 | if (root != NULL) |
---|
55 | this->loadParams(root); |
---|
56 | } |
---|
57 | |
---|
58 | /** |
---|
59 | * standard deconstructor |
---|
60 | */ |
---|
61 | SparkParticles::~SparkParticles() |
---|
62 | { } |
---|
63 | |
---|
64 | /** |
---|
65 | * @brief initializes the SparkParticles with default values |
---|
66 | */ |
---|
67 | void SparkParticles::init() |
---|
68 | { |
---|
69 | this->setClassID(CL_SPARK_PARTICLES, "SparkParticles"); |
---|
70 | |
---|
71 | this->material = NULL; |
---|
72 | } |
---|
73 | |
---|
74 | |
---|
75 | /** |
---|
76 | * loads Parameters from a TiXmlElement |
---|
77 | * @param root the XML-element to load from. |
---|
78 | */ |
---|
79 | void SparkParticles::loadParams(const TiXmlElement* root) |
---|
80 | { |
---|
81 | ParticleSystem::loadParams(root); |
---|
82 | } |
---|
83 | |
---|
84 | /** |
---|
85 | * @brief draws all the Particles of this System |
---|
86 | * |
---|
87 | * The Cases in this Function all do the same: |
---|
88 | * Drawing all the particles with the appropriate Type. |
---|
89 | * This is just the fastest Way to do this, but will most likely be changed in the future. |
---|
90 | */ |
---|
91 | void SparkParticles::draw() const |
---|
92 | { |
---|
93 | |
---|
94 | Particle* drawPart = particles; |
---|
95 | |
---|
96 | glDepthMask(GL_FALSE); |
---|
97 | glPushAttrib(GL_ENABLE_BIT); |
---|
98 | |
---|
99 | glDisable(GL_LIGHTING); |
---|
100 | glDisable(GL_TEXTURE_2D); |
---|
101 | |
---|
102 | glEnable(GL_LINE_SMOOTH); |
---|
103 | glEnable(GL_BLEND); |
---|
104 | glBlendFunc(GL_SRC_ALPHA, GL_DST_ALPHA); |
---|
105 | |
---|
106 | glLineWidth(2.0); |
---|
107 | glBegin(GL_LINES); |
---|
108 | while (likely(drawPart != NULL)) |
---|
109 | { |
---|
110 | // printf("%f %f %f %f\n", drawPart->color[0], drawPart->color[1], drawPart->color[2], drawPart->color[3]); |
---|
111 | glColor4fv(drawPart->color); |
---|
112 | glVertex3f(drawPart->position.x, drawPart->position.y, drawPart->position.z); |
---|
113 | glVertex3f(drawPart->position.x - drawPart->velocity.x * drawPart->radius, |
---|
114 | drawPart->position.y - drawPart->velocity.y * drawPart->radius, |
---|
115 | drawPart->position.z - drawPart->velocity.z * drawPart->radius); |
---|
116 | drawPart = drawPart->next; |
---|
117 | } |
---|
118 | glEnd(); |
---|
119 | |
---|
120 | glDepthMask(GL_TRUE); |
---|
121 | glPopAttrib(); |
---|
122 | } |
---|