Node3D.h 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  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_NODE3D_H
  19. #define HPL_NODE3D_H
  20. #include "math/MathTypes.h"
  21. #include "scene/SceneTypes.h"
  22. namespace hpl {
  23. class cNode3D
  24. {
  25. friend class iEntity3D;
  26. public:
  27. cNode3D(const tString &asName="", bool abAutoDeleteChildren = true);
  28. virtual ~cNode3D();
  29. ///////////////////////
  30. // Hierarchy
  31. bool AddEntity(iEntity3D* apEntity);
  32. bool RemoveEntity(iEntity3D* apEntity);
  33. void ClearEntities();
  34. cNode3D* GetParent();
  35. cNode3DIterator GetChildIterator();
  36. tNode3DList* GetChildList(){ return &mlstNode;}
  37. cEntity3DIterator GetEntityIterator();
  38. cNode3D* CreateChild(const tString &asName="", bool abAutoDeleteChildren = true);
  39. void RemoveChild(cNode3D* apNode);
  40. //Extra stuff that shouldn't be used externally
  41. void SetParent(cNode3D* apNode);
  42. void AddChild(cNode3D* apChild);
  43. ///////////////////////
  44. //Properties
  45. const tString& GetName();
  46. void SetActive(bool abX){mbActive = abX;}
  47. bool IsActive(){return mbActive;}
  48. int SetVisible(bool abX, bool abCascade);
  49. cVector3f GetLocalPosition();
  50. cMatrixf& GetLocalMatrix();
  51. cVector3f GetWorldPosition();
  52. cMatrixf& GetWorldMatrix();
  53. void SetPosition(const cVector3f& avPos);
  54. void SetMatrix(const cMatrixf& a_mtxTransform, bool abSetChildrenUpdated=true);
  55. void SetWorldPosition(const cVector3f& avWorldPos);
  56. void SetWorldMatrix(const cMatrixf& a_mtxWorldTransform);
  57. void AddRotation(const cVector3f& avRot, eEulerRotationOrder aOrder);
  58. void AddRotation(const cQuaternion& aqRotation);
  59. void AddScale(const cVector3f& avScale);
  60. void AddTranslation(const cVector3f& avTrans);
  61. bool GetUsePreAnimTransform(){ return mbUsePostTransform;}
  62. bool GetUsePostAnimTransform(){ return mbUsePostTransform;}
  63. const cMatrixf& GetPreAnimTransform(){ return m_mtxPostTransform;}
  64. const cMatrixf& GetPostAnimTransform(){ return m_mtxPostTransform;}
  65. void SetUsePreTransform(bool abX){ mbUsePreTransform = abX;}
  66. void SetUsePostTransform(bool abX){ mbUsePostTransform = abX;}
  67. void SetPreTransform(const cMatrixf& a_mtxTransform){ m_mtxPreTransform = a_mtxTransform;}
  68. void SetPostTransform(const cMatrixf& a_mtxTransform){ m_mtxPostTransform = a_mtxTransform;}
  69. /**
  70. * Applies the pre and post transforms to current matrix
  71. */
  72. void ApplyPreAnimTransform(bool abSetChildrenUpdated);
  73. void ApplyPostAnimTransform(bool abSetChildrenUpdated);
  74. void SetCustomFlags(int alX){ mlCustomFlags = alX;}
  75. int GetCustomFlags(){ return mlCustomFlags;}
  76. /**
  77. * Updates the matrix with the added scales, translations and rotation. It also resets these values.
  78. */
  79. void UpdateMatrix(bool abSetChildrenUpdated);
  80. void UpdateWorldTransform();
  81. void SetWorldTransformUpdated();
  82. void UpdateEntityChildren();
  83. private:
  84. tString msName;
  85. bool mbActive;
  86. int mlCustomFlags;
  87. bool mbAutoDeleteChildren;
  88. cMatrixf m_mtxLocalTransform;
  89. cMatrixf m_mtxWorldTransform;
  90. cVector3f mvWorldPosition;
  91. bool mbUsePreTransform;
  92. bool mbUsePostTransform;
  93. cMatrixf m_mtxPreTransform;
  94. cMatrixf m_mtxPostTransform;
  95. cQuaternion mqRotation;
  96. cVector3f mvScale;
  97. cVector3f mvTranslation;
  98. bool mbTransformUpdated;
  99. cNode3D* mpParent;
  100. iEntity3D* mpEntityParent;
  101. tEntity3DList mlstEntity;
  102. tNode3DList mlstNode;
  103. };
  104. };
  105. #endif // HPL_NODE3D_H