2
//! General body class, which all other body classes have to inherit.
6
* Describes general properties of a body in the simulation environment.
18
#include <dtCore/dt.h>
19
#include <dtCore/object.h>
20
#include <dtCore/globals.h>
21
#include <dtCore/transform.h>
22
#include <dtGame/gameactor.h>
23
#include <dtCore/refptr.h>
29
#include <osg/PositionAttitudeTransform>
30
#include <osgDB/ReadFile>
31
#include <osg/Material>
32
#include <osg/NodeVisitor>
36
#include <srCore/simulationUtils.h>
38
#define _I(i,j) I[(i)*4+(j)]
45
class osgBodyNodeVisitor;
47
class osgBodyTransform : public osg::PositionAttitudeTransform {
50
osgBodyTransform(dtCore::RefPtr<BodyBase> srBody);
52
dtCore::RefPtr<BodyBase> getMyBody();
53
virtual void accept(osgBodyNodeVisitor& bnv);
54
virtual void traverse (osgBodyNodeVisitor &bnv);
60
dtCore::RefPtr<BodyBase> myBody;
64
typedef std::vector< dtCore::RefPtr<osgBodyTransform> > BodyTransformNodeList;
66
class osgBodyNodeVisitor : public osg::NodeVisitor
69
osgBodyNodeVisitor(BodyBase* root, TraversalMode tm=TRAVERSE_NONE);
70
osgBodyNodeVisitor (TraversalMode tm=TRAVERSE_NONE);
71
osgBodyNodeVisitor (VisitorType type, TraversalMode tm=TRAVERSE_NONE);
73
virtual void apply(osgBodyTransform &node);
74
// virtual void accept(osgBodyNodeVisitor& bnv);
76
void addChildToBodyRoot (BodyBase* child);
77
BodyBase* returnBodyRoot ();
79
virtual ~osgBodyNodeVisitor ();
88
class BodyBase : public dtCore::Object
91
friend class ConnectorBase;
92
friend class SimulationUtils;
96
static std::map< dBodyID, BodyBase*> odeBodyMap;
101
//! Register the body to the simulation, i.e. map the BodyBase object to the ODE body ID
104
//! Merges the collision shape and the masses of two bodies together. theBody will become child of this body and the physics will be disabled of theBody
105
void mergeBody(BodyBase* theBody);
107
//! Adds the body to the scene, makes it visible and activates the physical behaviour
108
void addToScene(); //dtCore::Scene*& scene, osg::Group*& osgGroup);
110
//! Scaling of the model to Robot3D environment
111
void setScale(float scaleX, float scaleY, float scaleZ);
113
//! Show the collision geometry of the body.
115
/*! Activate this to check manually/optically if collision geometry fits to the model.
116
* Will also be used to indicate which robot is under manual control.
118
void renderCollisionGeometry(bool renderIt);
119
void renderCollisionGeometry2(bool renderIt);
120
void colorBody(osg::Vec4 color);
121
void colorCollisionShape(osg::Vec4 color);
123
/*! Initializes the body. Needs to be called before using the body
125
* @param name The name of the body
126
* @param robot The robot the body belongs to
127
* @param x,y,z The relative position of the body within the robot
128
* @param heading, roll, pitch The relative orientation of the body within the robot
131
void init( std::string name, RobotActorBase* robot,
132
float x, float y, float z,
133
float heading, float roll, float pitch);
135
//! Return the body Id, which represents the geomCollide and geomCategory bits
138
//! returns the global position of the body
139
osg::Vec3f getTranslation() const;
141
//! returns the global Rotation of the body ()
142
osg::Vec3f getRotation() const;
144
//! returns the scaling factor between the physical and the geometrical world
145
osg::Vec3f getScale() const;
147
//! returns the Transform of the Body
148
dtCore::Transform getTransform() const {return this->xform;}
150
//! sets the Transform of the Body
151
virtual void setTransform(dtCore::Transform &transform);
153
//! sets the position of the Body. Only use that while physics is deactivated.
154
virtual void setTranslation(osg::Vec3f pos);
156
//! sets the rotation of the Body. Only use that while physics is deactivated.
157
virtual void setRotation(osg::Vec3f hrp);
159
//! Returns the Robot the body belongs to
160
RobotActorBase* getRobot() const {return myRobot;};
162
//! Returns the current collision model of the body
163
dtCore::RefPtr<osg::Node> getCollisionModel() const {return collisionModel;};
165
//! Sets the collision model
166
void setCollisionModel(dtCore::RefPtr<osg::Node> collModel);
167
void setCollisionModel(osgBodyTransform* collModel);
168
osgBodyTransform* getCollisionModel();
171
unsigned long int getCollisionBits() const {return collCategoryBit;};
172
void setCollisionBits(unsigned long int bit);
174
//! Set the mass to this subOrgansim, consisting of this body and all its children
175
void setSubOrgBodyMass(dMass *mass) {dMassSetParameters(&subOrgBodyMass, mass->mass,
176
mass->c[0], mass->c[1], mass->c[2],
177
mass->_I(0,0), mass->_I(1,1), mass->_I(2,2),
178
mass->_I(1,2), mass->_I(1,3), mass->_I(2,3));};
180
//! Returns the mass to this subOrgansim, consisting of this body and all its children
181
void getSubOrgBodyMass(dMass &mass) {dMassSetParameters(&mass, subOrgBodyMass.mass,
182
subOrgBodyMass.c[0], subOrgBodyMass.c[1], subOrgBodyMass.c[2],
183
subOrgBodyMass._I(0,0), subOrgBodyMass._I(1,1), subOrgBodyMass._I(2,2),
184
subOrgBodyMass._I(1,2), subOrgBodyMass._I(1,3), subOrgBodyMass._I(2,3));};
186
//! Returns true, when the body has a contact with the floot or other obstacles
187
bool hasContact() {return bodyHasContact;};
192
//! To be set true, when that body has collided with an obstacle or the floor (currently by the simulationUtils class)
193
void setContact(bool contact) {bodyHasContact = true;};
198
RobotActorBase* myRobot;
199
float scaleX, scaleY, scaleZ;
201
//! collision model of merged bodies (e.g. the through the coupling devices merged bodies)
202
//dtCore::RefPtr<osg::PositionAttitudeTransform>
203
dtCore::RefPtr<osgBodyTransform> collisionModel;
204
dMass subOrgBodyMass;
208
void setModelTranslation(osg::Vec3 pos);
209
void setAllModelTranslations(dtCore::Object &object, std::string theOtherObjectName, osg::Vec3 pos);
211
// transformation of the body
212
dtCore::Transform xform;
214
//! If true, collision geometry will be rendered
220
//!collision model of the single body
221
dtCore::RefPtr<dtCore::Object> bodyCollisionModel;
223
unsigned long int collCategoryBit;
228
typedef std::map< dBodyID, BodyBase*> body_map_type;
229
typedef body_map_type::value_type body_pair_type;
233
//#include "../robotActorBase.h"