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
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 "class_id_DEPRECATED.h"
27
28ObjectListDefinitionID(ModelParticles, CL_MODEL_PARTICLES);
29CREATE_FACTORY(ModelParticles);
30
31SHELL_COMMAND(texture, ModelParticles, setMaterialTexture)
32->defaultValues("maps/evil-flower.png");
33
34
35
36/**
37 *  standard constructor
38 * @param maxCount the Count of particles in the System
39 * @param type The Type of the ModelParticles
40*/
41ModelParticles::ModelParticles (unsigned int maxCount)
42    : ParticleSystem(maxCount)
43{
44  this->init();
45}
46
47/**
48 * @brief creates a Particle System out of a XML-element
49 * @param root: the XML-element to load from
50 */
51ModelParticles::ModelParticles(const TiXmlElement* root)
52{
53  this->init();
54  if (root != NULL)
55    this->loadParams(root);
56}
57
58/**
59 *  standard deconstructor
60*/
61ModelParticles::~ModelParticles()
62{ }
63
64/**
65 * @brief initializes the ModelParticles with default values
66*/
67void ModelParticles::init()
68{
69  this->registerObject(this, ModelParticles::_objectList);
70
71  this->material.setDiffuseMap("maps/radial-trans-noise.png");
72}
73
74
75/**
76 * loads Parameters from a TiXmlElement
77 * @param root the XML-element to load from.
78 */
79void ModelParticles::loadParams(const TiXmlElement* root)
80{
81  ParticleSystem::loadParams(root);
82
83  LoadParam(root, "texture", this, ModelParticles, setMaterialTexture);
84}
85
86/**
87 * @brief sets the Texutre that is placed onto the particles
88 * @param textureFile the Texture to load onto these ModelParticles
89 */
90void ModelParticles::setMaterialTexture(const std::string& textureFile)
91{
92  this->material.setDiffuseMap(textureFile);
93}
94
95/**
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.
101 */
102void ModelParticles::draw() const
103{
104  glPushAttrib(GL_ENABLE_BIT);
105  Particle* drawPart = particles;
106
107  GLboolean checkLight = false;
108  glGetBooleanv(GL_LIGHTING, &checkLight);
109  if (checkLight == GL_TRUE)
110    glDisable(GL_LIGHTING);
111  glMatrixMode(GL_MODELVIEW);
112
113  this->material.select();
114  glBlendFunc(GL_SRC_ALPHA, GL_DST_ALPHA);
115
116  glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_ENV_MODE, GL_MODULATE);
117
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 );
130
131      this->getModel()->draw();
132
133      glPopMatrix();
134      drawPart = drawPart->next;
135    }
136  else
137    PRINTF(2)("no model loaded onto ParticleSystem-%s\n", this->getCName());
138  glPopAttrib();
139}
Note: See TracBrowser for help on using the repository browser.