~robot3d-team/robot3d/trunk

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
//! Specialized body class.

/*!
 * Predefined body class. Ready to use in a RobotActor.
 * This body represents the front part of the robot.
 *
 * @author Lutz Winkler
 *
 */

#include <srBody/kitScrew.h>

namespace srCore {

// units need to be around one to make the ode most stable. Hereby 1 length union is equal to 5cm.
#define SCALE_3DS   			0.02

#define COLLISION_SIDE 			(64*SCALE_3DS)					//60		// cm
#define COLLISION_LENGTH 		(64*SCALE_3DS)					//85

// units need to be around one to make the ode most stable. Hereby 1 length union is equal to 5cm.
#define BODY_LENGTH 			1.7					// equals 85 mm
#define BODY_HEIGHT 			1.2
#define BODY_WIDTH  			1.2
#define BODY_MASS   			0.3					//0.13

using namespace srCore;

//! Constructor
/*! @param id a 16bit id, used to set the colliding bit parameter.
 * 	@param x, y, z the position of the hinge in the world coordinate system.
 *  @param heading, pitch, roll the orientation of the axis of the hinge in the world coordinate system.
 *  @param Scene the scene in which the body should be placed.
 *
 */
KITScrew::KITScrew(	RobotActorBase* robot,
			float x, float y, float z,
			float heading, float pitch, float roll)

{

	// initializing. parameters: name, id (of the robot), position, orientation and the scene
	// needs to be done first
	// todo: at the moment scene needs to be given to each element, although we only have one scene
	this->init("KITScrew", robot, x, y, z, heading, pitch, roll);

	// loading 3ds model
	char file[250];

	if (SimulationUtils::getDetailedGraphics())
		sprintf(file, "%s/StaticMeshes/newKITScrew.3ds", SimulationUtils::getStageProjectPath().c_str());
	else
		sprintf(file, "%s/StaticMeshes/symbrionDummy.3ds", SimulationUtils::getStageProjectPath().c_str());  //use this model in case of a bad graphics card

	printf ("loading file %s ...\n", file);
	LoadFile(file);
	SetModelTranslation(osg::Vec3(0,0,0));

	printf ("done \n");

	// scaling the model
	this->setScale(SCALE_3DS,SCALE_3DS,SCALE_3DS);

	// defining the collision box
	this->setCollisionBox(COLLISION_SIDE, COLLISION_SIDE, COLLISION_SIDE);

	// our Object just needs a mass now ...
	this->setMass(BODY_MASS, COLLISION_SIDE, COLLISION_SIDE, COLLISION_SIDE);

	dtCore::Object* collModel = new dtCore::Object();

	dtCore::Transform xform;
	sprintf(file, "%s/StaticMeshes/screwCollModel.3ds",	SimulationUtils::getStageProjectPath().c_str());

	collModel->LoadFile(file);
	collModel->SetScale(this->GetScale());
	SetCollisionCategoryBits(UNSIGNED_BIT(2));
	SetCollisionCollideBits(UNSIGNED_BIT(1)); 			 
	SetCollisionMesh(collModel->GetOSGNode());
	
	osg::StateSet* stateset;
	stateset = collModel->GetOSGNode()->getOrCreateStateSet();
	osg::Material * mm = dynamic_cast<osg::Material*>(stateset->getAttribute
	(osg::StateAttribute::MATERIAL));
	if (!mm)
	{
	  mm = new osg::Material;
	}
	mm->setAlpha(osg::Material::FRONT, 0.2);
	mm->setAmbient(osg::Material::FRONT, osg::Vec4(0,0,0,0));
	stateset->setAttributeAndModes( mm, osg::StateAttribute::OVERRIDE |
	osg::StateAttribute::ON);
	stateset->setMode(GL_BLEND,   osg::StateAttribute::OVERRIDE |
	osg::StateAttribute::ON );
	stateset->setMode(GL_LIGHTING,osg::StateAttribute::OVERRIDE |
	osg::StateAttribute::ON );
	stateset->setRenderingHint(osg::StateSet::TRANSPARENT_BIN);
	
	
	
	this->renderCollisionGeometry(false);
	
	this->SetCollisionMesh(collModel->GetOSGNode());
	
	this->AddChild(collModel);
	
	this->setCollisionModel(collModel->GetOSGNode());
  
	

	// to check if the collision geometry fits to the model:
	// this->renderCollisionGeometry();

	// ... and then, it is ready to place it in the scene
	this->addToScene();
	
}


KITScrew::~KITScrew()
{
}

}