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
00040
00041
00042
00043
00044
00045
00046 #ifndef __PASSIVECAPSULE_H
00047 #define __PASSIVECAPSULE_H
00048
00049 #include <stdio.h>
00050 #include <cmath>
00051
00052 #include "primitive.h"
00053 #include "abstractobstacle.h"
00054
00055 namespace lpzrobots {
00056
00057
00058
00059
00060 class PassiveCapsule : public AbstractObstacle{
00061 float radius;
00062 float height;
00063 double mass;
00064
00065 Capsule* capsule;
00066
00067
00068 public:
00069
00070
00071
00072
00073 PassiveCapsule(const OdeHandle& odeHandle, const OsgHandle& osgHandle,
00074 float radius=1.0, float height=1.0, double mass = 1.0):
00075 AbstractObstacle::AbstractObstacle(odeHandle, osgHandle), radius(radius), height(height), mass(mass) {
00076 capsule=0;
00077 obstacle_exists=false;
00078 };
00079
00080 ~PassiveCapsule(){
00081 if(capsule) delete capsule;
00082 }
00083
00084
00085
00086
00087 virtual void update(){
00088 if(capsule) capsule->update();
00089 };
00090
00091 virtual void setTexture(const std::string& filename){
00092 if(capsule) capsule->getOSGPrimitive()->setTexture(filename);
00093 }
00094
00095 virtual void setPose(const osg::Matrix& pose){
00096 this->pose = osg::Matrix::translate(0,0,height*0.5f+radius) * pose;
00097 if (obstacle_exists){
00098 destroy();
00099 }
00100 create();
00101 };
00102
00103 virtual Primitive* getMainPrimitive() const { return capsule; }
00104
00105 protected:
00106 virtual void create(){
00107 capsule = new Capsule(radius,height);
00108 capsule->init(odeHandle, mass, osgHandle);
00109 osg::Vec3 pos=pose.getTrans();
00110 capsule->setPosition(pos);
00111
00112 obstacle_exists=true;
00113 };
00114
00115 virtual void destroy(){
00116 if(capsule) delete capsule;
00117 obstacle_exists=false;
00118 };
00119
00120 };
00121
00122 }
00123
00124 #endif
00125