BodyComponent.h 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  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. {
  11. /// @addtogroup scene
  12. /// @{
  13. /// Rigid body component.
  14. class BodyComponent : public SceneComponent
  15. {
  16. ANKI_SCENE_COMPONENT(BodyComponent)
  17. public:
  18. BodyComponent(SceneNode* node);
  19. ~BodyComponent();
  20. ANKI_USE_RESULT Error loadMeshResource(CString meshFilename);
  21. CString getMeshResourceFilename() const;
  22. void setMass(F32 mass);
  23. F32 getMass() const
  24. {
  25. return (m_body) ? m_body->getMass() : 0.0f;
  26. }
  27. void setWorldTransform(const Transform& trf)
  28. {
  29. if(m_body)
  30. {
  31. m_body->setTransform(trf);
  32. }
  33. else
  34. {
  35. m_trf = trf;
  36. }
  37. }
  38. Transform getWorldTransform() const
  39. {
  40. return (m_body) ? m_body->getTransform() : m_trf;
  41. }
  42. PhysicsBodyPtr getPhysicsBody() const
  43. {
  44. return m_body;
  45. }
  46. ANKI_USE_RESULT Error update(SceneNode& node, Second, Second, Bool& updated) override;
  47. Bool isEnabled() const
  48. {
  49. return m_mesh.isCreated();
  50. }
  51. private:
  52. SceneNode* m_node = nullptr;
  53. CpuMeshResourcePtr m_mesh;
  54. PhysicsBodyPtr m_body;
  55. Transform m_trf = Transform::getIdentity();
  56. Bool m_markedForUpdate = true;
  57. };
  58. /// @}
  59. } // end namespace anki