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 #ifndef __PASSIVEBOX_H
00033 #define __PASSIVEBOX_H
00034
00035 #include <stdio.h>
00036 #include <math.h>
00037
00038 #include "primitive.h"
00039 #include "abstractobstacle.h"
00040
00041 namespace lpzrobots {
00042
00043
00044
00045
00046 class PassiveBox : public AbstractObstacle{
00047 double radius;
00048 double mass;
00049
00050
00051
00052 osg::Vec3 pos;
00053 int texture;
00054
00055 Box* box;
00056
00057 bool obstacle_exists;
00058
00059 public:
00060
00061
00062
00063
00064 PassiveBox(const OdeHandle& odeHandle, const OsgHandle& osgHandle,
00065 const osg::Vec3& dimension = osg::Vec3(1.0, 1.0, 1.0), double mass = 1.0):
00066 AbstractObstacle::AbstractObstacle(odeHandle, osgHandle), dimension(dimension), mass(mass) {
00067 box=0;
00068 obstacle_exists=false;
00069 };
00070
00071 ~PassiveBox(){
00072 if(box) delete box;
00073 }
00074
00075
00076
00077
00078 virtual void update(){
00079 if(box) box->update();
00080 };
00081
00082 virtual void setTexture(const std::string& filename){
00083 if(box) box->getOSGPrimitive()->setTexture(filename);
00084 }
00085
00086 virtual void setPose(const osg::Matrix& pose){
00087 this->pose = osg::Matrix::transform(0,0,radius) * pose;
00088 if (obstacle_exists){
00089 destroy();
00090 }
00091 create();
00092 };
00093
00094 virtual osg::Matrix getPose(){
00095 return pose;
00096 }
00097
00098
00099
00100
00101 virtual void setPosition(const osg::Vec3& pos){
00102 this->pos = pos + osg::Vec3(0,0,radius);
00103
00104 if (obstacle_exists){
00105 destroy();
00106 }
00107 create();
00108 };
00109
00110
00111
00112
00113 virtual osg::Vec3 getPosition(){
00114 return pos;
00115 }
00116
00117 protected:
00118 virtual void create(){
00119 box = new Box(dimension.x(), dimension.y(), dimension.z());
00120 box->init(odeHandle, mass, osgHandle);
00121 box->setPosition(pos);
00122
00123 obstacle_exists=true;
00124 };
00125
00126
00127 virtual void destroy(){
00128 if(box) delete box;
00129 obstacle_exists=false;
00130 };
00131
00132 };
00133
00134 }
00135
00136 #endif