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 #ifndef __PRIMITIVE_H
00063 #define __PRIMITIVE_H
00064
00065 #include "osgprimitive.h"
00066 #include "odehandle.h"
00067 #include <osg/Matrix>
00068
00069 #include <ode/common.h>
00070
00071 namespace lpzrobots {
00072
00073
00074
00075 osg::Matrix osgPose( dGeomID geom );
00076
00077 osg::Matrix osgPose( dBodyID body );
00078
00079 osg::Matrix osgPose( const double * position , const double * rotation );
00080
00081 void odeRotation( const osg::Matrix& pose , dMatrix3& odematrix);
00082
00083
00084
00085
00086
00087 class Primitive {
00088 public:
00089
00090
00091
00092
00093 typedef enum Modes {Body=1, Geom=2, Draw=4};
00094
00095 Primitive ();
00096 virtual ~Primitive ();
00097
00098
00099
00100
00101
00102
00103 virtual void init(const OdeHandle& odeHandle, double mass,
00104 const OsgHandle& osgHandle,
00105 char mode = Body | Geom | Draw) = 0 ;
00106
00107
00108
00109
00110 virtual void update() =0 ;
00111
00112
00113 virtual OSGPrimitive* getOSGPrimitive() = 0;
00114
00115
00116 void setPosition(const osg::Vec3& pos);
00117
00118 void setPose(const osg::Matrix& pose);
00119
00120 osg::Vec3 getPosition() const;
00121
00122 osg::Matrix getPose() const;
00123
00124
00125 dGeomID getGeom() const;
00126
00127 dBodyID getBody() const;
00128
00129 protected:
00130 dGeomID geom;
00131 dBodyID body;
00132 char mode;
00133 };
00134
00135
00136
00137 class Plane : public Primitive {
00138 public:
00139 Plane();
00140 virtual ~Plane();
00141 virtual void init(const OdeHandle& odeHandle, double mass,
00142 const OsgHandle& osgHandle,
00143 char mode = Body | Geom | Draw) ;
00144
00145 virtual void update();
00146 virtual OSGPrimitive* getOSGPrimitive() { return osgplane; }
00147
00148 protected:
00149 OSGPlane* osgplane;
00150 };
00151
00152
00153
00154 class Box : public Primitive {
00155 public:
00156
00157 Box(float lengthX, float lengthY, float lengthZ);
00158 virtual ~Box();
00159
00160 virtual void init(const OdeHandle& odeHandle, double mass,
00161 const OsgHandle& osgHandle,
00162 char mode = Body | Geom | Draw) ;
00163
00164 virtual void update();
00165 virtual OSGPrimitive* getOSGPrimitive() { return osgbox; }
00166
00167 protected:
00168 OSGBox* osgbox;
00169 };
00170
00171
00172
00173 class Sphere : public Primitive {
00174 public:
00175 Sphere(float radius);
00176 virtual ~Sphere();
00177
00178 virtual void init(const OdeHandle& odeHandle, double mass,
00179 const OsgHandle& osgHandle,
00180 char mode = Body | Geom | Draw) ;
00181
00182 virtual void update();
00183 virtual OSGPrimitive* getOSGPrimitive() { return osgsphere; }
00184
00185 protected:
00186 OSGSphere* osgsphere;
00187 };
00188
00189
00190 class Capsule : public Primitive {
00191 public:
00192 Capsule(float radius, float height);
00193 virtual ~Capsule();
00194 virtual void init(const OdeHandle& odeHandle, double mass,
00195 const OsgHandle& osgHandle,
00196 char mode = Body | Geom | Draw) ;
00197
00198 virtual void update();
00199 virtual OSGPrimitive* getOSGPrimitive() { return osgcapsule; }
00200
00201 protected:
00202 OSGCapsule* osgcapsule;
00203 };
00204
00205
00206
00207
00208
00209
00210
00211 class Transform : public Primitive {
00212 public:
00213
00214
00215
00216
00217
00218 Transform(Primitive* parent, Primitive* child, const osg::Matrix& pose);
00219
00220 virtual void init(const OdeHandle& odeHandle, double mass,
00221 const OsgHandle& osgHandle,
00222 char mode = Body | Geom | Draw);
00223
00224 virtual void update();
00225 virtual OSGPrimitive* getOSGPrimitive() { return 0; }
00226
00227 protected:
00228 Primitive* parent;
00229 Primitive* child;
00230 osg::Matrix pose;
00231 };
00232
00233
00234
00235
00236
00237 class DummyPrimitive : public Primitive {
00238 public:
00239
00240
00241
00242
00243
00244 DummyPrimitive() {
00245 body=0;
00246 geom=0;
00247 }
00248 virtual void init(const OdeHandle& odeHandle, double mass,
00249 const OsgHandle& osgHandle, char mode = Body | Geom | Draw) {
00250 }
00251 virtual void update() {}
00252 virtual OSGPrimitive* getOSGPrimitive() { return 0; }
00253 };
00254
00255
00256 }
00257 #endif
00258