00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039 #include "oderobot.h"
00040 #include "primitive.h"
00041
00042 namespace lpzrobots {
00043
00044
00045
00046
00047
00048 OdeRobot::OdeRobot(const OdeHandle& odeHandle, const OsgHandle& osgHandle, const char* name)
00049 : AbstractRobot(name), odeHandle(odeHandle), osgHandle(osgHandle) {
00050 parentspace = odeHandle.space;
00051 };
00052
00053 OdeRobot::~OdeRobot(){}
00054
00055
00056
00057
00058 void OdeRobot::setColor(const Color& col){
00059 osgHandle.color = col;
00060 };
00061
00062
00063
00064
00065 void OdeRobot::place(const Pos& pos){
00066 place(osg::Matrix::translate(pos));
00067 }
00068
00069
00070
00071
00072 Position OdeRobot::getPosition() const {
00073 const Primitive* o = getMainPrimitive();
00074 if (o && o->getBody()){
00075 return Position(dBodyGetPosition(o->getBody()));
00076 } else return Position(0,0,0);
00077 }
00078
00079
00080
00081
00082 Position OdeRobot::getSpeed() const {
00083 const Primitive* o = getMainPrimitive();
00084 if (o && o->getBody()){
00085 return Position(dBodyGetLinearVel(o->getBody()));
00086 } else return Position(0,0,0);
00087 }
00088
00089
00090
00091
00092 matrix::Matrix OdeRobot::getOrientation() const {
00093 const Primitive* o = getMainPrimitive();
00094 if (o && o->getBody()){
00095 return odeRto3x3RotationMatrix(dBodyGetRotation(o->getBody()));
00096 } else {
00097 matrix::Matrix R(3,3);
00098 return R^0;
00099 }
00100 }
00101
00102
00103 bool OdeRobot::isGeomInPrimitiveList(Primitive** ps, int len, dGeomID geom){
00104 for(int i=0; i < len; i++){
00105 if(geom == ps[i]->getGeom()) return true;
00106 }
00107 return false;
00108 }
00109
00110 bool OdeRobot::isGeomInPrimitiveList(list<Primitive*> ps, dGeomID geom){
00111 for(list<Primitive*>::iterator i=ps.begin(); i != ps.end(); i++){
00112 if(geom == (*i)->getGeom()) return true;
00113 }
00114 return false;
00115 }
00116
00117 matrix::Matrix OdeRobot::odeRto3x3RotationMatrixT ( const double R[12] ) {
00118 matrix::Matrix matrix(3,3);
00119 matrix.val(0,0)=R[0];
00120 matrix.val(0,1)=R[4];
00121 matrix.val(0,2)=R[8];
00122 matrix.val(1,0)=R[1];
00123 matrix.val(1,1)=R[5];
00124 matrix.val(1,2)=R[9];
00125 matrix.val(2,0)=R[2];
00126 matrix.val(2,1)=R[6];
00127 matrix.val(2,2)=R[10];
00128 return matrix;
00129 }
00130
00131 matrix::Matrix OdeRobot::odeRto3x3RotationMatrix ( const double R[12] ) {
00132 matrix::Matrix matrix(3,3);
00133 matrix.val(0,0)=R[0];
00134 matrix.val(1,0)=R[4];
00135 matrix.val(2,0)=R[8];
00136 matrix.val(0,1)=R[1];
00137 matrix.val(1,1)=R[5];
00138 matrix.val(2,1)=R[9];
00139 matrix.val(0,2)=R[2];
00140 matrix.val(1,2)=R[6];
00141 matrix.val(2,2)=R[10];
00142 return matrix;
00143 }
00144
00145 }