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