Physics2D/PhysWorld: Add Raycast queries

This commit is contained in:
Jérôme Leclercq
2017-03-06 14:02:35 +01:00
parent f88174c8ca
commit ede6dd90b8
2 changed files with 64 additions and 0 deletions

View File

@@ -31,6 +31,7 @@ namespace Nz
public:
struct Callback;
struct NearestQueryResult;
struct RaycastHit;
PhysWorld2D();
PhysWorld2D(const PhysWorld2D&) = delete;
@@ -44,6 +45,9 @@ namespace Nz
bool NearestBodyQuery(const Vector2f& from, float maxDistance, Nz::UInt32 collisionGroup, Nz::UInt32 categoryMask, Nz::UInt32 collisionMask, RigidBody2D** nearestBody = nullptr);
bool NearestBodyQuery(const Vector2f& from, float maxDistance, Nz::UInt32 collisionGroup, Nz::UInt32 categoryMask, Nz::UInt32 collisionMask, NearestQueryResult* result);
bool RaycastQuery(const Nz::Vector2f& from, const Nz::Vector2f& to, float radius, Nz::UInt32 collisionGroup, Nz::UInt32 categoryMask, Nz::UInt32 collisionMask, std::vector<RaycastHit>* hitInfos);
bool RaycastQueryFirst(const Nz::Vector2f& from, const Nz::Vector2f& to, float radius, Nz::UInt32 collisionGroup, Nz::UInt32 categoryMask, Nz::UInt32 collisionMask, RaycastHit* hitInfo = nullptr);
void RegisterCallbacks(unsigned int collisionId, const Callback& callbacks);
void RegisterCallbacks(unsigned int collisionIdA, unsigned int collisionIdB, const Callback& callbacks);
@@ -72,6 +76,14 @@ namespace Nz
float distance;
};
struct RaycastHit
{
Nz::RigidBody2D* nearestBody;
Nz::Vector2f hitPos;
Nz::Vector2f hitNormal;
float fraction;
};
NazaraSignal(OnPhysWorld2DPreStep, const PhysWorld2D* /*physWorld*/);
NazaraSignal(OnPhysWorld2DPostStep, const PhysWorld2D* /*physWorld*/);