00001 #include "velocity.hh" 00002 #include "register.hh" 00003 #include "abstractworld.hh" 00004 #include "collisionmessage.hh" 00005 #include <iostream> 00006 00007 namespace anoid { 00008 namespace plugin { 00009 00010 using namespace std; 00011 using namespace simple; 00012 using namespace base; 00013 using namespace config; 00014 00015 void Velocity::init(Configuration &c) { 00016 if (c.hasElement("velocity")) 00017 velocity = c.getVector("movement"); 00018 else 00019 velocity = c.getVector("velocity"); 00020 00021 Move::init(c); 00022 registerName("Velocity"); 00023 } 00024 00025 Vector Velocity::getVelocity() { 00026 return velocity; 00027 } 00028 00029 void Velocity::setVelocity(Vector &v) { 00030 velocity = v; 00031 } 00032 00033 void Velocity::update() { 00034 movement = getWorld()->getTime() * velocity; 00035 Move::update(); 00036 } 00037 00038 void Velocity::receive(Message *m) { 00039 CollisionMessage *c = dynamic_cast<CollisionMessage *>(m); 00040 00041 if (c) { 00042 if (((Element *)c->getOther())->lookupAbility("Velocity") == NULL) { 00043 position = position - movement; 00044 cout << velocity << " --- " << *c->getNormal() << " --- " << *c->getP1() << " --- " << *c->getP2() << " --- "; 00045 velocity += ((-2 * (*c->getNormal() * velocity)) * *c->getNormal()); 00046 cout << velocity << endl; 00047 } 00048 } else 00049 Move::receive(m); 00050 } 00051 00052 Register(Velocity) 00053 00054 }; 00055 };