playground.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: playground.h,v $
00024  *   Revision 1.21  2010/01/07 14:06:17  der
00025  *   *** empty log message ***
00026  *
00027  *   Revision 1.20  2010/01/07 14:05:23  der
00028  *   adapted to new wall texture
00029  *
00030  *   Revision 1.19  2009/03/13 09:19:53  martius
00031  *   changed texture handling in osgprimitive
00032  *   new OsgBoxTex that supports custom texture repeats and so on
00033  *   Box uses osgBoxTex now. We also need osgSphereTex and so on.
00034  *   setTexture has to be called before init() of the primitive
00035  *
00036  *   Revision 1.18  2008/02/07 14:25:29  der
00037  *   added setWallTexture for PlayGround
00038  *
00039  *   Revision 1.17  2007/08/28 09:25:13  martius
00040  *   include primitive.h
00041  *
00042  *   Revision 1.16  2007/08/24 11:53:10  martius
00043  *   Change geometry
00044  *
00045  *   Revision 1.15  2007/07/03 13:06:41  martius
00046  *   groundplane thick
00047  *
00048  *   Revision 1.14  2007/03/16 11:01:37  martius
00049  *   abstractobstacle gets mor functionallity
00050  *   setSubstance
00051  *
00052  *   Revision 1.13  2006/09/21 22:09:12  martius
00053  *   *** empty log message ***
00054  *
00055  *   Revision 1.12  2006/08/11 15:41:04  martius
00056  *   playgrounds handle non-quadratic ground planes
00057  *
00058  *   Revision 1.11  2006/07/14 12:23:33  martius
00059  *   selforg becomes HEAD
00060  *
00061  *   Revision 1.10.4.16  2006/07/14 11:11:53  martius
00062  *   revert to 1.10.4.12
00063  *
00064  *   Revision 1.10.4.12  2006/06/29 16:39:55  robot3
00065  *   -you can now see bounding shapes if you type ./start -drawboundings
00066  *   -includes cleared up
00067  *   -abstractobstacle and abstractground have now .cpp-files
00068  *
00069  *   Revision 1.10.4.11  2006/05/23 13:37:34  robot3
00070  *   -fixed some creating bugs
00071  *   -setColor,setTexture and createGround must be
00072  *    called before setPosition now
00073  *
00074  *   Revision 1.10.4.10  2006/05/19 08:42:54  robot3
00075  *   -some code moved to abstractground.h
00076  *   -it's now possible creating a playground without a groundplane
00077  *
00078  *   Revision 1.10.4.9  2006/05/18 14:32:12  robot3
00079  *   walls are now textured with a wood texture
00080  *
00081  *   Revision 1.10.4.8  2006/05/18 12:54:24  robot3
00082  *   -fixed not being able to change the color after positioning
00083  *    the obstacle
00084  *   -cleared the files up
00085  *
00086  *   Revision 1.10.4.7  2006/05/18 09:43:24  robot3
00087  *   using existing texture image in cvs for the groundplane now
00088  *
00089  *   Revision 1.10.4.6  2006/05/18 07:42:36  robot3
00090  *   Grounds have now a groundPlane for shadowing issues
00091  *   osgprimitive.cpp contains a bug that repeating textures (wrapping)
00092  *   don't work, needs to be fixed
00093  *
00094  *   Revision 1.10.4.5  2006/05/11 08:59:15  robot3
00095  *   -fixed a positioning bug (e.g. for passivesphere)
00096  *   -some methods moved to abstractobstacle.h for avoiding inconsistencies
00097  *
00098  *   Revision 1.10.4.4  2006/03/29 15:04:39  martius
00099  *   have pose now
00100  *
00101  *   Revision 1.10.4.3  2006/01/10 20:27:15  martius
00102  *   protected members
00103  *
00104  *   Revision 1.10.4.2  2006/01/10 17:17:33  martius
00105  *   new mode for primitives
00106  *
00107  *   Revision 1.10.4.1  2005/12/06 10:13:23  martius
00108  *   openscenegraph integration started
00109  *
00110  *   Revision 1.10  2005/09/22 12:24:36  martius
00111  *   removed global variables
00112  *   OdeHandle and GlobalData are used instead
00113  *   sensor prepared
00114  *
00115  *   Revision 1.9  2005/09/13 13:19:57  martius
00116  *   no texture
00117  *
00118  *   Revision 1.8  2005/08/02 14:09:06  fhesse
00119  *   factor between length in x and y direction
00120  *   added to constructor
00121  *
00122  *   Revision 1.7  2005/07/29 14:27:59  martius
00123  *   color set to some red
00124  *
00125  *   Revision 1.6  2005/07/18 14:52:33  martius
00126  *   world and space are not pointers anymore.
00127  *
00128  *   Revision 1.5  2005/07/07 10:24:23  martius
00129  *   avoid internal collisions
00130  *
00131  *   Revision 1.4  2005/06/15 14:22:11  martius
00132  *   GPL included
00133  *                                                                 *
00134  ***************************************************************************/
00135 #ifndef __PLAYGROUND_H
00136 #define __PLAYGROUND_H
00137 
00138 #include "mathutils.h"
00139 #include "abstractground.h"
00140 #include "primitive.h"
00141  
00142 namespace lpzrobots {
00143 
00144   class Playground : public AbstractGround {
00145 
00146   protected:
00147 
00148     double length, width, height;
00149     double factorlength2;
00150 
00151   public:
00152   
00153     Playground(const OdeHandle& odeHandle, const OsgHandle& osgHandle , 
00154                const osg::Vec3& dimension = osg::Vec3(7.0, 0.2, 0.5) ,
00155                double factorxy = 1, bool createGround=true)
00156       : AbstractGround(odeHandle, osgHandle, createGround, dimension.x(), dimension.x()*factorxy, dimension.y()) {
00157 
00158       length=dimension.x();
00159       width=dimension.y();
00160       height=dimension.z();
00161       factorlength2=factorxy;
00162     };
00163 
00164     virtual void changeGeometry(double length, double width, double height, double factorxy){
00165       AbstractGround::changeGeometry(length, width, height, factorxy);
00166       this->length = length;
00167       this->width  = width;
00168       this->height  = height;
00169       this->factorlength2  = factorxy;
00170       if (obstacle_exists) {
00171         destroy();
00172         create();
00173       }      
00174     }
00175 
00176     virtual void setWallSubstance(const Substance& substance) {
00177       if (obstacle_exists) {
00178         FOREACH(std::vector<Primitive*>,obst,wall) {
00179           (*wall)->substance=substance;
00180         }
00181       } else
00182         std::cerr << "PlayGround::setWallSubstance() - PlayGround gound not created!\n";
00183 
00184     }
00185 
00186 
00187   protected:
00188     virtual void create(){
00189       createGround();
00190       
00191       Box* box;
00192       osg::Vec3 offset(- (length/2 + width/2),
00193                        0,
00194                        height/2+0.01f/*reduces graphic errors and ode collisions*/);
00195       box = new Box( width , (length * factorlength2) + 2 * width , height);
00196       box->setTexture(wallTextureFileName, -1.5, -3);
00197       box->init(odeHandle, 0, osgHandle, Primitive::Geom | Primitive::Draw);
00198       box->setPose(osg::Matrix::translate(offset) * pose);
00199       obst.push_back(box);
00200 
00201       offset.x() = length/2 + width/2;
00202       box = new Box( width , (length * factorlength2) + 2 * width , height);
00203       box->setTexture(wallTextureFileName, -1.5, -3);
00204       box->init(odeHandle, 0, osgHandle, Primitive::Geom | Primitive::Draw);
00205       box->setPose(osg::Matrix::translate(offset) * pose);
00206       obst.push_back(box);
00207 
00208       offset.x() = 0;
00209       offset.y() = -( (length*factorlength2)/2 +width/2);
00210       box = new Box( length, width, height);
00211       box->setTexture(wallTextureFileName, -1.5, -3);
00212       box->init(odeHandle, 0, osgHandle, Primitive::Geom | Primitive::Draw);
00213       box->setPose(osg::Matrix::translate(offset) * pose);
00214       obst.push_back(box);
00215 
00216       offset.y() = (length*factorlength2)/2 +width/2;
00217       box = new Box( length, width, height);
00218       box->setTexture(wallTextureFileName, -1.5, -3);
00219       box->init(odeHandle, 0, osgHandle, Primitive::Geom | Primitive::Draw);
00220       box->setPose(osg::Matrix::translate(offset) * pose);
00221       obst.push_back(box);
00222     
00223       obstacle_exists=true;
00224     };
00225 
00226   };
00227 
00228 }
00229 
00230 #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