From 04f7b401500def9530bb76a8f467ecea55466e3b Mon Sep 17 00:00:00 2001 From: Lynix Date: Thu, 2 Mar 2017 13:07:02 +0100 Subject: [PATCH] Physics2D/RigidBody2D: Fix querying --- include/Nazara/Physics2D/PhysWorld2D.hpp | 2 +- src/Nazara/Physics2D/RigidBody2D.cpp | 5 +++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/include/Nazara/Physics2D/PhysWorld2D.hpp b/include/Nazara/Physics2D/PhysWorld2D.hpp index efd49c008..f116b7729 100644 --- a/include/Nazara/Physics2D/PhysWorld2D.hpp +++ b/include/Nazara/Physics2D/PhysWorld2D.hpp @@ -41,7 +41,7 @@ namespace Nz cpSpace* GetHandle() const; float GetStepSize() const; - bool NearestBodyQuery(const Vector2f& from, float maxDistance, Nz::UInt32 collisionGroup, Nz::UInt32 categoryMask, Nz::UInt32 collisionMask, RigidBody2D** nearestBody); + 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); void RegisterCallbacks(unsigned int collisionId, const Callback& callbacks); diff --git a/src/Nazara/Physics2D/RigidBody2D.cpp b/src/Nazara/Physics2D/RigidBody2D.cpp index d4d5aafd0..d96ba3eb1 100644 --- a/src/Nazara/Physics2D/RigidBody2D.cpp +++ b/src/Nazara/Physics2D/RigidBody2D.cpp @@ -61,6 +61,8 @@ namespace Nz m_mass(object.m_mass) { cpBodySetUserData(m_handle, this); + for (cpShape* shape : m_shapes) + cpShapeSetUserData(shape, this); object.m_handle = nullptr; @@ -312,6 +314,8 @@ namespace Nz m_world = object.m_world; cpBodySetUserData(m_handle, this); + for (cpShape* shape : m_shapes) + cpShapeSetUserData(shape, this); object.m_handle = nullptr; @@ -324,6 +328,7 @@ namespace Nz { m_handle = cpBodyNew(mass, moment); cpBodySetUserData(m_handle, this); + cpSpaceAddBody(m_world->GetHandle(), m_handle); }