Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/branches/new_class_id/src/lib/particles/model_particles.cc @ 9716

Last change on this file since 9716 was 9716, checked in by bensch, 18 years ago

more renamings

File size: 3.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
[6629]18#include "model_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
[9716]26#include "class_id_DEPRECATED.h"
[4338]27
[9715]28ObjectListDefinitionID(ModelParticles, CL_MODEL_PARTICLES);
[9709]29CREATE_FACTORY(ModelParticles);
[6621]30
[6629]31SHELL_COMMAND(texture, ModelParticles, 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
[6629]39 * @param type The Type of the ModelParticles
[3245]40*/
[6629]41ModelParticles::ModelParticles (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 */
[6629]51ModelParticles::ModelParticles(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*/
[6629]61ModelParticles::~ModelParticles()
[6653]62{ }
[4123]63
[3945]64/**
[6629]65 * @brief initializes the ModelParticles with default values
[4602]66*/
[6629]67void ModelParticles::init()
[4602]68{
[9686]69  this->registerObject(this, ModelParticles::_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 */
[6629]79void ModelParticles::loadParams(const TiXmlElement* root)
[4602]80{
[6623]81  ParticleSystem::loadParams(root);
[4602]82
[6629]83  LoadParam(root, "texture", this, ModelParticles, setMaterialTexture);
[4602]84}
[4727]85
[4478]86/**
[6626]87 * @brief sets the Texutre that is placed onto the particles
[6629]88 * @param textureFile the Texture to load onto these ModelParticles
[6626]89 */
[7221]90void ModelParticles::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 */
[6629]102void ModelParticles::draw() const
[4338]103{
[4176]104  glPushAttrib(GL_ENABLE_BIT);
105  Particle* drawPart = particles;
[4597]106
[6628]107  GLboolean checkLight = false;
108  glGetBooleanv(GL_LIGHTING, &checkLight);
109  if (checkLight == GL_TRUE)
110    glDisable(GL_LIGHTING);
[6621]111  glMatrixMode(GL_MODELVIEW);
[4338]112
[6629]113  this->material.select();
[6621]114  glBlendFunc(GL_SRC_ALPHA, GL_DST_ALPHA);
[4863]115
[6629]116  glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_ENV_MODE, GL_MODULATE);
[4338]117
[6629]118  if (likely(this->getModel() != NULL))
119    while (likely(drawPart != NULL))
120    {
121      glPushMatrix();
122      glMatrixMode(GL_MODELVIEW);
123      /* move */
124      glTranslatef(drawPart->position.x, drawPart->position.y, drawPart->position.z);
125      /* scale */
126      glScalef(drawPart->radius, drawPart->radius, drawPart->radius);
127      /* rotate */
128      Vector tmpRot = drawPart->orientation.getSpacialAxis();
129      glRotatef (drawPart->orientation.getSpacialAxisAngle(), tmpRot.x, tmpRot.y, tmpRot.z );
[4597]130
[6629]131      this->getModel()->draw();
[4338]132
[6629]133      glPopMatrix();
134      drawPart = drawPart->next;
135    }
136  else
[9406]137    PRINTF(2)("no model loaded onto ParticleSystem-%s\n", this->getCName());
[4176]138  glPopAttrib();
[3932]139}
Note: See TracBrowser for help on using the repository browser.