passivesphere.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 __PASSIVESPHERE_H
00025 #define __PASSIVESPHERE_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) sphere as obstacle
00038  */
00039 class PassiveSphere : public AbstractObstacle{
00040   double radius;
00041   double mass;
00042   int texture;
00043 
00044   Sphere* sphere;
00045 
00046  public:
00047   
00048   /**
00049    * Constructor
00050    */
00051   PassiveSphere(const OdeHandle& odeHandle, const OsgHandle& osgHandle, double radius = 0.3, double mass = 1.0):
00052     AbstractObstacle::AbstractObstacle(odeHandle, osgHandle), radius(radius), mass(mass) {       
00053     sphere = new Sphere(radius);
00054     obst.push_back(sphere);
00055     obstacle_exists=false;    
00056   };
00057 
00058   virtual void setTexture(const std::string& filename){
00059     if(sphere) sphere->getOSGPrimitive()->setTexture(filename);
00060   }
00061   
00062   virtual void setPose(const osg::Matrix& pose){
00063     this->pose = osg::Matrix::translate(0,0,radius) * pose;
00064     if (!obstacle_exists) {
00065        create();
00066      }
00067      sphere->setPose(pose);
00068   };
00069 
00070   virtual Primitive* getMainPrimitive() const { return sphere; }
00071 
00072   
00073  protected:
00074   virtual void create(){
00075     sphere->setTextures(getTextures(0));
00076     if (mass==0.0) {
00077       sphere->init(odeHandle, mass, osgHandle, Primitive::Geom | Primitive::Draw);
00078      } else {
00079       sphere->init(odeHandle, mass, osgHandle);
00080     }
00081     obstacle_exists=true;
00082   };
00083 
00084 };
00085 
00086 }
00087 
00088 #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