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 #ifndef __PASSIVECAPSULE_H
00025 #define __PASSIVECAPSULE_H
00026
00027 #include <stdio.h>
00028 #include <cmath>
00029
00030 #include "primitive.h"
00031 #include "abstractobstacle.h"
00032
00033 namespace lpzrobots {
00034
00035
00036
00037
00038 class PassiveCapsule : public AbstractObstacle{
00039 float radius;
00040 float height;
00041 double mass;
00042
00043 Capsule* capsule;
00044
00045
00046 public:
00047
00048
00049
00050
00051 PassiveCapsule(const OdeHandle& odeHandle, const OsgHandle& osgHandle,
00052 float radius=1.0, float height=1.0, double mass = 1.0):
00053 AbstractObstacle::AbstractObstacle(odeHandle, osgHandle), radius(radius), height(height), mass(mass) {
00054 capsule = new Capsule(radius,height);
00055 obst.push_back(capsule);
00056 obstacle_exists=false;
00057 };
00058
00059 ~PassiveCapsule(){
00060 }
00061
00062
00063
00064
00065 virtual void update(){
00066 if(capsule) capsule->update();
00067 };
00068
00069 virtual void setTexture(const std::string& filename){
00070 if(capsule) capsule->getOSGPrimitive()->setTexture(filename);
00071 }
00072
00073 virtual void setPose(const osg::Matrix& pose){
00074 this->pose = osg::Matrix::translate(0,0,height*0.5f+radius) * pose;
00075 if (!obstacle_exists) {
00076 create();
00077 }
00078 capsule->setPose(pose);
00079 };
00080
00081 virtual Primitive* getMainPrimitive() const { return capsule; }
00082
00083 protected:
00084 virtual void create(){
00085 capsule->setTextures(getTextures(0));
00086 if (mass==0.0) {
00087 capsule->init(odeHandle, mass, osgHandle, Primitive::Geom | Primitive::Draw);
00088 } else {
00089 capsule->init(odeHandle, mass, osgHandle);
00090 }
00091 obstacle_exists=true;
00092 };
00093
00094 };
00095
00096 }
00097
00098 #endif
00099