1 | #include "dxstdafx.h"
|
---|
2 | #include ".\particlegroup.h"
|
---|
3 | #include "ParticleEmitter.h"
|
---|
4 | #include "GameManager.h"
|
---|
5 |
|
---|
6 | ParticleGroup::ParticleGroup(void) : Node()
|
---|
7 | {
|
---|
8 | this->useGravity(true);
|
---|
9 | this->nodeType |= Scene::NODE_PARTICLEGROUP;
|
---|
10 | this->useHeatHaze = false;
|
---|
11 | }
|
---|
12 |
|
---|
13 | ParticleGroup::~ParticleGroup(void)
|
---|
14 | {
|
---|
15 | }
|
---|
16 |
|
---|
17 | void ParticleGroup::addParticle(SPTR<Node> particle)
|
---|
18 | {
|
---|
19 | if(!particle->isA(Scene::NODE_PARTICLEEMITTER)) {
|
---|
20 | particle->setParticleGroup(this->particleGroup);
|
---|
21 | } else {
|
---|
22 | this->myScene->manager->printToConsole("Have not set the ParticleGroup to Emitter!");
|
---|
23 | }
|
---|
24 | particle->getFather()->removeChild(particle);
|
---|
25 | this->addChild(particle);
|
---|
26 |
|
---|
27 | if(this->hasRenderer()) {
|
---|
28 | if(particle->hasRenderer()) {
|
---|
29 | particle->removeRenderer();
|
---|
30 | }
|
---|
31 | }
|
---|
32 | if(particle->getActor()!=NULL && !this->gravity) {
|
---|
33 | particle->getActor()->raiseBodyFlag(NX_BF_DISABLE_GRAVITY);
|
---|
34 | }
|
---|
35 | }
|
---|
36 |
|
---|
37 | void ParticleGroup::addParticleEmitter(SPTR<Node> particleEmitter) {
|
---|
38 | ParticleEmitter* e = (ParticleEmitter*) particleEmitter.get();
|
---|
39 | e->setParticleGroup(this);
|
---|
40 | this->useHeatHaze |= e->getUseHeatHaze();
|
---|
41 | this->emitterList.push_back(e);
|
---|
42 | }
|
---|
43 |
|
---|
44 | void ParticleGroup::removeParticleEmitter(ParticleEmitter* particleEmitter) {
|
---|
45 | for(UINT i=0;i<this->emitterList.size();i++) {
|
---|
46 | if(this->emitterList.at(i)==particleEmitter) {
|
---|
47 | this->emitterList.erase((this->emitterList.begin()+i));
|
---|
48 | }
|
---|
49 | }
|
---|
50 | if(this->emitterList.size()==0 && this->children.size()==0) {
|
---|
51 | this->killMe();
|
---|
52 | }
|
---|
53 | }
|
---|
54 |
|
---|
55 | void ParticleGroup::setParticleGroup(int _group)
|
---|
56 | {
|
---|
57 | this->particleGroup = _group;
|
---|
58 | }
|
---|
59 |
|
---|
60 | void ParticleGroup::useGravity(bool _gravity)
|
---|
61 | {
|
---|
62 | this->gravity = _gravity;
|
---|
63 | }
|
---|
64 |
|
---|
65 | void ParticleGroup::removeChild(std::list<SPTR<Node> >::iterator _it)
|
---|
66 | {
|
---|
67 | this->children.remove((SPTR<Node>) *_it);
|
---|
68 | if(this->emitterList.size()==0 && this->children.size()==0) {
|
---|
69 | this->killMe();
|
---|
70 | }
|
---|
71 | }
|
---|
72 |
|
---|
73 | void ParticleGroup::removeChild(SPTR<Node> _child)
|
---|
74 | {
|
---|
75 | this->children.remove(_child);
|
---|
76 | if(this->emitterList.size()==0 && this->children.size()==0) {
|
---|
77 | this->killMe();
|
---|
78 | }
|
---|
79 | }
|
---|
80 |
|
---|
81 | void ParticleGroup::killMe()
|
---|
82 | {
|
---|
83 | for(UINT i=0;i<this->emitterList.size();i++) {
|
---|
84 | this->emitterList.at(i)->killMe();
|
---|
85 | }
|
---|
86 | Node::killMe();
|
---|
87 | }
|
---|
88 |
|
---|
89 | void ParticleGroup::setUseHeatHaze(bool _useHeatHaze)
|
---|
90 | {
|
---|
91 | this->useHeatHaze = _useHeatHaze;
|
---|
92 | }
|
---|
93 |
|
---|
94 | bool ParticleGroup::getUseHeatHaze()
|
---|
95 | {
|
---|
96 | return this->useHeatHaze;
|
---|
97 | }
|
---|
98 |
|
---|
99 | void ParticleGroup::updateBBox() {
|
---|
100 | std::list<SPTR<Node> >::iterator it;
|
---|
101 | std::list<SPTR<Node> >::iterator itEnd;
|
---|
102 | Node* node;
|
---|
103 | itEnd = this->children.end();
|
---|
104 | if(this->calcBoundingBox) {
|
---|
105 | Vector childMinBBox(9999999,9999999,9999999);
|
---|
106 | Vector childMaxBBox(-9999999,-9999999,-9999999);
|
---|
107 |
|
---|
108 | for(it=this->children.begin();it!=itEnd;it++) {
|
---|
109 | node = (*it).get();
|
---|
110 | if(!node->onStandBy() && node->isVisible()) {
|
---|
111 | node->updateBBox();
|
---|
112 | }
|
---|
113 | }
|
---|
114 | bool first = true;
|
---|
115 | for(it=this->children.begin();it!=itEnd;it++) {
|
---|
116 | node = (*it).get();
|
---|
117 | if(!node->onStandBy() && node->isVisible() &&
|
---|
118 | node->absMinAABBox.x!=0 && node->absMinAABBox.y!=0 && node->absMinAABBox.z!=0) {
|
---|
119 | if(first) {
|
---|
120 | first = false;
|
---|
121 | this->minAABBox = node->absMinAABBox;
|
---|
122 | this->maxAABBox = node->absMaxAABBox;
|
---|
123 | }
|
---|
124 | //min
|
---|
125 | childMinBBox.x = (childMinBBox.x < node->absMinAABBox.x) ? childMinBBox.x : node->absMinAABBox.x;
|
---|
126 | childMinBBox.y = (childMinBBox.y < node->absMinAABBox.y) ? childMinBBox.y : node->absMinAABBox.y;
|
---|
127 | childMinBBox.z = (childMinBBox.z < node->absMinAABBox.z) ? childMinBBox.z : node->absMinAABBox.z;
|
---|
128 |
|
---|
129 | //max
|
---|
130 | childMaxBBox.x = (childMaxBBox.x > node->absMaxAABBox.x) ? childMaxBBox.x : node->absMaxAABBox.x;
|
---|
131 | childMaxBBox.y = (childMaxBBox.y > node->absMaxAABBox.y) ? childMaxBBox.y : node->absMaxAABBox.y;
|
---|
132 | childMaxBBox.z = (childMaxBBox.z > node->absMaxAABBox.z) ? childMaxBBox.z : node->absMaxAABBox.z;
|
---|
133 | }
|
---|
134 | }
|
---|
135 |
|
---|
136 | corner[0] = this->minAABBox;
|
---|
137 | corner[1] = this->minAABBox; corner[1].x = this->maxAABBox.x;
|
---|
138 | corner[2] = this->maxAABBox; corner[2].y = this->minAABBox.y;
|
---|
139 | corner[3] = this->minAABBox; corner[3].z = this->maxAABBox.z;
|
---|
140 | corner[4] = this->minAABBox; corner[4].y = this->maxAABBox.y;
|
---|
141 | corner[5] = this->maxAABBox; corner[5].z = this->minAABBox.z;
|
---|
142 | corner[6] = this->maxAABBox;
|
---|
143 | corner[7] = this->maxAABBox; corner[7].x = this->minAABBox.x;
|
---|
144 | for(int i=0;i<8;i++) {
|
---|
145 | this->getAbsoluteVector(corner[i], corner[i]);
|
---|
146 | //min
|
---|
147 | childMinBBox.x = (childMinBBox.x < corner[i].x) ? childMinBBox.x : corner[i].x;
|
---|
148 | childMinBBox.y = (childMinBBox.y < corner[i].y) ? childMinBBox.y : corner[i].y;
|
---|
149 | childMinBBox.z = (childMinBBox.z < corner[i].z) ? childMinBBox.z : corner[i].z;
|
---|
150 |
|
---|
151 | childMaxBBox.x = (childMaxBBox.x > corner[i].x) ? childMaxBBox.x : corner[i].x;
|
---|
152 | childMaxBBox.y = (childMaxBBox.y > corner[i].y) ? childMaxBBox.y : corner[i].y;
|
---|
153 | childMaxBBox.z = (childMaxBBox.z > corner[i].z) ? childMaxBBox.z : corner[i].z;
|
---|
154 | }
|
---|
155 | this->absMinAABBox = childMinBBox;
|
---|
156 | this->absMaxAABBox = childMaxBBox;
|
---|
157 | this->absBoxCenter = (this->absMinAABBox + this->absMaxAABBox)/2;
|
---|
158 | } else {
|
---|
159 | for(it=this->children.begin();it!=itEnd;it++) {
|
---|
160 | node = (*it).get();
|
---|
161 | if(!node->onStandBy() && node->isVisible()) {
|
---|
162 | node->updateBBox();
|
---|
163 | }
|
---|
164 | }
|
---|
165 | }
|
---|
166 | }
|
---|
167 |
|
---|