diff --git a/SDK/include/NDK/Components/CollisionComponent2D.hpp b/SDK/include/NDK/Components/CollisionComponent2D.hpp index 140846d62..ef8043629 100644 --- a/SDK/include/NDK/Components/CollisionComponent2D.hpp +++ b/SDK/include/NDK/Components/CollisionComponent2D.hpp @@ -28,12 +28,12 @@ namespace Ndk CollisionComponent2D(const CollisionComponent2D& collision); ~CollisionComponent2D() = default; - void Align(const Nz::Rectf& aabb); - Nz::Rectf GetAABB() const; const Nz::Collider2DRef& GetGeom() const; const Nz::Vector2f& GetGeomOffset() const; + void Recenter(const Nz::Vector2f& origin); + void SetGeom(Nz::Collider2DRef geom); void SetGeomOffset(const Nz::Vector2f& geomOffset); diff --git a/SDK/src/NDK/Components/CollisionComponent2D.cpp b/SDK/src/NDK/Components/CollisionComponent2D.cpp index 84582c261..fddbe8842 100644 --- a/SDK/src/NDK/Components/CollisionComponent2D.cpp +++ b/SDK/src/NDK/Components/CollisionComponent2D.cpp @@ -17,12 +17,6 @@ namespace Ndk * \brief NDK class that represents a two-dimensional collision geometry */ - void CollisionComponent2D::Align(const Nz::Rectf& aabb) - { - const Nz::RigidBody2D* rigidBody = GetRigidBody(); - SetGeomOffset(aabb.GetCenter() - rigidBody->GetAABB().GetCenter() + rigidBody->GetPositionOffset()); - } - /*! * \brief Gets the collision box representing the entity * \return The physics collision box @@ -32,11 +26,28 @@ namespace Ndk return GetRigidBody()->GetAABB(); } + /*! + * \brief Gets the position offset between the actual rigid body center of mass position and the origin of the geometry + * \return Position offset + */ const Nz::Vector2f& CollisionComponent2D::GetGeomOffset() const { return GetRigidBody()->GetPositionOffset(); } + /*! + * \brief Convenience function to align center of geometry to a specific point + * + * \param geomOffset Position offset + * + * \remark This does not change the center of mass + */ + void CollisionComponent2D::Recenter(const Nz::Vector2f& origin) + { + const Nz::RigidBody2D* rigidBody = GetRigidBody(); + SetGeomOffset(origin - rigidBody->GetAABB().GetCenter() + rigidBody->GetPositionOffset()); + } + /*! * \brief Sets geometry for the entity * @@ -49,6 +60,11 @@ namespace Ndk GetRigidBody()->SetGeom(m_geom); } + /*! + * \brief Sets the position offset between the actual rigid body center of mass position and the origin of the geometry + * + * \param geomOffset Position offset + */ void CollisionComponent2D::SetGeomOffset(const Nz::Vector2f& geomOffset) { GetRigidBody()->SetPositionOffset(geomOffset);