[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" |
---|
[10532] | 25 | #include "camera.h" |
---|
| 26 | #include "cameraman.h" |
---|
[3930] | 27 | |
---|
[4338] | 28 | |
---|
[10114] | 29 | |
---|
| 30 | ObjectListDefinition(SpriteParticles); |
---|
[9709] | 31 | CREATE_FACTORY(SpriteParticles); |
---|
[6621] | 32 | |
---|
[10510] | 33 | SHELL_COMMAND(texture, SpriteParticles, setMaterialTexture); |
---|
| 34 | // ->defaultValues("textures/evil-flower.png"); |
---|
[4725] | 35 | |
---|
[1853] | 36 | |
---|
[9406] | 37 | |
---|
[3245] | 38 | /** |
---|
[4836] | 39 | * standard constructor |
---|
| 40 | * @param maxCount the Count of particles in the System |
---|
[6621] | 41 | * @param type The Type of the SpriteParticles |
---|
[3245] | 42 | */ |
---|
[6621] | 43 | SpriteParticles::SpriteParticles (unsigned int maxCount) |
---|
| 44 | : ParticleSystem(maxCount) |
---|
[3365] | 45 | { |
---|
[4602] | 46 | this->init(); |
---|
[3365] | 47 | } |
---|
[1853] | 48 | |
---|
[4677] | 49 | /** |
---|
[5445] | 50 | * @brief creates a Particle System out of a XML-element |
---|
| 51 | * @param root: the XML-element to load from |
---|
[4677] | 52 | */ |
---|
[6621] | 53 | SpriteParticles::SpriteParticles(const TiXmlElement* root) |
---|
[4602] | 54 | { |
---|
| 55 | this->init(); |
---|
[6623] | 56 | if (root != NULL) |
---|
| 57 | this->loadParams(root); |
---|
[4602] | 58 | } |
---|
[1853] | 59 | |
---|
[3245] | 60 | /** |
---|
[4836] | 61 | * standard deconstructor |
---|
[3245] | 62 | */ |
---|
[6621] | 63 | SpriteParticles::~SpriteParticles() |
---|
[6653] | 64 | { } |
---|
[4123] | 65 | |
---|
[3945] | 66 | /** |
---|
[6621] | 67 | * @brief initializes the SpriteParticles with default values |
---|
[4602] | 68 | */ |
---|
[6621] | 69 | void SpriteParticles::init() |
---|
[4602] | 70 | { |
---|
[9686] | 71 | this->registerObject(this, SpriteParticles::_objectList); |
---|
[4602] | 72 | |
---|
[10317] | 73 | this->material.setDiffuseMap("textures/radial-trans-noise.png"); |
---|
[4602] | 74 | } |
---|
| 75 | |
---|
| 76 | |
---|
| 77 | /** |
---|
| 78 | * loads Parameters from a TiXmlElement |
---|
| 79 | * @param root the XML-element to load from. |
---|
| 80 | */ |
---|
[6621] | 81 | void SpriteParticles::loadParams(const TiXmlElement* root) |
---|
[4602] | 82 | { |
---|
[6623] | 83 | ParticleSystem::loadParams(root); |
---|
[4602] | 84 | |
---|
[6621] | 85 | LoadParam(root, "texture", this, SpriteParticles, setMaterialTexture); |
---|
[4602] | 86 | } |
---|
[4727] | 87 | |
---|
[4478] | 88 | /** |
---|
[6626] | 89 | * @brief sets the Texutre that is placed onto the particles |
---|
| 90 | * @param textureFile the Texture to load onto these SpriteParticles |
---|
| 91 | */ |
---|
[7221] | 92 | void SpriteParticles::setMaterialTexture(const std::string& textureFile) |
---|
[5446] | 93 | { |
---|
[6621] | 94 | this->material.setDiffuseMap(textureFile); |
---|
[5446] | 95 | } |
---|
| 96 | |
---|
[3938] | 97 | /** |
---|
[6621] | 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. |
---|
[4338] | 103 | */ |
---|
[6621] | 104 | void SpriteParticles::draw() const |
---|
[4338] | 105 | { |
---|
| 106 | |
---|
[4176] | 107 | Particle* drawPart = particles; |
---|
[6799] | 108 | this->material.select(); |
---|
[4597] | 109 | |
---|
[6628] | 110 | GLboolean checkLight = false; |
---|
| 111 | glGetBooleanv(GL_LIGHTING, &checkLight); |
---|
[6846] | 112 | glPushAttrib(GL_LIGHTING_BIT); |
---|
[6729] | 113 | if (checkLight == GL_TRUE) |
---|
| 114 | glDisable(GL_LIGHTING); |
---|
[6812] | 115 | |
---|
| 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 | |
---|
[10532] | 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 |
---|
[6621] | 145 | Vector cameraPos = camera->getAbsCoor(); |
---|
[10532] | 146 | Vector cameraTargetPos = camera->getTarget()->getAbsCoor(); |
---|
[6621] | 147 | Vector view = cameraTargetPos - cameraPos; |
---|
[10532] | 148 | |
---|
[6621] | 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; |
---|
[4338] | 157 | |
---|
[6621] | 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); |
---|
[4338] | 175 | |
---|
[6621] | 176 | glEnd(); |
---|
[4597] | 177 | |
---|
[6621] | 178 | drawPart = drawPart->next; |
---|
[4663] | 179 | } |
---|
[6812] | 180 | glDepthMask(GL_TRUE); |
---|
[4176] | 181 | glPopAttrib(); |
---|
[3932] | 182 | } |
---|