| [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 | |
|---|
| [6652] | 18 | #include "dot_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 | |
|---|
| [6652] | 30 | CREATE_FACTORY(DotParticles, CL_SPRITE_PARTICLES); |
|---|
| [6621] | 31 | |
|---|
| [6652] | 32 | SHELL_COMMAND(texture, DotParticles, setMaterialTexture) |
|---|
| [5446] | 33 | ->defaultValues(1, "maps/evil-flower.png"); |
|---|
| [4725] | 34 | |
|---|
| [1856] | 35 | using namespace std; |
|---|
| [1853] | 36 | |
|---|
| [3245] | 37 | /** |
|---|
| [4836] | 38 | * standard constructor |
|---|
| 39 | * @param maxCount the Count of particles in the System |
|---|
| [6652] | 40 | * @param type The Type of the DotParticles |
|---|
| [3245] | 41 | */ |
|---|
| [6652] | 42 | DotParticles::DotParticles (unsigned int maxCount) |
|---|
| [6621] | 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 | */ |
|---|
| [6652] | 52 | DotParticles::DotParticles(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 | */ |
|---|
| [6652] | 62 | DotParticles::~DotParticles() |
|---|
| [3543] | 63 | { |
|---|
| [6621] | 64 | // deleting all the living Particles |
|---|
| 65 | while (this->particles) |
|---|
| 66 | { |
|---|
| 67 | Particle* tmpDelPart = this->particles; |
|---|
| 68 | this->particles = this->particles->next; |
|---|
| 69 | delete tmpDelPart; |
|---|
| 70 | } |
|---|
| [4123] | 71 | |
|---|
| [6621] | 72 | // deleting all the dead particles |
|---|
| 73 | while (this->deadList) |
|---|
| 74 | { |
|---|
| 75 | Particle* tmpDelPart = this->deadList; |
|---|
| 76 | this->deadList = this->deadList->next; |
|---|
| 77 | delete tmpDelPart; |
|---|
| 78 | } |
|---|
| [3543] | 79 | } |
|---|
| [1853] | 80 | |
|---|
| [3945] | 81 | /** |
|---|
| [6652] | 82 | * @brief initializes the DotParticles with default values |
|---|
| [4602] | 83 | */ |
|---|
| [6652] | 84 | void DotParticles::init() |
|---|
| [4602] | 85 | { |
|---|
| [6652] | 86 | this->setClassID(CL_SPRITE_PARTICLES, "DotParticles"); |
|---|
| [4602] | 87 | |
|---|
| [6626] | 88 | this->material.setDiffuseMap("maps/radial-trans-noise.png"); |
|---|
| [4602] | 89 | } |
|---|
| 90 | |
|---|
| 91 | |
|---|
| 92 | /** |
|---|
| 93 | * loads Parameters from a TiXmlElement |
|---|
| 94 | * @param root the XML-element to load from. |
|---|
| 95 | */ |
|---|
| [6652] | 96 | void DotParticles::loadParams(const TiXmlElement* root) |
|---|
| [4602] | 97 | { |
|---|
| [6623] | 98 | ParticleSystem::loadParams(root); |
|---|
| [4602] | 99 | |
|---|
| [6652] | 100 | LoadParam(root, "texture", this, DotParticles, setMaterialTexture); |
|---|
| [4602] | 101 | } |
|---|
| [4727] | 102 | |
|---|
| [4478] | 103 | /** |
|---|
| [6626] | 104 | * @brief sets the Texutre that is placed onto the particles |
|---|
| [6652] | 105 | * @param textureFile the Texture to load onto these DotParticles |
|---|
| [6626] | 106 | */ |
|---|
| [6652] | 107 | void DotParticles::setMaterialTexture(const char* textureFile) |
|---|
| [5446] | 108 | { |
|---|
| [6621] | 109 | this->material.setDiffuseMap(textureFile); |
|---|
| [5446] | 110 | } |
|---|
| 111 | |
|---|
| [3938] | 112 | /** |
|---|
| [6621] | 113 | * @brief draws all the Particles of this System |
|---|
| 114 | * |
|---|
| 115 | * The Cases in this Function all do the same: |
|---|
| 116 | * Drawing all the particles with the appropriate Type. |
|---|
| 117 | * This is just the fastest Way to do this, but will most likely be changed in the future. |
|---|
| [4338] | 118 | */ |
|---|
| [6652] | 119 | void DotParticles::draw() const |
|---|
| [4338] | 120 | { |
|---|
| [4176] | 121 | glPushAttrib(GL_ENABLE_BIT); |
|---|
| [4338] | 122 | |
|---|
| [4597] | 123 | |
|---|
| [6628] | 124 | GLboolean checkLight = false; |
|---|
| 125 | glGetBooleanv(GL_LIGHTING, &checkLight); |
|---|
| [6651] | 126 | // if (checkLight == GL_TRUE) |
|---|
| 127 | // glDisable(GL_LIGHTING); |
|---|
| [6621] | 128 | glMatrixMode(GL_MODELVIEW); |
|---|
| 129 | glDepthMask(GL_FALSE); |
|---|
| [4338] | 130 | |
|---|
| [6621] | 131 | material.select(); |
|---|
| 132 | glBlendFunc(GL_SRC_ALPHA, GL_DST_ALPHA); |
|---|
| [4863] | 133 | |
|---|
| [6652] | 134 | Particle* drawPart = particles; |
|---|
| [6621] | 135 | //glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_ENV_MODE, GL_MODULATE); |
|---|
| [4338] | 136 | |
|---|
| [6652] | 137 | glBegin(GL_POINTS); |
|---|
| [6621] | 138 | while (likely(drawPart != NULL)) |
|---|
| 139 | { |
|---|
| 140 | glColor4fv(drawPart->color); |
|---|
| [6652] | 141 | glVertex3f(drawPart->position.x, drawPart->position.y, drawPart->position.z); |
|---|
| [4338] | 142 | |
|---|
| [6621] | 143 | drawPart = drawPart->next; |
|---|
| [4663] | 144 | } |
|---|
| [6652] | 145 | glEnd(); |
|---|
| [6621] | 146 | glDepthMask(GL_TRUE); |
|---|
| [4176] | 147 | glPopAttrib(); |
|---|
| [3932] | 148 | } |
|---|