passivebox.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: passivebox.h,v $ 00023 * Revision 1.2 2006/07/14 12:23:33 martius 00024 * selforg becomes HEAD 00025 * 00026 * Revision 1.1.2.6 2006/06/16 22:27:26 martius 00027 * getMainPrimtive 00028 * 00029 * Revision 1.1.2.5 2006/05/18 12:54:24 robot3 00030 * -fixed not being able to change the color after positioning 00031 * the obstacle 00032 * -cleared the files up 00033 * 00034 * Revision 1.1.2.4 2006/05/11 12:53:04 robot3 00035 * fixed some errors in passivebox.h 00036 * 00037 * Revision 1.1.2.3 2006/05/11 08:59:15 robot3 00038 * -fixed a positioning bug (e.g. for passivesphere) 00039 * -some methods moved to abstractobstacle.h for avoiding inconsistencies 00040 * 00041 * Revision 1.1.2.2 2006/03/30 12:34:51 martius 00042 * documentation updated 00043 * 00044 * Revision 1.1.2.1 2006/03/29 15:04:39 martius 00045 * have pose now 00046 * 00047 * * 00048 * * 00049 ***************************************************************************/ 00050 #ifndef __PASSIVEBOX_H 00051 #define __PASSIVEBOX_H 00052 00053 #include <stdio.h> 00054 #include <math.h> 00055 00056 #include "primitive.h" 00057 #include "abstractobstacle.h" 00058 00059 namespace lpzrobots { 00060 00061 /** 00062 * (Passive) box as obstacle 00063 */ 00064 class PassiveBox : public AbstractObstacle{ 00065 osg::Vec3 dimension; 00066 double mass; 00067 int texture; 00068 00069 00070 Box* box; 00071 00072 00073 public: 00074 00075 /** 00076 * Constructor 00077 */ 00078 PassiveBox(const OdeHandle& odeHandle, const OsgHandle& osgHandle, 00079 const osg::Vec3& dimension = osg::Vec3(1.0, 1.0, 1.0), double mass = 1.0): 00080 AbstractObstacle::AbstractObstacle(odeHandle, osgHandle), dimension(dimension), mass(mass) { 00081 box=0; 00082 obstacle_exists=false; 00083 }; 00084 00085 ~PassiveBox(){ 00086 if(box) delete box; 00087 } 00088 00089 /** 00090 * update position of box 00091 */ 00092 virtual void update(){ 00093 if(box) box->update(); 00094 }; 00095 00096 virtual void setTexture(const std::string& filename){ 00097 if(box) box->getOSGPrimitive()->setTexture(filename); 00098 } 00099 00100 virtual void setPose(const osg::Matrix& pose){ 00101 this->pose = osg::Matrix::translate(0,0,dimension.z()/2) * pose; 00102 if (obstacle_exists){ 00103 destroy(); 00104 } 00105 create(); 00106 }; 00107 00108 virtual Primitive* getMainPrimitive() const { return box; } 00109 00110 protected: 00111 virtual void create(){ 00112 box = new Box(dimension.x(), dimension.y(), dimension.z()); 00113 box->init(odeHandle, mass, osgHandle); 00114 osg::Vec3 pos=pose.getTrans(); 00115 box->setPosition(pos); 00116 00117 obstacle_exists=true; 00118 }; 00119 00120 virtual void destroy(){ 00121 if(box) delete box; 00122 obstacle_exists=false; 00123 }; 00124 00125 }; 00126 00127 } 00128 00129 #endif 00130

Generated on Tue Jan 16 02:14:37 2007 for Robotsystem of the Robot Group Leipzig by doxygen 1.3.8