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

Generated on Tue Sep 16 22:00:22 2008 for Robotsystem of the Robot Group Leipzig by  doxygen 1.4.7