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.9 2009/04/02 13:10:03 fhesse 00024 * replace() removed; setPose() and create() adapted such 00025 * that replacing is now possible 00026 * 00027 * Revision 1.8 2009/04/02 11:46:28 fhesse 00028 * replace() added (doses not call create) 00029 * 00030 * Revision 1.7 2009/04/02 10:12:25 martius 00031 * Texture handling changed 00032 * 00033 * Revision 1.6 2009/01/09 16:52:36 martius 00034 * use pose instead of translation only 00035 * 00036 * Revision 1.5 2008/09/16 14:49:46 martius 00037 * use cmath instead of math.h 00038 * 00039 * Revision 1.4 2007/12/06 15:59:19 der 00040 * if you set the mass=0.0, a passive box without a body is created 00041 * 00042 * Revision 1.3 2007/03/16 11:01:37 martius 00043 * abstractobstacle gets mor functionallity 00044 * setSubstance 00045 * 00046 * Revision 1.2 2006/07/14 12:23:33 martius 00047 * selforg becomes HEAD 00048 * 00049 * Revision 1.1.2.6 2006/06/16 22:27:26 martius 00050 * getMainPrimtive 00051 * 00052 * Revision 1.1.2.5 2006/05/18 12:54:24 robot3 00053 * -fixed not being able to change the color after positioning 00054 * the obstacle 00055 * -cleared the files up 00056 * 00057 * Revision 1.1.2.4 2006/05/11 12:53:04 robot3 00058 * fixed some errors in passivebox.h 00059 * 00060 * Revision 1.1.2.3 2006/05/11 08:59:15 robot3 00061 * -fixed a positioning bug (e.g. for passivesphere) 00062 * -some methods moved to abstractobstacle.h for avoiding inconsistencies 00063 * 00064 * Revision 1.1.2.2 2006/03/30 12:34:51 martius 00065 * documentation updated 00066 * 00067 * Revision 1.1.2.1 2006/03/29 15:04:39 martius 00068 * have pose now 00069 * 00070 * * 00071 * * 00072 ***************************************************************************/ 00073 #ifndef __PASSIVEBOX_H 00074 #define __PASSIVEBOX_H 00075 00076 #include <stdio.h> 00077 #include <cmath> 00078 00079 #include "primitive.h" 00080 #include "abstractobstacle.h" 00081 00082 namespace lpzrobots { 00083 00084 /** 00085 * (Passive) box as obstacle 00086 */ 00087 class PassiveBox : public AbstractObstacle{ 00088 osg::Vec3 dimension; 00089 double mass; 00090 int texture; 00091 00092 00093 Box* box; 00094 00095 00096 public: 00097 00098 /** 00099 * Constructor, if you set mass=0.0, you get a box which cannot be moved 00100 */ 00101 PassiveBox(const OdeHandle& odeHandle, const OsgHandle& osgHandle, 00102 const osg::Vec3& dimension = osg::Vec3(1.0, 1.0, 1.0), double mass = 1.0): 00103 AbstractObstacle::AbstractObstacle(odeHandle, osgHandle), dimension(dimension), mass(mass) { 00104 box = new Box(dimension.x(), dimension.y(), dimension.z()); 00105 obst.push_back(box); 00106 obstacle_exists=false; 00107 }; 00108 00109 00110 virtual void setPose(const osg::Matrix& pose){ 00111 this->pose = osg::Matrix::translate(0,0,dimension.z()/2) * pose; 00112 if (!obstacle_exists) { 00113 create(); 00114 } 00115 box->setPose(pose); 00116 }; 00117 00118 00119 virtual Primitive* getMainPrimitive() const { return box; } 00120 00121 protected: 00122 virtual void create(){ 00123 if (mass==0.0) { 00124 box->init(odeHandle, mass, osgHandle, Primitive::Geom | Primitive::Draw); 00125 } else { 00126 box->init(odeHandle, mass, osgHandle); 00127 } 00128 // osg::Vec3 pos=pose.getTrans(); 00129 // box->setPosition(pos); 00130 obstacle_exists=true; 00131 }; 00132 00133 }; 00134 00135 } 00136 00137 #endif 00138