1 | #include "dxstdafx.h"
|
---|
2 | #include ".\node.h"
|
---|
3 | #include "Scene.h"
|
---|
4 | #include "GameManager.h"
|
---|
5 |
|
---|
6 | Node::Node(void)
|
---|
7 | {
|
---|
8 | this->testAgainstFrustum = true;
|
---|
9 | this->behaveAs = NORMAL;
|
---|
10 | this->updateMe = true;
|
---|
11 | this->visible = true;
|
---|
12 | this->standBy = false;
|
---|
13 | this->rendererAdded = false;
|
---|
14 | this->aClone = false;
|
---|
15 | this->calcBoundingBox = true;
|
---|
16 | this->absMaxAABBox.x = 0.1f;
|
---|
17 | this->absMaxAABBox.y = 0.1f;
|
---|
18 | this->absMaxAABBox.z = 0.1f;
|
---|
19 | this->absMinAABBox.x = -0.1f;
|
---|
20 | this->absMinAABBox.y = -0.1f;
|
---|
21 | this->absMinAABBox.z = -0.1f;
|
---|
22 | this->absBoxCenter.x = 0.0f;
|
---|
23 | this->absBoxCenter.y = 0.0f;
|
---|
24 | this->absBoxCenter.z = 0.0f;
|
---|
25 | D3DXMatrixIdentity(&this->myWorldMatrix);
|
---|
26 |
|
---|
27 | //Physic Stuff
|
---|
28 | this->pActor = NULL;
|
---|
29 | this->pActorDesc.density = 10.0f;
|
---|
30 | this->pActorDesc.body = &this->pBodyDesc;
|
---|
31 | this->pMaterialId = 0;
|
---|
32 |
|
---|
33 | this->bOverrideWorldMatrix = false;
|
---|
34 | this->timeToLive = -100;
|
---|
35 | this->pColDetGroup = 0;
|
---|
36 | this->nodeType = 0;
|
---|
37 | this->maxAge = 0;
|
---|
38 | this->userData = NULL;
|
---|
39 | this->father = NULL;
|
---|
40 | //this->pShapeDescSize = 0;
|
---|
41 |
|
---|
42 | this->softKill = false;
|
---|
43 | this->softKillDuration = 0;
|
---|
44 | this->doingSoftKill = false;
|
---|
45 | this->softKillAlpha = 1.0f;
|
---|
46 | }
|
---|
47 |
|
---|
48 | Node::~Node(void)
|
---|
49 | {
|
---|
50 | this->children.clear();
|
---|
51 | //if(this->pActor!=NULL)
|
---|
52 | // this->myScene->pScene->releaseActor(*this->pActor);
|
---|
53 | }
|
---|
54 |
|
---|
55 | void Node::setBehaveAs(int _behaveAs)
|
---|
56 | {
|
---|
57 | if(_behaveAs > this->NORMAL && this->pActor==NULL) {
|
---|
58 | this->pActorDesc.globalPose.t.set(this->myPosition.getNxVector());
|
---|
59 | if(_behaveAs == this->STATIC) {
|
---|
60 | this->pActorDesc.body = NULL;
|
---|
61 | this->calcStaticPhysicWorldMatrix();
|
---|
62 | }
|
---|
63 | this->pActorDesc.userData = this;
|
---|
64 | if(!this->pActorDesc.isValid()) {
|
---|
65 | this->myScene->manager->printToConsole("ActorDescriptor is not valid!!");
|
---|
66 | return;
|
---|
67 | }
|
---|
68 |
|
---|
69 | this->pActor = this->myScene->pScene->createActor(this->pActorDesc);
|
---|
70 | this->pActor->userData = this;
|
---|
71 | if(_behaveAs == this->KINEMATIC) {
|
---|
72 | this->pActor->raiseBodyFlag(NX_BF_KINEMATIC);
|
---|
73 | } else {
|
---|
74 | this->pActor->clearBodyFlag(NX_BF_KINEMATIC);
|
---|
75 | }
|
---|
76 |
|
---|
77 | } else if(_behaveAs == this->KINEMATIC && this->pActor!=NULL) {
|
---|
78 | this->pActor->raiseBodyFlag(NX_BF_KINEMATIC);
|
---|
79 | } else {
|
---|
80 | this->pActor->clearBodyFlag(NX_BF_KINEMATIC);
|
---|
81 | }
|
---|
82 | this->behaveAs = _behaveAs;
|
---|
83 | }
|
---|
84 |
|
---|
85 | void Node::setRenderer(SPTR<Renderer> &_myRenderer)
|
---|
86 | {
|
---|
87 | this->rendererAdded = true;
|
---|
88 | this->myRenderer = _myRenderer;
|
---|
89 | }
|
---|
90 |
|
---|
91 | void Node::removeRenderer()
|
---|
92 | {
|
---|
93 | if(this->rendererAdded) {
|
---|
94 | this->rendererAdded = false;
|
---|
95 | Renderer* r = this->myRenderer.get();
|
---|
96 | this->myScene->deleteRendererInList(r);
|
---|
97 | this->myRenderer.reset();
|
---|
98 | }
|
---|
99 | }
|
---|
100 |
|
---|
101 | SPTR<Renderer> Node::getRenderer()
|
---|
102 | {
|
---|
103 | return this->myRenderer;
|
---|
104 | }
|
---|
105 |
|
---|
106 | bool Node::hasRenderer()
|
---|
107 | {
|
---|
108 | return this->rendererAdded;
|
---|
109 | }
|
---|
110 |
|
---|
111 | void Node::setVisible(bool _visible)
|
---|
112 | {
|
---|
113 | this->visible = _visible;
|
---|
114 | std::list<SPTR<Node> >::iterator it;
|
---|
115 | for(it=this->children.begin(); it!=this->children.end();it++) {
|
---|
116 | (*it)->setVisible(_visible);
|
---|
117 | }
|
---|
118 | }
|
---|
119 |
|
---|
120 | bool Node::isVisible()
|
---|
121 | {
|
---|
122 | return this->visible;
|
---|
123 | }
|
---|
124 |
|
---|
125 | void Node::setStandBy(bool _standBy)
|
---|
126 | {
|
---|
127 | this->standBy = _standBy;
|
---|
128 | std::list<SPTR<Node> >::iterator it;
|
---|
129 | for(it=this->children.begin(); it!=this->children.end();it++) {
|
---|
130 | (*it)->setStandBy(_standBy);
|
---|
131 | }
|
---|
132 | if(this->pActor) {
|
---|
133 | if(_standBy) {
|
---|
134 | this->pActor->putToSleep();
|
---|
135 | } else {
|
---|
136 | this->pActor->wakeUp();
|
---|
137 | }
|
---|
138 | }
|
---|
139 | }
|
---|
140 |
|
---|
141 | bool Node::onStandBy()
|
---|
142 | {
|
---|
143 | return this->standBy;
|
---|
144 | }
|
---|
145 |
|
---|
146 | void Node::translate(float dx, float dy, float dz)
|
---|
147 | {
|
---|
148 | if(this->behaveAs != this->STATIC) {
|
---|
149 | this->myPosition.x += dx;
|
---|
150 | this->myPosition.y += dy;
|
---|
151 | this->myPosition.z += dz;
|
---|
152 |
|
---|
153 | if(this->pActor==NULL) {
|
---|
154 | this->pActorDesc.globalPose.t+=NxVec3(dx, dy, dz);
|
---|
155 | }
|
---|
156 | }
|
---|
157 | }
|
---|
158 |
|
---|
159 | void Node::translate(Vector &tv)
|
---|
160 | {
|
---|
161 | if(this->behaveAs != this->STATIC) {
|
---|
162 | this->myPosition += tv;
|
---|
163 |
|
---|
164 | if(this->pActor==NULL) {
|
---|
165 | this->pActorDesc.globalPose.t+=tv.getNxVector();
|
---|
166 | }
|
---|
167 | }
|
---|
168 | }
|
---|
169 |
|
---|
170 | void Node::rotate(float dalpha, float dbeta, float dgamma)
|
---|
171 | {
|
---|
172 | if(this->behaveAs != this->STATIC) {
|
---|
173 | this->myRotation.x += dalpha;
|
---|
174 | this->myRotation.y += dbeta;
|
---|
175 | this->myRotation.z += dgamma;
|
---|
176 |
|
---|
177 | if(this->pActor==NULL) {
|
---|
178 | NxQuat q;
|
---|
179 | q.setx(this->myRotation.x);
|
---|
180 | q.sety(this->myRotation.y);
|
---|
181 | q.setz(this->myRotation.z);
|
---|
182 | q.setw(1);
|
---|
183 | NxMat33 m(q);
|
---|
184 | this->pActorDesc.globalPose.M = this->pActorDesc.globalPose.M*m;
|
---|
185 | }
|
---|
186 | }
|
---|
187 | }
|
---|
188 |
|
---|
189 | void Node::setPosition(float x, float y, float z)
|
---|
190 | {
|
---|
191 | if(this->behaveAs == this->PARTICLE) {
|
---|
192 | this->pActor->setGlobalPosition(NxVec3(x,y,z));
|
---|
193 | return;
|
---|
194 | }
|
---|
195 | if(this->behaveAs != this->STATIC) {
|
---|
196 | this->myPosition.x = x;
|
---|
197 | this->myPosition.y = y;
|
---|
198 | this->myPosition.z = z;
|
---|
199 |
|
---|
200 | if(this->pActor==NULL) {
|
---|
201 | this->pActorDesc.globalPose.t.x = x;
|
---|
202 | this->pActorDesc.globalPose.t.y = y;
|
---|
203 | this->pActorDesc.globalPose.t.z = z;
|
---|
204 | }
|
---|
205 | }/* else if(this->behaveAs == this->PARTICLE) { //ZIEMLICHER SCHWACHSINN nach != STATIC!!
|
---|
206 | this->pActor->setGlobalPosition(NxVec3(x,y,z));
|
---|
207 | }*/
|
---|
208 | }
|
---|
209 |
|
---|
210 | void Node::setPosition(Vector &p)
|
---|
211 | {
|
---|
212 | if(this->behaveAs == this->PARTICLE) {
|
---|
213 | this->pActor->setGlobalPosition(p.getNxVector());
|
---|
214 | return;
|
---|
215 | }
|
---|
216 | if(this->behaveAs != this->STATIC) {
|
---|
217 | this->myPosition = p;
|
---|
218 |
|
---|
219 | if(this->pActor==NULL) {
|
---|
220 | this->pActorDesc.globalPose.t=p.getNxVector();
|
---|
221 | }
|
---|
222 | }
|
---|
223 | }
|
---|
224 |
|
---|
225 | Vector Node::getPosition()
|
---|
226 | {
|
---|
227 | return this->myPosition;
|
---|
228 | }
|
---|
229 |
|
---|
230 | void Node::setRotation(float alpha, float beta, float gamma)
|
---|
231 | {
|
---|
232 | if(this->behaveAs != this->STATIC) {
|
---|
233 | this->myRotation.x = alpha;
|
---|
234 | this->myRotation.y = beta;
|
---|
235 | this->myRotation.z = gamma;
|
---|
236 |
|
---|
237 | if(this->pActor==NULL) {
|
---|
238 | /*NxQuat q;
|
---|
239 | q.setx(this->myRotation.x);
|
---|
240 | q.sety(this->myRotation.y);
|
---|
241 | q.setz(this->myRotation.z);
|
---|
242 | q.setw(1);*/
|
---|
243 | NxMat33 m(this->myRotation.getNxQuatRotation());
|
---|
244 | this->pActorDesc.globalPose.M = m*this->pActorDesc.globalPose.M;
|
---|
245 | }
|
---|
246 | }
|
---|
247 | }
|
---|
248 |
|
---|
249 | void Node::setRotation(Vector &r)
|
---|
250 | {
|
---|
251 | if(this->behaveAs != this->STATIC) {
|
---|
252 | this->myRotation = r;
|
---|
253 |
|
---|
254 | if(this->pActor==NULL) {
|
---|
255 | /*NxQuat q;
|
---|
256 | q.setx(this->myRotation.x);
|
---|
257 | q.sety(this->myRotation.y);
|
---|
258 | q.setz(this->myRotation.z);
|
---|
259 | q.setw(1);*/
|
---|
260 | NxMat33 m(this->myRotation.getNxQuatRotation());
|
---|
261 | this->pActorDesc.globalPose.M = m*this->pActorDesc.globalPose.M;
|
---|
262 | }
|
---|
263 | }
|
---|
264 | }
|
---|
265 |
|
---|
266 | float Node::getRotationX()
|
---|
267 | {
|
---|
268 | return this->myRotation.x;
|
---|
269 | }
|
---|
270 |
|
---|
271 | float Node::getRotationY()
|
---|
272 | {
|
---|
273 | return this->myRotation.y;
|
---|
274 | }
|
---|
275 |
|
---|
276 | float Node::getRotationZ()
|
---|
277 | {
|
---|
278 | return this->myRotation.z;
|
---|
279 | }
|
---|
280 |
|
---|
281 |
|
---|
282 | std::list<SPTR<Node> >::iterator Node::addChild(SPTR<Node> _child)
|
---|
283 | {
|
---|
284 | //_child->myScene = this->myScene;
|
---|
285 | //this->myScene->nodeList.push_back(_child);
|
---|
286 | if(_child->getFather()) {
|
---|
287 | _child->getFather()->removeChild(_child);
|
---|
288 | }
|
---|
289 | _child->father = this;
|
---|
290 | this->children.push_back(_child);
|
---|
291 | std::list<SPTR<Node> >::iterator it = this->children.end();
|
---|
292 | it--;
|
---|
293 | return it;
|
---|
294 | }
|
---|
295 |
|
---|
296 | void Node::removeChild(std::list<SPTR<Node> >::iterator _it)
|
---|
297 | {
|
---|
298 | this->children.remove((SPTR<Node>) *_it);
|
---|
299 | }
|
---|
300 |
|
---|
301 | void Node::removeChild(SPTR<Node> _child)
|
---|
302 | {
|
---|
303 | this->children.remove(_child);
|
---|
304 | }
|
---|
305 |
|
---|
306 | void Node::removeAllChildren()
|
---|
307 | {
|
---|
308 | std::list<SPTR<Node> >::iterator it;
|
---|
309 | for(it=this->children.begin(); it!=this->children.end();it++) {
|
---|
310 | (*it)->killMe();
|
---|
311 | }
|
---|
312 | //this->children.clear();
|
---|
313 | }
|
---|
314 |
|
---|
315 | Vector* Node::getAbsMinBBox()
|
---|
316 | {
|
---|
317 | return &this->absMinAABBox;
|
---|
318 | }
|
---|
319 |
|
---|
320 | Vector* Node::getAbsMaxBBox()
|
---|
321 | {
|
---|
322 | return &this->absMaxAABBox;
|
---|
323 | }
|
---|
324 |
|
---|
325 | Vector Node::getAbsBoxCenter()
|
---|
326 | {
|
---|
327 | return this->absBoxCenter;
|
---|
328 | }
|
---|
329 |
|
---|
330 | void Node::update(float dt)
|
---|
331 | {
|
---|
332 | std::list<SPTR<Node> >::iterator it;
|
---|
333 | for(it=this->children.begin(); it!=this->children.end();it++) {
|
---|
334 | if(!(*it)->standBy && (*it)->updateMe) {
|
---|
335 | (*it)->update(dt);
|
---|
336 | }
|
---|
337 | }
|
---|
338 |
|
---|
339 | if(this->timeToLive!=-100) {
|
---|
340 | this->timeToLive-=dt;
|
---|
341 | if(this->timeToLive<=this->softKillDuration) {
|
---|
342 | this->doingSoftKill = true;
|
---|
343 | this->softKillAlpha = this->timeToLive/this->softKillDuration;
|
---|
344 | }
|
---|
345 | if(this->timeToLive<=0) {
|
---|
346 | this->setVisible(false);
|
---|
347 | this->killMe();
|
---|
348 | }
|
---|
349 | }
|
---|
350 | }
|
---|
351 |
|
---|
352 | void Node::calcWorldMatrix(D3DXMATRIX &pMatWorld)
|
---|
353 | {
|
---|
354 | if(this->standBy) {
|
---|
355 | return;
|
---|
356 | }
|
---|
357 | std::list<SPTR<Node> >::iterator it;
|
---|
358 | if(this->bOverrideWorldMatrix) {
|
---|
359 | this->bOverrideWorldMatrix = false;
|
---|
360 | for(it=this->children.begin(); it!=this->children.end();it++) {
|
---|
361 | (*it)->calcWorldMatrix(this->myWorldMatrix);
|
---|
362 | }
|
---|
363 | return;
|
---|
364 | }
|
---|
365 | switch(this->behaveAs) {
|
---|
366 | case NORMAL:
|
---|
367 | this->calcNormalWorldMatrix(pMatWorld);
|
---|
368 | break;
|
---|
369 | /*case STATIC:
|
---|
370 | this->calcStaticPhysicWorldMatrix(pMatWorld);
|
---|
371 | break;*/
|
---|
372 | case KINEMATIC:
|
---|
373 | this->calcKinematicWorldMatrix(pMatWorld);
|
---|
374 | break;
|
---|
375 | case RIGIDBODY:
|
---|
376 | case PARTICLE:
|
---|
377 | this->calcPhysicWorldMatrix(pMatWorld);
|
---|
378 | break;
|
---|
379 | }
|
---|
380 |
|
---|
381 | for(it=this->children.begin(); it!=this->children.end();it++) {
|
---|
382 | (*it)->calcWorldMatrix(this->myWorldMatrix);
|
---|
383 | }
|
---|
384 | this->getAbsoluteVector(this->absMinAABBox, this->minAABBox);
|
---|
385 | this->getAbsoluteVector(this->absMaxAABBox, this->maxAABBox);
|
---|
386 | this->getAbsoluteVector(this->myAbsPos, Vector(0, 0, 0));
|
---|
387 | Vector camPos = this->myScene->getActiveCamera()->getAbsolutePosition();
|
---|
388 | this->camDistance = (camPos - this->getAbsolutePosition()).length();
|
---|
389 | }
|
---|
390 |
|
---|
391 | void Node::calcNormalWorldMatrix(D3DXMATRIX &pMatWorld)
|
---|
392 | {
|
---|
393 | D3DXQUATERNION quat;
|
---|
394 | D3DXMATRIX tempWorld;
|
---|
395 | D3DXMATRIX tempTrans;
|
---|
396 | D3DXMATRIX MatRot; // Final rotation matrix, applied to
|
---|
397 | // pMatWorld.
|
---|
398 |
|
---|
399 | float x = this->myPosition.x;
|
---|
400 | float y = this->myPosition.y;
|
---|
401 | float z = this->myPosition.z;
|
---|
402 |
|
---|
403 | float a = this->myRotation.x;
|
---|
404 | float b = this->myRotation.y;
|
---|
405 | float g = this->myRotation.z;
|
---|
406 |
|
---|
407 | //tempWorld = pMatWorld;
|
---|
408 | D3DXMatrixTranslation(&tempTrans, x, y, z);
|
---|
409 | D3DXMatrixMultiply(&this->myWorldMatrix, &tempTrans, &pMatWorld);
|
---|
410 | if(a!=0 || b!=0 || g!=0) {
|
---|
411 | D3DXQuaternionIdentity(&quat);
|
---|
412 | D3DXQuaternionRotationYawPitchRoll(&quat, b, a, g);
|
---|
413 | D3DXMatrixRotationQuaternion(&MatRot, &quat);
|
---|
414 | D3DXMatrixMultiply(&this->myWorldMatrix, &MatRot, &this->myWorldMatrix);
|
---|
415 | }
|
---|
416 | }
|
---|
417 |
|
---|
418 | void Node::calcKinematicWorldMatrix(D3DXMATRIX &pMatWorld)
|
---|
419 | {
|
---|
420 | //calculate position of physic actor or particle
|
---|
421 | if(this->pActor!=NULL) {
|
---|
422 | //this->pActor->moveGlobalPosition(this->myPosition.getNxVector());
|
---|
423 | NxMat33 m(this->myRotation.getNxQuatRotation());
|
---|
424 | NxMat34 mat;
|
---|
425 | mat.M = m;
|
---|
426 | mat.t = this->myPosition.getNxVector();
|
---|
427 | this->pActor->moveGlobalPose(mat);
|
---|
428 | }
|
---|
429 | this->calcPhysicWorldMatrix(pMatWorld);
|
---|
430 | }
|
---|
431 |
|
---|
432 | void Node::calcPhysicWorldMatrix(D3DXMATRIX &pMatWorld)
|
---|
433 | {
|
---|
434 | if(this->pActor!=NULL) {
|
---|
435 | this->pActor->getGlobalPose().getColumnMajor44(((NxF32 *) &this->myWorldMatrix.m[0][0]));
|
---|
436 | }
|
---|
437 | }
|
---|
438 |
|
---|
439 | void Node::calcStaticPhysicWorldMatrix()
|
---|
440 | {
|
---|
441 | NxMat34 m(this->pActorDesc.globalPose.M, this->pActorDesc.globalPose.t);
|
---|
442 | m.getColumnMajor44(((NxF32 *) &this->myWorldMatrix.m[0][0]));
|
---|
443 | }
|
---|
444 |
|
---|
445 | void Node::getAbsoluteVector(Vector &pOut, Vector &pin)
|
---|
446 | {
|
---|
447 | //D3DXVECTOR4 temp;
|
---|
448 | D3DXVec4Transform(&pOut, &pin, &this->myWorldMatrix);
|
---|
449 | //Vector v(temp.x, temp.y, temp.z);
|
---|
450 | //return v;
|
---|
451 | }
|
---|
452 |
|
---|
453 | void Node::getAbsoluteDirectionVector(Vector &dirOut, Vector &dirIn)
|
---|
454 | {
|
---|
455 | Vector temp;
|
---|
456 | temp = this->getAbsolutePosition();
|
---|
457 | this->getAbsoluteVector(dirOut, dirIn);
|
---|
458 | dirOut.x-= temp.x;
|
---|
459 | dirOut.y-= temp.y;
|
---|
460 | dirOut.z-= temp.z;
|
---|
461 | }
|
---|
462 |
|
---|
463 | Vector Node::getAbsolutePosition()
|
---|
464 | {
|
---|
465 | /*Vector origin(0, 0, 0);
|
---|
466 | this->getAbsoluteVector(origin, origin);
|
---|
467 | return origin;*/
|
---|
468 | return this->myAbsPos;
|
---|
469 | }
|
---|
470 |
|
---|
471 | void Node::setWorldMatrix(D3DXMATRIXA16 &worldMatrix)
|
---|
472 | {
|
---|
473 | this->bOverrideWorldMatrix = true;
|
---|
474 | this->myWorldMatrix = worldMatrix;
|
---|
475 | this->getAbsoluteVector(this->myAbsPos, Vector(0, 0, 0));
|
---|
476 | }
|
---|
477 |
|
---|
478 |
|
---|
479 | D3DXMATRIXA16* Node::getWorldMatrix()
|
---|
480 | {
|
---|
481 | return &this->myWorldMatrix;
|
---|
482 | }
|
---|
483 |
|
---|
484 | void Node::setScene(Scene &scene)
|
---|
485 | {
|
---|
486 | this->myScene = &scene;
|
---|
487 | }
|
---|
488 |
|
---|
489 | void Node::killMe()
|
---|
490 | {
|
---|
491 | std::list<SPTR<Node> >::iterator it;
|
---|
492 | for(it=this->children.begin();it!=this->children.end();it++)
|
---|
493 | {
|
---|
494 | (*it)->killMe();
|
---|
495 | }
|
---|
496 | //this->myScene->manager->printToConsole("killMe called, but not yet implemented!");
|
---|
497 | //delete my, in father, the phyisc model, in scene...with (virtual void Scene::killNode(Node *node))
|
---|
498 | this->myScene->deleteNode(this);
|
---|
499 | this->updateMe = false;
|
---|
500 | }
|
---|
501 |
|
---|
502 | NxActorDesc* Node::getActorDescriptor()
|
---|
503 | {
|
---|
504 | return &this->pActorDesc;
|
---|
505 | }
|
---|
506 |
|
---|
507 | NxBodyDesc* Node::getBodyDescriptor()
|
---|
508 | {
|
---|
509 | return &this->pBodyDesc;
|
---|
510 | }
|
---|
511 |
|
---|
512 | NxActor* Node::getActor()
|
---|
513 | {
|
---|
514 | return this->pActor;
|
---|
515 | }
|
---|
516 |
|
---|
517 | void Node::setPMaterial(int id)
|
---|
518 | {
|
---|
519 | this->pMaterialId = id;
|
---|
520 | if(this->pActor) {
|
---|
521 | int nbShapes = this->pActor->getNbShapes();
|
---|
522 | for(int i=0;i<nbShapes;i++) {
|
---|
523 | this->pActor->getShapes()[i]->setMaterial(id);
|
---|
524 | }
|
---|
525 | }
|
---|
526 | }
|
---|
527 |
|
---|
528 | void Node::setColDetGroup(int group)
|
---|
529 | {
|
---|
530 | this->pColDetGroup = group;
|
---|
531 | if(this->pActor) {
|
---|
532 | bool disableRayCasting;
|
---|
533 | disableRayCasting = (group==UserContactReport::COLGROUP_NOCOL) ? true : false;
|
---|
534 | NxU32 shapeNb = this->pActor->getNbShapes();
|
---|
535 | NxShape *const* shapes = this->pActor->getShapes();
|
---|
536 | for(UINT i=0;i<shapeNb;i++) {
|
---|
537 | (*shapes)->setGroup(group);
|
---|
538 | (*shapes)->setFlag(NX_SF_DISABLE_RAYCASTING, disableRayCasting);
|
---|
539 | shapes++;
|
---|
540 | }
|
---|
541 | this->pActor->setGroup(group);
|
---|
542 | }/* else {
|
---|
543 | this->myScene->manager->printToConsole("Node::setColDetGroup called before actor created!!!");
|
---|
544 | }*/
|
---|
545 | }
|
---|
546 |
|
---|
547 | Node* Node::getFather()
|
---|
548 | {
|
---|
549 | return this->father;
|
---|
550 | }
|
---|
551 |
|
---|
552 | std::list<SPTR<Node> > *Node::getChildren() {
|
---|
553 | return &this->children;
|
---|
554 | }
|
---|
555 |
|
---|
556 | void Node::setParticleGroup(int _group)
|
---|
557 | {
|
---|
558 | this->particleGroup = _group;
|
---|
559 | if(this->pActorDesc.shapes.size()==0) {
|
---|
560 | this->myScene->manager->printToConsole("I HAVE NO SHAPES!!!");
|
---|
561 | } else {
|
---|
562 | this->setBehaveAs(this->PARTICLE);
|
---|
563 | }
|
---|
564 | }
|
---|
565 |
|
---|
566 | int Node::getParticleGroup()
|
---|
567 | {
|
---|
568 | return this->particleGroup;
|
---|
569 | }
|
---|
570 |
|
---|
571 | Node* Node::clone()
|
---|
572 | {
|
---|
573 | return NULL;
|
---|
574 | }
|
---|
575 |
|
---|
576 | void Node::setTimeToLive(float _timeToLive)
|
---|
577 | {
|
---|
578 | /*std::list<SPTR<Node> >::iterator it;
|
---|
579 | for(it=this->children.begin(); it!=this->children.end();it++) {
|
---|
580 | (*it)->setTimeToLive(_timeToLive);
|
---|
581 | }*/
|
---|
582 | this->timeToLive = _timeToLive;
|
---|
583 | this->maxAge = _timeToLive;
|
---|
584 | }
|
---|
585 |
|
---|
586 | float Node::getTimeToLive() {
|
---|
587 | return this->timeToLive;
|
---|
588 | }
|
---|
589 |
|
---|
590 | void Node::cloneChildren(Node *clonedNode)
|
---|
591 | {
|
---|
592 | Node* n;
|
---|
593 | std::list<SPTR<Node> >::iterator it;
|
---|
594 | for(it=this->children.begin();it!=this->children.end();it++) {
|
---|
595 | n = (*it).get();
|
---|
596 | SPTR<Node> sn = this->myScene->getSmartPointer(n->clone());
|
---|
597 | clonedNode->addChild(sn);
|
---|
598 | }
|
---|
599 | }
|
---|
600 |
|
---|
601 | void Node::updateBBox() {
|
---|
602 | std::list<SPTR<Node> >::iterator it;
|
---|
603 | std::list<SPTR<Node> >::iterator itEnd;
|
---|
604 | Node* node;
|
---|
605 | itEnd = this->children.end();
|
---|
606 | if(this->calcBoundingBox) {
|
---|
607 | Vector childMinBBox(9999999,9999999,9999999);
|
---|
608 | Vector childMaxBBox(-9999999,-9999999,-9999999);
|
---|
609 |
|
---|
610 | for(it=this->children.begin();it!=itEnd;it++) {
|
---|
611 | node = (*it).get();
|
---|
612 | if(!node->onStandBy() && node->isVisible()) {
|
---|
613 | node->updateBBox();
|
---|
614 | }
|
---|
615 | }
|
---|
616 | /*for(it=this->children.begin();it!=itEnd;it++) {
|
---|
617 | node = (*it).get();
|
---|
618 | if(!node->onStandBy() && node->isVisible() &&
|
---|
619 | node->absMinAABBox.x!=0 && node->absMinAABBox.y!=0 && node->absMinAABBox.z!=0) {
|
---|
620 | //min
|
---|
621 | childMinBBox.x = (childMinBBox.x < node->absMinAABBox.x) ? childMinBBox.x : node->absMinAABBox.x;
|
---|
622 | childMinBBox.y = (childMinBBox.y < node->absMinAABBox.y) ? childMinBBox.y : node->absMinAABBox.y;
|
---|
623 | childMinBBox.z = (childMinBBox.z < node->absMinAABBox.z) ? childMinBBox.z : node->absMinAABBox.z;
|
---|
624 |
|
---|
625 | //max
|
---|
626 | childMaxBBox.x = (childMaxBBox.x > node->absMaxAABBox.x) ? childMaxBBox.x : node->absMaxAABBox.x;
|
---|
627 | childMaxBBox.y = (childMaxBBox.y > node->absMaxAABBox.y) ? childMaxBBox.y : node->absMaxAABBox.y;
|
---|
628 | childMaxBBox.z = (childMaxBBox.z > node->absMaxAABBox.z) ? childMaxBBox.z : node->absMaxAABBox.z;
|
---|
629 | }
|
---|
630 | }*/
|
---|
631 |
|
---|
632 | corner[0] = this->minAABBox;
|
---|
633 | corner[1] = this->minAABBox; corner[1].x = this->maxAABBox.x;
|
---|
634 | corner[2] = this->maxAABBox; corner[2].y = this->minAABBox.y;
|
---|
635 | corner[3] = this->minAABBox; corner[3].z = this->maxAABBox.z;
|
---|
636 | corner[4] = this->minAABBox; corner[4].y = this->maxAABBox.y;
|
---|
637 | corner[5] = this->maxAABBox; corner[5].z = this->minAABBox.z;
|
---|
638 | corner[6] = this->maxAABBox;
|
---|
639 | corner[7] = this->maxAABBox; corner[7].x = this->minAABBox.x;
|
---|
640 | for(int i=0;i<8;i++) {
|
---|
641 | this->getAbsoluteVector(corner[i], corner[i]);
|
---|
642 | //min
|
---|
643 | childMinBBox.x = (childMinBBox.x < corner[i].x) ? childMinBBox.x : corner[i].x;
|
---|
644 | childMinBBox.y = (childMinBBox.y < corner[i].y) ? childMinBBox.y : corner[i].y;
|
---|
645 | childMinBBox.z = (childMinBBox.z < corner[i].z) ? childMinBBox.z : corner[i].z;
|
---|
646 |
|
---|
647 | childMaxBBox.x = (childMaxBBox.x > corner[i].x) ? childMaxBBox.x : corner[i].x;
|
---|
648 | childMaxBBox.y = (childMaxBBox.y > corner[i].y) ? childMaxBBox.y : corner[i].y;
|
---|
649 | childMaxBBox.z = (childMaxBBox.z > corner[i].z) ? childMaxBBox.z : corner[i].z;
|
---|
650 | }
|
---|
651 | this->absMinAABBox = childMinBBox;
|
---|
652 | this->absMaxAABBox = childMaxBBox;
|
---|
653 | this->absBoxCenter = (this->absMinAABBox + this->absMaxAABBox)/2;
|
---|
654 | } else {
|
---|
655 | for(it=this->children.begin();it!=itEnd;it++) {
|
---|
656 | node = (*it).get();
|
---|
657 | if(!node->onStandBy() && node->isVisible()) {
|
---|
658 | node->updateBBox();
|
---|
659 | }
|
---|
660 | }
|
---|
661 | }
|
---|
662 | }
|
---|
663 |
|
---|
664 | void Node::setDetail(Vector ObjectCenter) {
|
---|
665 | //nothing happens here, only in Object3d...
|
---|
666 | }
|
---|
667 |
|
---|
668 | void Node::orientAndMove(Vector direction, Vector upVec, Vector moveVec, bool moveRelative)
|
---|
669 | {
|
---|
670 | Vector globalPos;
|
---|
671 | //wenn !moveRelative ....absPos+=moveVec
|
---|
672 | if(moveRelative) {
|
---|
673 | globalPos = this->getAbsolutePosition();
|
---|
674 | } else {
|
---|
675 | this->getAbsoluteVector(globalPos, moveVec);
|
---|
676 | }
|
---|
677 |
|
---|
678 | //X Axis berechnen mit crossProd
|
---|
679 | Vector xAxis;
|
---|
680 | direction.normalize(); //z Axis
|
---|
681 | upVec.normalize(); //y Axis
|
---|
682 | xAxis = upVec.crossProd(direction); //x Axis
|
---|
683 | xAxis.normalize();
|
---|
684 | upVec = direction.crossProd(xAxis);
|
---|
685 | upVec.normalize();
|
---|
686 | /*Vector xAxis;
|
---|
687 | direction.normalize(); //z Axis
|
---|
688 | upVec.normalize(); //y Axis
|
---|
689 | xAxis = upVec.crossProd(direction); //x Axis*/
|
---|
690 |
|
---|
691 | //Matrix zusammensetzen + translation
|
---|
692 | D3DXMATRIXA16 wMat;
|
---|
693 | D3DXMatrixIdentity(&wMat);
|
---|
694 | wMat._11 = xAxis.x; wMat._12 = upVec.x; wMat._13 = direction.x;
|
---|
695 | wMat._21 = xAxis.y; wMat._22 = upVec.y; wMat._23 = direction.y;
|
---|
696 | wMat._31 = xAxis.z; wMat._32 = upVec.z; wMat._33 = direction.z;
|
---|
697 |
|
---|
698 | wMat._41 = globalPos.x; wMat._42 = globalPos.y; wMat._43 = globalPos.z;
|
---|
699 |
|
---|
700 | //wenn moveRelative, translationsMatrix erstellen und "moven"
|
---|
701 | if(moveRelative) {
|
---|
702 | D3DXMATRIXA16 trans;
|
---|
703 | D3DXMatrixTranslation(&trans, moveVec.x, moveVec.y, moveVec.z);
|
---|
704 | D3DXMatrixMultiply(&wMat, &trans, &wMat);
|
---|
705 | }
|
---|
706 |
|
---|
707 | //wenn pActor-> matrix dort auch setzen
|
---|
708 | if(this->pActor!=NULL) {
|
---|
709 | NxMat34 pMat;
|
---|
710 | //pMat.setColumnMajor44(((NxF32 *) &wMat.m[0][0]));
|
---|
711 | pMat.setRowMajor44(((NxF32 *) &wMat.m[0][0]));
|
---|
712 | this->pActor->setGlobalPose(pMat);
|
---|
713 | this->pActor->setGlobalPosition(globalPos.getNxVector());
|
---|
714 | } else {
|
---|
715 | this->setWorldMatrix(wMat);
|
---|
716 | }
|
---|
717 | this->myPosition = globalPos;
|
---|
718 | }
|
---|
719 |
|
---|
720 | bool Node::isA(int _nodeType)
|
---|
721 | {
|
---|
722 | return (this->nodeType & _nodeType);
|
---|
723 | }
|
---|
724 |
|
---|
725 | void Node::clonePhysicStuff(Node* obj)
|
---|
726 | {
|
---|
727 | /* obj->pBodyDesc = this->pBodyDesc;
|
---|
728 | obj->pActorDesc.body = &obj->pBodyDesc;
|
---|
729 |
|
---|
730 | obj->pActorDesc = this->pActorDesc;
|
---|
731 | obj->pActorDesc.shapes.clear();
|
---|
732 | this->pShapeDescSize = 0;
|
---|
733 | for(int i=0;i<this->pActorDesc.shapes.size();i++) {
|
---|
734 | NxShapeDesc shapeDesc = *this->pActorDesc.shapes[i];
|
---|
735 |
|
---|
736 | //this->pShapeDescVector.push_back(shapeDesc);
|
---|
737 | this->pShapeDesc[this->pShapeDescSize] = shapeDesc;
|
---|
738 | this->pShapeDescSize++;
|
---|
739 | //obj->pActorDesc.shapes.pushBack(&this->pShapeDescVector.at(i));
|
---|
740 | }*/
|
---|
741 | }
|
---|
742 |
|
---|
743 | void Node::OnLostDevice( void* pUserContext )
|
---|
744 | {
|
---|
745 | }
|
---|
746 |
|
---|
747 | void Node::OnDestroyDevice( void* pUserContext )
|
---|
748 | {
|
---|
749 | }
|
---|
750 |
|
---|
751 | HRESULT Node::OnResetDevice( IDirect3DDevice9* pd3dDevice, const D3DSURFACE_DESC* pBackBufferSurfaceDesc, void* pUserContext )
|
---|
752 | {
|
---|
753 | return S_OK;
|
---|
754 | }
|
---|
755 |
|
---|
756 | void Node::setSoftKill(bool _softKill, float _duration)
|
---|
757 | {
|
---|
758 | this->softKill = _softKill;
|
---|
759 | this->softKillDuration = _duration;
|
---|
760 | std::list<SPTR<Node> >::iterator it;
|
---|
761 | for(it=this->children.begin(); it!=this->children.end();it++) {
|
---|
762 | (*it)->setSoftKill(_softKill, _duration);
|
---|
763 | }
|
---|
764 | }
|
---|
765 |
|
---|
766 | bool Node::getSoftKill()
|
---|
767 | {
|
---|
768 | return this->softKill;
|
---|
769 | } |
---|