00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068
00069
00070
00071
00072
00073
00074
00075
00076
00077
00078
00079
00080
00081
00082
00083
00084
00085
00086
00087
00088
00089
00090
00091
00092
00093
00094 #ifndef __PRIMITIVE_H
00095 #define __PRIMITIVE_H
00096
00097 #include <osg/Matrix>
00098 #include <ode/common.h>
00099
00100
00101 #include "osgforwarddecl.h"
00102
00103 namespace lpzrobots {
00104
00105
00106 class BoundingShape;
00107 class OSGPrimitive;
00108 class OSGPlane;
00109 class OSGBox;
00110 class OSGSphere;
00111 class OSGCapsule;
00112 class OSGCylinder;
00113 class OSGDummy;
00114 class OSGMesh;
00115 typedef struct GlobalData;
00116 class OdeHandle;
00117 class OsgHandle;
00118
00119
00120
00121
00122 osg::Matrix osgPose( dGeomID geom );
00123
00124 osg::Matrix osgPose( dBodyID body );
00125
00126 osg::Matrix osgPose( const double * position , const double * rotation );
00127
00128 void odeRotation( const osg::Matrix& pose , dMatrix3& odematrix);
00129
00130
00131
00132
00133
00134 class Primitive {
00135 public:
00136
00137
00138
00139
00140 typedef enum Modes {Body=1, Geom=2, Draw=4};
00141
00142 Primitive ();
00143 virtual ~Primitive ();
00144
00145
00146
00147
00148
00149
00150 virtual void init(const OdeHandle& odeHandle, double mass,
00151 const OsgHandle& osgHandle,
00152 char mode = Body | Geom | Draw) = 0 ;
00153
00154
00155
00156
00157 virtual void update() =0 ;
00158
00159
00160 virtual OSGPrimitive* getOSGPrimitive() = 0;
00161
00162
00163 virtual void setTexture(const std::string& filename);
00164
00165 virtual void setTexture(const std::string& filename, bool repeatOnX, bool repeatOnY);
00166
00167
00168 void setPosition(const osg::Vec3& pos);
00169
00170 void setPose(const osg::Matrix& pose);
00171
00172 osg::Vec3 getPosition() const;
00173
00174 osg::Matrix getPose() const;
00175
00176
00177 dGeomID getGeom() const;
00178
00179 dBodyID getBody() const;
00180
00181 protected:
00182 dGeomID geom;
00183 dBodyID body;
00184 char mode;
00185 };
00186
00187
00188
00189 class Plane : public Primitive {
00190 public:
00191 Plane();
00192 virtual ~Plane();
00193 virtual void init(const OdeHandle& odeHandle, double mass,
00194 const OsgHandle& osgHandle,
00195 char mode = Body | Geom | Draw) ;
00196
00197 virtual void update();
00198 virtual OSGPrimitive* getOSGPrimitive();
00199
00200 protected:
00201 OSGPlane* osgplane;
00202 };
00203
00204
00205
00206 class Box : public Primitive {
00207 public:
00208
00209 Box(float lengthX, float lengthY, float lengthZ);
00210 virtual ~Box();
00211
00212 virtual void init(const OdeHandle& odeHandle, double mass,
00213 const OsgHandle& osgHandle,
00214 char mode = Body | Geom | Draw) ;
00215
00216 virtual void update();
00217 virtual OSGPrimitive* getOSGPrimitive();
00218
00219 protected:
00220 OSGBox* osgbox;
00221 };
00222
00223
00224
00225 class Sphere : public Primitive {
00226 public:
00227 Sphere(float radius);
00228 virtual ~Sphere();
00229
00230 virtual void init(const OdeHandle& odeHandle, double mass,
00231 const OsgHandle& osgHandle,
00232 char mode = Body | Geom | Draw) ;
00233
00234 virtual void update();
00235 virtual OSGPrimitive* getOSGPrimitive();
00236
00237 protected:
00238 OSGSphere* osgsphere;
00239 };
00240
00241
00242 class Capsule : public Primitive {
00243 public:
00244 Capsule(float radius, float height);
00245 virtual ~Capsule();
00246 virtual void init(const OdeHandle& odeHandle, double mass,
00247 const OsgHandle& osgHandle,
00248 char mode = Body | Geom | Draw) ;
00249
00250 virtual void update();
00251 virtual OSGPrimitive* getOSGPrimitive();
00252
00253 protected:
00254 OSGCapsule* osgcapsule;
00255 };
00256
00257
00258 class Cylinder : public Primitive {
00259 public:
00260 Cylinder(float radius, float height);
00261 virtual ~Cylinder();
00262 virtual void init(const OdeHandle& odeHandle, double mass,
00263 const OsgHandle& osgHandle,
00264 char mode = Body | Geom | Draw) ;
00265
00266 virtual void update();
00267 virtual OSGPrimitive* getOSGPrimitive();
00268
00269 protected:
00270 OSGCylinder* osgcylinder;
00271 };
00272
00273
00274
00275 class Mesh : public Primitive {
00276 public:
00277 Mesh(const std::string& filename,float scale,GlobalData& global);
00278 virtual ~Mesh();
00279 virtual void init(const OdeHandle& odeHandle, double mass,
00280 const OsgHandle& osgHandle,
00281 char mode = Body | Geom | Draw) ;
00282 virtual void update();
00283 virtual OSGPrimitive* getOSGPrimitive();
00284 virtual float getRadius();
00285
00286 protected:
00287 OSGMesh* osgmesh;
00288 char drawBoundingMode;
00289 const std::string filename;
00290 float scale;
00291 BoundingShape* boundshape;
00292 };
00293
00294
00295
00296
00297
00298
00299
00300 class Transform : public Primitive {
00301 public:
00302
00303
00304
00305
00306
00307 Transform(Primitive* parent, Primitive* child, const osg::Matrix& pose);
00308
00309 virtual void init(const OdeHandle& odeHandle, double mass,
00310 const OsgHandle& osgHandle,
00311 char mode = Body | Geom | Draw);
00312
00313 virtual void update();
00314 virtual OSGPrimitive* getOSGPrimitive();
00315
00316 protected:
00317 Primitive* parent;
00318 Primitive* child;
00319 osg::Matrix pose;
00320 };
00321
00322
00323
00324
00325
00326 class DummyPrimitive : public Primitive {
00327 public:
00328
00329
00330
00331
00332
00333 DummyPrimitive() {
00334 body=0;
00335 geom=0;
00336 }
00337 virtual void init(const OdeHandle& odeHandle, double mass,
00338 const OsgHandle& osgHandle, char mode = Body | Geom | Draw) {
00339 }
00340 virtual void update() {}
00341 virtual OSGPrimitive* getOSGPrimitive() { return 0; }
00342 };
00343
00344
00345 }
00346 #endif
00347