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
00095
00096
00097
00098
00099
00100
#ifndef __PRIMITIVE_H
00101
#define __PRIMITIVE_H
00102
00103
#include <osg/Matrix>
00104
#include <ode/common.h>
00105
00106
00107
#include "osgforwarddecl.h"
00108
00109
namespace lpzrobots {
00110
00111
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
00125
00126
00127
00128
osg::Matrix osgPose( dGeomID geom );
00129
00130
osg::Matrix osgPose( dBodyID body );
00131
00132
osg::Matrix osgPose(
const double * position ,
const double * rotation );
00133
00134
void odeRotation(
const osg::Matrix& pose , dMatrix3& odematrix);
00135
00136
00137
00138
00139
00140 class Primitive {
00141
public:
00142
00143
00144
00145
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
00153
00154
00155
00156
00157
00158
virtual void init(
const OdeHandle& odeHandle,
double mass,
00159
const OsgHandle& osgHandle,
00160
char mode = Body | Geom | Draw) = 0 ;
00161
00162
00163
00164
00165
virtual void update() =0 ;
00166
00167
00168
virtual OSGPrimitive*
getOSGPrimitive() = 0;
00169
00170
00171
virtual void setTexture(
const std::string& filename);
00172
00173
virtual void setTexture(
const std::string& filename,
bool repeatOnX,
bool repeatOnY);
00174
00175
00176
void setPosition(
const osg::Vec3& pos);
00177
00178
void setPose(
const osg::Matrix& pose);
00179
00180
osg::Vec3 getPosition() const;
00181
00182 osg::Matrix getPose() const;
00183
00184
00185 dGeomID getGeom() const;
00186
00187 dBodyID getBody() const;
00188
00189 protected:
00190
00191
00192
00193 virtual
void attachGeomAndSetColliderFlags();
00194
00195 protected:
00196 dGeomID geom;
00197 dBodyID body;
00198 char mode;
00199 };
00200
00201
00202
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
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
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
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
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
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
00311
00312
00313
00314 class Transform :
public Primitive {
00315
public:
00316
00317
00318
00319
00320
00321
Transform(
Primitive* parent,
Primitive* child,
const osg::Matrix& pose);
00322
00323
00324 ~
Transform();
00325
00326
00327
00328
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
00345
00346
00347 class DummyPrimitive :
public Primitive {
00348
public:
00349
00350
00351
00352
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