CollisionComponent2D: Rename Align to Center (and make it take a vector)
This commit is contained in:
parent
23887cc519
commit
59dffe1a7b
|
|
@ -28,12 +28,12 @@ namespace Ndk
|
||||||
CollisionComponent2D(const CollisionComponent2D& collision);
|
CollisionComponent2D(const CollisionComponent2D& collision);
|
||||||
~CollisionComponent2D() = default;
|
~CollisionComponent2D() = default;
|
||||||
|
|
||||||
void Align(const Nz::Rectf& aabb);
|
|
||||||
|
|
||||||
Nz::Rectf GetAABB() const;
|
Nz::Rectf GetAABB() const;
|
||||||
const Nz::Collider2DRef& GetGeom() const;
|
const Nz::Collider2DRef& GetGeom() const;
|
||||||
const Nz::Vector2f& GetGeomOffset() const;
|
const Nz::Vector2f& GetGeomOffset() const;
|
||||||
|
|
||||||
|
void Recenter(const Nz::Vector2f& origin);
|
||||||
|
|
||||||
void SetGeom(Nz::Collider2DRef geom);
|
void SetGeom(Nz::Collider2DRef geom);
|
||||||
void SetGeomOffset(const Nz::Vector2f& geomOffset);
|
void SetGeomOffset(const Nz::Vector2f& geomOffset);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -17,12 +17,6 @@ namespace Ndk
|
||||||
* \brief NDK class that represents a two-dimensional collision geometry
|
* \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
|
* \brief Gets the collision box representing the entity
|
||||||
* \return The physics collision box
|
* \return The physics collision box
|
||||||
|
|
@ -32,11 +26,28 @@ namespace Ndk
|
||||||
return GetRigidBody()->GetAABB();
|
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
|
const Nz::Vector2f& CollisionComponent2D::GetGeomOffset() const
|
||||||
{
|
{
|
||||||
return GetRigidBody()->GetPositionOffset();
|
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
|
* \brief Sets geometry for the entity
|
||||||
*
|
*
|
||||||
|
|
@ -49,6 +60,11 @@ namespace Ndk
|
||||||
GetRigidBody()->SetGeom(m_geom);
|
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)
|
void CollisionComponent2D::SetGeomOffset(const Nz::Vector2f& geomOffset)
|
||||||
{
|
{
|
||||||
GetRigidBody()->SetPositionOffset(geomOffset);
|
GetRigidBody()->SetPositionOffset(geomOffset);
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue