#include "dxstdafx.h" #include ".\particlecube.h" ParticleCube::ParticleCube(void) : Node() { this->width = 0; this->height = 0; this->depth = 0; this->calcLocalPosition = false; this->calcLocalVelocity = false; this->updatePlanes(); } ParticleCube::~ParticleCube(void) { } void ParticleCube::setDimensions(float _w, float _h, float _d) { this->width = _w; this->height = _h; this->depth = _d; this->updatePlanes(); } void ParticleCube::update(float dt) { this->myParticleList.clear(); this->myParticlePositionList.clear(); this->myParticleVelocityList.clear(); this->updatePlanes(); std::list >* allParticles = this->myScene->getParticleList(); std::list >::iterator it; Node *node; bool inside; Vector nPos; for(it=allParticles->begin();it!=allParticles->end();it++) { node = (*it).get(); inside = true; for(unsigned int j=0;j<6;j++) { nPos = node->getAbsolutePosition(); if(wall[j].inFront(nPos)) { inside = false; break; } } if(inside) { D3DXMATRIXA16 invWorldMat; Vector tempPos; Vector tempVel; if(this->calcLocalPosition || this->calcLocalVelocity) { D3DXMatrixInverse(&invWorldMat, NULL, &this->myWorldMatrix); } if(this->calcLocalPosition) { D3DXVec4Transform(&tempPos, &nPos, &invWorldMat); this->myParticlePositionList.push_back(tempPos); } if(this->calcLocalVelocity) { tempVel = Vector(node->getActor()->getLinearVelocity()); D3DXVec4Transform(&tempVel, &tempVel, &invWorldMat); tempVel = tempVel - nPos; this->myParticleVelocityList.push_back(tempVel); } this->myParticleList.push_back(node); } } } void ParticleCube::addForceToParticle(Node* particle, Vector force) { NxActor* actor = particle->getActor(); if(actor!=NULL) { //force = this->getAbsoluteVector(force) - this->getAbsolutePosition(); this->getAbsoluteDirectionVector(force, force); actor->addForceAtLocalPos(force.getNxVector(), NxVec3(0,0,0)); } } void ParticleCube::addVelocityToParticle(Node* particle, Vector velocity) { NxActor* actor = particle->getActor(); if(actor!=NULL) { //velocity = this->getAbsoluteVector(velocity) - this->getAbsolutePosition(); this->getAbsoluteDirectionVector(velocity, velocity); Vector tempV(actor->getLinearVelocity()); velocity = velocity + tempV; actor->setLinearVelocity(velocity.getNxVector()); } } void ParticleCube::updatePlanes() { Vector p[6]; Vector np[6]; p[FRONT].setXYZ(0, 0, this->depth/2); p[BACK].setXYZ(0, 0, -this->depth/2); p[TOP].setXYZ(0, this->height/2, 0); p[BOTTOM].setXYZ(0, -this->height/2, 0); p[LEFT].setXYZ(this->width/2, 0, 0); p[RIGHT].setXYZ(-this->width/2, 0, 0); np[FRONT].setXYZ(0,0,1); np[BACK].setXYZ(0,0,-1); np[TOP].setXYZ(0,1,0); np[BOTTOM].setXYZ(0,-1,0); np[LEFT].setXYZ(1, 0, 0); np[RIGHT].setXYZ(-1, 0, 0); for(int i=0;i<6;i++) { this->getAbsoluteVector(p[i], p[i]); this->getAbsoluteVector(np[i], np[i]); np[i] = np[i] - p[i]; wall[i].setPoint(p[i]); wall[i].setNormal(np[i]); } }