Robotsystem from Robot Group Leipzig: passivesphere.h Source File

- Main Page
- Modules
- Namespaces
- Classes
- Files
- Directories
- Examples

- File List
- File Members

# passivesphere.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  *                                                                         *
    00007  *   This program is free software; you can redistribute it and/or modify  *
    00008  *   it under the terms of the GNU General Public License as published by  *
    00009  *   the Free Software Foundation; either version 2 of the License, or     *
    00010  *   (at your option) any later version.                                   *
    00011  *                                                                         *
    00012  *   This program is distributed in the hope that it will be useful,       *
    00013  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
    00014  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
    00015  *   GNU General Public License for more details.                          *
    00016  *                                                                         *
    00017  *   You should have received a copy of the GNU General Public License     *
    00018  *   along with this program; if not, write to the                         *
    00019  *   Free Software Foundation, Inc.,                                       *
    00020  *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
    00021  *                                                                         *
    00022  *   $Log: passivesphere.h,v $
    00023  *   Revision 1.1.2.7  2006/03/31 09:59:23  fhesse
    00024  *   in create: z+=radius; added to place sphere on ground
    00025  *
    00026  *   Revision 1.1.2.6  2006/03/30 12:34:51  martius
    00027  *   documentation updated
    00028  *
    00029  *   Revision 1.1.2.5  2006/03/29 15:04:39  martius
    00030  *   have pose now
    00031  *
    00032  *   Revision 1.1.2.4  2006/01/18 16:46:39  martius
    00033  *   mass adjustable
    00034  *
    00035  *   Revision 1.1.2.3  2005/12/15 17:02:16  martius
    00036  *   *** empty log message ***
    00037  *
    00038  *   Revision 1.1.2.2  2005/12/11 23:35:07  martius
    00039  *   *** empty log message ***
    00040  *
    00041  *   Revision 1.1.2.1  2005/12/09 16:53:17  martius
    00042  *   camera is working now
    00043  *
    00044  *   Revision 1.5  2005/10/25 19:26:57  fhesse
    00045  *   comments adjusted and in doxygen style
    00046  *
    00047  *   Revision 1.4  2005/09/22 12:24:36  martius
    00048  *   removed global variables
    00049  *   OdeHandle and GlobalData are used instead
    00050  *   sensor prepared
    00051  *
    00052  *   Revision 1.3  2005/07/31 22:30:56  martius
    00053  *   textures
    00054  *
    00055  *   Revision 1.2  2005/07/18 14:52:33  martius
    00056  *   world and space are not pointers anymore.
    00057  *
    00058  *   Revision 1.1  2005/07/08 10:00:33  fhesse
    00059  *   initial version
    00060  *                                                    *
    00061  *                                                                         *
    00062  ***************************************************************************/
    00063 #ifndef __PASSIVESPHERE_H
    00064 #define __PASSIVESPHERE_H
    00065
    00066 #include <stdio.h>
    00067 #include <math.h>
    00068
    00069 #include "primitive.h"
    00070 #include "abstractobstacle.h"
    00071
    00072 namespace lpzrobots {
    00073
    00074 /**
    00075  *  (Passive) sphere as obstacle
    00076  */
    00077 class PassiveSphere : public AbstractObstacle{
    00078   double radius;
    00079   double mass;
    00080   /**
    00081    * initial coordinates
    00082    */
    00083   osg::Vec3 pos;
    00084   int texture;
    00085
    00086   Sphere* sphere;
    00087
    00088   bool obstacle_exists;
    00089
    00090  public:
    00091
    00092   /**
    00093    * Constructor
    00094    */
    00095   PassiveSphere(const OdeHandle& odeHandle, const OsgHandle& osgHandle, double radius = 0.3, double mass = 1.0):
    00096     AbstractObstacle::AbstractObstacle(odeHandle, osgHandle), radius(radius), mass(mass) {
    00097     sphere=0;
    00098     obstacle_exists=false;
    00099   };
    00100
    00101   ~PassiveSphere(){
    00102     if(sphere) delete sphere;
    00103   }
    00104
    00105   /**
    00106    * update position of sphere
    00107    */
    00108   virtual void update(){
    00109     if(sphere) sphere->update();
    00110   };
    00111
    00112   virtual void setTexture(const std::string& filename){
    00113     if(sphere) sphere->getOSGPrimitive()->setTexture(filename);
    00114   }
    00115
    00116   virtual void setPose(const osg::Matrix& pose){
    00117     this->pose = osg::Matrix::translate(0,0,radius) * pose;
    00118     if (obstacle_exists){
    00119       destroy();
    00120     }
    00121     create();
    00122   };
    00123
    00124   virtual osg::Matrix getPose(){
    00125     return pose;
    00126   }
    00127
    00128  protected:
    00129   virtual void create(){
    00130     sphere = new Sphere(radius);
    00131     sphere->init(odeHandle, mass, osgHandle);
    00132     pos[2]+=radius;
    00133     sphere->setPosition(pos);
    00134
    00135     obstacle_exists=true;
    00136   };
    00137
    00138
    00139   virtual void destroy(){
    00140     if(sphere) delete sphere;
    00141     obstacle_exists=false;
    00142   };
    00143
    00144 };
    00145
    00146 }
    00147
    00148 #endif