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  *                                                                         *
00007  *   This program is free software; you can redistribute it and/or modify  *
00008  *   it under the terms of the GNU General Public License as published by  *
00009  *   the Free Software Foundation; either version 2 of the License, or     *
00010  *   (at your option) any later version.                                   *
00011  *                                                                         *
00012  *   This program is distributed in the hope that it will be useful,       *
00013  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
00014  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
00015  *   GNU General Public License for more details.                          *
00016  *                                                                         *
00017  *   You should have received a copy of the GNU General Public License     *
00018  *   along with this program; if not, write to the                         *
00019  *   Free Software Foundation, Inc.,                                       *
00020  *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
00021  *                                                                         *
00022  *   $Log: playground.h,v $
00023  *   Revision 1.10.4.4  2006/03/29 15:04:39  martius
00024  *   have pose now
00025  *
00026  *   Revision 1.10.4.3  2006/01/10 20:27:15  martius
00027  *   protected members
00028  *
00029  *   Revision 1.10.4.2  2006/01/10 17:17:33  martius
00030  *   new mode for primitives
00031  *
00032  *   Revision 1.10.4.1  2005/12/06 10:13:23  martius
00033  *   openscenegraph integration started
00034  *
00035  *   Revision 1.10  2005/09/22 12:24:36  martius
00036  *   removed global variables
00037  *   OdeHandle and GlobalData are used instead
00038  *   sensor prepared
00039  *
00040  *   Revision 1.9  2005/09/13 13:19:57  martius
00041  *   no texture
00042  *
00043  *   Revision 1.8  2005/08/02 14:09:06  fhesse
00044  *   factor between length in x and y direction
00045  *   added to constructor
00046  *
00047  *   Revision 1.7  2005/07/29 14:27:59  martius
00048  *   color set to some red
00049  *
00050  *   Revision 1.6  2005/07/18 14:52:33  martius
00051  *   world and space are not pointers anymore.
00052  *
00053  *   Revision 1.5  2005/07/07 10:24:23  martius
00054  *   avoid internal collisions
00055  *
00056  *   Revision 1.4  2005/06/15 14:22:11  martius
00057  *   GPL included
00058  *                                                                 *
00059  ***************************************************************************/
00060 #ifndef __PLAYGROUND_H
00061 #define __PLAYGROUND_H
00062 
00063 
00064 #include <stdio.h>
00065 #include <math.h>
00066 
00067 #include "mathutils.h"
00068 #include "primitive.h"
00069 #include "abstractobstacle.h"
00070  
00071 namespace lpzrobots {
00072 
00073 //Fixme: playground creates collisions with ground and itself
00074 class Playground : public AbstractObstacle {
00075 protected:
00076 
00077   double length, width, height;
00078   double factorlength2;
00079 
00080   Box* box[4];
00081 
00082   bool obstacle_exists;
00083 
00084 public:
00085   
00086   Playground(const OdeHandle& odeHandle, const OsgHandle& osgHandle , 
00087              const osg::Vec3& dimension = osg::Vec3(7.0, 0.2, 0.5) , double factorxy = 1):
00088     AbstractObstacle::AbstractObstacle(odeHandle, osgHandle){
00089 
00090     length=dimension.x();
00091     width=dimension.y();
00092     height=dimension.z();
00093 
00094     factorlength2=factorxy;
00095 
00096     obstacle_exists=false;
00097     
00098     setColor(Color(226 / 255.0, 103 / 255.0, 66 / 255.0));
00099   };
00100 
00101   /**
00102    * updates the position of the geoms  ( not nessary for static objects)
00103    */
00104   virtual void update(){
00105   };
00106   
00107   
00108   virtual void setPose(const osg::Matrix& pose){
00109     this->pose = pose;
00110     if (obstacle_exists){
00111       destroy();
00112     }
00113     create();
00114   };
00115 
00116   virtual osg::Matrix getPose(){
00117     return pose;
00118   }
00119   
00120 
00121  protected:
00122   virtual void create(){
00123     osg::Vec3 offset(- (length/2 + width/2), 0, height/2);
00124     box[0] = new Box( width , (length * factorlength2) + 2 * width , height);
00125     box[0]->init(odeHandle, 0, osgHandle, Primitive::Geom | Primitive::Draw);
00126     box[0]->setPose(osg::Matrix::translate(offset) * pose);
00127 
00128     offset.x() = length/2 + width/2;
00129     box[1] = new Box( width , (length * factorlength2) + 2 * width , height);
00130     box[1]->init(odeHandle, 0, osgHandle, Primitive::Geom | Primitive::Draw);
00131     box[1]->setPose(osg::Matrix::translate(offset) * pose);
00132 
00133     offset.x() = 0;
00134     offset.y() = -( (length*factorlength2)/2 +width/2);
00135     box[2] = new Box( length, width, height);
00136     box[2]->init(odeHandle, 0, osgHandle, Primitive::Geom | Primitive::Draw);
00137     box[2]->setPose(osg::Matrix::translate(offset) * pose);
00138 
00139     offset.y() = (length*factorlength2)/2 +width/2;
00140     box[3] = new Box( length, width, height);
00141     box[3]->init(odeHandle, 0, osgHandle, Primitive::Geom | Primitive::Draw);
00142     box[3]->setPose(osg::Matrix::translate(offset) * pose);
00143     
00144     obstacle_exists=true;
00145   };
00146 
00147 
00148   virtual void destroy(){
00149     for(int i=0; i<4; i++){
00150       if(box[i]) delete(box[i]);
00151     }
00152     
00153     obstacle_exists=false;
00154   };
00155 
00156 };
00157 
00158 }
00159 
00160 #endif

Generated on Tue Apr 4 19:05:04 2006 for Robotsystem from Robot Group Leipzig by  doxygen 1.4.5