[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 | |
---|
[7193] | 20 | #include "util/loading/load_param.h" |
---|
| 21 | #include "util/loading/factory.h" |
---|
[3942] | 22 | #include "material.h" |
---|
[4338] | 23 | #include "state.h" |
---|
[5446] | 24 | #include "shell_command.h" |
---|
[3930] | 25 | |
---|
[4338] | 26 | |
---|
[10114] | 27 | |
---|
| 28 | ObjectListDefinition(SpriteParticles); |
---|
[9709] | 29 | CREATE_FACTORY(SpriteParticles); |
---|
[6621] | 30 | |
---|
| 31 | SHELL_COMMAND(texture, SpriteParticles, setMaterialTexture) |
---|
[7198] | 32 | ->defaultValues("maps/evil-flower.png"); |
---|
[4725] | 33 | |
---|
[1853] | 34 | |
---|
[9406] | 35 | |
---|
[3245] | 36 | /** |
---|
[4836] | 37 | * standard constructor |
---|
| 38 | * @param maxCount the Count of particles in the System |
---|
[6621] | 39 | * @param type The Type of the SpriteParticles |
---|
[3245] | 40 | */ |
---|
[6621] | 41 | SpriteParticles::SpriteParticles (unsigned int maxCount) |
---|
| 42 | : ParticleSystem(maxCount) |
---|
[3365] | 43 | { |
---|
[4602] | 44 | this->init(); |
---|
[3365] | 45 | } |
---|
[1853] | 46 | |
---|
[4677] | 47 | /** |
---|
[5445] | 48 | * @brief creates a Particle System out of a XML-element |
---|
| 49 | * @param root: the XML-element to load from |
---|
[4677] | 50 | */ |
---|
[6621] | 51 | SpriteParticles::SpriteParticles(const TiXmlElement* root) |
---|
[4602] | 52 | { |
---|
| 53 | this->init(); |
---|
[6623] | 54 | if (root != NULL) |
---|
| 55 | this->loadParams(root); |
---|
[4602] | 56 | } |
---|
[1853] | 57 | |
---|
[3245] | 58 | /** |
---|
[4836] | 59 | * standard deconstructor |
---|
[3245] | 60 | */ |
---|
[6621] | 61 | SpriteParticles::~SpriteParticles() |
---|
[6653] | 62 | { } |
---|
[4123] | 63 | |
---|
[3945] | 64 | /** |
---|
[6621] | 65 | * @brief initializes the SpriteParticles with default values |
---|
[4602] | 66 | */ |
---|
[6621] | 67 | void SpriteParticles::init() |
---|
[4602] | 68 | { |
---|
[9686] | 69 | this->registerObject(this, SpriteParticles::_objectList); |
---|
[4602] | 70 | |
---|
[6626] | 71 | this->material.setDiffuseMap("maps/radial-trans-noise.png"); |
---|
[4602] | 72 | } |
---|
| 73 | |
---|
| 74 | |
---|
| 75 | /** |
---|
| 76 | * loads Parameters from a TiXmlElement |
---|
| 77 | * @param root the XML-element to load from. |
---|
| 78 | */ |
---|
[6621] | 79 | void SpriteParticles::loadParams(const TiXmlElement* root) |
---|
[4602] | 80 | { |
---|
[6623] | 81 | ParticleSystem::loadParams(root); |
---|
[4602] | 82 | |
---|
[6621] | 83 | LoadParam(root, "texture", this, SpriteParticles, setMaterialTexture); |
---|
[4602] | 84 | } |
---|
[4727] | 85 | |
---|
[4478] | 86 | /** |
---|
[6626] | 87 | * @brief sets the Texutre that is placed onto the particles |
---|
| 88 | * @param textureFile the Texture to load onto these SpriteParticles |
---|
| 89 | */ |
---|
[7221] | 90 | void SpriteParticles::setMaterialTexture(const std::string& textureFile) |
---|
[5446] | 91 | { |
---|
[6621] | 92 | this->material.setDiffuseMap(textureFile); |
---|
[5446] | 93 | } |
---|
| 94 | |
---|
[3938] | 95 | /** |
---|
[6621] | 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. |
---|
[4338] | 101 | */ |
---|
[6621] | 102 | void SpriteParticles::draw() const |
---|
[4338] | 103 | { |
---|
| 104 | |
---|
[4176] | 105 | Particle* drawPart = particles; |
---|
[6799] | 106 | this->material.select(); |
---|
[4597] | 107 | |
---|
[6628] | 108 | GLboolean checkLight = false; |
---|
| 109 | glGetBooleanv(GL_LIGHTING, &checkLight); |
---|
[6846] | 110 | glPushAttrib(GL_LIGHTING_BIT); |
---|
[6729] | 111 | if (checkLight == GL_TRUE) |
---|
| 112 | glDisable(GL_LIGHTING); |
---|
[6812] | 113 | |
---|
| 114 | glDepthMask(GL_FALSE); |
---|
| 115 | /* |
---|
[6799] | 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); |
---|
[6812] | 124 | */ |
---|
[6799] | 125 | //glDepthMask(GL_FALSE); |
---|
| 126 | //glBlendFunc(GL_SRC_ALPHA, GL_DST_ALPHA); |
---|
[4338] | 127 | |
---|
[6729] | 128 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_ENV_MODE, GL_MODULATE); |
---|
[4338] | 129 | |
---|
[4597] | 130 | |
---|
[6621] | 131 | while (likely(drawPart != NULL)) |
---|
| 132 | { |
---|
| 133 | glColor4fv(drawPart->color); |
---|
| 134 | //! @todo implement a faster code for the look-at Camera algorithm. |
---|
[4338] | 135 | |
---|
[7014] | 136 | const PNode* camera = State::getCameraNode(); //!< @todo MUST be different |
---|
[6621] | 137 | Vector cameraPos = camera->getAbsCoor(); |
---|
[7014] | 138 | Vector cameraTargetPos = State::getCameraTargetNode()->getAbsCoor(); |
---|
[6621] | 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; |
---|
[4338] | 148 | |
---|
[6621] | 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); |
---|
[4338] | 166 | |
---|
[6621] | 167 | glEnd(); |
---|
[4597] | 168 | |
---|
[6621] | 169 | drawPart = drawPart->next; |
---|
[4663] | 170 | } |
---|
[6812] | 171 | glDepthMask(GL_TRUE); |
---|
[4176] | 172 | glPopAttrib(); |
---|
[3932] | 173 | } |
---|