1
//! Robot Actor base class.
5
* Handles general functions of the robot class.
11
#ifndef ROBOTACTORBASE_H_
12
#define ROBOTACTORBASE_H_
18
#include <osg/Texture2D>
20
#include <osg/Geometry>
23
#include <dtGame/gameactor.h>
24
#include <dtCore/refptr.h>
25
#include <dtCore/object.h>
26
#include <dtCore/camera.h>
27
#include <dtCore/transform.h>
28
#include <dtDAL/namedparameter.h>
29
#include <dtUtil/coordinates.h>
30
#include <dtGame/actorupdatemessage.h>
31
#include <dtGame/basemessages.h>
34
#include <srCore/export.h>
35
#include <srCore/xmlConfig.h>
36
#include <srCore/robot/objectBase.h>
37
#include <srCore/actuator/actuatorBase.h>
38
#include <srCore/sensor/sensorBase.h>
39
#include <srCore/actuator/connectorBase.h>
40
#include <srCore/robot/robotActorBase.h>
51
class ROBOT_EXPORT RobotActorBase : public dtGame::GameActor
55
//! Constructs the robot actor.
56
RobotActorBase(dtGame::GameActorProxy &proxy);
60
* This ID will be used for collision handling in the ode. It is not
63
virtual void setID(long int id);
64
virtual void setSelectionState(bool selState);
65
virtual void setConnectorStates(int state);
68
* Returns the robot ID. This ID will be used for collision handling in the ode. It is not
71
virtual long int getID() const { return myID; };
72
virtual bool getSelectionState() { return selectionState; };
73
virtual int getConnectorStates() const {
77
for (unsigned int i=0; i<myConnectors.size(); i++) {
79
if (myConnectors[i]->getState() != ConnectorBase::DISCONNECTED) state += bitCheck;
80
bitCheck = bitCheck << 1;
89
//! Returns the osgGroup. Will be used for shadows or later special scenes used for sensors
90
virtual dtCore::RefPtr<osg::Group> getOsgGroup() const { return osgGroup; };
92
//! Dirty short-cut to enable/disable physics
93
void EnableDynamics(bool enable);
95
//! Sets global position of the robot
96
virtual void setTranslation(const osg::Vec3& pos);
98
//! Sets global orientation (hpr) of the robot
99
virtual void setRotation(const osg::Vec3& rot);
102
* Gets global position of the robot. It is not position, it is translation.
105
virtual osg::Vec3f getTranslation() const { return myPos; };
107
virtual osg::Vec3f getPosition() const { return myPos; };
109
virtual void setPosition(const osg::Vec3 &pos);
111
//! Gets global orientation of the robot (hpr)
112
virtual osg::Vec3f getRotation(); // const { return myRot; };
114
dtCore::UniqueId* getBusID() const { return globalCommID; };
115
void setBusID(dtCore::UniqueId* id) {globalCommID = id;};
118
* This method is an invokable called when an object is local and
120
* @param tickMessage A message containing tick related information.
122
virtual void TickLocal(const dtGame::Message &tickMessage);
125
* This method is an invokable called when an object is remote and
127
* @param tickMessage A message containing tick related information.
129
virtual void TickRemote(const dtGame::Message &tickMessage);
132
* Generic handler for messages. Overridden from base class.
133
* This is the default invokable on GameActorProxy.
135
virtual void ProcessMessage(const dtGame::Message &message);
138
/** Called when the actor has been added to the game manager.
139
* You can respond to OnEnteredWorld on either the proxy or actor or both.
141
virtual void OnEnteredWorld();
143
inline std::vector<RobotActorBase* > getConnectedRobots() {
144
std::vector<RobotActorBase* > connectedRobots;
145
getConnectedRobots(connectedRobots);
146
return connectedRobots;
149
inline std::vector<BodyBase* > getConnectedBodies(BodyBase* parentBody) {
151
std::vector<BodyBase* > connectedBodies;
153
getConnectedBodies(connectedBodies, parentBody);
154
return connectedBodies;
157
inline std::vector<dtCore::RefPtr<SensorBase> > getSensors() const {return mySensors; }
159
//! Returns a list of actuators that are attached to the robot
160
inline std::vector<dtCore::RefPtr<ActuatorBase> > getActuators() const {return myActuators;}
162
//! Returns a list of bodies the robot consists of
163
inline std::vector<dtCore::RefPtr<BodyBase> > getBodies() const {return myBodies;}
165
//! Returns a list of connectors that are attached to the robot
166
inline std::vector<dtCore::RefPtr<ConnectorBase> > getConnectors() const {return myConnectors;}
168
//! Returns a list of objects that are attached to the robot and not of the types above
169
inline std::vector<dtCore::RefPtr<ObjectBase> > getObjects() const {return myObjects;}
171
//! If true, the collision geometry of the robot will be rendered
172
inline void renderCollisionGeometry(bool renderIt) {
174
for (unsigned int i=0; i<myBodies.size(); i++)
175
myBodies[i]->RenderCollisionGeometry(false);
176
// myBodies[i]->renderCollisionGeometry(renderIt);
180
//! colors the robot -- todo: stays in conflict with RenderCollisionGeometry
181
inline void colorCollisionGeometry(osg::Vec4 color) {
183
// for (unsigned int i=0; i<myBodies.size(); i++)
184
// myBodies[i]->colorBody(color);
188
//! sends message to the bus, robots within the same organsim receive that message
189
void sendBusMessage(const std::string& message);
191
inline std::string getLastBusMessage(const std::string& message) const {return globalMsg;};
193
inline void setSensorData(std::vector<SensorInitData> newSensorData) { sensorData = newSensorData; };
195
inline void setInitialJointAngles(std::vector<float> initialJointAngles) { jointAngles = initialJointAngles;};
198
virtual void initialize();
200
void getConnectedBodies (std::vector<BodyBase* > &connectedBodies, BodyBase* bodyNode);
201
void getConnectedRobots (std::vector<RobotActorBase* > &connectedRobots);
202
osg::Vec3f myPos, myRot; // position and rotation vectors of the first body element
203
// register this robot and all other robots connected to this robot to the same message type
204
void registerToCommBus(dtCore::UniqueId* id);
205
void unregisterFromCommBus();
207
void addBody(BodyBase* body);
208
void addActuator(ActuatorBase* actuator);
209
void addConnector(ConnectorBase* connector);
210
void addSensor(SensorBase* sensor);
212
dtCore::UniqueId* globalCommID;
213
std::string globalMsg;
215
bool selectionState; //is true if this robot is currently selected
218
dtCore::RefPtr<osg::Group> osgGroup; // all drawables that should be detected by sensors
221
std::vector<dtCore::RefPtr<SensorBase> > mySensors;
222
std::vector<dtCore::RefPtr<ActuatorBase> > myActuators;
223
std::vector<dtCore::RefPtr<BodyBase> > myBodies;
224
std::vector<dtCore::RefPtr<ConnectorBase> > myConnectors; // might be useful/necessary to have an extra container for the connectors
225
std::vector<dtCore::RefPtr<ObjectBase> > myObjects;
227
std::vector<SensorInitData> sensorData;
229
//! inital joint angles
230
std::vector<float> jointAngles;
236
osg::Vec3f initPos, initRot; // init position and rotation how the robot has been created
241
* Our proxy class for the robot actor. The proxy contains properties,
242
* invokables, and robot actor.
244
class ROBOT_EXPORT RobotActorBaseProxy : public dtGame::GameActorProxy
248
//! Constructs the proxy.
249
RobotActorBaseProxy();
252
virtual void setID(long int id);
255
virtual long int getID();
257
virtual void setConnectorStates(int state);
258
virtual int getConnectorStates();
261
//! Translate Robot -- use only if physics are deactived or robot is not attached to another one
262
virtual void setTranslation(osg::Vec3 pos);
264
//! Get global translation of the robot
265
virtual osg::Vec3 getTranslation();
267
//! Rotate Robot -- use only if physics are deactived or robot is not attached to another one
268
virtual void setRotation(osg::Vec3 rot);
270
//! Get global rotation of the robot
271
virtual osg::Vec3 getRotation();
273
//! Creates the properties that are custom to the robot proxy.
274
virtual void BuildPropertyMap();
276
//! Add a sensor to robot.
277
virtual void setSensors(std::vector<SensorInitData> sensors);
279
//! Set inital joint angles
280
virtual void setInitialJointAngles(std::vector<float> jointAngles);
283
virtual ~RobotActorBaseProxy();
285
//! Creates an instance of our robot tank actor
286
virtual void CreateActor();
289
* Called when this proxy is added to the game manager (ie, the "world")
290
* You can respond to OnEnteredWorld on either the proxy or actor or both.
292
virtual void OnEnteredWorld();
302
#endif /*ROBOTACTORBASE_H_*/