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
00059
00060 #ifndef __PLAYGROUND_H
00061 #define __PLAYGROUND_H
00062
00063
00064 #include <stdio.h>
00065 #include <math.h>
00066
00067 #include "mathutils.h"
00068 #include "primitive.h"
00069 #include "abstractobstacle.h"
00070
00071 namespace lpzrobots {
00072
00073
00074 class Playground : public AbstractObstacle {
00075 protected:
00076
00077 double length, width, height;
00078 double factorlength2;
00079
00080 Box* box[4];
00081
00082 bool obstacle_exists;
00083
00084 public:
00085
00086 Playground(const OdeHandle& odeHandle, const OsgHandle& osgHandle ,
00087 const osg::Vec3& dimension = osg::Vec3(7.0, 0.2, 0.5) , double factorxy = 1):
00088 AbstractObstacle::AbstractObstacle(odeHandle, osgHandle){
00089
00090 length=dimension.x();
00091 width=dimension.y();
00092 height=dimension.z();
00093
00094 factorlength2=factorxy;
00095
00096 obstacle_exists=false;
00097
00098 setColor(Color(226 / 255.0, 103 / 255.0, 66 / 255.0));
00099 };
00100
00101
00102
00103
00104 virtual void update(){
00105 };
00106
00107
00108 virtual void setPose(const osg::Matrix& pose){
00109 this->pose = pose;
00110 if (obstacle_exists){
00111 destroy();
00112 }
00113 create();
00114 };
00115
00116 virtual osg::Matrix getPose(){
00117 return pose;
00118 }
00119
00120
00121 protected:
00122 virtual void create(){
00123 osg::Vec3 offset(- (length/2 + width/2), 0, height/2);
00124 box[0] = new Box( width , (length * factorlength2) + 2 * width , height);
00125 box[0]->init(odeHandle, 0, osgHandle, Primitive::Geom | Primitive::Draw);
00126 box[0]->setPose(osg::Matrix::translate(offset) * pose);
00127
00128 offset.x() = length/2 + width/2;
00129 box[1] = new Box( width , (length * factorlength2) + 2 * width , height);
00130 box[1]->init(odeHandle, 0, osgHandle, Primitive::Geom | Primitive::Draw);
00131 box[1]->setPose(osg::Matrix::translate(offset) * pose);
00132
00133 offset.x() = 0;
00134 offset.y() = -( (length*factorlength2)/2 +width/2);
00135 box[2] = new Box( length, width, height);
00136 box[2]->init(odeHandle, 0, osgHandle, Primitive::Geom | Primitive::Draw);
00137 box[2]->setPose(osg::Matrix::translate(offset) * pose);
00138
00139 offset.y() = (length*factorlength2)/2 +width/2;
00140 box[3] = new Box( length, width, height);
00141 box[3]->init(odeHandle, 0, osgHandle, Primitive::Geom | Primitive::Draw);
00142 box[3]->setPose(osg::Matrix::translate(offset) * pose);
00143
00144 obstacle_exists=true;
00145 };
00146
00147
00148 virtual void destroy(){
00149 for(int i=0; i<4; i++){
00150 if(box[i]) delete(box[i]);
00151 }
00152
00153 obstacle_exists=false;
00154 };
00155
00156 };
00157
00158 }
00159
00160 #endif