Entity3D.h 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  1. /*
  2. * Copyright © 2011-2020 Frictional Games
  3. *
  4. * This file is part of Amnesia: A Machine For Pigs.
  5. *
  6. * Amnesia: A Machine For Pigs is free software: you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation, either version 3 of the License, or
  9. * (at your option) any later version.
  10. * Amnesia: A Machine For Pigs is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License
  16. * along with Amnesia: A Machine For Pigs. If not, see <https://www.gnu.org/licenses/>.
  17. */
  18. #ifndef HPL_ENTITY3D_H
  19. #define HPL_ENTITY3D_H
  20. #include <list>
  21. #include "math/MathTypes.h"
  22. #include "system/SystemTypes.h"
  23. #include "scene/SceneTypes.h"
  24. #include "system/Container.h"
  25. #include "math/BoundingVolume.h"
  26. namespace hpl {
  27. //------------------------------------
  28. //Used for the render container to add specific data to
  29. //the object.
  30. class iRenderContainerData
  31. {
  32. public:
  33. virtual ~iRenderContainerData() {}
  34. };
  35. typedef std::list<iRenderContainerData*> tRenderContainerDataList;
  36. typedef tRenderContainerDataList::iterator tRenderContainerDataListIt;
  37. //-----------------------------------------
  38. class cNode3D;
  39. //-----------------------------------------
  40. class iEntity3D
  41. {
  42. public:
  43. iEntity3D(tString asName);
  44. virtual ~iEntity3D();
  45. virtual tString GetEntityType()=0;
  46. virtual void UpdateLogic(float afTimeStep){}
  47. tString& GetName(){return msName;}
  48. void SetName(const tString& asName){msName = asName;}
  49. cNode3D* GetParent(){ return mpParentNode;}
  50. void SetParent(cNode3D* apNode){ mpParentNode = apNode;}
  51. bool HasParent(){ return mpParentNode!=NULL;}
  52. iEntity3D* GetParentEntity(){ return mpParent;}
  53. void SetParentEntity(iEntity3D* apEntity){ mpParent = apEntity;}
  54. bool HasParentEntity(){ return mpParent!=NULL;}
  55. bool IsActive(){ return mbIsActive; }
  56. void SetActive(bool abActive){ mbIsActive = abActive; }
  57. cVector3f GetLocalPosition();
  58. cMatrixf& GetLocalMatrix();
  59. cVector3f GetWorldPosition();
  60. cMatrixf& GetWorldMatrix();
  61. void SetPosition(const cVector3f& avPos);
  62. void SetMatrix(const cMatrixf& a_mtxTransform);
  63. void SetWorldPosition(const cVector3f& avWorldPos);
  64. void SetWorldMatrix(const cMatrixf& a_mtxWorldTransform);
  65. void SetTransformUpdated(bool abUpdateCallbacks = true);
  66. bool GetTransformUpdated();
  67. int GetTransformUpdateCount();
  68. void AddCallback(iEntityCallback *apCallback);
  69. void RemoveCallback(iEntityCallback *apCallback);
  70. void SetSourceFile(const tString& asFile){ msSourceFile = asFile;}
  71. const tString& GetSourceFile(){ return msSourceFile;}
  72. virtual cBoundingVolume* GetBoundingVolume();
  73. bool IsSaved(){ return mbIsSaved; }
  74. void SetIsSaved(bool abX){ mbIsSaved = abX; }
  75. void SetUniqueID(int alX){ mlUniqueID = alX;}
  76. int GetUniqueID(){ return mlUniqueID;}
  77. /**
  78. * The entity3d child hierarchy will only work if the child has no node parent.
  79. **/
  80. void AddChild(iEntity3D *apEntity);
  81. void RemoveChild(iEntity3D *apEntity);
  82. bool IsChild(iEntity3D *apEntity);
  83. iEntity3D *GetEntityParent();
  84. cEntity3DIterator GetChildIterator();
  85. /**
  86. * The node3d child hierarchy will only work if the node child has no node parent.
  87. **/
  88. void AddNodeChild(cNode3D *apNode);
  89. void RemoveNodeChild(cNode3D *apNode);
  90. bool IsNodeChild(cNode3D *apNode);
  91. inline int GetIteratorCount(){ return mlIteratorCount;}
  92. inline void SetIteratorCount(const int alX){ mlIteratorCount = alX;}
  93. protected:
  94. virtual void OnTransformUpdated(){}
  95. cNode3D* mpParentNode;
  96. tString msName;
  97. bool mbIsActive;
  98. bool mbIsSaved;
  99. int mlUniqueID;
  100. cMatrixf m_mtxLocalTransform;
  101. cMatrixf m_mtxWorldTransform;
  102. cBoundingVolume mBoundingVolume;
  103. bool mbUpdateBoundingVolume;
  104. bool mbApplyTransformToBV;
  105. bool mbTransformUpdated;
  106. int mlCount;
  107. tString msSourceFile;
  108. tEntityCallbackList mlstCallbacks;
  109. tEntity3DList mlstChildren;
  110. iEntity3D *mpParent;
  111. tNode3DList mlstNodeChildren;
  112. int mlIteratorCount;
  113. private:
  114. void UpdateWorldTransform();
  115. };
  116. };
  117. #endif // HPL_ENTITY3D_H