~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
//! 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/led.h>

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.
 *
 */
Led::Led(dtCore::RefPtr<BodyBase> attachedBody,
		osg::Vec3f translation, osg::Vec3f orientation,
		std::string name, std::string type,	bool active):
			ObjectBase(attachedBody, translation, orientation, name, type, active),
			myColor (new osg::Vec4(1.0f, 0.0f, 0.0f, 1.0f)),
			cv (new ColorVisitor( *myColor )),
			ledSize (0.2)
{

	// loading 3ds model
	char file[50];
	sprintf(file, "%s/StaticMeshes/sphere.3ds", SimulationUtils::getStageProjectPath().c_str());

	LoadFile(file, false);
//	this->mesh->SetModelRotation(osg::Vec3(90,90,0));//relOrientation.x(), relOrientation.y()+90, relOrientation.z()));
//	this->mesh->SetModelTranslation(osg::Vec3(relTranslation.x() * scale.x(), relTranslation.y() * scale.y(), relTranslation.z() * scale.z()));

	this->myBody->AddChild(this);

	dtCore::Transform offset(relTranslation.x(), relTranslation.y(), relTranslation.z(), relOrientation.x()+180, relOrientation.y(), relOrientation.z());
	SetTransform( offset, dtCore::Transformable::REL_CS );

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

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

    GetOSGNode()->traverse(*cv);

}

void Led::setColor(osg::Vec4 color) {
	cv = new ColorVisitor(color);
	GetOSGNode()->traverse(*cv);
}

Led::~Led()
{

	delete myColor;
	myColor = NULL;
	delete cv;
	cv = NULL;
}

}