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: Patrick Boenzli |
---|
14 | */ |
---|
15 | |
---|
16 | #define DEBUG_SPECIAL_MODULE DEBUG_MODULE_GRAPHICS |
---|
17 | |
---|
18 | #include "emitter_node.h" |
---|
19 | |
---|
20 | #include "particle_system.h" |
---|
21 | |
---|
22 | #include "util/loading/load_param.h" |
---|
23 | #include "debug.h" |
---|
24 | |
---|
25 | ObjectListDefinition(EmitterNode); |
---|
26 | |
---|
27 | /** |
---|
28 | * standard constructor |
---|
29 | */ |
---|
30 | EmitterNode::EmitterNode( float lifetime) |
---|
31 | { |
---|
32 | this->registerObject(this, EmitterNode::_objectList); |
---|
33 | |
---|
34 | this->system = NULL; |
---|
35 | this->emitter = NULL; |
---|
36 | this->lifeCycle = 0.0; |
---|
37 | this->lifeSpan = lifetime; |
---|
38 | } |
---|
39 | |
---|
40 | /** |
---|
41 | * standard destructor |
---|
42 | |
---|
43 | removes the EmitterSystem from the ParticleEngine |
---|
44 | */ |
---|
45 | EmitterNode::~EmitterNode () |
---|
46 | { |
---|
47 | this->emitter->setSystem(NULL); |
---|
48 | this->removeNode(); |
---|
49 | } |
---|
50 | |
---|
51 | /** |
---|
52 | * loads a EmitterNode from a XML-element |
---|
53 | * @param root the XML-element to load from |
---|
54 | */ |
---|
55 | void EmitterNode::loadParams(const TiXmlElement* root) |
---|
56 | { |
---|
57 | PNode::loadParams(root); |
---|
58 | |
---|
59 | LoadParam(root, "life-time", this, EmitterNode, setLifetime) |
---|
60 | .describe("Amount of time this emitter node shall remain"); |
---|
61 | } |
---|
62 | |
---|
63 | bool EmitterNode::start() |
---|
64 | { |
---|
65 | this->started = true; |
---|
66 | return this->started; |
---|
67 | } |
---|
68 | |
---|
69 | void EmitterNode::tick(float dt) |
---|
70 | { |
---|
71 | if( !this->started) |
---|
72 | return; |
---|
73 | |
---|
74 | this->lifeCycle += dt/this->lifeSpan; |
---|
75 | if (unlikely(this->lifeCycle >= 1)) |
---|
76 | { |
---|
77 | this->removeNode(); |
---|
78 | } |
---|
79 | PRINTF(0)("Coordinate Update EmitterNode: (%f,%f,%f) -> (%f,%f,%f)\n",this->getAbsCoor().x,this->getAbsCoor().y,this->getAbsCoor().z,this->velocity.x,this->velocity.y,this->velocity.z); |
---|
80 | this->setAbsCoor(this->getAbsCoor() + (this->velocity * dt)); |
---|
81 | } |
---|