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