Robot Simulator of the Robotics Group for Self-Organization of Control: passivecapsule.h Source File

# passivecapsule.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 __PASSIVECAPSULE_H
    00025 #define __PASSIVECAPSULE_H
    00026
    00027 #include <stdio.h>
    00028 #include <cmath>
    00029
    00030 #include "primitive.h"
    00031 #include "abstractobstacle.h"
    00032
    00033 namespace lpzrobots {
    00034
    00035 /**
    00036  *  (Passive) capsule as obstacle
    00037  */
    00038 class PassiveCapsule : public AbstractObstacle{
    00039   float radius;
    00040   float height;
    00041   double mass;
    00042
    00043   Capsule* capsule;
    00044
    00045
    00046  public:
    00047
    00048   /**
    00049    * Constructor
    00050    */
    00051   PassiveCapsule(const OdeHandle& odeHandle, const OsgHandle& osgHandle,
    00052                  float radius=1.0, float height=1.0, double mass = 1.0):
    00053     AbstractObstacle::AbstractObstacle(odeHandle, osgHandle), radius(radius), height(height), mass(mass) {
    00054     capsule = new Capsule(radius,height);
    00055     obst.push_back(capsule);
    00056     obstacle_exists=false;
    00057   };
    00058
    00059   ~PassiveCapsule(){
    00060   }
    00061
    00062   /**
    00063    * update position of box
    00064    */
    00065   virtual void update(){
    00066     if(capsule) capsule->update();
    00067   };
    00068
    00069   virtual void setTexture(const std::string& filename){
    00070     if(capsule) capsule->getOSGPrimitive()->setTexture(filename);
    00071   }
    00072
    00073   virtual void setPose(const osg::Matrix& pose){
    00074     this->pose = osg::Matrix::translate(0,0,height*0.5f+radius) * pose;
    00075     if (!obstacle_exists) {
    00076        create();
    00077      }
    00078      capsule->setPose(pose);
    00079   };
    00080
    00081   virtual Primitive* getMainPrimitive() const { return capsule; }
    00082
    00083  protected:
    00084   virtual void create(){
    00085     capsule->setTextures(getTextures(0));
    00086     if (mass==0.0) {
    00087       capsule->init(odeHandle, mass, osgHandle, Primitive::Geom | Primitive::Draw);
    00088     } else {
    00089       capsule->init(odeHandle, mass, osgHandle);
    00090     }
    00091     obstacle_exists=true;
    00092   };
    00093
    00094 };
    00095
    00096 }
    00097
    00098 #endif
    00099