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.5  2009/04/02 13:36:48  fhesse
00024  *   constructor, create() and setPose() adapted to allow replacing
00025  *   during siumulation; if mass=0.0 elements without a body are
00026  *   generated (as in PassiveBox)
00027  *
00028  *   Revision 1.4  2008/09/16 14:49:46  martius
00029  *   use cmath instead of math.h
00030  *
00031  *   Revision 1.3  2007/03/16 11:01:37  martius
00032  *   abstractobstacle gets mor functionallity
00033  *   setSubstance
00034  *
00035  *   Revision 1.2  2006/07/14 12:23:33  martius
00036  *   selforg becomes HEAD
00037  *
00038  *   Revision 1.1.2.11  2006/06/16 22:27:26  martius
00039  *   getMainPrimtive
00040  *
00041  *   Revision 1.1.2.10  2006/05/28 22:14:56  martius
00042  *   heightfield included
00043  *
00044  *   Revision 1.1.2.9  2006/05/18 12:54:24  robot3
00045  *   -fixed not being able to change the color after positioning
00046  *    the obstacle
00047  *   -cleared the files up
00048  *
00049  *   Revision 1.1.2.8  2006/05/11 08:59:15  robot3
00050  *   -fixed a positioning bug (e.g. for passivesphere)
00051  *   -some methods moved to abstractobstacle.h for avoiding inconsistencies
00052  *
00053  *   Revision 1.1.2.7  2006/03/31 09:59:23  fhesse
00054  *   in create: z+=radius; added to place sphere on ground
00055  *
00056  *   Revision 1.1.2.6  2006/03/30 12:34:51  martius
00057  *   documentation updated
00058  *
00059  *   Revision 1.1.2.5  2006/03/29 15:04:39  martius
00060  *   have pose now
00061  *
00062  *   Revision 1.1.2.4  2006/01/18 16:46:39  martius
00063  *   mass adjustable
00064  *
00065  *   Revision 1.1.2.3  2005/12/15 17:02:16  martius
00066  *   *** empty log message ***
00067  *
00068  *   Revision 1.1.2.2  2005/12/11 23:35:07  martius
00069  *   *** empty log message ***
00070  *
00071  *   Revision 1.1.2.1  2005/12/09 16:53:17  martius
00072  *   camera is working now
00073  *
00074  *   Revision 1.5  2005/10/25 19:26:57  fhesse
00075  *   comments adjusted and in doxygen style
00076  *
00077  *   Revision 1.4  2005/09/22 12:24:36  martius
00078  *   removed global variables
00079  *   OdeHandle and GlobalData are used instead
00080  *   sensor prepared
00081  *
00082  *   Revision 1.3  2005/07/31 22:30:56  martius
00083  *   textures
00084  *
00085  *   Revision 1.2  2005/07/18 14:52:33  martius
00086  *   world and space are not pointers anymore.
00087  *
00088  *   Revision 1.1  2005/07/08 10:00:33  fhesse
00089  *   initial version
00090  *                                                    *
00091  *                                                                         *
00092  ***************************************************************************/
00093 #ifndef __PASSIVESPHERE_H
00094 #define __PASSIVESPHERE_H
00095 
00096 #include <stdio.h>
00097 #include <cmath>
00098 
00099 #include "primitive.h"
00100 #include "osgprimitive.h"
00101 #include "abstractobstacle.h"
00102 
00103 namespace lpzrobots {
00104 
00105 /**
00106  *  (Passive) sphere as obstacle
00107  */
00108 class PassiveSphere : public AbstractObstacle{
00109   double radius;
00110   double mass;
00111   int texture;
00112 
00113   Sphere* sphere;
00114 
00115  public:
00116   
00117   /**
00118    * Constructor
00119    */
00120   PassiveSphere(const OdeHandle& odeHandle, const OsgHandle& osgHandle, double radius = 0.3, double mass = 1.0):
00121     AbstractObstacle::AbstractObstacle(odeHandle, osgHandle), radius(radius), mass(mass) {       
00122     sphere = new Sphere(radius);
00123     obst.push_back(sphere);
00124     obstacle_exists=false;    
00125   };
00126 
00127   virtual void setTexture(const std::string& filename){
00128     if(sphere) sphere->getOSGPrimitive()->setTexture(filename);
00129   }
00130   
00131   virtual void setPose(const osg::Matrix& pose){
00132     this->pose = osg::Matrix::translate(0,0,radius) * pose;
00133     if (!obstacle_exists) {
00134        create();
00135      }
00136      sphere->setPose(pose);
00137   };
00138 
00139   virtual Primitive* getMainPrimitive() const { return sphere; }
00140 
00141   
00142  protected:
00143   virtual void create(){
00144     if (mass==0.0) {
00145       sphere->init(odeHandle, mass, osgHandle, Primitive::Geom | Primitive::Draw);
00146      } else {
00147       sphere->init(odeHandle, mass, osgHandle);
00148     }
00149     obstacle_exists=true;
00150   };
00151 
00152 };
00153 
00154 }
00155 
00156 #endif

Generated on Fri Oct 30 16:29:01 2009 for Robot Simulator of the Robotics Group for Self-Organization of Control by  doxygen 1.4.7