Physics2D/RigidBody2D: Add ClosestPointQuery method

This commit is contained in:
Jérôme Leclercq
2018-06-12 15:11:16 +02:00
parent 56b23a2f27
commit b2185f2138
5 changed files with 56 additions and 0 deletions

View File

@@ -30,6 +30,8 @@ namespace Ndk
void AddImpulse(const Nz::Vector2f& impulse, const Nz::Vector2f& point, Nz::CoordSys coordSys = Nz::CoordSys_Global);
void AddTorque(float torque);
bool ClosestPointQuery(const Nz::Vector2f& position, Nz::Vector2f* closestPoint, float* closestDistance) const;
Nz::Rectf GetAABB() const;
float GetAngularVelocity() const;
Nz::Vector2f GetCenterOfGravity(Nz::CoordSys coordSys = Nz::CoordSys_Local) const;

View File

@@ -2,6 +2,7 @@
// This file is part of the "Nazara Development Kit"
// For conditions of distribution and use, see copyright notice in Prerequisites.hpp
#include <NDK/Components/PhysicsComponent2D.hpp>
#include <Nazara/Core/Error.hpp>
namespace Ndk
@@ -97,6 +98,23 @@ namespace Ndk
m_object->AddTorque(torque);
}
/*!
* \brief Finds the closest point on the entity relative to a position
* \return True if such a point exists (will return false if no collider exists)
*
* \param position The starting point which will be used for the query
* \param closestPoint The closest point on entity surface
* \param closestDistance The distance between the closest point and the starting point, may be negative if starting point is inside the entity
*
* \remark Produces a NazaraAssert if the physics object is invalid
*/
inline bool PhysicsComponent2D::ClosestPointQuery(const Nz::Vector2f& position, Nz::Vector2f* closestPoint, float* closestDistance) const
{
NazaraAssert(m_object, "Invalid physics object");
return m_object->ClosestPointQuery(position, closestPoint, closestDistance);
}
/*!
* \brief Gets the AABB of the physics object
* \return AABB of the object