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 "sprite_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 | |
---|
27 | |
---|
28 | ObjectListDefinition(SpriteParticles); |
---|
29 | CREATE_FACTORY(SpriteParticles); |
---|
30 | |
---|
31 | SHELL_COMMAND(texture, SpriteParticles, setMaterialTexture) |
---|
32 | ->defaultValues("maps/evil-flower.png"); |
---|
33 | |
---|
34 | |
---|
35 | |
---|
36 | /** |
---|
37 | * standard constructor |
---|
38 | * @param maxCount the Count of particles in the System |
---|
39 | * @param type The Type of the SpriteParticles |
---|
40 | */ |
---|
41 | SpriteParticles::SpriteParticles (unsigned int maxCount) |
---|
42 | : ParticleSystem(maxCount) |
---|
43 | { |
---|
44 | this->init(); |
---|
45 | } |
---|
46 | |
---|
47 | /** |
---|
48 | * @brief creates a Particle System out of a XML-element |
---|
49 | * @param root: the XML-element to load from |
---|
50 | */ |
---|
51 | SpriteParticles::SpriteParticles(const TiXmlElement* root) |
---|
52 | { |
---|
53 | this->init(); |
---|
54 | if (root != NULL) |
---|
55 | this->loadParams(root); |
---|
56 | } |
---|
57 | |
---|
58 | /** |
---|
59 | * standard deconstructor |
---|
60 | */ |
---|
61 | SpriteParticles::~SpriteParticles() |
---|
62 | { } |
---|
63 | |
---|
64 | /** |
---|
65 | * @brief initializes the SpriteParticles with default values |
---|
66 | */ |
---|
67 | void SpriteParticles::init() |
---|
68 | { |
---|
69 | this->registerObject(this, SpriteParticles::_objectList); |
---|
70 | |
---|
71 | this->material.setDiffuseMap("maps/radial-trans-noise.png"); |
---|
72 | } |
---|
73 | |
---|
74 | |
---|
75 | /** |
---|
76 | * loads Parameters from a TiXmlElement |
---|
77 | * @param root the XML-element to load from. |
---|
78 | */ |
---|
79 | void SpriteParticles::loadParams(const TiXmlElement* root) |
---|
80 | { |
---|
81 | ParticleSystem::loadParams(root); |
---|
82 | |
---|
83 | LoadParam(root, "texture", this, SpriteParticles, setMaterialTexture); |
---|
84 | } |
---|
85 | |
---|
86 | /** |
---|
87 | * @brief sets the Texutre that is placed onto the particles |
---|
88 | * @param textureFile the Texture to load onto these SpriteParticles |
---|
89 | */ |
---|
90 | void SpriteParticles::setMaterialTexture(const std::string& textureFile) |
---|
91 | { |
---|
92 | this->material.setDiffuseMap(textureFile); |
---|
93 | } |
---|
94 | |
---|
95 | /** |
---|
96 | * @brief draws all the Particles of this System |
---|
97 | * |
---|
98 | * The Cases in this Function all do the same: |
---|
99 | * Drawing all the particles with the appropriate Type. |
---|
100 | * This is just the fastest Way to do this, but will most likely be changed in the future. |
---|
101 | */ |
---|
102 | void SpriteParticles::draw() const |
---|
103 | { |
---|
104 | |
---|
105 | Particle* drawPart = particles; |
---|
106 | this->material.select(); |
---|
107 | |
---|
108 | GLboolean checkLight = false; |
---|
109 | glGetBooleanv(GL_LIGHTING, &checkLight); |
---|
110 | glPushAttrib(GL_LIGHTING_BIT); |
---|
111 | if (checkLight == GL_TRUE) |
---|
112 | glDisable(GL_LIGHTING); |
---|
113 | |
---|
114 | glDepthMask(GL_FALSE); |
---|
115 | /* |
---|
116 | glClearDepth(1.0); |
---|
117 | glDepthFunc(GL_LEQUAL); |
---|
118 | glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); |
---|
119 | glEnable(GL_BLEND); |
---|
120 | glAlphaFunc(GL_GREATER,0.1); |
---|
121 | glEnable(GL_ALPHA_TEST); |
---|
122 | glEnable(GL_TEXTURE_2D); |
---|
123 | glEnable(GL_CULL_FACE); |
---|
124 | */ |
---|
125 | //glDepthMask(GL_FALSE); |
---|
126 | //glBlendFunc(GL_SRC_ALPHA, GL_DST_ALPHA); |
---|
127 | |
---|
128 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_ENV_MODE, GL_MODULATE); |
---|
129 | |
---|
130 | |
---|
131 | while (likely(drawPart != NULL)) |
---|
132 | { |
---|
133 | glColor4fv(drawPart->color); |
---|
134 | //! @todo implement a faster code for the look-at Camera algorithm. |
---|
135 | |
---|
136 | const PNode* camera = State::getCameraNode(); //!< @todo MUST be different |
---|
137 | Vector cameraPos = camera->getAbsCoor(); |
---|
138 | Vector cameraTargetPos = State::getCameraTargetNode()->getAbsCoor(); |
---|
139 | Vector view = cameraTargetPos - cameraPos; |
---|
140 | Vector up = Vector(0, 1, 0); |
---|
141 | up = camera->getAbsDir().apply(up); |
---|
142 | Vector h = up.cross(view); |
---|
143 | Vector v = h.cross(view); |
---|
144 | h.normalize(); |
---|
145 | v.normalize(); |
---|
146 | v *= .5 * drawPart->radius; |
---|
147 | h *= .5 * drawPart->radius; |
---|
148 | |
---|
149 | glBegin(GL_TRIANGLE_STRIP); |
---|
150 | glTexCoord2i(1, 1); |
---|
151 | glVertex3f(drawPart->position.x - h.x - v.x, |
---|
152 | drawPart->position.y - h.y - v.y, |
---|
153 | drawPart->position.z - h.z - v.z); |
---|
154 | glTexCoord2i(0, 1); |
---|
155 | glVertex3f(drawPart->position.x - h.x + v.x, |
---|
156 | drawPart->position.y - h.y + v.y, |
---|
157 | drawPart->position.z - h.z + v.z); |
---|
158 | glTexCoord2i(1, 0); |
---|
159 | glVertex3f(drawPart->position.x + h.x - v.x, |
---|
160 | drawPart->position.y + h.y - v.y, |
---|
161 | drawPart->position.z + h.z - v.z); |
---|
162 | glTexCoord2i(0, 0); |
---|
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 | |
---|
167 | glEnd(); |
---|
168 | |
---|
169 | drawPart = drawPart->next; |
---|
170 | } |
---|
171 | glDepthMask(GL_TRUE); |
---|
172 | glPopAttrib(); |
---|
173 | } |
---|