octaplayground.h

Go to the documentation of this file.
00001 /***************************************************************************
00002  *   Copyright (C) 2005 by Robot Group Leipzig                             *
00003  *    martius@informatik.uni-leipzig.de                                    *
00004  *    fhesse@informatik.uni-leipzig.de                                     *
00005  *    der@informatik.uni-leipzig.de                                        *
00006  *    frankguettler@gmx.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  *   $Log: octaplayground.h,v $
00024  *   Revision 1.9  2007/07/03 13:06:41  martius
00025  *   groundplane thick
00026  *
00027  *   Revision 1.8  2007/03/16 11:01:37  martius
00028  *   abstractobstacle gets mor functionallity
00029  *   setSubstance
00030  *
00031  *   Revision 1.7  2006/09/20 12:55:30  martius
00032  *   correct size of ground
00033  *
00034  *   Revision 1.6  2006/08/11 15:41:04  martius
00035  *   playgrounds handle non-quadratic ground planes
00036  *
00037  *   Revision 1.5  2006/07/14 12:23:33  martius
00038  *   selforg becomes HEAD
00039  *
00040  *   Revision 1.4.4.11  2006/06/29 16:39:55  robot3
00041  *   -you can now see bounding shapes if you type ./start -drawboundings
00042  *   -includes cleared up
00043  *   -abstractobstacle and abstractground have now .cpp-files
00044  *
00045  *   Revision 1.4.4.10  2006/05/23 13:37:22  robot3
00046  *   -fixed some creating bugs
00047  *   -setColor,setTexture and createGround must be
00048  *    called before setPosition now
00049  *
00050  *   Revision 1.4.4.9  2006/05/19 08:42:36  robot3
00051  *   -some code moved to abstractground.h
00052  *   -it's now possible creating a playground without a groundplane
00053  *
00054  *   Revision 1.4.4.8  2006/05/18 14:38:28  robot3
00055  *   wall uses wall texture now
00056  *
00057  *   Revision 1.4.4.7  2006/05/18 12:54:24  robot3
00058  *   -fixed not being able to change the color after positioning
00059  *    the obstacle
00060  *   -cleared the files up
00061  *
00062  *   Revision 1.4.4.6  2006/05/18 12:00:57  robot3
00063  *   removed unused variables
00064  *
00065  *   Revision 1.4.4.5  2006/05/18 09:40:03  robot3
00066  *   using existing texture image in cvs for the groundplane now
00067  *
00068  *   Revision 1.4.4.4  2006/05/18 07:42:36  robot3
00069  *   Grounds have now a groundPlane for shadowing issues
00070  *   osgprimitive.cpp contains a bug that repeating textures (wrapping)
00071  *   don't work, needs to be fixed
00072  *
00073  *   Revision 1.4.4.3  2006/05/11 08:59:15  robot3
00074  *   -fixed a positioning bug (e.g. for passivesphere)
00075  *   -some methods moved to abstractobstacle.h for avoiding inconsistencies
00076  *
00077  *   Revision 1.4.4.2  2006/03/29 15:04:39  martius
00078  *   have pose now
00079  *
00080  *   Revision 1.4.4.1  2006/01/10 20:11:12  martius
00081  *   moved to osg
00082  *
00083  *   Revision 1.4  2005/11/09 13:29:21  fhesse
00084  *   GPL added
00085  *                                                                 *
00086  *                                                                         *
00087  ***************************************************************************/
00088 #ifndef __OCTAPLAYGROUND_H
00089 #define __OCTAPLAYGROUND_H
00090 
00091 #include "abstractground.h"
00092 
00093 namespace lpzrobots {
00094 
00095   class OctaPlayground : public AbstractGround {
00096   
00097 
00098   protected:
00099     double radius, width, height;
00100     
00101     int number_elements;
00102     double angle;    
00103     double box_length;
00104 
00105   public:
00106   
00107 
00108     OctaPlayground(const OdeHandle& odeHandle, const OsgHandle& osgHandle, 
00109                  const Pos& geometry = Pos(7,0.2,0.5), int numberCorners=8, bool createGround=true):
00110     AbstractGround::AbstractGround(odeHandle, osgHandle,createGround,2*geometry.x(),2*geometry.x(), geometry.y()) {
00111     radius = geometry.x();
00112     width  = geometry.y();
00113     height = geometry.z();
00114 
00115     number_elements=numberCorners;
00116     angle= 2*M_PI/number_elements;    
00117     obst.resize(number_elements);
00118 
00119     calcBoxLength();
00120   };
00121   
00122 protected:
00123 
00124   virtual void create(){
00125     createGround();
00126 
00127     // radius for positioning is smaller than radius since we use secants. 
00128     //  r is the smallest distance of the secant to the center of the circle.
00129     double r = sqrt(pow((1+cos(angle))/2, 2) + pow( sin(angle)/2 ,2)) * radius;
00130     for (int i=0; i<number_elements; i++){
00131       Box* box =  new Box(width , box_length , height);
00132       box->init(odeHandle, 0, osgHandle, Primitive::Geom | Primitive::Draw);
00133       osg::Matrix R = osg::Matrix::rotate(- i*angle, 0,0,1) * 
00134         osg::Matrix::translate( cos(M_PI - i*angle) * r, 
00135                                 sin(M_PI - i*angle) * r, 
00136                                 height/2+0.01f /*reduces graphic errors and ode collisions*/
00137                                 )* pose;
00138       box->setPose(R);
00139       box->getOSGPrimitive()->setTexture(wallTextureFileName);
00140       obst.push_back(box);
00141     }
00142     obstacle_exists=true;
00143   };
00144 
00145   virtual void calcBoxLength(){
00146     double r = radius+width/2; 
00147     //    box_length =1.4 * sqrt( 2 * pow(radius,2) * (1 - cos(angle)) );
00148     box_length =  sqrt(pow( 1 - cos(angle), 2) + pow(sin(angle),2)) * r;  
00149   }
00150 
00151 };
00152 
00153 }
00154 
00155 #endif

Generated on Tue Sep 16 22:00:22 2008 for Robotsystem of the Robot Group Leipzig by  doxygen 1.4.7