1
//! Specialized body class.
4
* Predefined body class. Ready to use in a RobotActor.
5
* This body represents the front part of the robot.
11
#include <srBody/kitBody1.h>
15
// units need to be around one to make the ode most stable. Hereby 1 length union is equal to 5cm.
16
#define SCALE_3DS 0.02
18
#define COLLISION_SIDE (64*SCALE_3DS) //60 // cm
19
#define COLLISION_LENGTH (64*SCALE_3DS) //85
21
// units need to be around one to make the ode most stable. Hereby 1 length union is equal to 5cm.
22
#define BODY_LENGTH 1.7 // equals 85 mm
23
#define BODY_HEIGHT 1.2
24
#define BODY_WIDTH 1.2
25
#define BODY_MASS 0.3 //0.13
27
using namespace srCore;
30
/*! @param id a 16bit id, used to set the colliding bit parameter.
31
* @param x, y, z the position of the hinge in the world coordinate system.
32
* @param heading, pitch, roll the orientation of the axis of the hinge in the world coordinate system.
33
* @param Scene the scene in which the body should be placed.
36
KITBody1::KITBody1( RobotActorBase* robot,
37
float x, float y, float z,
38
float heading, float pitch, float roll)
42
// initializing. parameters: name, id (of the robot), position, orientation and the scene
43
// needs to be done first
44
// todo: at the moment scene needs to be given to each element, although we only have one scene
45
this->init("KITBody1", robot, x, y, z, heading, pitch, roll);
50
if (SimulationUtils::getDetailedGraphics())
51
sprintf(file, "%s/StaticMeshes/KITcollBody.3ds", SimulationUtils::getStageProjectPath().c_str());
53
sprintf(file, "%s/StaticMeshes/KITcollBody1.3ds", SimulationUtils::getStageProjectPath().c_str()); //use this model in case of a bad graphics card
55
printf ("loading file %s ...\n", file);
57
// SetModelTranslation(osg::Vec3(0,0,COLLISION_SIDE*25));
59
// printf ("done \n");
62
this->setScale(SCALE_3DS,SCALE_3DS,SCALE_3DS);
63
// defining the collision box
64
this->setCollisionBox(COLLISION_SIDE, COLLISION_SIDE, COLLISION_SIDE);
66
// our Object just needs a mass now ...
67
this->setMass(BODY_MASS, COLLISION_SIDE, COLLISION_SIDE, COLLISION_SIDE);
69
this->GetOSGNode()->setNodeMask(SimulationUtils::geometryDetailsNodeMask);
71
dtCore::Object* collModel = new dtCore::Object();
72
dtCore::Transform xform;
74
switch (SimulationUtils::getCollisionGeometryDetails()) {
76
case 0: //sprintf(file, "%s/StaticMeshes/KITcollBodySquare1.3ds", SimulationUtils::getStageProjectPath().c_str()); break;
77
case 1: //sprintf(file, "%s/StaticMeshes/KITcollBodyPolygone1.3ds", SimulationUtils::getStageProjectPath().c_str()); break;
78
case 2: sprintf(file, "%s/StaticMeshes/KITcollBody.3ds", SimulationUtils::getStageProjectPath().c_str()); break;
79
case 15: sprintf(file, "%s/StaticMeshes/newKITBody1.3ds", SimulationUtils::getStageProjectPath().c_str()); break;
83
collModel->LoadFile(file);
86
collModel->SetScale(osg::Vec3(0.021,0.021,0.021));//this->GetScale());
88
osg::StateSet* stateset;
89
collModel->GetOSGNode()->setNodeMask(SimulationUtils::collisionNodeMask);
90
stateset = collModel->GetOSGNode()->getOrCreateStateSet();
91
osg::Material * mm = dynamic_cast<osg::Material*>(stateset->getAttribute(osg::StateAttribute::MATERIAL));
94
mm = new osg::Material;
96
mm->setAlpha(osg::Material::FRONT, 0.2);
97
mm->setAmbient(osg::Material::FRONT, osg::Vec4(0,0,0,0));
98
stateset->setAttributeAndModes( mm, osg::StateAttribute::OVERRIDE |
99
osg::StateAttribute::ON);
100
stateset->setMode(GL_BLEND, osg::StateAttribute::OVERRIDE |
101
osg::StateAttribute::ON );
102
stateset->setMode(GL_LIGHTING,osg::StateAttribute::OVERRIDE |
103
osg::StateAttribute::ON );
104
stateset->setRenderingHint(osg::StateSet::TRANSPARENT_BIN);
108
this->renderCollisionGeometry(true);
110
this->SetCollisionMesh(collModel->GetOSGNode());
112
this->AddChild(collModel);
114
this->setCollisionModel(collModel->GetOSGNode());
117
// to check if the collision geometry fits to the model:
118
// this->renderCollisionGeometry();
120
// ... and then, it is ready to place it in the scene
126
KITBody1::~KITBody1()