00001 #include "spinvelocity.hh" 00002 #include "register.hh" 00003 #include <iostream> 00004 #include "abstractworld.hh" 00005 00006 namespace anoid { 00007 namespace plugin { 00008 00009 using namespace simple; 00010 using namespace config; 00011 00012 void SpinVelocity::init(Configuration &c) { 00013 spinvelocity = c.getVector("spinvelocity"); 00014 00015 Ability::init(c); 00016 Spin::init(c); 00017 Scale::init(c); 00018 Mass::init(c); 00019 00020 if (parentElement) { 00021 if (parentElement->getShape()) { 00022 parentElement->getShape()->getInverseInertiaTensor( 00023 inverseInertiaTensor, 00024 scale.getX(), 00025 scale.getY(), 00026 scale.getZ()); 00027 inverseInertiaTensor[0] /= mass; 00028 inverseInertiaTensor[1] /= mass; 00029 inverseInertiaTensor[2] /= mass; 00030 inverseInertiaTensor[4] /= mass; 00031 inverseInertiaTensor[5] /= mass; 00032 inverseInertiaTensor[6] /= mass; 00033 inverseInertiaTensor[8] /= mass; 00034 inverseInertiaTensor[9] /= mass; 00035 inverseInertiaTensor[10] /= mass; 00036 } 00037 } 00038 00039 spinvelocity.setX(spinvelocity.getX() / inverseInertiaTensor[0]); 00040 spinvelocity.setY(spinvelocity.getY() / inverseInertiaTensor[5]); 00041 spinvelocity.setZ(spinvelocity.getZ() / inverseInertiaTensor[10]); 00042 00043 registerName("SpinVelocity"); 00044 } 00045 00046 Vector SpinVelocity::getSpinVelocity() { 00047 return spinvelocity; 00048 } 00049 00050 void SpinVelocity::setSpinVelocity(Vector &s) { 00051 spinvelocity = s; 00052 } 00053 00054 void SpinVelocity::update() { 00055 Vector tmp; 00056 00057 copyMatrix(inverseWorldInertiaTensor, rotation); 00058 00059 matMult(inverseWorldInertiaTensor, inverseInertiaTensor); 00060 matMult(inverseWorldInertiaTensor, transpose(rotation)); 00061 transpose(rotation); 00062 00063 tmp = inverseWorldInertiaTensor * spinvelocity; 00064 00065 double t = getWorld()->getTime(); 00066 00067 matMult(tilde(spin, tmp), rotation); 00068 spin[0] *= t; 00069 spin[1] *= t; 00070 spin[2] *= t; 00071 spin[4] *= t; 00072 spin[5] *= t; 00073 spin[6] *= t; 00074 spin[8] *= t; 00075 spin[9] *= t; 00076 spin[10] *= t; 00077 00078 Spin::update(); 00079 Scale::update(); 00080 Mass::update(); 00081 Ability::update(); 00082 } 00083 00084 void SpinVelocity::redraw() { 00085 Spin::redraw(); 00086 Scale::redraw(); 00087 Mass::redraw(); 00088 Ability::redraw(); 00089 } 00090 00091 Register(SpinVelocity) 00092 00093 }; 00094 };