~robot3d-team/robot3d/trunk

« back to all changes in this revision

Viewing changes to inc/srCore/robot/objectBase.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
#ifndef OBJECTBASE_H_
 
2
#define OBJECTBASE_H_
 
3
 
 
4
// Delta3D files
 
5
#include <dtGame/gamemanager.h>
 
6
#include <dtABC/application.h>
 
7
#include <dtCore/transform.h>
 
8
#include <dtCore/scene.h>
 
9
 
 
10
// Robot3D files
 
11
#include <srCore/body/bodyBase.h>
 
12
 
 
13
//TODO: scale function for scaling the object mesh.
 
14
 
 
15
namespace srCore {
 
16
 
 
17
struct Parameters{
 
18
 
 
19
        std::string valueName;
 
20
        std::string valueType;
 
21
 
 
22
};
 
23
 
 
24
 
 
25
//! Object base class.
 
26
 
 
27
/*!
 
28
 *
 
29
 * Handles general properties of the objects.
 
30
 *
 
31
 * @author Lutz Winkler
 
32
 *
 
33
 */
 
34
class ObjectBase : public dtCore::Object
 
35
{
 
36
public:
 
37
 
 
38
        /**
 
39
         * \brief  Constructor
 
40
         *
 
41
         * \param                       attachedTo                                      Body, where the object is attached to
 
42
         * \param               translation                                     Local position of the object
 
43
         * \param                       orientation                                     Local orientation of the object
 
44
         * \param                       name                                            name of the object
 
45
         * \param                       type                                            type of the object
 
46
         *
 
47
         */
 
48
        ObjectBase( dtCore::RefPtr<BodyBase> attachedBody = NULL,
 
49
                                osg::Vec3f translation = osg::Vec3f(0,0,0), osg::Vec3f orientation= osg::Vec3f(0,0,0),
 
50
                                std::string name = "noName", std::string type = "noType",
 
51
                                bool active = true);
 
52
 
 
53
        //! Returns the name of the object
 
54
        inline std::string getName() const {return name;};
 
55
 
 
56
        //! Returns the type of the object
 
57
        inline std::string getType() const {return type;};
 
58
 
 
59
        //! Returns translation of the object - currently only local translation
 
60
        osg::Vec3f getTranslation(dtCore::Transformable::CoordSysEnum cs = dtCore::Transformable::REL_CS);
 
61
 
 
62
        //! Returns orientation of the object - currently only local orientation
 
63
        virtual osg::Vec3f getOrientation(dtCore::Transformable::CoordSysEnum cs = dtCore::Transformable::REL_CS);
 
64
 
 
65
        /**
 
66
         * \brief  Writes the parameter value in parameter
 
67
         *
 
68
         *              The available parameters can be retrieved by calling getParameterList()
 
69
         *
 
70
         * \param               name                                            name of the parameter
 
71
         * \param                       parameter                                       pointer where parameter value will be written to
 
72
         *
 
73
         * Example:
 
74
         * parameter is type of float, myHinge is instance of HingeActuator. The following program snippet writes the
 
75
         * parameter value of "RelPosition" to parameter. getParameter() checks hereby if the type of parameter is valid.
 
76
         *
 
77
         * myHinge->getParameter("RelPosition", MAKE_PARAMETER_VALUE(&parameter));
 
78
         *
 
79
         *
 
80
         */
 
81
        virtual void getParameter(const std::string &name, ParameterReturnValue  parameter);
 
82
 
 
83
        /**
 
84
         * \brief  Sets a parameter
 
85
         *
 
86
         *              See also getParameter()
 
87
         *
 
88
         */
 
89
        virtual void setParameter(const std::string &name, ParameterReturnValue  parameter);
 
90
 
 
91
        //! Returns the body, the object is attached to
 
92
        inline dtCore::RefPtr<BodyBase> getAttachedBody() const {return myBody;};
 
93
 
 
94
        //! Returns the parameter list. See also getParameter()
 
95
        inline std::vector<Parameters> getParameterList() const {return myParameters;}
 
96
 
 
97
        //! Activate/deactivate object. A deactivated object has no influence in the simulation
 
98
        inline void setActive(bool activate) {active = activate;}
 
99
 
 
100
        //! Returns true, if object is activated, else false.
 
101
        inline bool isActive() const {return active;}
 
102
 
 
103
        //! Will be called in RobotActorBase::TickLocal()
 
104
        virtual void update(float deltaSimTme) {};
 
105
 
 
106
protected:
 
107
        virtual ~ObjectBase();
 
108
 
 
109
        void setName(std::string name) {this->name = name;};
 
110
        void setType(std::string name) {this->type = type;};
 
111
        virtual void attachToBody(dtCore::RefPtr<BodyBase> body) {myBody = body; };
 
112
 
 
113
        std::vector<Parameters> myParameters;
 
114
        std::string name, type;
 
115
        osg::Vec3f relTranslation, relOrientation;
 
116
        osg::Vec3f absTranslation, absOrientation;
 
117
        dtCore::RefPtr<BodyBase> myBody;
 
118
        bool active;
 
119
 
 
120
};
 
121
}
 
122
 
 
123
#endif /*OBJECTBASE_H_*/