Robotsystem of the Robot Group Leipzig: passivemesh.h Source File

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

- Search for |

- File List
- File Members

# passivemesh.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: passivemesh.h,v $
    00024  *   Revision 1.5  2008/09/16 14:49:46  martius
    00025  *   use cmath instead of math.h
    00026  *
    00027  *   Revision 1.4  2007/07/31 08:20:49  martius
    00028  *   mesh without global
    00029  *
    00030  *   Revision 1.3  2006/10/15 15:42:59  robot3
    00031  *   fixed package relation
    00032  *
    00033  *   Revision 1.2  2006/07/14 12:23:33  martius
    00034  *   selforg becomes HEAD
    00035  *
    00036  *   Revision 1.1.2.5  2006/06/29 16:39:55  robot3
    00037  *   -you can now see bounding shapes if you type ./start -drawboundings
    00038  *   -includes cleared up
    00039  *   -abstractobstacle and abstractground have now .cpp-files
    00040  *
    00041  *   Revision 1.1.2.4  2006/06/27 14:14:29  robot3
    00042  *   -optimized mesh and boundingshape code
    00043  *   -other changes
    00044  *
    00045  *   Revision 1.1.2.3  2006/06/23 09:01:14  robot3
    00046  *   made changes on primitive Mesh
    00047  *
    00048  *   Revision 1.1.2.2  2006/06/16 22:27:26  martius
    00049  *   getMainPrimtive
    00050  *
    00051  *   Revision 1.1.2.1  2006/05/29 19:17:41  robot3
    00052  *   first version
    00053  *
    00054  *                                                                         *
    00055  *                                                                         *
    00056  ***************************************************************************/
    00057 #ifndef __PASSIVEMESH_H
    00058 #define __PASSIVEMESH_H
    00059
    00060 #include <stdio.h>
    00061 #include <cmath>
    00062
    00063 #include "primitive.h"
    00064 #include "osgprimitive.h"
    00065 #include "abstractobstacle.h"
    00066
    00067 namespace lpzrobots {
    00068
    00069 /**
    00070  *  (Passive) mesh as obstacle
    00071  */
    00072 class PassiveMesh : public AbstractObstacle{
    00073   std::string filename;
    00074   float scale;
    00075   double mass;
    00076
    00077   Mesh* mesh;
    00078
    00079  public:
    00080
    00081   /**
    00082    * Constructor
    00083    */
    00084   PassiveMesh(const OdeHandle& odeHandle,
    00085               const OsgHandle& osgHandle,
    00086               const std::string& filename,
    00087               double scale = 1.0, double mass = 1.0):
    00088     AbstractObstacle::AbstractObstacle(odeHandle, osgHandle),
    00089     filename(filename), scale(scale), mass(mass){
    00090     mesh=0;
    00091     obstacle_exists=false;
    00092   };
    00093
    00094   ~PassiveMesh(){
    00095     if(mesh) delete mesh;
    00096   }
    00097
    00098   /**
    00099    * update position of mesh
    00100    */
    00101   virtual void update(){
    00102     if(mesh) mesh->update();
    00103   };
    00104
    00105 /*   virtual void setTexture(const std::string& filename){ */
    00106 /*     if(mesh) mesh->getOSGPrimitive()->setTexture(filename); */
    00107 /*   } */
    00108
    00109   virtual void setPose(const osg::Matrix& pose){
    00110     this->pose = pose;
    00111     if (obstacle_exists){
    00112       destroy();
    00113     }
    00114     create();
    00115   };
    00116
    00117
    00118   virtual Primitive* getMainPrimitive() const { return mesh; }
    00119
    00120  protected:
    00121
    00122   virtual void create(){
    00123     mesh = new Mesh(filename,scale);
    00124     mesh->init(odeHandle, mass, osgHandle);
    00125     osg::Vec3 pos=pose.getTrans();
    00126     pos[2]+=mesh->getRadius();
    00127     mesh->setPosition(pos);
    00128     obstacle_exists=true;
    00129   };
    00130
    00131
    00132   virtual void destroy(){
    00133     if(mesh) delete mesh;
    00134     obstacle_exists=false;
    00135   };
    00136
    00137 };
    00138
    00139 }
    00140
    00141 #endif