Robotsystem from Robot Group Leipzig: octaplayground.h Source File

- Main Page
- Modules
- Namespaces
- Classes
- Files
- Directories
- Examples

- File List
- File Members

# octaplayground.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: octaplayground.h,v $
    00023  *   Revision 1.4.4.2  2006/03/29 15:04:39  martius
    00024  *   have pose now
    00025  *
    00026  *   Revision 1.4.4.1  2006/01/10 20:11:12  martius
    00027  *   moved to osg
    00028  *
    00029  *   Revision 1.4  2005/11/09 13:29:21  fhesse
    00030  *   GPL added
    00031  *                                                                 *
    00032  *                                                                         *
    00033  ***************************************************************************/
    00034 #ifndef __OCTAPLAYGROUND_H
    00035 #define __OCTAPLAYGROUND_H
    00036
    00037 #include <math.h>
    00038 #include <vector>
    00039 #include <osg/Matrix>
    00040
    00041 #include "primitive.h"
    00042 #include "abstractobstacle.h"
    00043
    00044 namespace lpzrobots {
    00045
    00046 class OctaPlayground : public AbstractObstacle {
    00047
    00048   double radius, width, height;
    00049   Pos pos;
    00050
    00051   vector<Primitive*> obst; //obstacles
    00052
    00053   bool obstacle_exists;
    00054
    00055   int number_elements;
    00056   double angle;
    00057   double box_length;
    00058
    00059 public:
    00060
    00061   OctaPlayground(const OdeHandle& odeHandle, const OsgHandle& osgHandle,
    00062                  const Pos& geometry = Pos(7,0.2,0.5), int numberCorners=8):
    00063     AbstractObstacle::AbstractObstacle(odeHandle, osgHandle){
    00064
    00065     radius = geometry.x();
    00066     width  = geometry.y();
    00067     height = geometry.z();
    00068
    00069     obstacle_exists=false;
    00070
    00071     number_elements=numberCorners;
    00072     angle= 2*M_PI/number_elements;
    00073     obst.resize(number_elements);
    00074
    00075     calcBoxLength();
    00076   };
    00077
    00078   virtual ~OctaPlayground(){
    00079     for (unsigned int i=0; i < obst.size(); i++){
    00080       if(obst[i]) delete obst[i];
    00081     }
    00082     obst.clear();
    00083   }
    00084
    00085   virtual void update(){
    00086     for (unsigned int i=0; i<obst.size(); i++){
    00087       if(obst[i]) obst[i]->update();
    00088     }
    00089   };
    00090
    00091
    00092   virtual void setPose(const osg::Matrix& pose){
    00093     this->pose = pose;
    00094     if (obstacle_exists){
    00095       destroy();
    00096     }
    00097     create();
    00098   };
    00099
    00100   virtual osg::Matrix getPose(){
    00101     return pose;
    00102   }
    00103
    00104 protected:
    00105
    00106   virtual void create(){
    00107     // radius for positioning is smaller than radius since we use secants.
    00108     //  r is the smallest distance of the secant to the center of the circle.
    00109     double r = sqrt(pow((1+cos(angle))/2, 2) + pow( sin(angle)/2 ,2)) * radius;
    00110     for (int i=0; i<number_elements; i++){
    00111       obst[i] = new Box(width , box_length , height);
    00112       obst[i]->init(odeHandle, 0, osgHandle, Primitive::Geom | Primitive::Draw);
    00113       osg::Matrix R = osg::Matrix::rotate(- i*angle, 0,0,1) *
    00114         osg::Matrix::translate( cos(M_PI - i*angle) * r,
    00115                                 sin(M_PI - i*angle) * r,
    00116                                 height/2) * pose;
    00117       obst[i]->setPose(R);
    00118
    00119     }
    00120   };
    00121
    00122
    00123   virtual void destroy(){
    00124     for(int i=0; i < number_elements; i++){
    00125       if(obst[i]) delete obst[i];
    00126     }
    00127     obstacle_exists=false;
    00128   };
    00129
    00130   virtual void calcBoxLength(){
    00131     double r = radius+width/2;
    00132     //    box_length =1.4 * sqrt( 2 * pow(radius,2) * (1 - cos(angle)) );
    00133     box_length =  sqrt(pow( 1 - cos(angle), 2) + pow(sin(angle),2)) * r;
    00134   }
    00135
    00136 };
    00137
    00138 }
    00139
    00140 #endif