Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 4663 in orxonox.OLD


Ignore:
Timestamp:
Jun 23, 2005, 1:49:25 PM (19 years ago)
Author:
bensch
Message:

orxonox/trunk: ParticleSystem now able to render Models

Location:
orxonox/trunk/src
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • orxonox/trunk/src/lib/graphics/graphics_engine.cc

    r4619 r4663  
    9393
    9494  // setting up the Resolution
    95   this->setResolution(800, 600, 16);
     95  this->setResolution(1000, 800, 16);
    9696
    9797
  • orxonox/trunk/src/lib/particles/particle_system.cc

    r4655 r4663  
    2626#include "material.h"
    2727#include "state.h"
     28#include "objModel.h"
    2829
    2930#include "tinyxml.h"
     
    8687
    8788  this->material = NULL;
     89  this->model = NULL;
    8890  this->maxCount = PARTICLE_DEFAULT_MAX_COUNT;
    8991  this->count = 0;
     
    141143  this->material = NULL;
    142144
    143   if (this->particleType == PARTICLE_SPRITE)
     145  switch (this->particleType)
    144146    {
    145       this->material = new Material("transperencyMap");
    146       this->material->setDiffuseMap("pictures/radialTransparency.png");
     147      case PARTICLE_SPRITE:
     148        this->material = new Material("transperencyMap");
     149        this->material->setDiffuseMap("pictures/radialTransparency.png");
    147150      //  material->setTransparency(.5);
     151        break;
     152      case PARTICLE_MODEL:
     153        if (!this->model)
     154        {
     155          PRINTF(2)("Model not loaded yet, please do this through ParticleSystem::loadModel()");
     156          this->setType(PARTICLE_SPRITE);
     157        }
     158        break;
    148159    }
    149160}
     
    159170{
    160171  this->material = material;
     172}
     173
     174
     175
     176/**
     177 * sets a Model to the Particles
     178 * @param modelName the Name of the Model to load
     179 */
     180void ParticleSystem::setModel(const char* modelName)
     181{
     182  if (this->model)
     183    delete this->model;
     184  if (modelName)
     185    this->model = new OBJModel(modelName);
     186  this->setType(PARTICLE_MODEL);
    161187}
    162188
     
    312338   Drawing all the particles with the appropriate Type.
    313339   This is just the fastest Way to do this, but will most likely be changed in the future.
    314 */
     340 */
    315341void ParticleSystem::draw(void) const
    316342{
     
    321347
    322348  switch (this->particleType)
    323     {
     349  {
    324350    default:
    325351    case PARTICLE_SPRITE:
     
    332358
    333359      while (likely(drawPart != NULL))
    334         {
    335           glColor4fv(drawPart->color);
     360      {
     361        glColor4fv(drawPart->color);
    336362          //! \todo implement a faster code for the look-at Camera algorithm.
    337363
    338           const PNode* camera = State::getInstance()->getCamera();  //!< \todo MUST be different
    339           Vector cameraPos = camera->getAbsCoor();
    340           Vector cameraTargetPos = State::getInstance()->getCameraTarget()->getAbsCoor();
    341           Vector view = cameraTargetPos - cameraPos;
    342           Vector up = Vector(0, 1, 0);
    343           up = camera->getAbsDir().apply(up);
    344           Vector h = up.cross(view);
    345           Vector v = h.cross(view);
    346           h.normalize();
    347           v.normalize();
    348           v *= .5 * drawPart->radius;
    349           h *= .5 * drawPart->radius;
    350 
    351           glBegin(GL_TRIANGLE_STRIP);
    352           glTexCoord2i(1, 1);
    353           glVertex3f(drawPart->position.x - h.x - v.x,
    354                      drawPart->position.y - h.y - v.y,
    355                      drawPart->position.z - h.z - v.z);
    356           glTexCoord2i(0, 1);
    357           glVertex3f(drawPart->position.x - h.x + v.x,
    358                      drawPart->position.y - h.y + v.y,
    359                      drawPart->position.z - h.z + v.z);
    360           glTexCoord2i(1, 0);
    361           glVertex3f(drawPart->position.x + h.x - v.x,
    362                      drawPart->position.y + h.y - v.y,
    363                      drawPart->position.z + h.z - v.z);
    364           glTexCoord2i(0, 0);
    365           glVertex3f(drawPart->position.x + h.x + v.x,
    366                      drawPart->position.y + h.y + v.y,
    367                      drawPart->position.z + h.z + v.z);
    368 
    369           glEnd();
    370 
    371           drawPart = drawPart->next;
    372         }
     364        const PNode* camera = State::getInstance()->getCamera();  //!< \todo MUST be different
     365        Vector cameraPos = camera->getAbsCoor();
     366        Vector cameraTargetPos = State::getInstance()->getCameraTarget()->getAbsCoor();
     367        Vector view = cameraTargetPos - cameraPos;
     368        Vector up = Vector(0, 1, 0);
     369        up = camera->getAbsDir().apply(up);
     370        Vector h = up.cross(view);
     371        Vector v = h.cross(view);
     372        h.normalize();
     373        v.normalize();
     374        v *= .5 * drawPart->radius;
     375        h *= .5 * drawPart->radius;
     376
     377        glBegin(GL_TRIANGLE_STRIP);
     378        glTexCoord2i(1, 1);
     379        glVertex3f(drawPart->position.x - h.x - v.x,
     380                   drawPart->position.y - h.y - v.y,
     381                   drawPart->position.z - h.z - v.z);
     382        glTexCoord2i(0, 1);
     383        glVertex3f(drawPart->position.x - h.x + v.x,
     384                   drawPart->position.y - h.y + v.y,
     385                   drawPart->position.z - h.z + v.z);
     386        glTexCoord2i(1, 0);
     387        glVertex3f(drawPart->position.x + h.x - v.x,
     388                   drawPart->position.y + h.y - v.y,
     389                   drawPart->position.z + h.z - v.z);
     390        glTexCoord2i(0, 0);
     391        glVertex3f(drawPart->position.x + h.x + v.x,
     392                   drawPart->position.y + h.y + v.y,
     393                   drawPart->position.z + h.z + v.z);
     394
     395        glEnd();
     396
     397        drawPart = drawPart->next;
     398      }
    373399      glDepthMask(GL_TRUE);
    374400      break;
     
    378404      glBegin(GL_LINES);
    379405      while (likely(drawPart != NULL))
    380         {
    381           glColor4fv(drawPart->color);
    382           glVertex3f(drawPart->position.x, drawPart->position.y, drawPart->position.z);
    383           glVertex3f(drawPart->position.x - drawPart->velocity.x,
    384                      drawPart->position.y - drawPart->velocity.y,
    385                      drawPart->position.z - drawPart->velocity.z);
    386           drawPart = drawPart->next;
    387         }
     406      {
     407        glColor4fv(drawPart->color);
     408        glVertex3f(drawPart->position.x, drawPart->position.y, drawPart->position.z);
     409        glVertex3f(drawPart->position.x - drawPart->velocity.x,
     410                   drawPart->position.y - drawPart->velocity.y,
     411                   drawPart->position.z - drawPart->velocity.z);
     412        drawPart = drawPart->next;
     413      }
    388414      glEnd();
     415      break;
     416
     417    case PARTICLE_MODEL:
     418      if (likely(this->model != NULL))
     419        while (likely(drawPart != NULL))
     420      {
     421        glPushMatrix();
     422        glMatrixMode(GL_MODELVIEW);
     423
     424        glTranslatef(drawPart->position.x, drawPart->position.y, drawPart->position.z);
     425        glScalef(drawPart->radius, drawPart->radius, drawPart->radius);
     426
     427        this->model->draw();
     428
     429        glPopMatrix();
     430        drawPart = drawPart->next;
     431      }
    389432      break;
    390433
     
    392435      glBegin(GL_POINTS);
    393436      while (likely(drawPart != NULL))
    394         {
    395           glColor4fv(drawPart->color);
    396 
    397           glLineWidth(drawPart->radius);
    398 
    399           glVertex3f(drawPart->position.x, drawPart->position.y, drawPart->position.z);
    400           drawPart = drawPart->next;
    401         }
     437      {
     438        glColor4fv(drawPart->color);
     439
     440        glLineWidth(drawPart->radius);
     441
     442        glVertex3f(drawPart->position.x, drawPart->position.y, drawPart->position.z);
     443        drawPart = drawPart->next;
     444      }
    402445      glEnd();
    403446      break;
    404     }
     447  }
    405448  glPopAttrib();
    406449}
  • orxonox/trunk/src/lib/particles/particle_system.h

    r4602 r4663  
    7777  void setType(PARTICLE_TYPE particleType, int count = 0);
    7878  void setMaterial(Material* material);
     79  void setModel(const char* modelName = NULL);
    7980  void setLifeSpan(float lifeSpan, float randomLifeSpan = 0.0);
    8081  void setConserve(float conserve);
     
    122123  PARTICLE_TYPE     particleType;        //!< A type for all the Particles
    123124  Material*         material;            //!< A Material for all the Particles.
     125  Model*            model;               //!< A Model to be displayed (PARTICLE_MODEL)
    124126  Particle*         particles;           //!< A list of particles of this System.
    125127  Particle*         deadList;            //!< A list of dead Particles in the System.
  • orxonox/trunk/src/story_entities/world.cc

    r4654 r4663  
    483483  system->setRadius(1.0, 0.0, .0);
    484484  system->setMass (0.0, 1.0);
     485  system->setModel(ResourceManager::getFullName("models/orx-rocket.obj"));
    485486
    486487  system->setColor(0, .5, 0, 0, 1);
     
    490491
    491492  // Creating a Test Particle Emitter
    492   ParticleEmitter* emitter = new ParticleEmitter(Vector(-1, 0, 0), M_PI_4, 400, .5);
     493  ParticleEmitter* emitter = new ParticleEmitter(Vector(-1, 0, 0), M_PI_4, 40, .5);
    493494  emitter->setType(EMITTER_DOT);
    494495  emitter->setSize(20);
Note: See TracChangeset for help on using the changeset viewer.