Physics2D: Add DebugDraw method

This commit is contained in:
Jérôme Leclercq
2017-10-13 15:14:37 +02:00
parent b14a9f219a
commit 101783126c
4 changed files with 148 additions and 0 deletions

View File

@@ -8,6 +8,7 @@
#define NAZARA_PHYSWORLD2D_HPP
#include <Nazara/Prerequesites.hpp>
#include <Nazara/Core/Color.hpp>
#include <Nazara/Core/Signal.hpp>
#include <Nazara/Math/Vector2.hpp>
#include <Nazara/Physics2D/Config.hpp>
@@ -30,8 +31,16 @@ namespace Nz
using ContactPostSolveCallback = std::function<void(PhysWorld2D& world, RigidBody2D& bodyA, RigidBody2D& bodyB, void* userdata)>;
using ContactStartCallback = std::function<bool(PhysWorld2D& world, RigidBody2D& bodyA, RigidBody2D& bodyB, void* userdata)>;
using DebugDrawCircleCallback = std::function<void(const Vector2f& origin, float rotation, float radius, Color outlineColor, Color fillColor, void* userdata)>;
using DebugDrawDotCallback = std::function<void(const Vector2f& origin, float radius, Color color, void* userdata)>;
using DebugDrawPolygonCallback = std::function<void(const Vector2f* vertices, std::size_t vertexCount, float radius, Color outlineColor, Color fillColor, void* userdata)>;
using DebugDrawSegmentCallback = std::function<void(const Vector2f& first, const Vector2f& second, Color color, void* userdata)>;
using DebugDrawTickSegmentCallback = std::function<void(const Vector2f& first, const Vector2f& second, float thickness, Color outlineColor, Color fillColor, void* userdata)>;
using DebugDrawGetColorCallback = std::function<Color(RigidBody2D& body, std::size_t shapeIndex, void* userdata)>;
public:
struct Callback;
struct DebugDrawOptions;
struct NearestQueryResult;
struct RaycastHit;
@@ -40,6 +49,8 @@ namespace Nz
PhysWorld2D(PhysWorld2D&&) = delete; ///TODO
~PhysWorld2D();
void DebugDraw(const DebugDrawOptions& options, bool drawShapes = true, bool drawConstraints = true, bool drawCollisions = true);
float GetDamping() const;
Vector2f GetGravity() const;
cpSpace* GetHandle() const;
@@ -74,6 +85,22 @@ namespace Nz
void* userdata;
};
struct DebugDrawOptions
{
Color constraintColor;
Color collisionPointColor;
Color shapeOutlineColor;
DebugDrawCircleCallback circleCallback;
DebugDrawGetColorCallback colorCallback;
DebugDrawDotCallback dotCallback;
DebugDrawPolygonCallback polygonCallback;
DebugDrawSegmentCallback segmentCallback;
DebugDrawTickSegmentCallback thickSegmentCallback;
void* userdata;
};
struct NearestQueryResult
{
Nz::RigidBody2D* nearestBody;

View File

@@ -13,6 +13,7 @@
#include <Nazara/Math/Rect.hpp>
#include <Nazara/Physics2D/Config.hpp>
#include <Nazara/Physics2D/Collider2D.hpp>
#include <limits>
struct cpBody;
@@ -44,6 +45,7 @@ namespace Nz
float GetMomentOfInertia() const;
Vector2f GetPosition() const;
float GetRotation() const;
std::size_t GetShapeIndex(cpShape* shape) const;
void* GetUserdata() const;
Vector2f GetVelocity() const;
PhysWorld2D* GetWorld() const;
@@ -67,6 +69,8 @@ namespace Nz
NazaraSignal(OnRigidBody2DMove, RigidBody2D* /*oldPointer*/, RigidBody2D* /*newPointer*/);
NazaraSignal(OnRigidBody2DRelease, RigidBody2D* /*rigidBody*/);
static constexpr std::size_t InvalidShapeIndex = std::numeric_limits<std::size_t>::max();
private:
void CopyBodyData(cpBody* body);
cpBody* Create(float mass = 1.f, float moment = 1.f);