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 __PLAYGROUND_H
00025 #define __PLAYGROUND_H
00026
00027 #include "mathutils.h"
00028 #include "abstractground.h"
00029 #include "primitive.h"
00030
00031 namespace lpzrobots {
00032
00033 class Playground : public AbstractGround {
00034
00035 protected:
00036
00037 double length, width, height;
00038 double factorlength2;
00039
00040 public:
00041
00042 Playground(const OdeHandle& odeHandle, const OsgHandle& osgHandle ,
00043 const osg::Vec3& dimension = osg::Vec3(7.0, 0.2, 0.5) ,
00044 double factorxy = 1, bool createGround=true)
00045 : AbstractGround(odeHandle, osgHandle, createGround, dimension.x(), dimension.x()*factorxy, dimension.y()) {
00046
00047 length=dimension.x();
00048 width=dimension.y();
00049 height=dimension.z();
00050 factorlength2=factorxy;
00051 };
00052
00053 virtual void changeGeometry(double length, double width, double height, double factorxy){
00054 AbstractGround::changeGeometry(length, width, height, factorxy);
00055 this->length = length;
00056 this->width = width;
00057 this->height = height;
00058 this->factorlength2 = factorxy;
00059 if (obstacle_exists) {
00060 destroy();
00061 create();
00062 }
00063 }
00064
00065 protected:
00066 virtual void create(){
00067 createGround();
00068
00069 Box* box;
00070 osg::Vec3 offset(0,
00071 (length/2 * factorlength2 + width/2),
00072 height/2+0.01f);
00073 box = new Box( length + 2 * width , width, height);
00074 box->setTextures(getTextures(0));
00075 box->init(odeHandle, 0, osgHandle, Primitive::Geom | Primitive::Draw);
00076 box->setPose(osg::Matrix::translate(offset) * pose);
00077 obst.push_back(box);
00078
00079 box = new Box( length + 2 * width , width, height);
00080 box->setTextures(getTextures(1));
00081 box->init(odeHandle, 0, osgHandle, Primitive::Geom | Primitive::Draw);
00082 box->setPose(osg::Matrix::translate(offset) * osg::Matrix::rotate(M_PI, 0,0,1) * pose);
00083 obst.push_back(box);
00084
00085 osg::Vec3 offset2(0, (length/2 + width/2),
00086 height/2+0.01f);
00087 box = new Box( length * factorlength2 , width, height);
00088 box->setTextures(getTextures(2));
00089 box->init(odeHandle, 0, osgHandle, Primitive::Geom | Primitive::Draw);
00090 box->setPose(osg::Matrix::translate(offset2) * osg::Matrix::rotate(M_PI/2.0, 0,0,1) * pose);
00091 obst.push_back(box);
00092
00093 box = new Box( length * factorlength2 , width, height);
00094 box->setTextures(getTextures(3));
00095 box->init(odeHandle, 0, osgHandle, Primitive::Geom | Primitive::Draw);
00096 box->setPose(osg::Matrix::translate(offset2) * osg::Matrix::rotate(3.0*M_PI/2.0, 0,0,1)
00097 * pose);
00098 obst.push_back(box);
00099
00100
00101 obstacle_exists=true;
00102 };
00103
00104 };
00105
00106 }
00107
00108 #endif