Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 6629 in orxonox.OLD for trunk/src/lib/particles/model_particles.cc


Ignore:
Timestamp:
Jan 20, 2006, 8:11:04 PM (18 years ago)
Author:
bensch
Message:

trunk: particles: precache and ModelParticles

File:
1 copied

Legend:

Unmodified
Added
Removed
  • trunk/src/lib/particles/model_particles.cc

    r6628 r6629  
    1616#define DEBUG_SPECIAL_MODULE DEBUG_MODULE_GRAPHICS
    1717
    18 #include "sprite_particles.h"
     18#include "model_particles.h"
    1919
    2020#include "load_param.h"
     
    2828
    2929
    30 CREATE_FACTORY(SpriteParticles, CL_SPRITE_PARTICLES);
     30CREATE_FACTORY(ModelParticles, CL_MODEL_PARTICLES);
    3131
    32 SHELL_COMMAND(texture, SpriteParticles, setMaterialTexture)
    33     ->defaultValues(1, "maps/evil-flower.png");
     32SHELL_COMMAND(texture, ModelParticles, setMaterialTexture)
     33->defaultValues(1, "maps/evil-flower.png");
    3434
    3535using namespace std;
     
    3838 *  standard constructor
    3939 * @param maxCount the Count of particles in the System
    40  * @param type The Type of the SpriteParticles
     40 * @param type The Type of the ModelParticles
    4141*/
    42 SpriteParticles::SpriteParticles (unsigned int maxCount)
    43   : ParticleSystem(maxCount)
     42ModelParticles::ModelParticles (unsigned int maxCount)
     43    : ParticleSystem(maxCount)
    4444{
    4545  this->init();
     
    5050 * @param root: the XML-element to load from
    5151 */
    52 SpriteParticles::SpriteParticles(const TiXmlElement* root)
     52ModelParticles::ModelParticles(const TiXmlElement* root)
    5353{
    5454  this->init();
     
    6060 *  standard deconstructor
    6161*/
    62 SpriteParticles::~SpriteParticles()
     62ModelParticles::~ModelParticles()
    6363{
    6464  // deleting all the living Particles
     
    8080
    8181/**
    82  * @brief initializes the SpriteParticles with default values
     82 * @brief initializes the ModelParticles with default values
    8383*/
    84 void SpriteParticles::init()
     84void ModelParticles::init()
    8585{
    86   this->setClassID(CL_SPRITE_PARTICLES, "SpriteParticles");
     86  this->setClassID(CL_MODEL_PARTICLES, "ModelParticles");
    8787
    8888  this->material.setDiffuseMap("maps/radial-trans-noise.png");
     
    9494 * @param root the XML-element to load from.
    9595 */
    96 void SpriteParticles::loadParams(const TiXmlElement* root)
     96void ModelParticles::loadParams(const TiXmlElement* root)
    9797{
    9898  ParticleSystem::loadParams(root);
    9999
    100   LoadParam(root, "texture", this, SpriteParticles, setMaterialTexture);
     100  LoadParam(root, "texture", this, ModelParticles, setMaterialTexture);
    101101}
    102102
    103103/**
    104104 * @brief sets the Texutre that is placed onto the particles
    105  * @param textureFile the Texture to load onto these SpriteParticles
     105 * @param textureFile the Texture to load onto these ModelParticles
    106106 */
    107 void SpriteParticles::setMaterialTexture(const char* textureFile)
     107void ModelParticles::setMaterialTexture(const char* textureFile)
    108108{
    109109  this->material.setDiffuseMap(textureFile);
     
    117117 * This is just the fastest Way to do this, but will most likely be changed in the future.
    118118 */
    119 void SpriteParticles::draw() const
     119void ModelParticles::draw() const
    120120{
    121121  glPushAttrib(GL_ENABLE_BIT);
    122 
    123122  Particle* drawPart = particles;
    124123
     
    128127    glDisable(GL_LIGHTING);
    129128  glMatrixMode(GL_MODELVIEW);
    130   glDepthMask(GL_FALSE);
    131129
    132   material.select();
     130  this->material.select();
    133131  glBlendFunc(GL_SRC_ALPHA, GL_DST_ALPHA);
    134132
    135   //glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_ENV_MODE, GL_MODULATE);
     133  glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_ENV_MODE, GL_MODULATE);
    136134
     135  if (likely(this->getModel() != NULL))
     136    while (likely(drawPart != NULL))
     137    {
     138      glPushMatrix();
     139      glMatrixMode(GL_MODELVIEW);
     140      /* move */
     141      glTranslatef(drawPart->position.x, drawPart->position.y, drawPart->position.z);
     142      /* scale */
     143      glScalef(drawPart->radius, drawPart->radius, drawPart->radius);
     144      /* rotate */
     145      Vector tmpRot = drawPart->orientation.getSpacialAxis();
     146      glRotatef (drawPart->orientation.getSpacialAxisAngle(), tmpRot.x, tmpRot.y, tmpRot.z );
    137147
    138   while (likely(drawPart != NULL))
    139   {
    140     glColor4fv(drawPart->color);
    141     //! @todo implement a faster code for the look-at Camera algorithm.
     148      this->getModel()->draw();
    142149
    143     const PNode* camera = State::getCamera();  //!< @todo MUST be different
    144     Vector cameraPos = camera->getAbsCoor();
    145     Vector cameraTargetPos = State::getCameraTarget()->getAbsCoor();
    146     Vector view = cameraTargetPos - cameraPos;
    147     Vector up = Vector(0, 1, 0);
    148     up = camera->getAbsDir().apply(up);
    149     Vector h = up.cross(view);
    150     Vector v = h.cross(view);
    151     h.normalize();
    152     v.normalize();
    153     v *= .5 * drawPart->radius;
    154     h *= .5 * drawPart->radius;
    155 
    156     glBegin(GL_TRIANGLE_STRIP);
    157     glTexCoord2i(1, 1);
    158     glVertex3f(drawPart->position.x - h.x - v.x,
    159                drawPart->position.y - h.y - v.y,
    160                drawPart->position.z - h.z - v.z);
    161     glTexCoord2i(0, 1);
    162     glVertex3f(drawPart->position.x - h.x + v.x,
    163                drawPart->position.y - h.y + v.y,
    164                drawPart->position.z - h.z + v.z);
    165     glTexCoord2i(1, 0);
    166     glVertex3f(drawPart->position.x + h.x - v.x,
    167                drawPart->position.y + h.y - v.y,
    168                drawPart->position.z + h.z - v.z);
    169     glTexCoord2i(0, 0);
    170     glVertex3f(drawPart->position.x + h.x + v.x,
    171                drawPart->position.y + h.y + v.y,
    172                drawPart->position.z + h.z + v.z);
    173 
    174     glEnd();
    175 
    176     drawPart = drawPart->next;
    177   }
    178   glDepthMask(GL_TRUE);
     150      glPopMatrix();
     151      drawPart = drawPart->next;
     152    }
     153  else
     154    PRINTF(2)("no model loaded onto ParticleSystem-%s\n", this->getName());
    179155  glPopAttrib();
    180156}
Note: See TracChangeset for help on using the changeset viewer.