passivemesh.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 __PASSIVEMESH_H
00025 #define __PASSIVEMESH_H
00026 
00027 #include <stdio.h>
00028 #include <cmath>
00029 
00030 #include "primitive.h"
00031 #include "osgprimitive.h"
00032 #include "abstractobstacle.h"
00033 
00034 namespace lpzrobots {
00035 
00036 /**
00037  *  (Passive) mesh as obstacle
00038  */
00039 class PassiveMesh : public AbstractObstacle{
00040   std::string filename;
00041   float scale;
00042   double mass;
00043 
00044   Mesh* mesh;
00045 
00046  public:
00047   
00048   /**
00049    * Constructor
00050    */
00051   PassiveMesh(const OdeHandle& odeHandle,
00052               const OsgHandle& osgHandle,
00053               const std::string& filename,
00054               double scale = 1.0, double mass = 1.0):
00055     AbstractObstacle::AbstractObstacle(odeHandle, osgHandle), 
00056     filename(filename), scale(scale), mass(mass){       
00057     mesh=0;
00058     obstacle_exists=false;    
00059   };
00060 
00061   ~PassiveMesh(){
00062     if(mesh) delete mesh;
00063   }
00064 
00065   /**
00066    * update position of mesh
00067    */
00068   virtual void update(){
00069     if(mesh) mesh->update();
00070   };
00071 
00072 /*   virtual void setTexture(const std::string& filename){ */
00073 /*     if(mesh) mesh->getOSGPrimitive()->setTexture(filename); */
00074 /*   } */
00075   
00076   virtual void setPose(const osg::Matrix& pose){
00077     this->pose = pose;
00078     if (obstacle_exists){
00079       destroy();
00080     }
00081     create();
00082   };
00083 
00084 
00085   virtual Primitive* getMainPrimitive() const { return mesh; }
00086   
00087  protected:
00088 
00089   virtual void create(){
00090     mesh = new Mesh(filename,scale);
00091     mesh->init(odeHandle, mass, osgHandle);
00092 //     osg::Vec3 pos=pose.getTrans();
00093 //     pos[2]+=mesh->getRadius();
00094     mesh->setPose(pose);
00095     obstacle_exists=true;
00096   };
00097 
00098 
00099   virtual void destroy(){
00100     if(mesh) delete mesh;    
00101     obstacle_exists=false;
00102   };
00103 
00104 };
00105 
00106 }
00107 
00108 #endif
Generated on Thu Jun 28 14:45:37 2012 for Robot Simulator of the Robotics Group for Self-Organization of Control by  doxygen 1.6.3