Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/trunk/src/world_entities/particles/sprite_particles.cc @ 10621

Last change on this file since 10621 was 10618, checked in by bknecht, 18 years ago

merged cleanup into trunk (only improvements)

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