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
#ifndef __PASSIVEMESH_H
00052
#define __PASSIVEMESH_H
00053
00054
#include <stdio.h>
00055
#include <math.h>
00056
00057
#include "primitive.h"
00058
#include "osgprimitive.h"
00059
#include "abstractobstacle.h"
00060
00061
namespace lpzrobots {
00062
00063
00064
00065
00066 class PassiveMesh :
public AbstractObstacle{
00067 std::string
filename;
00068 float scale;
00069 double mass;
00070
00071 Mesh*
mesh;
00072 GlobalData globalData;
00073
00074
00075
public:
00076
00077
00078
00079
00080 PassiveMesh(
const OdeHandle& odeHandle,
00081
const OsgHandle& osgHandle,
00082
const std::string& filename,
00083
GlobalData& globalData,
double scale = 1.0,
double mass = 1.0):
00084
AbstractObstacle::
AbstractObstacle(odeHandle, osgHandle),
00085 filename(filename), scale(scale), mass(mass), globalData(globalData) {
00086
mesh=0;
00087 obstacle_exists=
false;
00088 };
00089
00090 ~PassiveMesh(){
00091
if(
mesh)
delete mesh;
00092 }
00093
00094
00095
00096
00097 virtual void update(){
00098
if(
mesh)
mesh->
update();
00099 };
00100
00101
00102
00103
00104
00105 virtual void setPose(
const osg::Matrix& pose){
00106 this->pose = pose;
00107
if (obstacle_exists){
00108
destroy();
00109 }
00110
create();
00111 };
00112
00113
00114 virtual Primitive*
getMainPrimitive()
const {
return mesh; }
00115
00116
protected:
00117
00118 bool drawBoundings;
00119
00120 virtual void create(){
00121
mesh =
new Mesh(
filename,
scale,
globalData);
00122
mesh->
init(odeHandle,
mass, osgHandle);
00123
osg::Vec3 pos=pose.getTrans();
00124 pos[2]+=
mesh->
getRadius();
00125
mesh->
setPosition(pos);
00126 obstacle_exists=
true;
00127 };
00128
00129
00130 virtual void destroy(){
00131
if(
mesh)
delete mesh;
00132 obstacle_exists=
false;
00133 };
00134
00135 };
00136
00137 }
00138
00139
#endif