CmGameObject.h 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. #pragma once
  2. #include "CmPrerequisites.h"
  3. #include "CmMatrix4.h"
  4. #include "CmVector3.h"
  5. #include "CmQuaternion.h"
  6. namespace CamelotEngine
  7. {
  8. class CM_EXPORT GameObject
  9. {
  10. public:
  11. GameObject(const String& name);
  12. ~GameObject();
  13. /************************************************************************/
  14. /* Transform */
  15. /************************************************************************/
  16. public:
  17. void setPosition(const Vector3& position);
  18. Vector3 getPosition() const { return mPosition; }
  19. void setRotation(const Quaternion& rotation);
  20. Quaternion getRotation() const { return mRotation; }
  21. void setScale(const Vector3& scale);
  22. Vector3 getScale() const { return mScale; }
  23. const Matrix4& getWorldTfrm();
  24. const Matrix4& getLocalTfrm();
  25. private:
  26. String mName;
  27. Vector3 mPosition;
  28. Quaternion mRotation;
  29. Vector3 mScale;
  30. Matrix4 mCachedLocalTfrm;
  31. bool mIsCachedLocalTfrmUpToDate;
  32. Matrix4 mCachedWorldTfrm;
  33. bool mIsCachedWorldTfrmUpToDate;
  34. Matrix4 mCustomWorldTfrm; // TODO
  35. bool mIsCustomTfrmModeActive; // TODO
  36. void markTfrmDirty();
  37. void updateLocalTfrm();
  38. void updateWorldTfrm();
  39. /************************************************************************/
  40. /* Hierarchy */
  41. /************************************************************************/
  42. public:
  43. /**
  44. * @brief Changes the parent of this object. Also removes the object from the current parent,
  45. * and assigns it to the new parent.
  46. *
  47. * @param [in] parent New parent.
  48. */
  49. void setParent(GameObject* parent);
  50. /**
  51. * @brief Gets the parent of this object.
  52. *
  53. * @return Parent object, or nullptr if this GameObject is at root level.
  54. */
  55. GameObject* getParent() const { return mParent; }
  56. /**
  57. * @brief Gets a child of this item.
  58. *
  59. * @param idx The zero based index of the child.
  60. *
  61. * @return GameObject of the child.
  62. *
  63. * @throws ERR_INVALIDPARAMS If the index is out of range.
  64. */
  65. GameObject* getChild(unsigned int idx) const;
  66. /**
  67. * @brief Find the index of the specified child. Don't persist this value as
  68. * it may change whenever you add/remove children.
  69. *
  70. * @param child The child to look for.
  71. *
  72. * @return The zero-based index of the found child, or -1 if no match was found.
  73. */
  74. int indexOfChild(const GameObject* child) const;
  75. /**
  76. * @brief Gets the number of all child GameObjects.
  77. */
  78. int getNumChildren() const { return mChildren.size(); }
  79. private:
  80. GameObject* mParent;
  81. vector<GameObject*>::type mChildren;
  82. /**
  83. * @brief Adds a child to the child array. This method doesn't check for null or duplicate values.
  84. *
  85. * @param [in] object New child.
  86. */
  87. void addChild(GameObject* object);
  88. /**
  89. * @brief Removes the child from the object.
  90. *
  91. * @param [in] object Child to remove.
  92. *
  93. * @throws INTERNAL_ERROR If the provided child isn't a child of the current object.
  94. */
  95. void removeChild(GameObject* object);
  96. };
  97. }