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