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