~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
//! Specialized body class.

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

#include <srBody/wheel.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.2				//0.2
#define WHEEL_SIZE  			SCALE_3DS
#define WHEEL_MASS  			0.01
#define WHEEL_RADIUS			0.5 * SCALE_3DS //4.5
#define WHEEL_LENGTH			1 * SCALE_3DS	//2

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.
 *
 */
Wheel::Wheel(	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
	this->init("wheel", robot, x, y, z, heading, pitch, roll);

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

	sprintf(file, "%s/StaticMeshes/wheel.3ds", SimulationUtils::getStageProjectPath().c_str());
	//sprintf(file, "%s/StaticMeshes/barrel.ive", SimulationUtils::getStageProjectPath().c_str());

	LoadFile(file, false);

	// scaling the model
	SetScale(osg::Vec3(WHEEL_SIZE, WHEEL_SIZE, WHEEL_SIZE));


	// our Object just needs a mass now ...
	this->setMass(WHEEL_MASS, WHEEL_RADIUS, WHEEL_LENGTH);

	// defining the collision box
	this->setCollisionCylinder(WHEEL_RADIUS, WHEEL_LENGTH);

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

	// to check if the collision geometry fits to the model:
	this->renderCollisionGeometry(true);
	this->colorCollisionShape(osg::Vec4(255,0,0,0));
// 	this->colorBody(osg::Vec4(1,0,0,0));

	// need to be set to let the wheels rotate
    dBodySetFiniteRotationMode(GetBodyID(), 1);

    setCollisionBits(2);
}

Wheel::~Wheel()
{
}

}