octaplayground.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 __OCTAPLAYGROUND_H
00025 #define __OCTAPLAYGROUND_H
00026
00027 #include "abstractground.h"
00028
00029 namespace lpzrobots {
00030
00031 class OctaPlayground : public AbstractGround {
00032
00033
00034 protected:
00035 double radius, width, height;
00036
00037 int number_elements;
00038 double angle;
00039 double box_length;
00040
00041 public:
00042
00043
00044 OctaPlayground(const OdeHandle& odeHandle, const OsgHandle& osgHandle,
00045 const Pos& geometry = Pos(7,0.2,0.5), int numberCorners=8, bool createGround=true):
00046 AbstractGround::AbstractGround(odeHandle, osgHandle,createGround,2*geometry.x(),2*geometry.x(), geometry.y()) {
00047 radius = geometry.x();
00048 width = geometry.y();
00049 height = geometry.z();
00050
00051 number_elements=numberCorners;
00052 angle= 2*M_PI/number_elements;
00053
00054
00055 calcBoxLength();
00056 };
00057
00058 protected:
00059
00060 virtual void create(){
00061 createGround();
00062
00063
00064
00065 double r = sqrt(pow((1+cos(angle))/2, 2) + pow( sin(angle)/2 ,2)) * radius;
00066 for (int i=0; i<number_elements; i++){
00067 Box* box = new Box(width , box_length , height);
00068 box->setTextures(getTextures(i));
00069 box->init(odeHandle, 0, osgHandle, Primitive::Geom | Primitive::Draw);
00070 osg::Matrix R = osg::Matrix::rotate(- i*angle, 0,0,1) *
00071 osg::Matrix::translate( cos(M_PI - i*angle) * r,
00072 sin(M_PI - i*angle) * r,
00073 height/2+0.01f
00074 )* pose;
00075 box->setPose(R);
00076 obst.push_back(box);
00077 }
00078 obstacle_exists=true;
00079 };
00080
00081 virtual void calcBoxLength(){
00082 double r = radius+width/2;
00083
00084 box_length = sqrt(pow( 1 - cos(angle), 2) + pow(sin(angle),2)) * r;
00085 }
00086
00087 };
00088
00089 }
00090
00091 #endif