playground.h

Go to the documentation of this file.
00001 /***************************************************************************
00002  *   Copyright (C) 2005-2011 LpzRobots development team                    *
00003  *    Georg Martius  <georg dot martius at web dot de>                     *
00004  *    Frank Guettler <guettler at informatik dot uni-leipzig dot de        *
00005  *    Frank Hesse    <frank at nld dot ds dot mpg dot de>                  *
00006  *    Ralf Der       <ralfder at mis dot mpg dot 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  ***************************************************************************/
00024 #ifndef __PLAYGROUND_H
00025 #define __PLAYGROUND_H
00026 
00027 #include "mathutils.h"
00028 #include "abstractground.h"
00029 #include "primitive.h"
00030  
00031 namespace lpzrobots {
00032 
00033   class Playground : public AbstractGround {
00034 
00035   protected:
00036 
00037     double length, width, height;
00038     double factorlength2;
00039 
00040   public:
00041   
00042     Playground(const OdeHandle& odeHandle, const OsgHandle& osgHandle , 
00043                const osg::Vec3& dimension = osg::Vec3(7.0, 0.2, 0.5) ,
00044                double factorxy = 1, bool createGround=true)
00045       : AbstractGround(odeHandle, osgHandle, createGround, dimension.x(), dimension.x()*factorxy, dimension.y()) {
00046 
00047       length=dimension.x();
00048       width=dimension.y();
00049       height=dimension.z();
00050       factorlength2=factorxy;
00051     };
00052 
00053     virtual void changeGeometry(double length, double width, double height, double factorxy){
00054       AbstractGround::changeGeometry(length, width, height, factorxy);
00055       this->length = length;
00056       this->width  = width;
00057       this->height  = height;
00058       this->factorlength2  = factorxy;
00059       if (obstacle_exists) {
00060         destroy();
00061         create();
00062       }      
00063     }
00064 
00065   protected:
00066     virtual void create(){
00067       createGround();
00068       
00069       Box* box;
00070       osg::Vec3 offset(0, 
00071                        (length/2 * factorlength2 + width/2),                   
00072                        height/2+0.01f/*reduces graphic errors and ode collisions*/);
00073       box = new Box( length + 2 * width , width, height);      
00074       box->setTextures(getTextures(0));
00075       box->init(odeHandle, 0, osgHandle, Primitive::Geom | Primitive::Draw);
00076       box->setPose(osg::Matrix::translate(offset) * pose);
00077       obst.push_back(box);
00078 
00079       box = new Box( length + 2 * width , width, height);      
00080       box->setTextures(getTextures(1));
00081       box->init(odeHandle, 0, osgHandle, Primitive::Geom | Primitive::Draw);
00082       box->setPose(osg::Matrix::translate(offset) * osg::Matrix::rotate(M_PI, 0,0,1) * pose);
00083       obst.push_back(box);
00084 
00085       osg::Vec3 offset2(0, (length/2 + width/2), 
00086                        height/2+0.01f/*reduces graphic errors and ode collisions*/);
00087       box = new Box( length * factorlength2 , width, height);      
00088       box->setTextures(getTextures(2));
00089       box->init(odeHandle, 0, osgHandle, Primitive::Geom | Primitive::Draw);
00090       box->setPose(osg::Matrix::translate(offset2) * osg::Matrix::rotate(M_PI/2.0, 0,0,1) * pose);
00091       obst.push_back(box);
00092 
00093       box = new Box( length * factorlength2 , width, height);      
00094       box->setTextures(getTextures(3));
00095       box->init(odeHandle, 0, osgHandle, Primitive::Geom | Primitive::Draw);
00096       box->setPose(osg::Matrix::translate(offset2) * osg::Matrix::rotate(3.0*M_PI/2.0, 0,0,1) 
00097                    * pose);
00098       obst.push_back(box);
00099 
00100     
00101       obstacle_exists=true;
00102     };
00103 
00104   };
00105 
00106 }
00107 
00108 #endif
Generated on Thu Jun 28 14:45:37 2012 for Robot Simulator of the Robotics Group for Self-Organization of Control by  doxygen 1.6.3