vrecko
virtual reality framework
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
EnvironmentObject.h
Go to the documentation of this file.
1 /***************************************************************************
2  EnvironmentObject.h - description
3  -------------------
4  begin : May 2002
5  copyright : (C) 2002 by Jan Flasar, Ludek Pokluda, Lubosek Markovic
6  email : flasar|xpokluda|markovic@fi.muni.cz
7  ***************************************************************************/
8 
9 
10 #ifndef ENVIRONMENTOBJECT_H
11 #define ENVIRONMENTOBJECT_H
12 
13 #include <osg/Vec3>
14 #include <osg/Matrix>
15 #include <osg/MatrixTransform>
16 #include <vrecko/IOPins.h>
17 #include <vrecko/BaseClass.h>
18 #include <vrecko/Ability.h>
19 #include <vrecko/Message.h>
20 
21 //#include <esg/OSGAdapter.h>
22 
23 #include <vector>
24 
25 #include <esg/Definitions.h>
26 
27 #define SYSTEM_VISIBLE_OBJECT_TRAVERSAL_MASK 0x00000001
28 #define RECEIVES_SHADOW_TRAVERSAL_MASK 0x20
29 #define CASTS_SHADOW_TRAVERSAL_MASK 0x40
30 #define SYSTEM_TRAVERSAL_MASK__MASK (RECEIVES_SHADOW_TRAVERSAL_MASK | CASTS_SHADOW_TRAVERSAL_MASK)
31 
32 
33 namespace esg {
34  class OSGAdapter;
35 }
36 
37 namespace osg {
38  class Geometry;
39  class Geode;
40 }
41 
42 
43 namespace vrecko {
44 
45 
46 class VRECKO_EXPORT Scene;
47 
48 class VRECKO_EXPORT EnvironmentObject: public BaseClass, public osg::MatrixTransform {
49  friend class World;
50  public:
54 
55  virtual bool initialize(XERCES_CPP_NAMESPACE_QUALIFIER DOMNode *parameters = NULL);
56 
67  void setID(unsigned long new_id);
68 
69 
75  inline const unsigned long getID() const {return id;}
76 
86  void setName(const std::string &n) {name = n;}
87 
88 
96  inline const std::string &getName(void) const {return name;}
97 
98 
115  bool loadGeometry(const char *filename, bool bOutputErrors = true);
116 
117 
126  bool setGeometry(osg::Geode *new_geomtetry, long int k = 1, long int l = 100000);
127 
136  void setModelFileName(const std::string mfn) {modelFileName = mfn;}
137 
138 
144  inline const std::string &getModelFileName(void) const {return modelFileName;}
145 
160  bool addAbility(Ability *ability, bool bCreateNewIdIfColliding = true);
161 
171  bool removeAbility(Ability *pAbility);
172 
182  bool removeAbility(const std::string &ability_id);
183 
184 
190  bool removeAllAbilities() { ability_dispatcher.removeAllAbilities(); return true; }
191 
192 
199  inline Ability *getAbility(const std::string &ab_id) { return ability_dispatcher.getAbility(ab_id); }
200 
201 
212  Ability *getAbility(const std::string &pluginName, const std::string &abilityName);
213 
215  inline Ability *getAbilityWithInput(const std::string &input_name) {return ability_dispatcher.getAbilityWithInput(input_name);}
216 
218  inline Ability *getAbilityWithOutput(const std::string &output_name) {return ability_dispatcher.getAbilityWithOutput(output_name);}
219 
220 
230  std::map<std::string, Ability*> &getAbilityMap(void) {return ability_dispatcher.getAbilityMap();}
231 
232 
246  osg::Matrix &getWorldTransformation(void);
247 
248 
257  osg::Vec3 getWorldPosition(void);
258 
259 
268  osg::Matrix getWorldRotation(void);
269 
271  void setIdentityTransformation(void);
272 
274  void setPosition( const osg::Vec3 & coords );
275 
277  void setPosition( float x, float y, float z );
278 
280  osg::Vec3 &getPosition();
281 
283  void setRotation(float angle, float x, float y, float z);
284 
286  void setRotation(const osg::Vec3 & angles);
287 
289  void setRotation(const osg::Matrix & new_matrix);
290 
292  void setRotation(const osg::Quat & quat);
293 
295  osg::Matrix &getRotation(void) {return rotation_matrix;}
296 
298  void setScale(const osg::Vec3 &new_scale);
299 
301  void setScale(float x, float y, float z);
302 
304  osg::Vec3& getScale(void) {return scale_vec;}
305 
315  void setOSGAdapter(std::vector<esg::OSGAdapter *> new_osga) {osgadapter_vector = new_osga;}
316 
325  std::vector<esg::OSGAdapter *>* getOSGAdapter(void) {return &osgadapter_vector;}
326 
341  EnvironmentObject* getParentEO(void);
342 
344 
359  bool addEOChild(EnvironmentObject *new_EO);
360 
370  bool removeEOChild(EnvironmentObject *new_EO);
371 
372 
374  typedef enum {
375  UD_UNKNOWN = 0,
388  UD_USER
389  } UserData_Type;
390 
391 /* // This struct is used to define user type UserData and functions for load and save.
392  typedef struct {
393  // Return the XML-DOMNode with parameters.
394  virtual DOMNode *saveXMLParameters(XERCES_CPP_NAMESPACE_QUALIFIER DOMDocument *) {return NULL;}
395  // This virtual function serves to load XML-parameters.
396  virtual bool loadXMLParameters(XERCES_CPP_NAMESPACE_QUALIFIER DOMNode *) {return false;}
397  } UserDataStruct;
398 */
400  typedef struct {
401  void *pointer;
403  } UserData;
404 
417  void addUserData(const std::string &nlabel, void *npointer, UserData_Type ntype);
418 
428  bool removeUserData(const std::string &label);
429 
440  UserData *getUserData(const std::string &label);
441 
451  std::map<std::string, UserData *> getUserDataMap(void) {return user_data;}
452 
461  void setTransparency(float transp);
462 
464  inline float getTransparency(void) {return transparency;}
465 
467  inline void show() {bVisible = true; updateNodeMask();}
468 
470  inline void hide() {bVisible = false; updateNodeMask();}
471 
473  inline bool isVisible() { return bVisible;}
474 
476  inline bool isCollisionFree() {return bCollisionFree;}
477 
479  void setCastShadows(bool cast);
480 
481  protected:
483  unsigned long id;
484 
486  std::string name;
487 
489  std::string modelFileName;
490 
493 
494  // Temporary transform matrix variable, so it doesn't need to be allocated
495  // every time the getWorldTransformation() is called and then copied to the caller
496  osg::Matrix tempTransformMatrix;
497 
499  osg::Vec3 trans_vec;
500 
502  osg::Matrix rotation_matrix;
503 
505  osg::Vec3 scale_vec;
506 
509 
510  // Visibility of object
511  bool bVisible;
512 
513  // True equals that the object is not able to collision to any onther objects
515 
517  std::vector<esg::OSGAdapter *> osgadapter_vector;
518 
520  std::map<std::string, UserData *> user_data;
521 
523  void updateNodeMask();
524 
526  void createCollisionHierarchy(osg::Node *pNode);
527 
530  void fixGeometryMirroring(const osg::Node *node);
531 
533  void fixGeometryHelper(const osg::Node *node, bool bMirrored);
534 
536  void fixGeometryDrawableHelper(const osg::Drawable *draw, bool bMirrored);
537 
543  DECLARE_INPUT(Position, MessageVec3);
544 
545  DECLARE_INPUT(Orientation, MessageQuat);
546  DECLARE_INPUT(Location, MessageMatrix);
547  DECLARE_INPUT(RelativePosition, MessageVec3);
548  DECLARE_INPUT(RelativeOrientation, MessageQuat);
549  DECLARE_INPUT(RelativeLocation, MessageMatrix);
550 };
551 
552 }
553 
554 #endif
555 
556