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

Generated on Fri Oct 30 16:29:01 2009 for Robot Simulator of the Robotics Group for Self-Organization of Control by  doxygen 1.4.7