flockanimatorexplode.cpp

00001 #include "debug.h"
00002 #include "flock.h"
00003 #include "boid.h"
00004 #include "flockanimatorexplode.h"
00005 
00006 using namespace irr;
00007 using namespace core;
00008 using namespace scene;
00009 
00010 extern Debug* dbg;
00011 
00012 FlockAnimatorExplode::FlockAnimatorExplode(IrrlichtDevice* d, vector3df explCenter, u32 startMs, u32 durationMs, f32 pwr)
00013 {
00014     // ctor
00015     device = d;
00016     center = explCenter;
00017     startTime = startMs;
00018     durationTime = durationMs;
00019     endTime = startMs + durationMs;
00020     power = pwr;
00021     dbg->log("create FlockAnimatorExplode");
00022 }
00023 
00024 FlockAnimatorExplode::~FlockAnimatorExplode()
00025 {
00026     // dtor
00027     dbg->log("FlockAnimatorExplode deleted");
00028 }
00029 
00030 void FlockAnimatorExplode::animateNode(ISceneNode* node, u32 timeMs)
00031 {
00032     if (timeMs > endTime)
00033     {
00034         return;
00035     }
00036     if (timeMs > startTime)
00037     {
00038         Flock* f = ((Flock*) node);
00039         list<Boid*>::Iterator it = f->getBoidList().begin();
00040         for (; it != f->getBoidList().end(); ++it)
00041         {
00042             f32 distance = (*it)->position.getDistanceFrom(center);
00043             (*it)->velocity = center + ((*it)->position - center).normalize() * 50000.0f/distance * power;
00044             f32 gravity = (*it)->position.Y/10;
00045             (*it)->velocity += vector3df(0, -gravity, 0);
00046         }
00047     }
00048 }

Generated on Sun Dec 2 17:09:57 2007 for Swarm by  doxygen 1.4.6-NO