~robot3d-team/robot3d/trunk

« back to all changes in this revision

Viewing changes to src/srBody/led.cpp

  • Committer: Anne van Rossum
  • Date: 2010-08-10 15:58:55 UTC
  • Revision ID: anne@gamix-20100810155855-kve7x2vwouagdij9
Initial import

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
//! Specialized body class.
 
2
 
 
3
/*!
 
4
 * Predefined body class. Ready to use in a RobotActor.
 
5
 * This body represents the wheels of the robot.
 
6
 *
 
7
 * @author Lutz Winkler
 
8
 *
 
9
 */
 
10
 
 
11
#include <srBody/led.h>
 
12
 
 
13
namespace srCore {
 
14
 
 
15
//! Constructor
 
16
/*! @param id a 16bit id, used to set the colliding bit parameter.
 
17
 *      @param x, y, z the position of the hinge in the world coordinate system.
 
18
 *  @param heading, pitch, roll the orientation of the axis of the hinge in the world coordinate system.
 
19
 *  @param Scene the scene in which the body should be placed.
 
20
 *
 
21
 */
 
22
Led::Led(dtCore::RefPtr<BodyBase> attachedBody,
 
23
                osg::Vec3f translation, osg::Vec3f orientation,
 
24
                std::string name, std::string type,     bool active):
 
25
                        ObjectBase(attachedBody, translation, orientation, name, type, active),
 
26
                        myColor (new osg::Vec4(1.0f, 0.0f, 0.0f, 1.0f)),
 
27
                        cv (new ColorVisitor( *myColor )),
 
28
                        ledSize (0.2)
 
29
{
 
30
 
 
31
        // loading 3ds model
 
32
        char file[50];
 
33
        sprintf(file, "%s/StaticMeshes/sphere.3ds", SimulationUtils::getStageProjectPath().c_str());
 
34
 
 
35
        LoadFile(file, false);
 
36
//      this->mesh->SetModelRotation(osg::Vec3(90,90,0));//relOrientation.x(), relOrientation.y()+90, relOrientation.z()));
 
37
//      this->mesh->SetModelTranslation(osg::Vec3(relTranslation.x() * scale.x(), relTranslation.y() * scale.y(), relTranslation.z() * scale.z()));
 
38
 
 
39
        this->myBody->AddChild(this);
 
40
 
 
41
        dtCore::Transform offset(relTranslation.x(), relTranslation.y(), relTranslation.z(), relOrientation.x()+180, relOrientation.y(), relOrientation.z());
 
42
        SetTransform( offset, dtCore::Transformable::REL_CS );
 
43
 
 
44
        // scaling the model
 
45
        SetScale(osg::Vec3(ledSize, ledSize, ledSize));
 
46
 
 
47
        // ... and then, it is ready to place it in the scene
 
48
        //this->addToScene(gamemanager->GetScene(), osgGroup);
 
49
 
 
50
    GetOSGNode()->traverse(*cv);
 
51
 
 
52
}
 
53
 
 
54
void Led::setColor(osg::Vec4 color) {
 
55
        cv = new ColorVisitor(color);
 
56
        GetOSGNode()->traverse(*cv);
 
57
}
 
58
 
 
59
Led::~Led()
 
60
{
 
61
 
 
62
        delete myColor;
 
63
        myColor = NULL;
 
64
        delete cv;
 
65
        cv = NULL;
 
66
}
 
67
 
 
68
}