passivemesh.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 __PASSIVEMESH_H
00025 #define __PASSIVEMESH_H
00026
00027 #include <stdio.h>
00028 #include <cmath>
00029
00030 #include "primitive.h"
00031 #include "osgprimitive.h"
00032 #include "abstractobstacle.h"
00033
00034 namespace lpzrobots {
00035
00036
00037
00038
00039 class PassiveMesh : public AbstractObstacle{
00040 std::string filename;
00041 float scale;
00042 double mass;
00043
00044 Mesh* mesh;
00045
00046 public:
00047
00048
00049
00050
00051 PassiveMesh(const OdeHandle& odeHandle,
00052 const OsgHandle& osgHandle,
00053 const std::string& filename,
00054 double scale = 1.0, double mass = 1.0):
00055 AbstractObstacle::AbstractObstacle(odeHandle, osgHandle),
00056 filename(filename), scale(scale), mass(mass){
00057 mesh=0;
00058 obstacle_exists=false;
00059 };
00060
00061 ~PassiveMesh(){
00062 if(mesh) delete mesh;
00063 }
00064
00065
00066
00067
00068 virtual void update(){
00069 if(mesh) mesh->update();
00070 };
00071
00072
00073
00074
00075
00076 virtual void setPose(const osg::Matrix& pose){
00077 this->pose = pose;
00078 if (obstacle_exists){
00079 destroy();
00080 }
00081 create();
00082 };
00083
00084
00085 virtual Primitive* getMainPrimitive() const { return mesh; }
00086
00087 protected:
00088
00089 virtual void create(){
00090 mesh = new Mesh(filename,scale);
00091 mesh->init(odeHandle, mass, osgHandle);
00092
00093
00094 mesh->setPose(pose);
00095 obstacle_exists=true;
00096 };
00097
00098
00099 virtual void destroy(){
00100 if(mesh) delete mesh;
00101 obstacle_exists=false;
00102 };
00103
00104 };
00105
00106 }
00107
00108 #endif