BodyComponent.h 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. // Copyright (C) 2009-2021, Panagiotis Christopoulos Charitos and contributors.
  2. // All rights reserved.
  3. // Code licensed under the BSD License.
  4. // http://www.anki3d.org/LICENSE
  5. #pragma once
  6. #include <AnKi/Scene/Components/SceneComponent.h>
  7. #include <AnKi/Physics/PhysicsBody.h>
  8. #include <AnKi/Resource/Forward.h>
  9. namespace anki {
  10. /// @addtogroup scene
  11. /// @{
  12. /// Rigid body component.
  13. class BodyComponent : public SceneComponent
  14. {
  15. ANKI_SCENE_COMPONENT(BodyComponent)
  16. public:
  17. BodyComponent(SceneNode* node);
  18. ~BodyComponent();
  19. ANKI_USE_RESULT Error loadMeshResource(CString meshFilename);
  20. CString getMeshResourceFilename() const;
  21. void setMass(F32 mass);
  22. F32 getMass() const
  23. {
  24. return (m_body) ? m_body->getMass() : 0.0f;
  25. }
  26. void setWorldTransform(const Transform& trf)
  27. {
  28. if(m_body)
  29. {
  30. m_body->setTransform(trf);
  31. }
  32. else
  33. {
  34. m_trf = trf;
  35. }
  36. }
  37. Transform getWorldTransform() const
  38. {
  39. return (m_body) ? m_body->getTransform() : m_trf;
  40. }
  41. PhysicsBodyPtr getPhysicsBody() const
  42. {
  43. return m_body;
  44. }
  45. ANKI_USE_RESULT Error update(SceneNode& node, Second, Second, Bool& updated) override;
  46. Bool isEnabled() const
  47. {
  48. return m_mesh.isCreated();
  49. }
  50. private:
  51. SceneNode* m_node = nullptr;
  52. CpuMeshResourcePtr m_mesh;
  53. PhysicsBodyPtr m_body;
  54. Transform m_trf = Transform::getIdentity();
  55. Bool m_markedForUpdate = true;
  56. };
  57. /// @}
  58. } // end namespace anki