Changeset 4338 in orxonox.OLD for orxonox/trunk/src/lib/graphics
- Timestamp:
- May 27, 2005, 9:16:53 PM (20 years ago)
- Location:
- orxonox/trunk/src/lib/graphics
- Files:
-
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
orxonox/trunk/src/lib/graphics/light.h
r3603 r4338 11 11 #define _LIGHT_H 12 12 13 #include " world_entity.h"13 #include "p_node.h" 14 14 #include "glincl.h" 15 15 … … 21 21 22 22 //! A class that handles Lights. The LightManager operates on this. 23 class Light : public WorldEntity23 class Light : public PNode 24 24 { 25 25 public: -
orxonox/trunk/src/lib/graphics/particles/particle_emitter.cc
r4320 r4338 31 31 { 32 32 this->setClassID(CL_PARTICLE_EMITTER, "ParticleEmitter"); 33 34 this->type = EMITTER_DOT; 35 this->emitterSize = 1.0; 33 36 this->direction = direction; 34 37 this->setSpread(angle); 35 38 this->setEmissionRate(emissionRate); 36 this->set Velocity(velocity);39 this->setEmissionVelocity(velocity); 37 40 38 41 this->saveTime = 0.0; … … 50 53 { 51 54 ParticleEngine::getInstance()->removeEmitter(this); 52 53 55 } 54 56 … … 71 73 72 74 /** 75 \param type the new Type of this emitter 76 */ 77 void ParticleEmitter::setType(EMITTER_TYPE type) 78 { 79 this->type = type; 80 } 81 82 void ParticleEmitter::setSize(float emitterSize) 83 { 84 if (emitterSize > 0.0) 85 this->emitterSize = emitterSize; 86 else 87 emitterSize = 0.0; 88 } 89 90 /** 73 91 \brief set the emission rate 74 92 \param sets the number of particles emitted per second … … 79 97 void ParticleEmitter::setEmissionRate(float emissionRate) 80 98 { 81 this->emissionRate = emissionRate; 99 if (emissionRate > 0.0) 100 this->emissionRate = emissionRate; 101 else 102 this->emissionRate = 0.0; 82 103 } 83 104 … … 104 125 you may want to use the animation class 105 126 */ 106 void ParticleEmitter::set Velocity(float velocity, float randomVelocity)127 void ParticleEmitter::setEmissionVelocity(float velocity, float randomVelocity) 107 128 { 108 129 this->velocity = velocity; … … 139 160 140 161 // this should spread the Particles evenly. if the Emitter is moved around quickly 141 Vector equalSpread = this->getVelocity() * random()/RAND_MAX * dt; 162 Vector equalSpread = this->getVelocity() * rand()/RAND_MAX * dt; 163 Vector extension; // the Vector for different fields. 142 164 143 system->addParticle(this->getAbsCoor() - equalSpread, velocityV); 165 if (this->type & 2) 166 { 167 extension = Vector(this->emitterSize * ((float)rand()/RAND_MAX -.5), 0, this->emitterSize * ((float)rand()/RAND_MAX - .5)); 168 extension = this->getAbsDir().apply(extension); 169 } 170 else if (this->type & 8) 171 { 172 extension = Vector((float)rand()/RAND_MAX -.5, (float)rand()/RAND_MAX -.5, (float)rand()/RAND_MAX -.5) * this->emitterSize; 173 } 174 175 system->addParticle(this->getAbsCoor() + extension - equalSpread, velocityV); 176 144 177 } 145 178 } -
orxonox/trunk/src/lib/graphics/particles/particle_emitter.h
r4176 r4338 13 13 class ParticleSystem; 14 14 15 typedef enum EMITTER_TYPE {EMITTER_DOT, 16 EMITTER_PLANE, 17 EMITTER_SPHERE, 18 EMITTER_CUBE}; 15 //! The form of the Emitter to emit from 16 typedef enum EMITTER_TYPE {EMITTER_DOT = 1, 17 EMITTER_PLANE = 2, 18 EMITTER_SPHERE= 4, 19 EMITTER_CUBE = 8}; 19 20 20 21 //! A default singleton class. … … 32 33 33 34 /* controlling the behavour: these can be used as Animation interfaces */ 35 void setType(EMITTER_TYPE type); 36 void setSize(float emitterSize); 34 37 void setEmissionRate(float emissionRate); 35 38 void setSpread(float angle, float randomAngle = 0.0); 36 void setVelocity(float velocity, float randomVelocity = 0.0); 39 void setEmissionVelocity(float velocity, float randomVelocity = 0.0); 40 41 /** \returns the type of the emitter */ 42 inline EMITTER_TYPE getType(void) const { return this->type; }; 43 /** \returns the Size of the emitter */ 44 inline float getSize(void) const { return this->emitterSize; }; 45 /** \returns the emissionRate */ 46 inline float getEmissionRate(void) const { return this->emissionRate; }; 47 /** \returns the SpreadAngle of the emitter */ 48 inline float getSpread(void) { return this->angle; }; 49 /** \returns the EmissionVelocity of the emitter */ 50 inline float getEmissionVelocity(void) { return this->velocity; }; 37 51 38 52 void debug(void); 39 53 40 54 private: 55 EMITTER_TYPE type; //!< The type of emitter this is 56 float emitterSize; //!< The size of the emitter (not for EMITTER_DOT) 41 57 Vector direction; //!< emition direction 42 58 float angle; //!< max angle from the direction of the emitter -
orxonox/trunk/src/lib/graphics/particles/particle_engine.cc
r4320 r4338 267 267 268 268 /** 269 \param systemName the name of the system to search for 270 \returns the system called by systemName or NULL if not found 271 */ 272 ParticleSystem* ParticleEngine::getSystemByName(const char* systemName) const 273 { 274 tIterator<ParticleSystem>* tmpIt = systemList->getIterator(); 275 ParticleSystem* tmpSys = tmpIt->nextElement(); 276 while(tmpSys) 277 { 278 if (!strcmp(systemName, tmpSys->getName())) 279 { 280 delete tmpIt; 281 return tmpSys; 282 } 283 tmpSys = tmpIt->nextElement(); 284 } 285 delete tmpIt; 286 return NULL; 287 } 288 289 /** 290 \param number the n-th system to return 291 \returns the system called by number or NULL if not found 292 */ 293 ParticleSystem* ParticleEngine::getSystemByNumber(unsigned int number) const 294 { 295 int count = 0; 296 tIterator<ParticleSystem>* tmpIt = systemList->getIterator(); 297 ParticleSystem* tmpSys = tmpIt->nextElement(); 298 while(tmpSys) 299 { 300 count++; 301 if ( count == number) 302 { 303 delete tmpIt; 304 return tmpSys; 305 } 306 tmpSys = tmpIt->nextElement(); 307 } 308 delete tmpIt; 309 return NULL; 310 } 311 312 /** 313 \param emitterName the name of the emitter to search for 314 \returns the emitter called by emitterName or NULL if not found 315 */ 316 ParticleEmitter* ParticleEngine::getEmitterByName(const char* emitterName) const 317 { 318 tIterator<ParticleEmitter>* tmpIt = emitterList->getIterator(); 319 ParticleEmitter* tmpEmit = tmpIt->nextElement(); 320 while(tmpEmit) 321 { 322 if (!strcmp(emitterName, tmpEmit->getName())) 323 { 324 delete tmpIt; 325 return tmpEmit; 326 } 327 tmpEmit = tmpIt->nextElement(); 328 } 329 delete tmpIt; 330 return NULL; 331 } 332 333 334 /** 335 \param number the n-th emitter to return 336 \returns the emitter called by number or NULL if not found 337 */ 338 ParticleEmitter* ParticleEngine::getEmitterByNumber(unsigned int number) const 339 { 340 int count = 0; 341 tIterator<ParticleEmitter>* tmpIt = emitterList->getIterator(); 342 ParticleEmitter* tmpEmit = tmpIt->nextElement(); 343 while(tmpEmit) 344 { 345 count++; 346 if ( count == number) 347 { 348 delete tmpIt; 349 return tmpEmit; 350 } 351 tmpEmit = tmpIt->nextElement(); 352 } 353 delete tmpIt; 354 return NULL; 355 } 356 357 /** 269 358 \brief outputs some nice debug information 270 359 */ -
orxonox/trunk/src/lib/graphics/particles/particle_engine.h
r4176 r4338 13 13 // FORWARD DEFINITION 14 14 template<class T> class tList; 15 class ParticleSystem;16 class ParticleEmitter;17 15 18 16 struct ParticleConnection … … 41 39 bool breakConnection(ParticleConnection* connection); 42 40 41 ParticleSystem* getSystemByName(const char* systemName) const; 42 ParticleSystem* getSystemByNumber(unsigned int number) const; 43 ParticleEmitter* getEmitterByName(const char* emitterName) const; 44 ParticleEmitter* getEmitterByNumber(unsigned int number) const; 45 43 46 void debug(); 44 47 -
orxonox/trunk/src/lib/graphics/particles/particle_system.cc
r4320 r4338 20 20 #include "particle_emitter.h" 21 21 #include "particle_engine.h" 22 23 #include "field.h" 24 22 25 #include "compiler.h" 23 26 #include "material.h" 27 #include "state.h" 28 29 30 // needed to find the Position of the Camera 31 #include "world.h" 24 32 25 33 using namespace std; … … 34 42 ParticleSystem::ParticleSystem (unsigned int maxCount, PARTICLE_TYPE type) 35 43 { 36 this->setClassID(CL_PARTICLE_SYSTEM, "ParticleSystem"); 37 this->material = NULL; 38 this->name = NULL; 39 this->maxCount = maxCount; 40 this->count = 0; 41 this->particles = NULL; 42 this->deadList = NULL; 43 this->setConserve(1); 44 this->setLifeSpan(1); 45 this->setInheritSpeed(0); 46 this->glID = NULL; 47 this->setRadius(1.0, 1.0, 0.0); 48 this->setType(type, 1); 49 ParticleEngine::getInstance()->addSystem(this); 44 this->setClassID(CL_PARTICLE_SYSTEM, "ParticleSystem"); 45 this->material = NULL; 46 this->name = NULL; 47 this->maxCount = maxCount; 48 this->count = 0; 49 this->particles = NULL; 50 this->deadList = NULL; 51 this->setConserve(1); 52 this->setLifeSpan(1); 53 this->setInheritSpeed(0); 54 this->glID = NULL; 55 this->setRadius(1.0, 1.0, 0.0); 56 this->setType(type, 1); 57 this->setColor(1.0,1.0,1.0,1.0, .5,.5,.5,.5, .0,.0,.0,.0); 58 ParticleEngine::getInstance()->addSystem(this); 50 59 } 51 60 … … 106 115 this->particleType = particleType; 107 116 this->dialectCount = count; 108 if (glID != NULL) 109 delete glID; 110 111 glID = new GLuint[count]; 112 for (int i = 0; i< count; i++) 113 glID[i] = 0; 114 115 glID[0] = glGenLists(count); 116 117 material = new Material("transperencyMap"); 118 material->setDiffuseMap("pictures/radialTransparency.png"); 119 // material->setTransparency(.5); 120 121 glNewList(glID[0], GL_COMPILE); 122 glBegin(GL_TRIANGLE_STRIP); 123 glTexCoord2f(1, 1); 124 glVertex3f(0.0, .5, .5); 125 glTexCoord2f(1, 0); 126 glVertex3f(0.0, -.5, .5); 127 glTexCoord2f(0, 1); 128 glVertex3f(0.0, .5, -.5); 129 glTexCoord2f(0, 0); 130 glVertex3f(0.0, -.5, -.5); 131 glEnd(); 132 glEndList(); 117 // if (glID != NULL) 118 // delete glID; 119 120 // glID = new GLuint[count]; 121 // for (int i = 0; i< count; i++) 122 // glID[i] = 0; 123 124 // glID[0] = glGenLists(count); 125 if (this->material) 126 delete this->material; 127 this->material = NULL; 128 129 if (this->particleType == PARTICLE_SPRITE) 130 { 131 this->material = new Material("transperencyMap"); 132 this->material->setDiffuseMap("pictures/radialTransparency.png"); 133 // material->setTransparency(.5); 134 } 133 135 } 134 136 … … 192 194 } 193 195 196 197 /** 198 \brief Tells the ParticleSystem how it should iterate the color over time 199 \param .... 200 */ 201 void ParticleSystem::setColor(GLfloat br, GLfloat bg, GLfloat bb, GLfloat ba, 202 GLfloat mr, GLfloat mg, GLfloat mb, GLfloat ma, 203 GLfloat er, GLfloat eg, GLfloat eb, GLfloat ea) 204 { 205 this->startColor[0] = br; 206 this->startColor[1] = bg; 207 this->startColor[2] = bb; 208 this->startColor[3] = ba; 209 210 this->midColor[0] = mr; 211 this->midColor[1] = mg; 212 this->midColor[2] = mb; 213 this->midColor[3] = ma; 214 215 this->endColor[0] = er; 216 this->endColor[1] = eg; 217 this->endColor[2] = eb; 218 this->endColor[3] = ea; 219 } 220 194 221 /** 195 222 \brief ticks the system. … … 207 234 tickPart->radius += tickPart->radiusIt * dt; 208 235 236 // applying force to the System. 237 tickPart->velocity += tickPart->extForce * tickPart->mass; 238 tickPart->extForce = Vector(0,0,0); 239 240 // applying Color 241 //! \todo better algorithm to do this \todo also implement the midColor 242 if (tickPart->lifeCycle < .5) 243 { 244 tickPart->color[0] = this->startColor[0] *(1.0-tickPart->lifeCycle*2.0) + this->midColor[0] *(tickPart->lifeCycle*2); 245 tickPart->color[1] = this->startColor[1] *(1.0-tickPart->lifeCycle*2.0) + this->midColor[1] *(tickPart->lifeCycle*2); 246 tickPart->color[2] = this->startColor[2] *(1.0-tickPart->lifeCycle*2.0) + this->midColor[2] *(tickPart->lifeCycle*2); 247 tickPart->color[3] = this->startColor[3] *(1.0-tickPart->lifeCycle*2.0) + this->midColor[3] *(tickPart->lifeCycle*2); 248 } 249 else 250 { 251 tickPart->color[0] = this->midColor[0] *(2.0-tickPart->lifeCycle*2.0) + this->endColor[0] *(tickPart->lifeCycle*2); 252 tickPart->color[1] = this->midColor[1] *(2.0-tickPart->lifeCycle*2.0) + this->endColor[1] *(tickPart->lifeCycle*2); 253 tickPart->color[2] = this->midColor[2] *(2.0-tickPart->lifeCycle*2.0) + this->endColor[2] *(tickPart->lifeCycle*2); 254 tickPart->color[3] = this->midColor[3] *(2.0-tickPart->lifeCycle*2.0) + this->endColor[3] *(tickPart->lifeCycle*2); 255 } 209 256 // many more to come 210 211 257 212 258 if (this->conserve < 1.0) 213 259 tickPart->velocity = tickPart->velocity * this->conserve; 214 260 // find out if we have to delete tickPart 215 if ((tickPart-> timeToLive -= dt) <=0)261 if ((tickPart->lifeCycle += dt/tickPart->lifeTime) >= 1.0) 216 262 { 217 263 // remove the particle from the list … … 241 287 } 242 288 289 /** 290 \brief applies some force to a Particle. 291 */ 292 void ParticleSystem::applyField(float dt, Field* field) 293 { 294 Particle* tickPart = particles; 295 while (tickPart) 296 { 297 tickPart->extForce += field->calcForce(dt, tickPart->position); 298 tickPart = tickPart->next; 299 } 300 } 301 302 243 303 /** 244 304 \brief draws all the Particles of this System 245 305 \param the time passed in seconds (since the last draw) 306 307 The Cases in this Function all do the same: 308 Drawing all the particles with the appropriate Type. 309 This is just the fastest Way to do this, but will most likely be changed in the future. 246 310 */ 247 311 void ParticleSystem::draw(float dt) 248 312 { 249 313 glPushAttrib(GL_ENABLE_BIT); 250 // material->select(); 314 glDisable(GL_LIGHTING); 315 251 316 Particle* drawPart = particles; 252 317 253 318 switch (this->particleType) 254 319 { 320 default: 255 321 case PARTICLE_SPRITE: 256 322 glMatrixMode(GL_MODELVIEW); 257 // glDisable(GL_LIGHTING); 323 glDisable(GL_DEPTH_TEST); 324 258 325 material->select(); 259 glDisable(GL_DEPTH_TEST); 326 // glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_ENV_MODE, GL_MODULATE); 327 328 260 329 while (likely(drawPart != NULL)) 261 330 { 262 glPushMatrix(); 263 glTranslatef(drawPart->position.x, drawPart->position.y, drawPart->position.z); 264 glScalef(drawPart->radius, drawPart->radius, drawPart->radius); 265 glCallList(*this->glID); 266 267 //glVertex3f(drawPart->position.x, drawPart->position.y, drawPart->position.z); 331 glColor4fv(drawPart->color); 332 //! \todo implement a faster code for the look-at Camera algorithm. 333 334 const PNode* camera = State::getInstance()->getCamera(); //!< \todo MUST be different 335 Vector cameraPos = camera->getAbsCoor(); 336 Vector cameraTargetPos = State::getInstance()->getCameraTarget()->getAbsCoor(); 337 Vector view = cameraTargetPos - cameraPos; 338 Vector up = Vector(0, 1, 0); 339 up = camera->getAbsDir().apply(up); 340 Vector h = up.cross(view); 341 Vector v = h.cross(view); 342 h.normalize(); 343 v.normalize(); 344 v *= .5 * drawPart->radius; 345 h *= .5 * drawPart->radius; 346 347 glBegin(GL_TRIANGLE_STRIP); 348 glTexCoord2i(1, 1); 349 glVertex3f(drawPart->position.x - h.x - v.x, 350 drawPart->position.y - h.y - v.y, 351 drawPart->position.z - h.z - v.z); 352 glTexCoord2i(0, 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(1, 0); 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(0, 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 365 glEnd(); 366 268 367 drawPart = drawPart->next; 269 glPopMatrix(); 270 } 271 // glEnd(); 272 273 // glEnable(GL_LIGHTING); 274 275 glEnable(GL_DEPTH_TEST); 368 } 369 370 276 371 break; 277 default:278 372 279 373 case PARTICLE_SPARK: … … 282 376 while (likely(drawPart != NULL)) 283 377 { 378 glColor4fv(drawPart->color); 284 379 glVertex3f(drawPart->position.x, drawPart->position.y, drawPart->position.z); 285 380 glVertex3f(drawPart->position.x - drawPart->velocity.x, … … 295 390 while (likely(drawPart != NULL)) 296 391 { 392 glColor4fv(drawPart->color); 393 297 394 glLineWidth(drawPart->radius); 298 395 … … 349 446 } 350 447 351 particles->timeToLive = this->lifeSpan + (float)(rand()/RAND_MAX)* this->randomLifeSpan; 448 particles->lifeTime = this->lifeSpan + (float)(rand()/RAND_MAX)* this->randomLifeSpan; 449 particles->lifeCycle = 0.0; 352 450 particles->position = position; 353 451 particles->velocity = velocity; … … 357 455 particles->radius = this->startRadius + (rand()/RAND_MAX-.5)*this->randomStartRadius; 358 456 359 particles->radiusIt = (this->endRadius + (rand()/RAND_MAX-.5)*this->randomEndRadius - particles->radius) / particles-> timeToLive;457 particles->radiusIt = (this->endRadius + (rand()/RAND_MAX-.5)*this->randomEndRadius - particles->radius) / particles->lifeTime; 360 458 361 459 ++this->count; -
orxonox/trunk/src/lib/graphics/particles/particle_system.h
r4176 r4338 31 31 class Material; 32 32 class ParticleEmitter; 33 33 class Field; 34 34 35 35 //! A struct for one Particle 36 36 typedef struct Particle 37 37 { 38 float timeToLive; //!< The time this particle lives from NOW on. 38 float lifeTime; //!< The time this particle has to live. 39 float lifeCycle; //!< The fraction of time passed. (in percentage of its lifeTime) 40 39 41 Vector position; //!< The current position of this particle. 40 42 Vector velocity; //!< The current velocity of this particle. 43 Vector extForce; //!< The external Force that influences this Particle. 41 44 Quaternion rotation; //!< The current rotation of this particle. 42 45 float mass; //!< The mass of this particle. 43 46 float radius; //!< The current size of this particle. 44 47 float radiusIt; //!< The difference of the Size per second. 48 49 GLfloat color [4]; //!< A Color for the particles. 45 50 46 51 PARTICLE_TYPE type; … … 69 74 void setMass(float mass, float randomMass); 70 75 76 void setColor(GLfloat br, GLfloat bg, GLfloat bb, GLfloat ba, 77 GLfloat mr, GLfloat mg, GLfloat mb, GLfloat ma, 78 GLfloat er, GLfloat eg, GLfloat eb, GLfloat ea); 79 80 /** \returns the Type of the particles */ 81 inline PARTICLE_TYPE getType(void) const { return this->particleType; }; 82 /** \returns the Material that lies on this particles */ 83 inline const Material* getMaterial(void) const { return this->material; }; 84 /** \returns the inherit-speed-factor */ 85 inline float getInheritSpeed(void) const { return this->inheritSpeed; }; 86 /** \returns the lifespan of the particles */ 87 inline float getLifeSpan(void) const { return this->lifeSpan; }; 88 /** \returns the starting-radius of the particles */ 89 inline float getStartRadius(void) const { return this->startRadius; }; 90 /** \returns the end-radius of the particles */ 91 inline float getEndRadius(void) const { return this->endRadius; }; 92 /** \returns the conserve-factor of the particles */ 93 inline float getConserve(void) const { return this->conserve; }; 94 /** \returns the initial mass of the particles */ 95 inline float getMass(void) const { return this->initialMass; }; 96 97 void applyField(float dt, Field* field); 98 71 99 void tick(float dt); 72 100 void draw(float dt); … … 79 107 float conserve; //!< How much energy gets conserved to the next Tick. 80 108 float lifeSpan; //!< Initial lifetime of a Particle. 81 float randomLifeSpan; 82 float startRadius; 83 float endRadius; 84 float randomStartRadius; 85 float randomEndRadius; 86 float initialMass; 87 float randomInitialMass; 88 float inheritSpeed; 109 float randomLifeSpan; //!< A random value for the Lifespan (around the initial lifetime) 110 float startRadius; //!< The beginning Radius of the Particle 111 float endRadius; //!< The end Radius of the Particle 112 float randomStartRadius; //!< The Random start Radius (begin + rand*randomValue) 113 float randomEndRadius; //!< Random end value 114 float initialMass; //!< The initial Mass of the Particle 115 float randomInitialMass; //!< The random initial Mass of the Particle 116 float inheritSpeed; //!< How much speed the particle inherits from the Emitters speed \todo move this to the emitter 117 118 GLfloat startColor[4]; //!< Color of the Particle at the beginning 119 GLfloat midColor[4]; //!< Color of the Particle at the middle of its lifeSpan 120 GLfloat endColor[4]; //!< Color of the Particle at the end of its lifeSpan 89 121 90 122 // particles
Note: See TracChangeset
for help on using the changeset viewer.