SceneNode.h 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. #ifndef SCENE_NODE_H
  2. #define SCENE_NODE_H
  3. #include <memory>
  4. #include "Vec.h"
  5. #include "Math.h"
  6. #include "Object.h"
  7. #include "Properties.h"
  8. class Material;
  9. class Controller;
  10. /// The backbone of scene. It is also an Object for memory management reasons
  11. class SceneNode: public Object
  12. {
  13. friend class Scene;
  14. public:
  15. enum SceneNodeType
  16. {
  17. SNT_GHOST,
  18. SNT_LIGHT,
  19. SNT_CAMERA,
  20. SNT_PARTICLE_EMITTER,
  21. SNT_MODEL
  22. };
  23. PROPERTY_RW(Transform, localTransform, getLocalTransform, setLocalTransform) ///< The transformation in local space
  24. PROPERTY_RW(Transform, worldTransform, getWorldTransform, setWorldTransform) ///< The transformation in world space (local combined with parent transformation)
  25. public:
  26. SceneNode* parent;
  27. Vec<SceneNode*> childs;
  28. SceneNodeType type;
  29. bool isCompound;
  30. SceneNode(SceneNodeType type_, SceneNode* parent = NULL);
  31. virtual ~SceneNode();
  32. virtual void init(const char*) = 0; ///< init using a script
  33. /// @name Updates
  34. /// Two separate updates happen every loop. The update happens anyway and the updateTrf only when the node is being
  35. /// moved
  36. /// @{
  37. virtual void update() {};
  38. virtual void updateTrf() {};
  39. /// @}
  40. /// @name Mess with the local transform
  41. /// @{
  42. void rotateLocalX(float angDegrees) {localTransform.rotation.rotateXAxis(angDegrees);}
  43. void rotateLocalY(float angDegrees) {localTransform.rotation.rotateYAxis(angDegrees);}
  44. void rotateLocalZ(float angDegrees) {localTransform.rotation.rotateZAxis(angDegrees);}
  45. void moveLocalX(float distance);
  46. void moveLocalY(float distance);
  47. void moveLocalZ(float distance);
  48. /// @}
  49. void addChild(SceneNode* node);
  50. void removeChild(SceneNode* node);
  51. private:
  52. void commonConstructorCode(); ///< Cause we cannot call constructor from other constructor
  53. void updateWorldTransform(); ///< This update happens only when the object gets moved
  54. };
  55. inline SceneNode::SceneNode(SceneNodeType type_, SceneNode* parent):
  56. Object(parent),
  57. type(type_)
  58. {
  59. commonConstructorCode();
  60. if(parent != NULL)
  61. {
  62. parent->addChild(this);
  63. }
  64. }
  65. #endif