Physics2D: Add Arbiter2D
This commit is contained in:
parent
2f3f02b2fc
commit
b92e23fcd6
|
|
@ -128,6 +128,7 @@ Nazara Engine:
|
|||
- Added LuaImplQueryArg & LuaImplReplyVal functions for Vector[2|3]<int>
|
||||
- Fixed bug in ENet implementation causing legit reliable packets to be dropped on sequence number overflow
|
||||
- Fixed bug where index wouldn't be used in String::FindLast and String::FindWord
|
||||
- Physics 2D contact callbacks now include an arbiter allowing to query/set parameters about the collision
|
||||
|
||||
Nazara Development Kit:
|
||||
- Added ImageWidget (#139)
|
||||
|
|
|
|||
|
|
@ -0,0 +1,57 @@
|
|||
// Copyright (C) 2017 Jérôme Leclercq
|
||||
// This file is part of the "Nazara Engine - Physics 2D module"
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifndef NAZARA_ARBITER2D_HPP
|
||||
#define NAZARA_ARBITER2D_HPP
|
||||
|
||||
#include <Nazara/Prerequisites.hpp>
|
||||
#include <Nazara/Core/MovablePtr.hpp>
|
||||
#include <Nazara/Math/Vector2.hpp>
|
||||
#include <Nazara/Physics2D/Config.hpp>
|
||||
|
||||
struct cpArbiter;
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
class NAZARA_PHYSICS2D_API Arbiter2D
|
||||
{
|
||||
public:
|
||||
inline Arbiter2D(cpArbiter* arbiter);
|
||||
Arbiter2D(const Arbiter2D&) = delete;
|
||||
Arbiter2D(Arbiter2D&&) = default;
|
||||
~Arbiter2D() = default;
|
||||
|
||||
float ComputeTotalKinematicEnergy() const;
|
||||
Nz::Vector2f ComputeTotalImpulse() const;
|
||||
|
||||
std::size_t GetContactCount() const;
|
||||
float GetContactDepth(std::size_t i) const;
|
||||
Nz::Vector2f GetContactPointA(std::size_t i) const;
|
||||
Nz::Vector2f GetContactPointB(std::size_t i) const;
|
||||
|
||||
float GetElasticity() const;
|
||||
float GetFriction() const;
|
||||
Nz::Vector2f GetNormal() const;
|
||||
Nz::Vector2f GetSurfaceVelocity() const;
|
||||
|
||||
bool IsFirstContact() const;
|
||||
bool IsRemoval() const;
|
||||
|
||||
void SetElasticity(float elasticity);
|
||||
void SetFriction(float friction);
|
||||
void SetSurfaceVelocity(const Nz::Vector2f& surfaceVelocity);
|
||||
|
||||
Arbiter2D& operator=(const Arbiter2D&) = delete;
|
||||
Arbiter2D& operator=(Arbiter2D&&) = default;
|
||||
|
||||
private:
|
||||
MovablePtr<cpArbiter> m_arbiter;
|
||||
};
|
||||
}
|
||||
|
||||
#include <Nazara/Physics2D/Arbiter2D.inl>
|
||||
|
||||
#endif // NAZARA_ARBITER2D_HPP
|
||||
|
|
@ -0,0 +1,17 @@
|
|||
// Copyright (C) 2017 Jérôme Leclercq
|
||||
// This file is part of the "Nazara Engine - Physics 2D module"
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#include <Nazara/Physics2D/Arbiter2D.hpp>
|
||||
#include <memory>
|
||||
#include <Nazara/Physics2D/Debug.hpp>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
inline Arbiter2D::Arbiter2D(cpArbiter* arbiter) :
|
||||
m_arbiter(arbiter)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
#include <Nazara/Physics2D/DebugOff.hpp>
|
||||
|
|
@ -22,14 +22,16 @@ struct cpSpace;
|
|||
|
||||
namespace Nz
|
||||
{
|
||||
class Arbiter2D;
|
||||
|
||||
class NAZARA_PHYSICS2D_API PhysWorld2D
|
||||
{
|
||||
friend RigidBody2D;
|
||||
|
||||
using ContactEndCallback = std::function<void(PhysWorld2D& world, RigidBody2D& bodyA, RigidBody2D& bodyB, void* userdata)>;
|
||||
using ContactPreSolveCallback = std::function<bool(PhysWorld2D& world, RigidBody2D& bodyA, RigidBody2D& bodyB, void* userdata)>;
|
||||
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 ContactEndCallback = std::function<void(PhysWorld2D& world, Arbiter2D& arbiter, RigidBody2D& bodyA, RigidBody2D& bodyB, void* userdata)>;
|
||||
using ContactPreSolveCallback = std::function<bool(PhysWorld2D& world, Arbiter2D& arbiter, RigidBody2D& bodyA, RigidBody2D& bodyB, void* userdata)>;
|
||||
using ContactPostSolveCallback = std::function<void(PhysWorld2D& world, Arbiter2D& arbiter, RigidBody2D& bodyA, RigidBody2D& bodyB, void* userdata)>;
|
||||
using ContactStartCallback = std::function<bool(PhysWorld2D& world, Arbiter2D& arbiter, 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)>;
|
||||
|
|
|
|||
|
|
@ -0,0 +1,89 @@
|
|||
// Copyright (C) 2017 Jérôme Leclercq
|
||||
// This file is part of the "Nazara Engine - Physics 2D module"
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#include <Nazara/Physics2D/Arbiter2D.hpp>
|
||||
#include <chipmunk/chipmunk.h>
|
||||
#include <Nazara/Physics3D/Debug.hpp>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
float Nz::Arbiter2D::ComputeTotalKinematicEnergy() const
|
||||
{
|
||||
return float(cpArbiterTotalKE(m_arbiter));
|
||||
}
|
||||
|
||||
Nz::Vector2f Arbiter2D::ComputeTotalImpulse() const
|
||||
{
|
||||
cpVect impulse = cpArbiterTotalImpulse(m_arbiter);
|
||||
return Nz::Vector2f(Nz::Vector2<cpFloat>(impulse.x, impulse.y));
|
||||
}
|
||||
|
||||
std::size_t Arbiter2D::GetContactCount() const
|
||||
{
|
||||
return cpArbiterGetCount(m_arbiter);
|
||||
}
|
||||
|
||||
float Arbiter2D::GetContactDepth(std::size_t i) const
|
||||
{
|
||||
return cpArbiterGetDepth(m_arbiter, int(i));
|
||||
}
|
||||
|
||||
Nz::Vector2f Arbiter2D::GetContactPointA(std::size_t i) const
|
||||
{
|
||||
cpVect point = cpArbiterGetPointA(m_arbiter, int(i));
|
||||
return Nz::Vector2f(Nz::Vector2<cpFloat>(point.x, point.y));
|
||||
}
|
||||
|
||||
Nz::Vector2f Arbiter2D::GetContactPointB(std::size_t i) const
|
||||
{
|
||||
cpVect point = cpArbiterGetPointB(m_arbiter, int(i));
|
||||
return Nz::Vector2f(Nz::Vector2<cpFloat>(point.x, point.y));
|
||||
}
|
||||
|
||||
float Arbiter2D::GetElasticity() const
|
||||
{
|
||||
return float(cpArbiterGetRestitution(m_arbiter));
|
||||
}
|
||||
float Arbiter2D::GetFriction() const
|
||||
{
|
||||
return float(cpArbiterGetFriction(m_arbiter));
|
||||
}
|
||||
|
||||
Nz::Vector2f Arbiter2D::GetNormal() const
|
||||
{
|
||||
cpVect normal = cpArbiterGetNormal(m_arbiter);
|
||||
return Nz::Vector2f(Nz::Vector2<cpFloat>(normal.x, normal.y));
|
||||
}
|
||||
|
||||
Nz::Vector2f Arbiter2D::GetSurfaceVelocity() const
|
||||
{
|
||||
cpVect velocity = cpArbiterGetNormal(m_arbiter);
|
||||
return Nz::Vector2f(Nz::Vector2<cpFloat>(velocity.x, velocity.y));
|
||||
}
|
||||
|
||||
bool Arbiter2D::IsFirstContact() const
|
||||
{
|
||||
return cpArbiterIsFirstContact(m_arbiter) == cpTrue;
|
||||
}
|
||||
|
||||
bool Arbiter2D::IsRemoval() const
|
||||
{
|
||||
return cpArbiterIsRemoval(m_arbiter) == cpTrue;
|
||||
}
|
||||
|
||||
void Arbiter2D::SetElasticity(float elasticity)
|
||||
{
|
||||
cpArbiterSetRestitution(m_arbiter, elasticity);
|
||||
}
|
||||
|
||||
void Arbiter2D::SetFriction(float friction)
|
||||
{
|
||||
cpArbiterSetFriction(m_arbiter, friction);
|
||||
}
|
||||
|
||||
void Arbiter2D::SetSurfaceVelocity(const Nz::Vector2f& surfaceVelocity)
|
||||
{
|
||||
cpArbiterSetSurfaceVelocity(m_arbiter, cpv(surfaceVelocity.x, surfaceVelocity.y));
|
||||
}
|
||||
}
|
||||
|
|
@ -3,6 +3,7 @@
|
|||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#include <Nazara/Physics2D/PhysWorld2D.hpp>
|
||||
#include <Nazara/Physics2D/Arbiter2D.hpp>
|
||||
#include <Nazara/Core/StackArray.hpp>
|
||||
#include <chipmunk/chipmunk.h>
|
||||
#include <Nazara/Physics2D/Debug.hpp>
|
||||
|
|
@ -358,8 +359,10 @@ namespace Nz
|
|||
RigidBody2D* firstRigidBody = static_cast<RigidBody2D*>(cpBodyGetUserData(firstBody));
|
||||
RigidBody2D* secondRigidBody = static_cast<RigidBody2D*>(cpBodyGetUserData(secondBody));
|
||||
|
||||
Arbiter2D arbiter(arb);
|
||||
|
||||
const Callback* customCallbacks = static_cast<const Callback*>(data);
|
||||
if (customCallbacks->startCallback(*world, *firstRigidBody, *secondRigidBody, customCallbacks->userdata))
|
||||
if (customCallbacks->startCallback(*world, arbiter, *firstRigidBody, *secondRigidBody, customCallbacks->userdata))
|
||||
{
|
||||
cpBool retA = cpArbiterCallWildcardBeginA(arb, space);
|
||||
cpBool retB = cpArbiterCallWildcardBeginB(arb, space);
|
||||
|
|
@ -382,8 +385,10 @@ namespace Nz
|
|||
RigidBody2D* firstRigidBody = static_cast<RigidBody2D*>(cpBodyGetUserData(firstBody));
|
||||
RigidBody2D* secondRigidBody = static_cast<RigidBody2D*>(cpBodyGetUserData(secondBody));
|
||||
|
||||
Arbiter2D arbiter(arb);
|
||||
|
||||
const Callback* customCallbacks = static_cast<const Callback*>(data);
|
||||
customCallbacks->endCallback(*world, *firstRigidBody, *secondRigidBody, customCallbacks->userdata);
|
||||
customCallbacks->endCallback(*world, arbiter, *firstRigidBody, *secondRigidBody, customCallbacks->userdata);
|
||||
|
||||
cpArbiterCallWildcardSeparateA(arb, space);
|
||||
cpArbiterCallWildcardSeparateB(arb, space);
|
||||
|
|
@ -402,8 +407,10 @@ namespace Nz
|
|||
RigidBody2D* firstRigidBody = static_cast<RigidBody2D*>(cpBodyGetUserData(firstBody));
|
||||
RigidBody2D* secondRigidBody = static_cast<RigidBody2D*>(cpBodyGetUserData(secondBody));
|
||||
|
||||
Arbiter2D arbiter(arb);
|
||||
|
||||
const Callback* customCallbacks = static_cast<const Callback*>(data);
|
||||
if (customCallbacks->preSolveCallback(*world, *firstRigidBody, *secondRigidBody, customCallbacks->userdata))
|
||||
if (customCallbacks->preSolveCallback(*world, arbiter, *firstRigidBody, *secondRigidBody, customCallbacks->userdata))
|
||||
{
|
||||
cpBool retA = cpArbiterCallWildcardPreSolveA(arb, space);
|
||||
cpBool retB = cpArbiterCallWildcardPreSolveB(arb, space);
|
||||
|
|
@ -426,8 +433,10 @@ namespace Nz
|
|||
RigidBody2D* firstRigidBody = static_cast<RigidBody2D*>(cpBodyGetUserData(firstBody));
|
||||
RigidBody2D* secondRigidBody = static_cast<RigidBody2D*>(cpBodyGetUserData(secondBody));
|
||||
|
||||
Arbiter2D arbiter(arb);
|
||||
|
||||
const Callback* customCallbacks = static_cast<const Callback*>(data);
|
||||
customCallbacks->postSolveCallback(*world, *firstRigidBody, *secondRigidBody, customCallbacks->userdata);
|
||||
customCallbacks->postSolveCallback(*world, arbiter, *firstRigidBody, *secondRigidBody, customCallbacks->userdata);
|
||||
|
||||
cpArbiterCallWildcardPostSolveA(arb, space);
|
||||
cpArbiterCallWildcardPostSolveB(arb, space);
|
||||
|
|
|
|||
Loading…
Reference in New Issue