T3DSceneComponent.h 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178
  1. //-----------------------------------------------------------------------------
  2. // Copyright (c) 2012 GarageGames, LLC
  3. //
  4. // Permission is hereby granted, free of charge, to any person obtaining a copy
  5. // of this software and associated documentation files (the "Software"), to
  6. // deal in the Software without restriction, including without limitation the
  7. // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
  8. // sell copies of the Software, and to permit persons to whom the Software is
  9. // furnished to do so, subject to the following conditions:
  10. //
  11. // The above copyright notice and this permission notice shall be included in
  12. // all copies or substantial portions of the Software.
  13. //
  14. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  15. // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  16. // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  17. // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  18. // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
  19. // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
  20. // IN THE SOFTWARE.
  21. //-----------------------------------------------------------------------------
  22. #ifndef _T3DSCENECOMPONENT_H_
  23. #define _T3DSCENECOMPONENT_H_
  24. #include "T3DTransform.h"
  25. #include "component/simComponent.h"
  26. #include "sceneGraph/sceneobject.h"
  27. class T3DSceneClient;
  28. class IRenderable3D
  29. {
  30. public:
  31. // TODO: what parameters to use?
  32. virtual void Render() = 0;
  33. };
  34. class ISolid3D
  35. {
  36. public:
  37. virtual Box3F getObjectBox() = 0;
  38. virtual Transform3D * getTransform3D() = 0;
  39. };
  40. class T3DSceneComponent : public SceneObject, public Transform3D::IDirtyListener
  41. {
  42. typedef SceneObject Parent;
  43. public:
  44. T3DSceneComponent()
  45. {
  46. _transform = new Transform3DInPlace();
  47. _objectBox = new ValueWrapperInterface<Box3F>();
  48. _flags = T3DSceneComponent::Visible | T3DSceneComponent::DirtyObjectBox | T3DSceneComponent::DirtyWorldBox | T3DSceneComponent::UseOwnerObjectType;
  49. _visibilityLevel = 1.0f;
  50. _objectType = 0;
  51. _sceneGroup = NULL;
  52. _parentTransformName = NULL;
  53. setSceneGroup(NULL);
  54. }
  55. StringTableEntry getSceneGroup() const { return _sceneGroup; }
  56. void setSceneGroup(const char * sceneGroup);
  57. StringTableEntry getParentTransformName() const { return _parentTransformName; }
  58. void setParentTransformName(const char * name);
  59. U32 getObjectType() const { return _objectType; } // TODO: use owner if useowner set
  60. void setObjectType(U32 objectTypeMask);
  61. void setUseOwnerObjectType(bool val) { _SetFlag(T3DSceneComponent::UseOwnerObjectType, val); }
  62. bool useOwnerObjectType() const { return _TestFlag(T3DSceneComponent::UseOwnerObjectType); }
  63. bool isDirtyObjectBox() const { return _TestFlag(T3DSceneComponent::DirtyObjectBox); }
  64. void setDirtyObjectBox(bool val);
  65. bool isDirtyWorldBox() const { return _TestFlag(T3DSceneComponent::DirtyWorldBox); }
  66. void setDirtyWorldBox(bool val);
  67. bool isObjectBoxLocked() const { return _TestFlag(T3DSceneComponent::LockObjectBox); }
  68. void setObjectBoxLocked(bool val);
  69. bool isWorldBoxLocked() const { return _TestFlag(T3DSceneComponent::LockWorldBox); }
  70. void setWorldBoxLocked(bool val);
  71. bool doRenderObjectBounds() const { return _TestFlag(T3DSceneComponent::RenderObjectBounds); }
  72. void setRenderObjectBounds(bool val) { _SetFlag(T3DSceneComponent::RenderObjectBounds, val); }
  73. bool doRenderWorldBounds() const { return _TestFlag(T3DSceneComponent::RenderWorldBounds); }
  74. void setRenderWorldBounds(bool val) { _SetFlag(T3DSceneComponent::RenderWorldBounds, val); }
  75. bool doRenderSubBounds() const { return _TestFlag(T3DSceneComponent::RenderSubBounds); }
  76. void setRenderSubBounds(bool val) { _SetFlag(T3DSceneComponent::RenderSubBounds, val); }
  77. bool isVisible() const { return _TestFlag(T3DSceneComponent::Visible); }
  78. void setVisible(bool val) { _SetFlag(T3DSceneComponent::Visible, val); }
  79. float getVisibilityLevel() const { return _visibilityLevel; }
  80. void setVisibilityLevel(float val) { _visibilityLevel = val; }
  81. Point3F getPosition() const { return _transform->getPosition(); }
  82. void setPosition(const Point3F & pos);
  83. QuatF getRotation() const { return _transform->getRotation(); }
  84. void setRotation(const QuatF & rotation);
  85. Point3F getScale() const { return _transform->getScale(); }
  86. void setScale(const Point3F & scale);
  87. Transform3D * getTransform3D(){ return _transform; }
  88. void setTransform(const MatrixF & mat);
  89. Box3F getObjectBox();
  90. Box3F getWorldBox();
  91. T3DSceneClient * getSceneClientList() const { return _sceneClientList; }
  92. void Render();
  93. void AddSceneClient(T3DSceneClient * sceneClient);
  94. void RemoveClientObject(T3DSceneClient * sceneClient);
  95. void OnTransformDirty() { setDirtyWorldBox(true); }
  96. protected:
  97. bool onComponentRegister(SimComponent * owner);
  98. void onComponentUnRegister();
  99. void registerInterfaces(SimComponent * owner);
  100. void _ComputeObjectBox();
  101. void _UpdateWorldBox();
  102. void setTransform3D(Transform3D * transform);
  103. bool _TestFlag(U32 test) const
  104. {
  105. return (_flags & test) != T3DSceneComponent::None;
  106. }
  107. void _SetFlag(U32 test, bool value)
  108. {
  109. if (value)
  110. _flags |= test;
  111. else
  112. _flags &= ~test;
  113. }
  114. enum SceneFlags
  115. {
  116. None = 0,
  117. Visible = 1 << 0,
  118. DirtyObjectBox = 1 << 1,
  119. DirtyWorldBox = 1 << 2,
  120. LockObjectBox = 1 << 3,
  121. LockWorldBox = 1 << 4,
  122. UseOwnerObjectType = 1 << 5,
  123. RenderDebug = 1 << 6,
  124. RenderObjectBounds = 1 << 7,
  125. RenderWorldBounds = 1 << 8,
  126. RenderSubBounds = 1 << 9,
  127. LastFlag = 1 << 9
  128. };
  129. Transform3D * _transform;
  130. T3DSceneClient * _sceneClientList;
  131. ValueWrapperInterface<Box3F> * _objectBox;
  132. U32 _flags;
  133. float _visibilityLevel;
  134. U32 _objectType;
  135. StringTableEntry _sceneGroup;
  136. StringTableEntry _parentTransformName ;
  137. };
  138. #endif // #ifndef _T3DSCENECOMPONENT_H_