octaplayground.h

Go to the documentation of this file.
00001 /***************************************************************************
00002  *   Copyright (C) 2005-2011 LpzRobots development team                    *
00003  *    Georg Martius  <georg dot martius at web dot de>                     *
00004  *    Frank Guettler <guettler at informatik dot uni-leipzig dot de        *
00005  *    Frank Hesse    <frank at nld dot ds dot mpg dot de>                  *
00006  *    Ralf Der       <ralfder at mis dot mpg dot de>                       *
00007  *                                                                         *
00008  *   This program is free software; you can redistribute it and/or modify  *
00009  *   it under the terms of the GNU General Public License as published by  *
00010  *   the Free Software Foundation; either version 2 of the License, or     *
00011  *   (at your option) any later version.                                   *
00012  *                                                                         *
00013  *   This program is distributed in the hope that it will be useful,       *
00014  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
00015  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
00016  *   GNU General Public License for more details.                          *
00017  *                                                                         *
00018  *   You should have received a copy of the GNU General Public License     *
00019  *   along with this program; if not, write to the                         *
00020  *   Free Software Foundation, Inc.,                                       *
00021  *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
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     //    obst.resize(number_elements);
00054 
00055     calcBoxLength();
00056   };
00057   
00058 protected:
00059 
00060   virtual void create(){
00061     createGround();
00062 
00063     // radius for positioning is smaller than radius since we use secants. 
00064     //  r is the smallest distance of the secant to the center of the circle.
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 /*reduces graphic errors and ode collisions*/
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     //    box_length =1.4 * sqrt( 2 * pow(radius,2) * (1 - cos(angle)) );
00084     box_length =  sqrt(pow( 1 - cos(angle), 2) + pow(sin(angle),2)) * r;  
00085   }
00086 
00087 };
00088 
00089 }
00090 
00091 #endif
Generated on Thu Jun 28 14:45:36 2012 for Robot Simulator of the Robotics Group for Self-Organization of Control by  doxygen 1.6.3