Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

new_class_id: many more classes done

File size: 3.5 KB
Line 
1/*
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.
10
11   ### File Specific:
12   main-programmer: Benjamin Grauer
13   co-programmer: ...
14*/
15
16#define DEBUG_SPECIAL_MODULE DEBUG_MODULE_GRAPHICS
17
18#include "model_particles.h"
19
20#include "util/loading/load_param.h"
21#include "util/loading/factory.h"
22#include "material.h"
23#include "state.h"
24#include "shell_command.h"
25
26#include "parser/tinyxml/tinyxml.h"
27#include <algorithm>
28
29
30CREATE_FACTORY(ModelParticles, CL_MODEL_PARTICLES);
31NewObjectListDefinitionID(ModelParticles, CL_MODEL_PARTICLES);
32
33SHELL_COMMAND(texture, ModelParticles, setMaterialTexture)
34->defaultValues("maps/evil-flower.png");
35
36
37
38/**
39 *  standard constructor
40 * @param maxCount the Count of particles in the System
41 * @param type The Type of the ModelParticles
42*/
43ModelParticles::ModelParticles (unsigned int maxCount)
44    : ParticleSystem(maxCount)
45{
46  this->init();
47}
48
49/**
50 * @brief creates a Particle System out of a XML-element
51 * @param root: the XML-element to load from
52 */
53ModelParticles::ModelParticles(const TiXmlElement* root)
54{
55  this->init();
56  if (root != NULL)
57    this->loadParams(root);
58}
59
60/**
61 *  standard deconstructor
62*/
63ModelParticles::~ModelParticles()
64{ }
65
66/**
67 * @brief initializes the ModelParticles with default values
68*/
69void ModelParticles::init()
70{
71  this->registerObject(this, ModelParticles::_objectList);
72
73  this->material.setDiffuseMap("maps/radial-trans-noise.png");
74}
75
76
77/**
78 * loads Parameters from a TiXmlElement
79 * @param root the XML-element to load from.
80 */
81void ModelParticles::loadParams(const TiXmlElement* root)
82{
83  ParticleSystem::loadParams(root);
84
85  LoadParam(root, "texture", this, ModelParticles, setMaterialTexture);
86}
87
88/**
89 * @brief sets the Texutre that is placed onto the particles
90 * @param textureFile the Texture to load onto these ModelParticles
91 */
92void ModelParticles::setMaterialTexture(const std::string& textureFile)
93{
94  this->material.setDiffuseMap(textureFile);
95}
96
97/**
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.
103 */
104void ModelParticles::draw() const
105{
106  glPushAttrib(GL_ENABLE_BIT);
107  Particle* drawPart = particles;
108
109  GLboolean checkLight = false;
110  glGetBooleanv(GL_LIGHTING, &checkLight);
111  if (checkLight == GL_TRUE)
112    glDisable(GL_LIGHTING);
113  glMatrixMode(GL_MODELVIEW);
114
115  this->material.select();
116  glBlendFunc(GL_SRC_ALPHA, GL_DST_ALPHA);
117
118  glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_ENV_MODE, GL_MODULATE);
119
120  if (likely(this->getModel() != NULL))
121    while (likely(drawPart != NULL))
122    {
123      glPushMatrix();
124      glMatrixMode(GL_MODELVIEW);
125      /* move */
126      glTranslatef(drawPart->position.x, drawPart->position.y, drawPart->position.z);
127      /* scale */
128      glScalef(drawPart->radius, drawPart->radius, drawPart->radius);
129      /* rotate */
130      Vector tmpRot = drawPart->orientation.getSpacialAxis();
131      glRotatef (drawPart->orientation.getSpacialAxisAngle(), tmpRot.x, tmpRot.y, tmpRot.z );
132
133      this->getModel()->draw();
134
135      glPopMatrix();
136      drawPart = drawPart->next;
137    }
138  else
139    PRINTF(2)("no model loaded onto ParticleSystem-%s\n", this->getCName());
140  glPopAttrib();
141}
Note: See TracBrowser for help on using the repository browser.