Robotsystem from Robot Group Leipzig: passivebox.h Source File

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

- File List
- File Members

# passivebox.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: passivebox.h,v $
    00023  *   Revision 1.1.2.2  2006/03/30 12:34:51  martius
    00024  *   documentation updated
    00025  *
    00026  *   Revision 1.1.2.1  2006/03/29 15:04:39  martius
    00027  *   have pose now
    00028  *
    00029  *                                                    *
    00030  *                                                                         *
    00031  ***************************************************************************/
    00032 #ifndef __PASSIVEBOX_H
    00033 #define __PASSIVEBOX_H
    00034
    00035 #include <stdio.h>
    00036 #include <math.h>
    00037
    00038 #include "primitive.h"
    00039 #include "abstractobstacle.h"
    00040
    00041 namespace lpzrobots {
    00042
    00043 /**
    00044  *  (Passive) box as obstacle
    00045  */
    00046 class PassiveBox : public AbstractObstacle{
    00047   double radius;
    00048   double mass;
    00049   /**
    00050    * initial coordinates
    00051    */
    00052   osg::Vec3 pos;
    00053   int texture;
    00054
    00055   Box* box;
    00056
    00057   bool obstacle_exists;
    00058
    00059  public:
    00060
    00061   /**
    00062    * Constructor
    00063    */
    00064   PassiveBox(const OdeHandle& odeHandle, const OsgHandle& osgHandle,
    00065              const osg::Vec3& dimension = osg::Vec3(1.0, 1.0, 1.0), double mass = 1.0):
    00066     AbstractObstacle::AbstractObstacle(odeHandle, osgHandle), dimension(dimension), mass(mass) {
    00067     box=0;
    00068     obstacle_exists=false;
    00069   };
    00070
    00071   ~PassiveBox(){
    00072     if(box) delete box;
    00073   }
    00074
    00075   /**
    00076    * update position of box
    00077    */
    00078   virtual void update(){
    00079     if(box) box->update();
    00080   };
    00081
    00082   virtual void setTexture(const std::string& filename){
    00083     if(box) box->getOSGPrimitive()->setTexture(filename);
    00084   }
    00085
    00086   virtual void setPose(const osg::Matrix& pose){
    00087     this->pose = osg::Matrix::transform(0,0,radius) * pose;
    00088     if (obstacle_exists){
    00089       destroy();
    00090     }
    00091     create();
    00092   };
    00093
    00094   virtual osg::Matrix getPose(){
    00095     return pose;
    00096   }
    00097
    00098   /**
    00099    * sets position of the box and creates/recreates it if necessary
    00100    */
    00101   virtual void setPosition(const osg::Vec3& pos){
    00102     this->pos = pos + osg::Vec3(0,0,radius);
    00103
    00104     if (obstacle_exists){
    00105       destroy();
    00106     }
    00107     create();
    00108   };
    00109
    00110   /**
    00111    * gives actual position of box
    00112    */
    00113   virtual osg::Vec3 getPosition(){
    00114     return pos;
    00115   }
    00116
    00117  protected:
    00118   virtual void create(){
    00119     box = new Box(dimension.x(), dimension.y(), dimension.z());
    00120     box->init(odeHandle, mass, osgHandle);
    00121     box->setPosition(pos);
    00122
    00123     obstacle_exists=true;
    00124   };
    00125
    00126
    00127   virtual void destroy(){
    00128     if(box) delete box;
    00129     obstacle_exists=false;
    00130   };
    00131
    00132 };
    00133
    00134 }
    00135
    00136 #endif