Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/trunk/src/lib/particles/sprite_particles.cc @ 6818

Last change on this file since 6818 was 6812, checked in by bensch, 19 years ago

trunk: Particles should work again

File size: 4.4 KB
RevLine 
[4597]1/*
[1853]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.
[1855]10
11   ### File Specific:
[3925]12   main-programmer: Benjamin Grauer
[1855]13   co-programmer: ...
[1853]14*/
15
[5357]16#define DEBUG_SPECIAL_MODULE DEBUG_MODULE_GRAPHICS
[1853]17
[6621]18#include "sprite_particles.h"
[1853]19
[5155]20#include "load_param.h"
[5652]21#include "factory.h"
[3942]22#include "material.h"
[4338]23#include "state.h"
[5446]24#include "shell_command.h"
[3930]25
[5944]26#include "parser/tinyxml/tinyxml.h"
[6612]27#include <algorithm>
[4338]28
[6612]29
[6621]30CREATE_FACTORY(SpriteParticles, CL_SPRITE_PARTICLES);
31
32SHELL_COMMAND(texture, SpriteParticles, setMaterialTexture)
[5446]33    ->defaultValues(1, "maps/evil-flower.png");
[4725]34
[1856]35using namespace std;
[1853]36
[3245]37/**
[4836]38 *  standard constructor
39 * @param maxCount the Count of particles in the System
[6621]40 * @param type The Type of the SpriteParticles
[3245]41*/
[6621]42SpriteParticles::SpriteParticles (unsigned int maxCount)
43  : ParticleSystem(maxCount)
[3365]44{
[4602]45  this->init();
[3365]46}
[1853]47
[4677]48/**
[5445]49 * @brief creates a Particle System out of a XML-element
50 * @param root: the XML-element to load from
[4677]51 */
[6621]52SpriteParticles::SpriteParticles(const TiXmlElement* root)
[4602]53{
54  this->init();
[6623]55  if (root != NULL)
56    this->loadParams(root);
[4602]57}
[1853]58
[3245]59/**
[4836]60 *  standard deconstructor
[3245]61*/
[6621]62SpriteParticles::~SpriteParticles()
[6653]63{ }
[4123]64
[3945]65/**
[6621]66 * @brief initializes the SpriteParticles with default values
[4602]67*/
[6621]68void SpriteParticles::init()
[4602]69{
[6621]70  this->setClassID(CL_SPRITE_PARTICLES, "SpriteParticles");
[4602]71
[6626]72  this->material.setDiffuseMap("maps/radial-trans-noise.png");
[4602]73}
74
75
76/**
77 * loads Parameters from a TiXmlElement
78 * @param root the XML-element to load from.
79 */
[6621]80void SpriteParticles::loadParams(const TiXmlElement* root)
[4602]81{
[6623]82  ParticleSystem::loadParams(root);
[4602]83
[6621]84  LoadParam(root, "texture", this, SpriteParticles, setMaterialTexture);
[4602]85}
[4727]86
[4478]87/**
[6626]88 * @brief sets the Texutre that is placed onto the particles
89 * @param textureFile the Texture to load onto these SpriteParticles
90 */
[6621]91void SpriteParticles::setMaterialTexture(const char* textureFile)
[5446]92{
[6621]93  this->material.setDiffuseMap(textureFile);
[5446]94}
95
[3938]96/**
[6621]97 * @brief draws all the Particles of this System
98 *
99 * The Cases in this Function all do the same:
100 * Drawing all the particles with the appropriate Type.
101 * This is just the fastest Way to do this, but will most likely be changed in the future.
[4338]102 */
[6621]103void SpriteParticles::draw() const
[4338]104{
[4176]105  glPushAttrib(GL_ENABLE_BIT);
[4338]106
[4176]107  Particle* drawPart = particles;
[6799]108  this->material.select();
[4597]109
[6628]110  GLboolean checkLight = false;
111  glGetBooleanv(GL_LIGHTING, &checkLight);
[6729]112  if (checkLight == GL_TRUE)
113    glDisable(GL_LIGHTING);
[6812]114
[6799]115  glEnable(GL_ALPHA_TEST);
[6812]116  glDepthMask(GL_FALSE);
117  /*
[6799]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);
[6812]126  */
[6799]127  //glDepthMask(GL_FALSE);
128//glBlendFunc(GL_SRC_ALPHA, GL_DST_ALPHA);
[4338]129
[6729]130  glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_ENV_MODE, GL_MODULATE);
[4338]131
[4597]132
[6621]133  while (likely(drawPart != NULL))
134  {
135    glColor4fv(drawPart->color);
136    //! @todo implement a faster code for the look-at Camera algorithm.
[4338]137
[6621]138    const PNode* camera = State::getCamera();  //!< @todo MUST be different
139    Vector cameraPos = camera->getAbsCoor();
140    Vector cameraTargetPos = State::getCameraTarget()->getAbsCoor();
141    Vector view = cameraTargetPos - cameraPos;
142    Vector up = Vector(0, 1, 0);
143    up = camera->getAbsDir().apply(up);
144    Vector h = up.cross(view);
145    Vector v = h.cross(view);
146    h.normalize();
147    v.normalize();
148    v *= .5 * drawPart->radius;
149    h *= .5 * drawPart->radius;
[4338]150
[6621]151    glBegin(GL_TRIANGLE_STRIP);
152    glTexCoord2i(1, 1);
153    glVertex3f(drawPart->position.x - h.x - v.x,
154               drawPart->position.y - h.y - v.y,
155               drawPart->position.z - h.z - v.z);
156    glTexCoord2i(0, 1);
157    glVertex3f(drawPart->position.x - h.x + v.x,
158               drawPart->position.y - h.y + v.y,
159               drawPart->position.z - h.z + v.z);
160    glTexCoord2i(1, 0);
161    glVertex3f(drawPart->position.x + h.x - v.x,
162               drawPart->position.y + h.y - v.y,
163               drawPart->position.z + h.z - v.z);
164    glTexCoord2i(0, 0);
165    glVertex3f(drawPart->position.x + h.x + v.x,
166               drawPart->position.y + h.y + v.y,
167               drawPart->position.z + h.z + v.z);
[4338]168
[6621]169    glEnd();
[4597]170
[6621]171    drawPart = drawPart->next;
[4663]172  }
[6812]173  glDepthMask(GL_TRUE);
[4176]174  glPopAttrib();
[3932]175}
Note: See TracBrowser for help on using the repository browser.