primitive.h

Go to the documentation of this file.
00001 00002 /*************************************************************************** 00003 * Copyright (C) 2005 by Robot Group Leipzig * 00004 * martius@informatik.uni-leipzig.de * 00005 * fhesse@informatik.uni-leipzig.de * 00006 * der@informatik.uni-leipzig.de * 00007 * frankguettler@gmx.de * 00008 * * 00009 * This program is free software; you can redistribute it and/or modify * 00010 * it under the terms of the GNU General Public License as published by * 00011 * the Free Software Foundation; either version 2 of the License, or * 00012 * (at your option) any later version. * 00013 * * 00014 * This program is distributed in the hope that it will be useful, * 00015 * but WITHOUT ANY WARRANTY; without even the implied warranty of * 00016 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * 00017 * GNU General Public License for more details. * 00018 * * 00019 * You should have received a copy of the GNU General Public License * 00020 * along with this program; if not, write to the * 00021 * Free Software Foundation, Inc., * 00022 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * 00023 * * 00024 *************************************************************************** 00025 * * 00026 * This file provides basic primitives for ODE and openscenegraph * 00027 * * 00028 * * 00029 * $Log: primitive.h,v $ 00030 * Revision 1.4 2006/12/13 09:09:56 martius 00031 * transform objects delete child 00032 * 00033 * Revision 1.3 2006/08/30 08:58:56 martius 00034 * categories and collision mask used for static geoms to reduce number of collision checks 00035 * 00036 * Revision 1.2 2006/07/14 12:23:35 martius 00037 * selforg becomes HEAD 00038 * 00039 * Revision 1.1.2.18 2006/07/14 11:23:38 martius 00040 * revert to older revision of robot3 00041 * 00042 * Revision 1.1.2.16 2006/06/29 16:35:32 robot3 00043 * -Mesh code optimized 00044 * -includes cleared up, more using forward declarations 00045 * (sometimes additionally #include "osgprimitive.h" is needed) 00046 * 00047 * Revision 1.1.2.15 2006/06/27 14:14:29 robot3 00048 * -optimized mesh and boundingshape code 00049 * -other changes 00050 * 00051 * Revision 1.1.2.14 2006/06/23 08:53:56 robot3 00052 * made some changes on primitive Mesh 00053 * 00054 * Revision 1.1.2.13 2006/05/29 22:03:26 martius 00055 * cylinder 00056 * 00057 * Revision 1.1.2.12 2006/05/29 21:27:02 robot3 00058 * made some preparations for the boundingshape of the Mesh 00059 * 00060 * Revision 1.1.2.11 2006/05/28 22:14:57 martius 00061 * heightfield included 00062 * 00063 * Revision 1.1.2.10 2006/05/24 12:23:10 robot3 00064 * -passive_mesh works now (simple bound_version) 00065 * -Primitive Mesh now exists (simple bound_version) 00066 * 00067 * Revision 1.1.2.9 2006/04/04 14:13:24 fhesse 00068 * documentation improved 00069 * 00070 * Revision 1.1.2.8 2006/03/29 15:07:17 martius 00071 * Dummy Primitive 00072 * 00073 * Revision 1.1.2.7 2006/01/31 15:45:35 martius 00074 * proper destruction 00075 * 00076 * Revision 1.1.2.6 2006/01/12 14:21:00 martius 00077 * drawmode, material 00078 * 00079 * Revision 1.1.2.5 2005/12/29 12:58:42 martius 00080 * *** empty log message *** 00081 * 00082 * Revision 1.1.2.4 2005/12/15 17:03:43 martius 00083 * cameramanupulator setPose is working 00084 * joints have setter and getter parameters 00085 * Primitives are not longer inherited from OSGPrimitive, moreover 00086 * they aggregate them 00087 * 00088 * Revision 1.1.2.3 2005/12/14 15:36:45 martius 00089 * joints are visible now 00090 * 00091 * Revision 1.1.2.2 2005/12/13 18:11:14 martius 00092 * transform primitive added, some joints stuff done, forward declaration 00093 * 00094 * Revision 1.1.2.1 2005/12/06 10:13:25 martius 00095 * openscenegraph integration started 00096 * 00097 * * 00098 * * 00099 ***************************************************************************/ 00100 #ifndef __PRIMITIVE_H 00101 #define __PRIMITIVE_H 00102 00103 #include <osg/Matrix> 00104 #include <ode/common.h> 00105 00106 // another forward declaration "block" 00107 #include "osgforwarddecl.h" 00108 00109 namespace lpzrobots { 00110 00111 /***** begin of forward declaration block *****/ 00112 class BoundingShape; 00113 class OSGPrimitive; 00114 class OSGPlane; 00115 class OSGBox; 00116 class OSGSphere; 00117 class OSGCapsule; 00118 class OSGCylinder; 00119 class OSGDummy; 00120 class OSGMesh; 00121 typedef struct GlobalData; 00122 class OdeHandle; 00123 class OsgHandle; 00124 /***** end of forward declaration block *****/ 00125 00126 00127 /// returns the osg (4x4) pose matrix of the ode geom 00128 osg::Matrix osgPose( dGeomID geom ); 00129 /// returns the osg (4x4) pose matrix of the ode body 00130 osg::Matrix osgPose( dBodyID body ); 00131 /// converts a position vector and a rotation matrix from ode to osg 4x4 matrix 00132 osg::Matrix osgPose( const double * position , const double * rotation ); 00133 /// converts the rotation component of pose into an ode rotation matrix 00134 void odeRotation( const osg::Matrix& pose , dMatrix3& odematrix); 00135 00136 /** 00137 Interface class for primitives represented in the physical and graphical world. 00138 This is intended to bring OSG and ODE together and hide most implementation details. 00139 */ 00140 class Primitive { 00141 public: 00142 /** Body means that it is a dynamic object with a body. 00143 Geom means it has a geometrical represenation used for collision detection. 00144 Draw means the primitive is drawn 00145 Child is only used internally and is used for transformed geoms. 00146 */ 00147 typedef enum Modes {Body=1, Geom=2, Draw=4, Child=8}; 00148 typedef enum Category { Dyn=1, Stat=2}; 00149 00150 Primitive (); 00151 virtual ~Primitive (); 00152 /** registers primitive in ODE and OSG. 00153 @param osgHandle scruct with ODE variables inside (to specify space, world...) 00154 @param mass Mass of the object in ODE (if withBody = true) 00155 @param osgHandle scruct with OSG variables inside (scene node, color ...) 00156 @param mode is a conjuction of Modes. 00157 */ 00158 virtual void init(const OdeHandle& odeHandle, double mass, 00159 const OsgHandle& osgHandle, 00160 char mode = Body | Geom | Draw) = 0 ; 00161 00162 /** Updates the OSG nodes with ODE coordinates. 00163 This function must be overloaded (usually calls setMatrix of OsgPrimitives) 00164 */ 00165 virtual void update() =0 ; 00166 00167 /// returns the assoziated osg primitive if there or 0 00168 virtual OSGPrimitive* getOSGPrimitive() = 0; 00169 00170 /// assigns a texture to the primitive 00171 virtual void setTexture(const std::string& filename); 00172 /// assigns a texture to the primitive, you can choose if the texture should be repeated 00173 virtual void setTexture(const std::string& filename, bool repeatOnX, bool repeatOnY); 00174 00175 /// set the position of the primitive (orientation is preserved) 00176 void setPosition(const osg::Vec3& pos); 00177 /// set the pose of the primitive 00178 void setPose(const osg::Matrix& pose); 00179 /// returns the position 00180 osg::Vec3 getPosition() const; 00181 /// returns the pose 00182 osg::Matrix getPose() const; 00183 00184 /// returns ODE geomID if there 00185 dGeomID getGeom() const; 00186 /// returns ODE bodyID if there 00187 dBodyID getBody() const; 00188 00189 protected: 00190 /** attaches geom to body (if any) and sets the category bits and collision bitfields. 00191 assumes: mode & Geom != 0 00192 */ 00193 virtual void attachGeomAndSetColliderFlags(); 00194 00195 protected: 00196 dGeomID geom; 00197 dBodyID body; 00198 char mode; 00199 }; 00200 00201 00202 /** Plane primitive */ 00203 class Plane : public Primitive { 00204 public: 00205 Plane(); 00206 virtual ~Plane(); 00207 virtual void init(const OdeHandle& odeHandle, double mass, 00208 const OsgHandle& osgHandle, 00209 char mode = Body | Geom | Draw) ; 00210 00211 virtual void update(); 00212 virtual OSGPrimitive* getOSGPrimitive(); 00213 00214 protected: 00215 OSGPlane* osgplane; 00216 }; 00217 00218 00219 /** Box primitive */ 00220 class Box : public Primitive { 00221 public: 00222 00223 Box(float lengthX, float lengthY, float lengthZ); 00224 virtual ~Box(); 00225 00226 virtual void init(const OdeHandle& odeHandle, double mass, 00227 const OsgHandle& osgHandle, 00228 char mode = Body | Geom | Draw) ; 00229 00230 virtual void update(); 00231 virtual OSGPrimitive* getOSGPrimitive(); 00232 00233 protected: 00234 OSGBox* osgbox; 00235 }; 00236 00237 00238 /** Sphere primitive */ 00239 class Sphere : public Primitive { 00240 public: 00241 Sphere(float radius); 00242 virtual ~Sphere(); 00243 00244 virtual void init(const OdeHandle& odeHandle, double mass, 00245 const OsgHandle& osgHandle, 00246 char mode = Body | Geom | Draw) ; 00247 00248 virtual void update(); 00249 virtual OSGPrimitive* getOSGPrimitive(); 00250 00251 protected: 00252 OSGSphere* osgsphere; 00253 }; 00254 00255 /** Capsule primitive */ 00256 class Capsule : public Primitive { 00257 public: 00258 Capsule(float radius, float height); 00259 virtual ~Capsule(); 00260 virtual void init(const OdeHandle& odeHandle, double mass, 00261 const OsgHandle& osgHandle, 00262 char mode = Body | Geom | Draw) ; 00263 00264 virtual void update(); 00265 virtual OSGPrimitive* getOSGPrimitive(); 00266 00267 protected: 00268 OSGCapsule* osgcapsule; 00269 }; 00270 00271 /** Cylinder primitive */ 00272 class Cylinder : public Primitive { 00273 public: 00274 Cylinder(float radius, float height); 00275 virtual ~Cylinder(); 00276 virtual void init(const OdeHandle& odeHandle, double mass, 00277 const OsgHandle& osgHandle, 00278 char mode = Body | Geom | Draw) ; 00279 00280 virtual void update(); 00281 virtual OSGPrimitive* getOSGPrimitive(); 00282 00283 protected: 00284 OSGCylinder* osgcylinder; 00285 }; 00286 00287 00288 /** Mesh primitive */ 00289 class Mesh : public Primitive { 00290 public: 00291 Mesh(const std::string& filename,float scale,GlobalData& global); 00292 virtual ~Mesh(); 00293 virtual void init(const OdeHandle& odeHandle, double mass, 00294 const OsgHandle& osgHandle, 00295 char mode = Body | Geom | Draw) ; 00296 virtual void update(); 00297 virtual OSGPrimitive* getOSGPrimitive(); 00298 virtual float getRadius(); 00299 00300 protected: 00301 OSGMesh* osgmesh; 00302 char drawBoundingMode; 00303 const std::string filename; 00304 float scale; 00305 BoundingShape* boundshape; 00306 }; 00307 00308 00309 /** 00310 Primitive for transforming a geom (primitive without body) 00311 in respect to a body (primitive with body). 00312 Hides complexity of ODE TransformGeoms. 00313 */ 00314 class Transform : public Primitive { 00315 public: 00316 /** 00317 @param parent primitive should have a body and should be initialised 00318 @param child is transformed by pose in respect to parent. 00319 This Primitive must NOT have a body and should not be initialised 00320 */ 00321 Transform(Primitive* parent, Primitive* child, const osg::Matrix& pose); 00322 00323 /// destructor deletes child object 00324 ~Transform(); 00325 00326 /** initialised the transform object. This automatically 00327 initialises the child geom. 00328 @param mode is the mode for the child, except that Body bit is ignored (child can't have a body) 00329 */ 00330 virtual void init(const OdeHandle& odeHandle, double mass, 00331 const OsgHandle& osgHandle, 00332 char mode = Body | Geom | Draw); 00333 00334 virtual void update(); 00335 virtual OSGPrimitive* getOSGPrimitive(); 00336 00337 protected: 00338 Primitive* parent; 00339 Primitive* child; 00340 osg::Matrix pose; 00341 }; 00342 00343 /** 00344 Dummy Primitive which returns 0 for geom and body. 00345 Only useful for representing the static world in terms of primitives. 00346 */ 00347 class DummyPrimitive : public Primitive { 00348 public: 00349 /** 00350 @param parent primitive should have a body and should be initialised 00351 @param child is transformed by pose in respect to parent. 00352 This Primitive must NOT have a body 00353 */ 00354 DummyPrimitive() { 00355 body=0; 00356 geom=0; 00357 } 00358 virtual void init(const OdeHandle& odeHandle, double mass, 00359 const OsgHandle& osgHandle, char mode = Body | Geom | Draw) { 00360 } 00361 virtual void update() {} 00362 virtual OSGPrimitive* getOSGPrimitive() { return 0; } 00363 }; 00364 00365 00366 } 00367 #endif 00368

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