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

- Main Page
- Namespaces
- Classes
- Files
- Directories
- Related Pages
- Examples

- Search for |

- File List
- File Members

# passivecapsule.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  *    frankguettler@gmx.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  *   $Log: passivecapsule.h,v $
    00024  *   Revision 1.5  2009/04/02 13:36:48  fhesse
    00025  *   constructor, create() and setPose() adapted to allow replacing
    00026  *   during siumulation; if mass=0.0 elements without a body are
    00027  *   generated (as in PassiveBox)
    00028  *
    00029  *   Revision 1.4  2009/01/09 16:52:36  martius
    00030  *   use pose instead of translation only
    00031  *
    00032  *   Revision 1.3  2008/09/16 14:49:46  martius
    00033  *   use cmath instead of math.h
    00034  *
    00035  *   Revision 1.2  2006/07/14 12:23:33  martius
    00036  *   selforg becomes HEAD
    00037  *
    00038  *   Revision 1.1.2.4  2006/06/16 22:27:26  martius
    00039  *   getMainPrimtive
    00040  *
    00041  *   Revision 1.1.2.3  2006/05/18 15:40:32  robot3
    00042  *   fixed setPose
    00043  *
    00044  *   Revision 1.1.2.2  2006/05/18 15:36:15  robot3
    00045  *   fixed compiling bug
    00046  *
    00047  *   Revision 1.1.2.1  2006/05/18 13:06:51  robot3
    00048  *   added a passive passive capsule
    00049  *
    00050  *
    00051  *                                                    *
    00052  *                                                                         *
    00053  ***************************************************************************/
    00054 #ifndef __PASSIVECAPSULE_H
    00055 #define __PASSIVECAPSULE_H
    00056
    00057 #include <stdio.h>
    00058 #include <cmath>
    00059
    00060 #include "primitive.h"
    00061 #include "abstractobstacle.h"
    00062
    00063 namespace lpzrobots {
    00064
    00065 /**
    00066  *  (Passive) capsule as obstacle
    00067  */
    00068 class PassiveCapsule : public AbstractObstacle{
    00069   float radius;
    00070   float height;
    00071   double mass;
    00072
    00073   Capsule* capsule;
    00074
    00075
    00076  public:
    00077
    00078   /**
    00079    * Constructor
    00080    */
    00081   PassiveCapsule(const OdeHandle& odeHandle, const OsgHandle& osgHandle,
    00082                  float radius=1.0, float height=1.0, double mass = 1.0):
    00083     AbstractObstacle::AbstractObstacle(odeHandle, osgHandle), radius(radius), height(height), mass(mass) {
    00084     capsule = new Capsule(radius,height);
    00085     obst.push_back(capsule);
    00086     obstacle_exists=false;
    00087   };
    00088
    00089   ~PassiveCapsule(){
    00090     if(capsule) delete capsule;
    00091   }
    00092
    00093   /**
    00094    * update position of box
    00095    */
    00096   virtual void update(){
    00097     if(capsule) capsule->update();
    00098   };
    00099
    00100   virtual void setTexture(const std::string& filename){
    00101     if(capsule) capsule->getOSGPrimitive()->setTexture(filename);
    00102   }
    00103
    00104   virtual void setPose(const osg::Matrix& pose){
    00105     this->pose = osg::Matrix::translate(0,0,height*0.5f+radius) * pose;
    00106     if (!obstacle_exists) {
    00107        create();
    00108      }
    00109      capsule->setPose(pose);
    00110   };
    00111
    00112   virtual Primitive* getMainPrimitive() const { return capsule; }
    00113
    00114  protected:
    00115   virtual void create(){
    00116     if (mass==0.0) {
    00117       capsule->init(odeHandle, mass, osgHandle, Primitive::Geom | Primitive::Draw);
    00118     } else {
    00119       capsule->init(odeHandle, mass, osgHandle);
    00120     }
    00121     obstacle_exists=true;
    00122   };
    00123
    00124   virtual void destroy(){
    00125     if(capsule) delete capsule;
    00126     obstacle_exists=false;
    00127   };
    00128
    00129 };
    00130
    00131 }
    00132
    00133 #endif
    00134