Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

Last change on this file since 10554 was 10532, checked in by stefalie, 18 years ago

spriteparticles-cam-bug fixxed

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 "camera.h"
26#include "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    const CameraMan* man = State::getCameraman();
144    const Camera* camera = man->getCurrentCam(); //!< @todo MUST be different
145    Vector cameraPos = camera->getAbsCoor();
146    Vector cameraTargetPos = camera->getTarget()->getAbsCoor();
147    Vector view = cameraTargetPos - cameraPos;
148
149    Vector up = Vector(0, 1, 0);
150    up = camera->getAbsDir().apply(up);
151    Vector h = up.cross(view);
152    Vector v = h.cross(view);
153    h.normalize();
154    v.normalize();
155    v *= .5 * drawPart->radius;
156    h *= .5 * drawPart->radius;
157
158    glBegin(GL_TRIANGLE_STRIP);
159    glTexCoord2i(1, 1);
160    glVertex3f(drawPart->position.x - h.x - v.x,
161               drawPart->position.y - h.y - v.y,
162               drawPart->position.z - h.z - v.z);
163    glTexCoord2i(0, 1);
164    glVertex3f(drawPart->position.x - h.x + v.x,
165               drawPart->position.y - h.y + v.y,
166               drawPart->position.z - h.z + v.z);
167    glTexCoord2i(1, 0);
168    glVertex3f(drawPart->position.x + h.x - v.x,
169               drawPart->position.y + h.y - v.y,
170               drawPart->position.z + h.z - v.z);
171    glTexCoord2i(0, 0);
172    glVertex3f(drawPart->position.x + h.x + v.x,
173               drawPart->position.y + h.y + v.y,
174               drawPart->position.z + h.z + v.z);
175
176    glEnd();
177
178    drawPart = drawPart->next;
179  }
180  glDepthMask(GL_TRUE);
181  glPopAttrib();
182}
Note: See TracBrowser for help on using the repository browser.