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