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.5 2008/09/16 14:49:46 martius 00024 * use cmath instead of math.h 00025 * 00026 * Revision 1.4 2007/12/06 15:59:19 der 00027 * if you set the mass=0.0, a passive box without a body is created 00028 * 00029 * Revision 1.3 2007/03/16 11:01:37 martius 00030 * abstractobstacle gets mor functionallity 00031 * setSubstance 00032 * 00033 * Revision 1.2 2006/07/14 12:23:33 martius 00034 * selforg becomes HEAD 00035 * 00036 * Revision 1.1.2.6 2006/06/16 22:27:26 martius 00037 * getMainPrimtive 00038 * 00039 * Revision 1.1.2.5 2006/05/18 12:54:24 robot3 00040 * -fixed not being able to change the color after positioning 00041 * the obstacle 00042 * -cleared the files up 00043 * 00044 * Revision 1.1.2.4 2006/05/11 12:53:04 robot3 00045 * fixed some errors in passivebox.h 00046 * 00047 * Revision 1.1.2.3 2006/05/11 08:59:15 robot3 00048 * -fixed a positioning bug (e.g. for passivesphere) 00049 * -some methods moved to abstractobstacle.h for avoiding inconsistencies 00050 * 00051 * Revision 1.1.2.2 2006/03/30 12:34:51 martius 00052 * documentation updated 00053 * 00054 * Revision 1.1.2.1 2006/03/29 15:04:39 martius 00055 * have pose now 00056 * 00057 * * 00058 * * 00059 ***************************************************************************/ 00060 #ifndef __PASSIVEBOX_H 00061 #define __PASSIVEBOX_H 00062 00063 #include <stdio.h> 00064 #include <cmath> 00065 00066 #include "primitive.h" 00067 #include "abstractobstacle.h" 00068 00069 namespace lpzrobots { 00070 00071 /** 00072 * (Passive) box as obstacle 00073 */ 00074 class PassiveBox : public AbstractObstacle{ 00075 osg::Vec3 dimension; 00076 double mass; 00077 int texture; 00078 00079 00080 Box* box; 00081 00082 00083 public: 00084 00085 /** 00086 * Constructor, if you set mass=0.0, you get a box which cannot be moved 00087 */ 00088 PassiveBox(const OdeHandle& odeHandle, const OsgHandle& osgHandle, 00089 const osg::Vec3& dimension = osg::Vec3(1.0, 1.0, 1.0), double mass = 1.0): 00090 AbstractObstacle::AbstractObstacle(odeHandle, osgHandle), dimension(dimension), mass(mass) { 00091 box=0; 00092 obstacle_exists=false; 00093 }; 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 if (mass==0.0) { 00114 box->init(odeHandle, mass, osgHandle, Primitive::Geom | Primitive::Draw); 00115 } else { 00116 box->init(odeHandle, mass, osgHandle); 00117 } 00118 osg::Vec3 pos=pose.getTrans(); 00119 box->setPosition(pos); 00120 obst.push_back(box); 00121 00122 obstacle_exists=true; 00123 }; 00124 00125 }; 00126 00127 } 00128 00129 #endif 00130