~robot3d-team/robot3d/trunk

« back to all changes in this revision

Viewing changes to inc/srBody/led.h

  • 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 a  robot.
 
6
 *
 
7
 * @author Lutz Winkler
 
8
 *
 
9
 */
 
10
 
 
11
#ifndef LED_H_
 
12
#define LED_H_
 
13
 
 
14
#include <srCore/robot/objectBase.h>
 
15
 
 
16
 
 
17
namespace srCore {
 
18
 
 
19
class ColorVisitor : public osg::NodeVisitor
 
20
{
 
21
public:
 
22
 
 
23
   ColorVisitor (const osg::Vec4& pColor): osg::NodeVisitor(TRAVERSE_ALL_CHILDREN), mColor(pColor)
 
24
   {
 
25
 
 
26
   }
 
27
 
 
28
   virtual void apply(osg::Geode& geode)
 
29
   {
 
30
 
 
31
//      osg::StateSet* ss = geode.getOrCreateStateSet();
 
32
 
 
33
      unsigned pNumDrawables = geode.getNumDrawables();
 
34
      for(unsigned i = 0; i < pNumDrawables; ++i)
 
35
      {
 
36
         osg::Drawable* draw = geode.getDrawable(i);
 
37
         osg::Material* mat = dynamic_cast<osg::Material*>(draw->getOrCreateStateSet()->getAttribute(osg::StateAttribute::MATERIAL));
 
38
         if(mat)
 
39
         {
 
40
            mat->setDiffuse(osg::Material::FRONT_AND_BACK, mColor);
 
41
            mat->setEmission(osg::Material::FRONT_AND_BACK, mColor);
 
42
         }
 
43
      }
 
44
 
 
45
   }
 
46
 
 
47
 
 
48
private:
 
49
 
 
50
   osg::Vec4 mColor;
 
51
};
 
52
 
 
53
class Led : public ObjectBase
 
54
{
 
55
public:
 
56
        //! Constructor
 
57
        /*! @param id                                           a 16bit id, used to set the colliding bit parameter.
 
58
         *      @param x, y, z                                  the position of the hinge in the world coordinate system.
 
59
         *  @param heading, pitch, roll         the orientation of the axis of the hinge in the world coordinate system.
 
60
         *  @param Scene                                        the scene in which the body should be placed.
 
61
         *  @param osgGroup                                     using this group, another scene will be created that will be used by sensors
 
62
         *
 
63
         */
 
64
        Led(    dtCore::RefPtr<BodyBase> attachedBody,
 
65
                        osg::Vec3f translation, osg::Vec3f orientation,
 
66
                        std::string name = "noName", std::string type = "noType",
 
67
                        bool active = true);
 
68
 
 
69
        //! sets the position of the Body. Only use that while physics is deactivated.
 
70
        void setTranslation(osg::Vec3f pos) {};
 
71
 
 
72
        //! sets the rotation of the Body. Only use that while physics is deactivated.
 
73
        void setRotation(osg::Vec3f hrp) {};
 
74
 
 
75
        void setColor(osg::Vec4 color);
 
76
 
 
77
protected:
 
78
        virtual ~Led();
 
79
 
 
80
private:
 
81
        osg::Vec4* myColor;
 
82
        ColorVisitor* cv;
 
83
 
 
84
        float ledSize;
 
85
 
 
86
 
 
87
};
 
88
 
 
89
}
 
90
 
 
91
#endif /*LED_H_*/