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