Group.h 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  1. /***************************************************************************
  2. Group.h - description
  3. -------------------
  4. begin : Wed Jan 26 2000
  5. copyright : (C) 2000 by Henrik Enqvist
  6. email : henqvist@excite.com
  7. ***************************************************************************/
  8. #ifndef GROUP_H
  9. #define GROUP_H
  10. // Define some properties
  11. #define EM_GROUP_TRANSFORM_ONCE 0x1
  12. #define EM_GROUP_NO_TRANSFORM 0x2
  13. #define EM_GROUP_LIGHT_ONCE 0x4
  14. #define EM_GROUP_NO_LIGHT 0x8
  15. #define EM_GROUP_NO_SIGNAL 0x10
  16. #define EM_GROUP_NO_BEHAVIOR 0x20
  17. #include <vector>
  18. using namespace std;
  19. #include "Node.h"
  20. class Shape3D;
  21. class Visitor;
  22. class Behavior;
  23. class CollisionBounds;
  24. class Sound;
  25. class Camera;
  26. class Light;
  27. class BillBoard;
  28. /** Groups are a essential element when building the 3D world.</p>
  29. ** All Shape3Ds, Sounds, Lights, Behavoir etc must be added to
  30. ** Groups ( the Camera is a execption, it is recommended that it is added
  31. ** to a Group, but this is not requirement for the context to be render ). Groups
  32. ** are then added to the Engine or added to other Groups that are in
  33. ** the Engine. Engine itself is the matter a fact a Group.
  34. ** Groups must form a tree structure, loops will cause the program to hang. There
  35. ** is currently no check for illegal loop structures, it is up to the programmer
  36. ** to avoid cyclic graphs.
  37. **
  38. ** Example:
  39. ** <pre>
  40. ** Legal tree: Illegal tree:
  41. **
  42. ** engine engine
  43. ** / \ / \
  44. ** group group group group
  45. ** / \ \ /
  46. ** group group group
  47. ** </pre>
  48. **
  49. ** Usage.
  50. ** Groups are used to group elements together. Each Group represent a transform that
  51. ** is applied to all its children.
  52. ** Example: A butterfly with two wings. The butterfly as a whole is reprented by a Group ( bfGroup ).
  53. ** To this group we have attached two Groups ( lwGroup and rwGroup ), one for each wing. By adding
  54. ** a Animation to lwGroup and an other for rwGroup we can make the butterfly flap with the wings.
  55. ** We can then apply transformation to the bfGroup and make the butterfly to move. We have created
  56. ** a nice little butterfly who flaps with its wing and flies around</p>
  57. ** <pre>
  58. ** bfGroup
  59. ** / \
  60. ** / \
  61. ** Animation -- lwGroup rwGroup -- Animation
  62. ** </pre> */
  63. class Group : public Node {
  64. public:
  65. Group();
  66. virtual ~Group();
  67. void setName(const char * name);
  68. const char * getName();
  69. void accept(Visitor * v);
  70. void add(Group * g);
  71. /** Removes the group from the tree. You must call 'delete group' after
  72. * this function if you wish to deallocate the group. */
  73. void removeGroup(Group * g);
  74. // void addBehavior(Behavior * b, bool signal=true);
  75. void setBehavior(Behavior * b, bool signal = true);
  76. // void removeBehavior(Behavior * b);
  77. void addShape3D(Shape3D * s);
  78. /** Removes the shape from the tree. You must call 'delete shape' after
  79. * this function if you wish to deallocate the shape. */
  80. void removeShape3D(Shape3D * s);
  81. void setBillBoard(BillBoard * b);
  82. void setCamera(Camera * c);
  83. void setLight(Light * l);
  84. void setCollisionBounds(CollisionBounds * cb);
  85. void setSound(Sound * s);
  86. // int getBehaviorSize();
  87. int getShape3DSize();
  88. // Behavior * getBehavior(int i);
  89. Behavior * getBehavior();
  90. Group * getGroup(int i);
  91. Shape3D * getShape3D(int i);
  92. BillBoard * getBillBoard();
  93. Camera * getCamera();
  94. Light * getLight();
  95. CollisionBounds * getCollisionBounds();
  96. Group * getParent();
  97. Sound * getSound();
  98. /** Deletes every object added to this group. Dealloctes also the objects. */
  99. void freeObjects();
  100. int getProperties();
  101. void setProperty(int p);
  102. void setPropertyRecursive(int p);
  103. void setUserProperty(int p);
  104. int getUserProperties();
  105. void unsetProperty(int p);
  106. void unsetPropertyRecursive(int p);
  107. void unsetUserProperty(int p);
  108. inline int getCollisionGroup() { return m_iCollisionGroup; };
  109. inline void setCollisionGroup(int c) { m_iCollisionGroup = c; };
  110. private:
  111. friend class BehaviorVisitor;
  112. friend class AlignVisitor;
  113. friend class AllegroVisitor;
  114. friend class PNormalVisitor;
  115. friend class TransformVisitor;
  116. friend class SoundVisitor;
  117. friend class OctTree;
  118. friend class RendererVisitor;
  119. friend class PointLightVisitor;
  120. friend class CollisionBounds;
  121. friend class CollisionVisitor;
  122. friend class AmbientLightVisitor;
  123. friend class OpenGLVisitor;
  124. friend class OpenGLTransVisitor;
  125. friend class SignalSender;
  126. BillBoard* p_BillBoard;
  127. Camera* p_Camera;
  128. Light* p_Light;
  129. Sound* p_Sound;
  130. CollisionBounds* p_CollisionBounds;
  131. Group* p_Parent;
  132. vector<Group*> m_vChildren;
  133. vector<Shape3D*> m_vShape3D;
  134. // vector<Behavior*> m_vBehavior;
  135. Behavior * p_Behavior;
  136. char m_Name[256];
  137. int m_iProperties;
  138. int m_iUserProperties;
  139. int m_iCollisionGroup;
  140. // void propagateSignal(int signal, Group* sender);
  141. void setParent(Group* g);
  142. };
  143. #endif // GROUP_H