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