Rename Physics2D to ChipmunkPhysics2D
This commit is contained in:
committed by
Jérôme Leclercq
parent
b1255ad2ad
commit
26b23ccce6
61
include/Nazara/ChipmunkPhysics2D/ChipmunkArbiter2D.hpp
Normal file
61
include/Nazara/ChipmunkPhysics2D/ChipmunkArbiter2D.hpp
Normal file
@@ -0,0 +1,61 @@
|
||||
// Copyright (C) 2023 Jérôme "Lynix" Leclercq (lynix680@gmail.com)
|
||||
// This file is part of the "Nazara Engine - Physics2D module"
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifndef NAZARA_CHIPMUNKPHYSICS2D_ARBITER2D_HPP
|
||||
#define NAZARA_CHIPMUNKPHYSICS2D_ARBITER2D_HPP
|
||||
|
||||
#include <NazaraUtils/Prerequisites.hpp>
|
||||
#include <Nazara/Math/Vector2.hpp>
|
||||
#include <Nazara/ChipmunkPhysics2D/Config.hpp>
|
||||
#include <NazaraUtils/MovablePtr.hpp>
|
||||
|
||||
struct cpArbiter;
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
class ChipmunkRigidBody2D;
|
||||
|
||||
class NAZARA_CHIPMUNKPHYSICS2D_API ChipmunkArbiter2D
|
||||
{
|
||||
public:
|
||||
inline ChipmunkArbiter2D(cpArbiter* arbiter);
|
||||
ChipmunkArbiter2D(const ChipmunkArbiter2D&) = delete;
|
||||
ChipmunkArbiter2D(ChipmunkArbiter2D&&) = default;
|
||||
~ChipmunkArbiter2D() = default;
|
||||
|
||||
float ComputeTotalKinematicEnergy() const;
|
||||
Nz::Vector2f ComputeTotalImpulse() const;
|
||||
|
||||
std::pair<ChipmunkRigidBody2D*, ChipmunkRigidBody2D*> GetBodies() const;
|
||||
|
||||
std::size_t GetContactCount() const;
|
||||
float GetContactDepth(std::size_t i) const;
|
||||
Vector2f GetContactPointA(std::size_t i) const;
|
||||
Vector2f GetContactPointB(std::size_t i) const;
|
||||
|
||||
float GetElasticity() const;
|
||||
float GetFriction() const;
|
||||
Vector2f GetNormal() const;
|
||||
Vector2f GetSurfaceVelocity() const;
|
||||
|
||||
bool IsFirstContact() const;
|
||||
bool IsRemoval() const;
|
||||
|
||||
void SetElasticity(float elasticity);
|
||||
void SetFriction(float friction);
|
||||
void SetSurfaceVelocity(const Vector2f& surfaceVelocity);
|
||||
|
||||
ChipmunkArbiter2D& operator=(const ChipmunkArbiter2D&) = delete;
|
||||
ChipmunkArbiter2D& operator=(ChipmunkArbiter2D&&) = default;
|
||||
|
||||
private:
|
||||
MovablePtr<cpArbiter> m_arbiter;
|
||||
};
|
||||
}
|
||||
|
||||
#include <Nazara/ChipmunkPhysics2D/ChipmunkArbiter2D.inl>
|
||||
|
||||
#endif // NAZARA_CHIPMUNKPHYSICS2D_ARBITER2D_HPP
|
||||
16
include/Nazara/ChipmunkPhysics2D/ChipmunkArbiter2D.inl
Normal file
16
include/Nazara/ChipmunkPhysics2D/ChipmunkArbiter2D.inl
Normal file
@@ -0,0 +1,16 @@
|
||||
// Copyright (C) 2023 Jérôme "Lynix" Leclercq (lynix680@gmail.com)
|
||||
// This file is part of the "Nazara Engine - Physics2D module"
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#include <memory>
|
||||
#include <Nazara/ChipmunkPhysics2D/Debug.hpp>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
inline ChipmunkArbiter2D::ChipmunkArbiter2D(cpArbiter* arbiter) :
|
||||
m_arbiter(arbiter)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
#include <Nazara/ChipmunkPhysics2D/DebugOff.hpp>
|
||||
211
include/Nazara/ChipmunkPhysics2D/ChipmunkCollider2D.hpp
Normal file
211
include/Nazara/ChipmunkPhysics2D/ChipmunkCollider2D.hpp
Normal file
@@ -0,0 +1,211 @@
|
||||
// Copyright (C) 2023 Jérôme "Lynix" Leclercq (lynix680@gmail.com)
|
||||
// This file is part of the "Nazara Engine - Physics2D module"
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifndef NAZARA_CHIPMUNKPHYSICS2D_COLLIDER2D_HPP
|
||||
#define NAZARA_CHIPMUNKPHYSICS2D_COLLIDER2D_HPP
|
||||
|
||||
#include <NazaraUtils/Prerequisites.hpp>
|
||||
#include <Nazara/Core/ObjectLibrary.hpp>
|
||||
#include <Nazara/Math/Rect.hpp>
|
||||
#include <Nazara/Math/Vector2.hpp>
|
||||
#include <Nazara/ChipmunkPhysics2D/Config.hpp>
|
||||
#include <Nazara/ChipmunkPhysics2D/Enums.hpp>
|
||||
#include <NazaraUtils/Signal.hpp>
|
||||
#include <NazaraUtils/SparsePtr.hpp>
|
||||
#include <vector>
|
||||
|
||||
struct cpBody;
|
||||
struct cpShape;
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
class ChipmunkRigidBody2D;
|
||||
|
||||
class NAZARA_CHIPMUNKPHYSICS2D_API ChipmunkCollider2D
|
||||
{
|
||||
friend ChipmunkRigidBody2D;
|
||||
friend class ChipmunkCompoundCollider2D; //< See CompoundCollider2D::CreateShapes
|
||||
|
||||
public:
|
||||
inline ChipmunkCollider2D();
|
||||
ChipmunkCollider2D(const ChipmunkCollider2D&) = delete;
|
||||
ChipmunkCollider2D(ChipmunkCollider2D&&) = delete;
|
||||
virtual ~ChipmunkCollider2D();
|
||||
|
||||
virtual Vector2f ComputeCenterOfMass() const = 0;
|
||||
virtual float ComputeMomentOfInertia(float mass) const = 0;
|
||||
|
||||
virtual void ForEachPolygon(const std::function<void(const Vector2f* vertices, std::size_t vertexCount)>& callback) const;
|
||||
|
||||
inline UInt32 GetCategoryMask() const;
|
||||
inline UInt32 GetCollisionGroup() const;
|
||||
inline unsigned int GetCollisionId() const;
|
||||
inline UInt32 GetCollisionMask() const;
|
||||
inline float GetElasticity() const;
|
||||
inline float GetFriction() const;
|
||||
inline Vector2f GetSurfaceVelocity() const;
|
||||
|
||||
virtual ChipmunkColliderType2D GetType() const = 0;
|
||||
|
||||
inline bool IsTrigger() const;
|
||||
|
||||
inline void SetCategoryMask(UInt32 categoryMask);
|
||||
inline void SetCollisionGroup(UInt32 groupId);
|
||||
inline void SetCollisionId(unsigned int typeId);
|
||||
inline void SetCollisionMask(UInt32 mask);
|
||||
inline void SetElasticity(float elasticity);
|
||||
inline void SetFriction(float friction);
|
||||
inline void SetSurfaceVelocity(const Vector2f& surfaceVelocity);
|
||||
inline void SetTrigger(bool trigger);
|
||||
|
||||
ChipmunkCollider2D& operator=(const ChipmunkCollider2D&) = delete;
|
||||
ChipmunkCollider2D& operator=(ChipmunkCollider2D&&) = delete;
|
||||
|
||||
// Signals:
|
||||
NazaraSignal(OnColliderRelease, const ChipmunkCollider2D* /*collider*/);
|
||||
|
||||
protected:
|
||||
virtual std::size_t CreateShapes(cpBody* body, std::vector<cpShape*>* shapes) const = 0;
|
||||
|
||||
UInt32 m_categoryMask;
|
||||
UInt32 m_collisionGroup;
|
||||
UInt32 m_collisionMask;
|
||||
Vector2f m_surfaceVelocity;
|
||||
bool m_trigger;
|
||||
float m_elasticity;
|
||||
float m_friction;
|
||||
unsigned int m_collisionId;
|
||||
|
||||
private:
|
||||
virtual std::size_t GenerateShapes(cpBody* body, std::vector<cpShape*>* shapes) const;
|
||||
};
|
||||
|
||||
class NAZARA_CHIPMUNKPHYSICS2D_API ChipmunkBoxCollider2D : public ChipmunkCollider2D
|
||||
{
|
||||
public:
|
||||
ChipmunkBoxCollider2D(const Vector2f& size, float radius = 0.f);
|
||||
ChipmunkBoxCollider2D(const Rectf& rect, float radius = 0.f);
|
||||
|
||||
Nz::Vector2f ComputeCenterOfMass() const override;
|
||||
float ComputeMomentOfInertia(float mass) const override;
|
||||
|
||||
inline float GetRadius() const;
|
||||
inline const Rectf& GetRect() const;
|
||||
inline Vector2f GetSize() const;
|
||||
ChipmunkColliderType2D GetType() const override;
|
||||
|
||||
private:
|
||||
std::size_t CreateShapes(cpBody* body, std::vector<cpShape*>* shapes) const override;
|
||||
|
||||
Rectf m_rect;
|
||||
float m_radius;
|
||||
};
|
||||
|
||||
class NAZARA_CHIPMUNKPHYSICS2D_API ChipmunkCircleCollider2D : public ChipmunkCollider2D
|
||||
{
|
||||
public:
|
||||
ChipmunkCircleCollider2D(float radius, const Vector2f& offset = Vector2f::Zero());
|
||||
|
||||
Nz::Vector2f ComputeCenterOfMass() const override;
|
||||
float ComputeMomentOfInertia(float mass) const override;
|
||||
|
||||
inline const Vector2f& GetOffset() const;
|
||||
inline float GetRadius() const;
|
||||
ChipmunkColliderType2D GetType() const override;
|
||||
|
||||
private:
|
||||
std::size_t CreateShapes(cpBody* body, std::vector<cpShape*>* shapes) const override;
|
||||
|
||||
Vector2f m_offset;
|
||||
float m_radius;
|
||||
};
|
||||
|
||||
class NAZARA_CHIPMUNKPHYSICS2D_API ChipmunkCompoundCollider2D : public ChipmunkCollider2D
|
||||
{
|
||||
public:
|
||||
ChipmunkCompoundCollider2D(std::vector<std::shared_ptr<ChipmunkCollider2D>> geoms);
|
||||
|
||||
Nz::Vector2f ComputeCenterOfMass() const override;
|
||||
float ComputeMomentOfInertia(float mass) const override;
|
||||
|
||||
inline bool DoesOverrideCollisionProperties() const;
|
||||
|
||||
inline const std::vector<std::shared_ptr<ChipmunkCollider2D>>& GetGeoms() const;
|
||||
ChipmunkColliderType2D GetType() const override;
|
||||
|
||||
inline void OverridesCollisionProperties(bool shouldOverride);
|
||||
|
||||
private:
|
||||
std::size_t CreateShapes(cpBody* body, std::vector<cpShape*>* shapes) const override;
|
||||
std::size_t GenerateShapes(cpBody* body, std::vector<cpShape*>* shapes) const override;
|
||||
|
||||
std::vector<std::shared_ptr<ChipmunkCollider2D>> m_geoms;
|
||||
bool m_doesOverrideCollisionProperties;
|
||||
};
|
||||
|
||||
class NAZARA_CHIPMUNKPHYSICS2D_API ChipmunkConvexCollider2D : public ChipmunkCollider2D
|
||||
{
|
||||
public:
|
||||
ChipmunkConvexCollider2D(SparsePtr<const Vector2f> vertices, std::size_t vertexCount, float radius = 0.f);
|
||||
|
||||
Nz::Vector2f ComputeCenterOfMass() const override;
|
||||
float ComputeMomentOfInertia(float mass) const override;
|
||||
|
||||
ChipmunkColliderType2D GetType() const override;
|
||||
inline const std::vector<Vector2d>& GetVertices() const;
|
||||
|
||||
private:
|
||||
std::size_t CreateShapes(cpBody* body, std::vector<cpShape*>* shapes) const override;
|
||||
|
||||
std::vector<Vector2d> m_vertices;
|
||||
float m_radius;
|
||||
};
|
||||
|
||||
class NAZARA_CHIPMUNKPHYSICS2D_API ChipmunkNullCollider2D : public ChipmunkCollider2D
|
||||
{
|
||||
public:
|
||||
ChipmunkNullCollider2D() = default;
|
||||
|
||||
Nz::Vector2f ComputeCenterOfMass() const override;
|
||||
float ComputeMomentOfInertia(float mass) const override;
|
||||
|
||||
ChipmunkColliderType2D GetType() const override;
|
||||
|
||||
private:
|
||||
std::size_t CreateShapes(cpBody* body, std::vector<cpShape*>* shapes) const override;
|
||||
};
|
||||
|
||||
class NAZARA_CHIPMUNKPHYSICS2D_API ChipmunkSegmentCollider2D : public ChipmunkCollider2D
|
||||
{
|
||||
public:
|
||||
inline ChipmunkSegmentCollider2D(const Vector2f& first, const Vector2f& second, float thickness = 1.f);
|
||||
inline ChipmunkSegmentCollider2D(const Vector2f& first, const Vector2f& firstNeighbor, const Vector2f& second, const Vector2f& secondNeighbor, float thickness = 1.f);
|
||||
|
||||
Nz::Vector2f ComputeCenterOfMass() const override;
|
||||
float ComputeMomentOfInertia(float mass) const override;
|
||||
|
||||
inline const Vector2f& GetFirstPoint() const;
|
||||
inline const Vector2f& GetFirstPointNeighbor() const;
|
||||
inline float GetLength() const;
|
||||
inline const Vector2f& GetSecondPoint() const;
|
||||
inline const Vector2f& GetSecondPointNeighbor() const;
|
||||
inline float GetThickness() const;
|
||||
ChipmunkColliderType2D GetType() const override;
|
||||
|
||||
private:
|
||||
std::size_t CreateShapes(cpBody* body, std::vector<cpShape*>* shapes) const override;
|
||||
|
||||
Vector2f m_first;
|
||||
Vector2f m_firstNeighbor;
|
||||
Vector2f m_second;
|
||||
Vector2f m_secondNeighbor;
|
||||
float m_thickness;
|
||||
};
|
||||
}
|
||||
|
||||
#include <Nazara/ChipmunkPhysics2D/ChipmunkCollider2D.inl>
|
||||
|
||||
#endif // NAZARA_CHIPMUNKPHYSICS2D_COLLIDER2D_HPP
|
||||
196
include/Nazara/ChipmunkPhysics2D/ChipmunkCollider2D.inl
Normal file
196
include/Nazara/ChipmunkPhysics2D/ChipmunkCollider2D.inl
Normal file
@@ -0,0 +1,196 @@
|
||||
// Copyright (C) 2023 Jérôme "Lynix" Leclercq (lynix680@gmail.com)
|
||||
// This file is part of the "Nazara Engine - Physics2D module"
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#include <memory>
|
||||
#include <Nazara/ChipmunkPhysics2D/Debug.hpp>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
inline ChipmunkCollider2D::ChipmunkCollider2D() :
|
||||
m_categoryMask(0xFFFFFFFF),
|
||||
m_collisionGroup(0),
|
||||
m_collisionMask(0xFFFFFFFF),
|
||||
m_surfaceVelocity(Vector2f::Zero()),
|
||||
m_trigger(false),
|
||||
m_elasticity(0.f),
|
||||
m_friction(0.f),
|
||||
m_collisionId(0)
|
||||
{
|
||||
}
|
||||
|
||||
inline UInt32 ChipmunkCollider2D::GetCategoryMask() const
|
||||
{
|
||||
return m_categoryMask;
|
||||
}
|
||||
|
||||
inline UInt32 ChipmunkCollider2D::GetCollisionGroup() const
|
||||
{
|
||||
return m_collisionGroup;
|
||||
}
|
||||
|
||||
inline unsigned int ChipmunkCollider2D::GetCollisionId() const
|
||||
{
|
||||
return m_collisionId;
|
||||
}
|
||||
|
||||
inline UInt32 ChipmunkCollider2D::GetCollisionMask() const
|
||||
{
|
||||
return m_collisionMask;
|
||||
}
|
||||
|
||||
inline float ChipmunkCollider2D::GetElasticity() const
|
||||
{
|
||||
return m_elasticity;
|
||||
}
|
||||
|
||||
inline float ChipmunkCollider2D::GetFriction() const
|
||||
{
|
||||
return m_friction;
|
||||
}
|
||||
|
||||
inline Vector2f ChipmunkCollider2D::GetSurfaceVelocity() const
|
||||
{
|
||||
return m_surfaceVelocity;
|
||||
}
|
||||
|
||||
inline bool ChipmunkCollider2D::IsTrigger() const
|
||||
{
|
||||
return m_trigger;
|
||||
}
|
||||
|
||||
inline void ChipmunkCollider2D::SetCategoryMask(UInt32 categoryMask)
|
||||
{
|
||||
m_categoryMask = categoryMask;
|
||||
}
|
||||
|
||||
inline void ChipmunkCollider2D::SetCollisionGroup(UInt32 groupId)
|
||||
{
|
||||
m_collisionGroup = groupId;
|
||||
}
|
||||
|
||||
inline void ChipmunkCollider2D::SetCollisionId(unsigned int typeId)
|
||||
{
|
||||
m_collisionId = typeId;
|
||||
}
|
||||
|
||||
inline void ChipmunkCollider2D::SetCollisionMask(UInt32 mask)
|
||||
{
|
||||
m_collisionMask = mask;
|
||||
}
|
||||
|
||||
inline void ChipmunkCollider2D::SetElasticity(float elasticity)
|
||||
{
|
||||
m_elasticity = elasticity;
|
||||
}
|
||||
|
||||
inline void ChipmunkCollider2D::SetFriction(float friction)
|
||||
{
|
||||
m_friction = friction;
|
||||
}
|
||||
|
||||
inline void ChipmunkCollider2D::SetSurfaceVelocity(const Vector2f& surfaceVelocity)
|
||||
{
|
||||
m_surfaceVelocity = surfaceVelocity;
|
||||
}
|
||||
|
||||
inline void ChipmunkCollider2D::SetTrigger(bool trigger)
|
||||
{
|
||||
m_trigger = trigger;
|
||||
}
|
||||
|
||||
inline float ChipmunkBoxCollider2D::GetRadius() const
|
||||
{
|
||||
return m_radius;
|
||||
}
|
||||
|
||||
inline const Rectf& ChipmunkBoxCollider2D::GetRect() const
|
||||
{
|
||||
return m_rect;
|
||||
}
|
||||
|
||||
inline Vector2f ChipmunkBoxCollider2D::GetSize() const
|
||||
{
|
||||
return m_rect.GetLengths();
|
||||
}
|
||||
|
||||
|
||||
inline const Vector2f& ChipmunkCircleCollider2D::GetOffset() const
|
||||
{
|
||||
return m_offset;
|
||||
}
|
||||
|
||||
inline float ChipmunkCircleCollider2D::GetRadius() const
|
||||
{
|
||||
return m_radius;
|
||||
}
|
||||
|
||||
|
||||
inline bool Nz::ChipmunkCompoundCollider2D::DoesOverrideCollisionProperties() const
|
||||
{
|
||||
return m_doesOverrideCollisionProperties;
|
||||
}
|
||||
|
||||
inline const std::vector<std::shared_ptr<ChipmunkCollider2D>>& ChipmunkCompoundCollider2D::GetGeoms() const
|
||||
{
|
||||
return m_geoms;
|
||||
}
|
||||
|
||||
inline void Nz::ChipmunkCompoundCollider2D::OverridesCollisionProperties(bool shouldOverride)
|
||||
{
|
||||
m_doesOverrideCollisionProperties = shouldOverride;
|
||||
}
|
||||
|
||||
|
||||
inline const std::vector<Vector2d>& ChipmunkConvexCollider2D::GetVertices() const
|
||||
{
|
||||
return m_vertices;
|
||||
}
|
||||
|
||||
|
||||
ChipmunkSegmentCollider2D::ChipmunkSegmentCollider2D(const Vector2f& first, const Vector2f& second, float thickness) :
|
||||
ChipmunkSegmentCollider2D(first, first, second, second, thickness)
|
||||
{
|
||||
}
|
||||
|
||||
inline ChipmunkSegmentCollider2D::ChipmunkSegmentCollider2D(const Vector2f& first, const Vector2f& firstNeighbor, const Vector2f& second, const Vector2f& secondNeighbor, float thickness) :
|
||||
m_first(first),
|
||||
m_firstNeighbor(firstNeighbor),
|
||||
m_second(second),
|
||||
m_secondNeighbor(secondNeighbor),
|
||||
m_thickness(thickness)
|
||||
{
|
||||
}
|
||||
|
||||
inline const Vector2f& ChipmunkSegmentCollider2D::GetFirstPoint() const
|
||||
{
|
||||
return m_first;
|
||||
}
|
||||
|
||||
inline const Vector2f& ChipmunkSegmentCollider2D::GetFirstPointNeighbor() const
|
||||
{
|
||||
return m_firstNeighbor;
|
||||
}
|
||||
|
||||
inline float ChipmunkSegmentCollider2D::GetLength() const
|
||||
{
|
||||
return m_first.Distance(m_second);
|
||||
}
|
||||
|
||||
inline const Vector2f& ChipmunkSegmentCollider2D::GetSecondPoint() const
|
||||
{
|
||||
return m_second;
|
||||
}
|
||||
|
||||
inline const Vector2f& ChipmunkSegmentCollider2D::GetSecondPointNeighbor() const
|
||||
{
|
||||
return m_secondNeighbor;
|
||||
}
|
||||
|
||||
inline float ChipmunkSegmentCollider2D::GetThickness() const
|
||||
{
|
||||
return m_thickness;
|
||||
}
|
||||
}
|
||||
|
||||
#include <Nazara/ChipmunkPhysics2D/DebugOff.hpp>
|
||||
233
include/Nazara/ChipmunkPhysics2D/ChipmunkConstraint2D.hpp
Normal file
233
include/Nazara/ChipmunkPhysics2D/ChipmunkConstraint2D.hpp
Normal file
@@ -0,0 +1,233 @@
|
||||
// Copyright (C) 2023 Jérôme "Lynix" Leclercq (lynix680@gmail.com)
|
||||
// This file is part of the "Nazara Engine - Physics2D module"
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifndef NAZARA_CHIPMUNKPHYSICS2D_CONSTRAINT2D_HPP
|
||||
#define NAZARA_CHIPMUNKPHYSICS2D_CONSTRAINT2D_HPP
|
||||
|
||||
#include <NazaraUtils/Prerequisites.hpp>
|
||||
#include <Nazara/Core/HandledObject.hpp>
|
||||
#include <Nazara/Core/ObjectHandle.hpp>
|
||||
#include <Nazara/Math/Angle.hpp>
|
||||
#include <Nazara/ChipmunkPhysics2D/Config.hpp>
|
||||
#include <Nazara/ChipmunkPhysics2D/ChipmunkPhysWorld2D.hpp>
|
||||
#include <Nazara/ChipmunkPhysics2D/ChipmunkRigidBody2D.hpp>
|
||||
#include <NazaraUtils/MovablePtr.hpp>
|
||||
#include <vector>
|
||||
|
||||
struct cpConstraint;
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
class ChipmunkConstraint2D;
|
||||
|
||||
using ChipmunkConstraint2DHandle = ObjectHandle<ChipmunkConstraint2D>;
|
||||
|
||||
class NAZARA_CHIPMUNKPHYSICS2D_API ChipmunkConstraint2D : public HandledObject<ChipmunkConstraint2D>
|
||||
{
|
||||
public:
|
||||
ChipmunkConstraint2D(const ChipmunkConstraint2D&) = delete;
|
||||
ChipmunkConstraint2D(ChipmunkConstraint2D&& rhs);
|
||||
virtual ~ChipmunkConstraint2D();
|
||||
|
||||
void EnableBodyCollision(bool enable);
|
||||
|
||||
ChipmunkRigidBody2D& GetBodyA();
|
||||
const ChipmunkRigidBody2D& GetBodyA() const;
|
||||
ChipmunkRigidBody2D& GetBodyB();
|
||||
const ChipmunkRigidBody2D& GetBodyB() const;
|
||||
float GetErrorBias() const;
|
||||
float GetLastImpulse() const;
|
||||
float GetMaxBias() const;
|
||||
float GetMaxForce() const;
|
||||
ChipmunkPhysWorld2D& GetWorld();
|
||||
const ChipmunkPhysWorld2D& GetWorld() const;
|
||||
|
||||
bool IsBodyCollisionEnabled() const;
|
||||
|
||||
void SetErrorBias(float bias);
|
||||
void SetMaxBias(float bias);
|
||||
void SetMaxForce(float force);
|
||||
|
||||
ChipmunkConstraint2D& operator=(const ChipmunkConstraint2D&) = delete;
|
||||
ChipmunkConstraint2D& operator=(ChipmunkConstraint2D&& rhs);
|
||||
|
||||
protected:
|
||||
ChipmunkConstraint2D(ChipmunkPhysWorld2D* world, cpConstraint* constraint);
|
||||
|
||||
MovablePtr<cpConstraint> m_constraint;
|
||||
};
|
||||
|
||||
class ChipmunkDampedSpringConstraint2D;
|
||||
|
||||
using ChipmunkDampedSpringConstraint2DHandle = ObjectHandle<ChipmunkDampedSpringConstraint2D>;
|
||||
|
||||
class NAZARA_CHIPMUNKPHYSICS2D_API ChipmunkDampedSpringConstraint2D : public ChipmunkConstraint2D
|
||||
{
|
||||
public:
|
||||
ChipmunkDampedSpringConstraint2D(ChipmunkRigidBody2D& first, ChipmunkRigidBody2D& second, const Vector2f& firstAnchor, const Vector2f& secondAnchor, float restLength, float stiffness, float damping);
|
||||
~ChipmunkDampedSpringConstraint2D() = default;
|
||||
|
||||
float GetDamping() const;
|
||||
Vector2f GetFirstAnchor() const;
|
||||
float GetRestLength() const;
|
||||
Vector2f GetSecondAnchor() const;
|
||||
float GetStiffness() const;
|
||||
|
||||
void SetDamping(float newDamping);
|
||||
void SetFirstAnchor(const Vector2f& firstAnchor);
|
||||
void SetRestLength(float newLength);
|
||||
void SetSecondAnchor(const Vector2f& firstAnchor);
|
||||
void SetStiffness(float newStiffness);
|
||||
};
|
||||
|
||||
class ChipmunkDampedRotarySpringConstraint2D;
|
||||
|
||||
using ChipmunkDampedRotarySpringConstraint2DHandle = ObjectHandle<ChipmunkDampedRotarySpringConstraint2D>;
|
||||
|
||||
class NAZARA_CHIPMUNKPHYSICS2D_API ChipmunkDampedRotarySpringConstraint2D : public ChipmunkConstraint2D
|
||||
{
|
||||
public:
|
||||
ChipmunkDampedRotarySpringConstraint2D(ChipmunkRigidBody2D& first, ChipmunkRigidBody2D& second, const RadianAnglef& restAngle, float stiffness, float damping);
|
||||
~ChipmunkDampedRotarySpringConstraint2D() = default;
|
||||
|
||||
float GetDamping() const;
|
||||
RadianAnglef GetRestAngle() const;
|
||||
float GetStiffness() const;
|
||||
|
||||
void SetDamping(float newDamping);
|
||||
void SetRestAngle(const RadianAnglef& newAngle);
|
||||
void SetStiffness(float newStiffness);
|
||||
};
|
||||
|
||||
class ChipmunkGearConstraint2D;
|
||||
|
||||
using ChipmunkGearConstraint2DHandle = ObjectHandle<ChipmunkGearConstraint2D>;
|
||||
|
||||
class NAZARA_CHIPMUNKPHYSICS2D_API ChipmunkGearConstraint2D : public ChipmunkConstraint2D
|
||||
{
|
||||
public:
|
||||
ChipmunkGearConstraint2D(ChipmunkRigidBody2D& first, ChipmunkRigidBody2D& second, float phase, float ratio);
|
||||
~ChipmunkGearConstraint2D() = default;
|
||||
|
||||
float GetPhase() const;
|
||||
float GetRatio() const;
|
||||
|
||||
void SetPhase(float phase);
|
||||
void SetRatio(float ratio);
|
||||
};
|
||||
|
||||
class ChipmunkMotorConstraint2D;
|
||||
|
||||
using ChipmunkMotorConstraint2DHandle = ObjectHandle<ChipmunkMotorConstraint2D>;
|
||||
|
||||
class NAZARA_CHIPMUNKPHYSICS2D_API ChipmunkMotorConstraint2D : public ChipmunkConstraint2D
|
||||
{
|
||||
public:
|
||||
ChipmunkMotorConstraint2D(ChipmunkRigidBody2D& first, ChipmunkRigidBody2D& second, float rate);
|
||||
~ChipmunkMotorConstraint2D() = default;
|
||||
|
||||
float GetRate() const;
|
||||
void SetRate(float rate);
|
||||
};
|
||||
|
||||
class ChipmunkPinConstraint2D;
|
||||
|
||||
using ChipmunkPinConstraint2DHandle = ObjectHandle<ChipmunkPinConstraint2D>;
|
||||
|
||||
class NAZARA_CHIPMUNKPHYSICS2D_API ChipmunkPinConstraint2D : public ChipmunkConstraint2D
|
||||
{
|
||||
public:
|
||||
ChipmunkPinConstraint2D(ChipmunkRigidBody2D& first, ChipmunkRigidBody2D& second, const Vector2f& firstAnchor, const Vector2f& secondAnchor);
|
||||
~ChipmunkPinConstraint2D() = default;
|
||||
|
||||
float GetDistance() const;
|
||||
Vector2f GetFirstAnchor() const;
|
||||
Vector2f GetSecondAnchor() const;
|
||||
|
||||
void SetDistance(float newDistance);
|
||||
void SetFirstAnchor(const Vector2f& firstAnchor);
|
||||
void SetSecondAnchor(const Vector2f& firstAnchor);
|
||||
};
|
||||
|
||||
class ChipmunkPivotConstraint2D;
|
||||
|
||||
using ChipmunkPivotConstraint2DHandle = ObjectHandle<ChipmunkPivotConstraint2D>;
|
||||
|
||||
class NAZARA_CHIPMUNKPHYSICS2D_API ChipmunkPivotConstraint2D : public ChipmunkConstraint2D
|
||||
{
|
||||
public:
|
||||
ChipmunkPivotConstraint2D(ChipmunkRigidBody2D& first, ChipmunkRigidBody2D& second, const Vector2f& anchor);
|
||||
ChipmunkPivotConstraint2D(ChipmunkRigidBody2D& first, ChipmunkRigidBody2D& second, const Vector2f& firstAnchor, const Vector2f& secondAnchor);
|
||||
~ChipmunkPivotConstraint2D() = default;
|
||||
|
||||
Vector2f GetFirstAnchor() const;
|
||||
Vector2f GetSecondAnchor() const;
|
||||
|
||||
void SetFirstAnchor(const Vector2f& firstAnchor);
|
||||
void SetSecondAnchor(const Vector2f& firstAnchor);
|
||||
};
|
||||
|
||||
class ChipmunkRatchetConstraint2D;
|
||||
|
||||
using ChipmunkRatchetConstraint2DHandle = ObjectHandle<ChipmunkRatchetConstraint2D>;
|
||||
|
||||
class NAZARA_CHIPMUNKPHYSICS2D_API ChipmunkRatchetConstraint2D : public ChipmunkConstraint2D
|
||||
{
|
||||
public:
|
||||
ChipmunkRatchetConstraint2D(ChipmunkRigidBody2D& first, ChipmunkRigidBody2D& second, float phase, float ratchet);
|
||||
~ChipmunkRatchetConstraint2D() = default;
|
||||
|
||||
RadianAnglef GetAngle() const;
|
||||
float GetPhase() const;
|
||||
float GetRatchet() const;
|
||||
|
||||
void SetAngle(const RadianAnglef& angle);
|
||||
void SetPhase(float phase);
|
||||
void SetRatchet(float ratchet);
|
||||
};
|
||||
|
||||
class ChipmunkRotaryLimitConstraint2D;
|
||||
|
||||
using ChipmunkRotaryLimitConstraint2DHandle = ObjectHandle<ChipmunkRotaryLimitConstraint2D>;
|
||||
|
||||
class NAZARA_CHIPMUNKPHYSICS2D_API ChipmunkRotaryLimitConstraint2D : public ChipmunkConstraint2D
|
||||
{
|
||||
public:
|
||||
ChipmunkRotaryLimitConstraint2D(ChipmunkRigidBody2D& first, ChipmunkRigidBody2D& second, const RadianAnglef& minAngle, const RadianAnglef& maxAngle);
|
||||
~ChipmunkRotaryLimitConstraint2D() = default;
|
||||
|
||||
RadianAnglef GetMaxAngle() const;
|
||||
RadianAnglef GetMinAngle() const;
|
||||
|
||||
void SetMaxAngle(const RadianAnglef& maxAngle);
|
||||
void SetMinAngle(const RadianAnglef& minAngle);
|
||||
};
|
||||
|
||||
class ChipmunkSlideConstraint2D;
|
||||
|
||||
using ChipmunkSlideConstraint2DHandle = ObjectHandle<ChipmunkSlideConstraint2D>;
|
||||
|
||||
class NAZARA_CHIPMUNKPHYSICS2D_API ChipmunkSlideConstraint2D : public ChipmunkConstraint2D
|
||||
{
|
||||
public:
|
||||
ChipmunkSlideConstraint2D(ChipmunkRigidBody2D& first, ChipmunkRigidBody2D& second, const Vector2f& firstAnchor, const Vector2f& secondAnchor, float min, float max);
|
||||
~ChipmunkSlideConstraint2D() = default;
|
||||
|
||||
Vector2f GetFirstAnchor() const;
|
||||
float GetMaxDistance() const;
|
||||
float GetMinDistance() const;
|
||||
Vector2f GetSecondAnchor() const;
|
||||
|
||||
void SetFirstAnchor(const Vector2f& firstAnchor);
|
||||
void SetMaxDistance(float newMaxDistance);
|
||||
void SetMinDistance(float newMinDistance);
|
||||
void SetSecondAnchor(const Vector2f& firstAnchor);
|
||||
};
|
||||
}
|
||||
|
||||
#include <Nazara/ChipmunkPhysics2D/ChipmunkConstraint2D.inl>
|
||||
|
||||
#endif // NAZARA_CHIPMUNKPHYSICS2D_CONSTRAINT2D_HPP
|
||||
12
include/Nazara/ChipmunkPhysics2D/ChipmunkConstraint2D.inl
Normal file
12
include/Nazara/ChipmunkPhysics2D/ChipmunkConstraint2D.inl
Normal file
@@ -0,0 +1,12 @@
|
||||
// Copyright (C) 2023 Jérôme "Lynix" Leclercq (lynix680@gmail.com)
|
||||
// This file is part of the "Nazara Engine - Physics2D module"
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#include <memory>
|
||||
#include <Nazara/ChipmunkPhysics2D/Debug.hpp>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
}
|
||||
|
||||
#include <Nazara/ChipmunkPhysics2D/DebugOff.hpp>
|
||||
166
include/Nazara/ChipmunkPhysics2D/ChipmunkPhysWorld2D.hpp
Normal file
166
include/Nazara/ChipmunkPhysics2D/ChipmunkPhysWorld2D.hpp
Normal file
@@ -0,0 +1,166 @@
|
||||
// Copyright (C) 2023 Jérôme "Lynix" Leclercq (lynix680@gmail.com)
|
||||
// This file is part of the "Nazara Engine - Physics2D module"
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifndef NAZARA_CHIPMUNKPHYSICS2D_PHYSWORLD2D_HPP
|
||||
#define NAZARA_CHIPMUNKPHYSICS2D_PHYSWORLD2D_HPP
|
||||
|
||||
#include <NazaraUtils/Prerequisites.hpp>
|
||||
#include <Nazara/Core/Color.hpp>
|
||||
#include <Nazara/Core/Time.hpp>
|
||||
#include <Nazara/Math/Angle.hpp>
|
||||
#include <Nazara/Math/Vector2.hpp>
|
||||
#include <Nazara/ChipmunkPhysics2D/Config.hpp>
|
||||
#include <Nazara/ChipmunkPhysics2D/ChipmunkRigidBody2D.hpp>
|
||||
#include <NazaraUtils/FunctionRef.hpp>
|
||||
#include <NazaraUtils/Signal.hpp>
|
||||
#include <functional>
|
||||
#include <memory>
|
||||
#include <unordered_map>
|
||||
|
||||
struct cpCollisionHandler;
|
||||
struct cpSpace;
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
class ChipmunkArbiter2D;
|
||||
|
||||
class NAZARA_CHIPMUNKPHYSICS2D_API ChipmunkPhysWorld2D
|
||||
{
|
||||
friend ChipmunkRigidBody2D;
|
||||
|
||||
using ContactEndCallback = std::function<void(ChipmunkPhysWorld2D& world, ChipmunkArbiter2D& arbiter, ChipmunkRigidBody2D& bodyA, ChipmunkRigidBody2D& bodyB, void* userdata)>;
|
||||
using ContactPreSolveCallback = std::function<bool(ChipmunkPhysWorld2D& world, ChipmunkArbiter2D& arbiter, ChipmunkRigidBody2D& bodyA, ChipmunkRigidBody2D& bodyB, void* userdata)>;
|
||||
using ContactPostSolveCallback = std::function<void(ChipmunkPhysWorld2D& world, ChipmunkArbiter2D& arbiter, ChipmunkRigidBody2D& bodyA, ChipmunkRigidBody2D& bodyB, void* userdata)>;
|
||||
using ContactStartCallback = std::function<bool(ChipmunkPhysWorld2D& world, ChipmunkArbiter2D& arbiter, ChipmunkRigidBody2D& bodyA, ChipmunkRigidBody2D& bodyB, void* userdata)>;
|
||||
|
||||
using DebugDrawCircleCallback = std::function<void(const Vector2f& origin, const RadianAnglef& rotation, float radius, const Color& outlineColor, const Color& fillColor, void* userdata)>;
|
||||
using DebugDrawDotCallback = std::function<void(const Vector2f& origin, float radius, const Color& color, void* userdata)>;
|
||||
using DebugDrawPolygonCallback = std::function<void(const Vector2f* vertices, std::size_t vertexCount, float radius, const Color& outlineColor, const Color& fillColor, void* userdata)>;
|
||||
using DebugDrawSegmentCallback = std::function<void(const Vector2f& first, const Vector2f& second, const Color& color, void* userdata)>;
|
||||
using DebugDrawTickSegmentCallback = std::function<void(const Vector2f& first, const Vector2f& second, float thickness, const Color& outlineColor, const Color& fillColor, void* userdata)>;
|
||||
using DebugDrawGetColorCallback = std::function<Color(ChipmunkRigidBody2D& body, std::size_t shapeIndex, void* userdata)>;
|
||||
|
||||
public:
|
||||
struct Callback;
|
||||
struct DebugDrawOptions;
|
||||
struct NearestQueryResult;
|
||||
struct RaycastHit;
|
||||
|
||||
ChipmunkPhysWorld2D();
|
||||
ChipmunkPhysWorld2D(const ChipmunkPhysWorld2D&) = delete;
|
||||
ChipmunkPhysWorld2D(ChipmunkPhysWorld2D&&) = delete; ///TODO
|
||||
~ChipmunkPhysWorld2D();
|
||||
|
||||
void DebugDraw(const DebugDrawOptions& options, bool drawShapes = true, bool drawConstraints = true, bool drawCollisions = true);
|
||||
|
||||
float GetDamping() const;
|
||||
Vector2f GetGravity() const;
|
||||
cpSpace* GetHandle() const;
|
||||
std::size_t GetIterationCount() const;
|
||||
std::size_t GetMaxStepCount() const;
|
||||
Time GetStepSize() const;
|
||||
|
||||
bool NearestBodyQuery(const Vector2f& from, float maxDistance, UInt32 collisionGroup, UInt32 categoryMask, UInt32 collisionMask, ChipmunkRigidBody2D** nearestBody = nullptr);
|
||||
bool NearestBodyQuery(const Vector2f& from, float maxDistance, UInt32 collisionGroup, UInt32 categoryMask, UInt32 collisionMask, NearestQueryResult* result);
|
||||
|
||||
void RaycastQuery(const Vector2f& from, const Vector2f& to, float radius, UInt32 collisionGroup, UInt32 categoryMask, UInt32 collisionMask, const FunctionRef<void(const RaycastHit&)>& callback);
|
||||
bool RaycastQuery(const Vector2f& from, const Vector2f& to, float radius, UInt32 collisionGroup, UInt32 categoryMask, UInt32 collisionMask, std::vector<RaycastHit>* hitInfos);
|
||||
bool RaycastQueryFirst(const Vector2f& from, const Vector2f& to, float radius, UInt32 collisionGroup, UInt32 categoryMask, UInt32 collisionMask, RaycastHit* hitInfo = nullptr);
|
||||
|
||||
void RegionQuery(const Rectf& boundingBox, UInt32 collisionGroup, UInt32 categoryMask, UInt32 collisionMask, const FunctionRef<void(ChipmunkRigidBody2D*)>& callback);
|
||||
void RegionQuery(const Rectf& boundingBox, UInt32 collisionGroup, UInt32 categoryMask, UInt32 collisionMask, std::vector<ChipmunkRigidBody2D*>* bodies);
|
||||
|
||||
void RegisterCallbacks(unsigned int collisionId, Callback callbacks);
|
||||
void RegisterCallbacks(unsigned int collisionIdA, unsigned int collisionIdB, Callback callbacks);
|
||||
|
||||
void SetDamping(float dampingValue);
|
||||
void SetGravity(const Vector2f& gravity);
|
||||
void SetIterationCount(std::size_t iterationCount);
|
||||
void SetMaxStepCount(std::size_t maxStepCount);
|
||||
void SetSleepTime(Time sleepTime);
|
||||
void SetStepSize(Time stepSize);
|
||||
|
||||
void Step(Time timestep);
|
||||
|
||||
void UseSpatialHash(float cellSize, std::size_t entityCount);
|
||||
|
||||
ChipmunkPhysWorld2D& operator=(const ChipmunkPhysWorld2D&) = delete;
|
||||
ChipmunkPhysWorld2D& operator=(ChipmunkPhysWorld2D&&) = delete; ///TODO
|
||||
|
||||
struct Callback
|
||||
{
|
||||
ContactEndCallback endCallback = nullptr;
|
||||
ContactPreSolveCallback preSolveCallback = nullptr;
|
||||
ContactPostSolveCallback postSolveCallback = nullptr;
|
||||
ContactStartCallback startCallback = nullptr;
|
||||
void* userdata = nullptr;
|
||||
};
|
||||
|
||||
struct DebugDrawOptions
|
||||
{
|
||||
Color constraintColor;
|
||||
Color collisionPointColor;
|
||||
Color shapeOutlineColor;
|
||||
|
||||
DebugDrawCircleCallback circleCallback;
|
||||
DebugDrawGetColorCallback colorCallback;
|
||||
DebugDrawDotCallback dotCallback;
|
||||
DebugDrawPolygonCallback polygonCallback;
|
||||
DebugDrawSegmentCallback segmentCallback;
|
||||
DebugDrawTickSegmentCallback thickSegmentCallback;
|
||||
|
||||
void* userdata;
|
||||
};
|
||||
|
||||
struct NearestQueryResult
|
||||
{
|
||||
ChipmunkRigidBody2D* nearestBody;
|
||||
Vector2f closestPoint;
|
||||
Vector2f fraction;
|
||||
float distance;
|
||||
};
|
||||
|
||||
struct RaycastHit
|
||||
{
|
||||
ChipmunkRigidBody2D* nearestBody;
|
||||
Vector2f hitPos;
|
||||
Vector2f hitNormal;
|
||||
float fraction;
|
||||
};
|
||||
|
||||
NazaraSignal(OnPhysWorld2DPreStep, const ChipmunkPhysWorld2D* /*physWorld*/, float /*invStepCount*/);
|
||||
NazaraSignal(OnPhysWorld2DPostStep, const ChipmunkPhysWorld2D* /*physWorld*/, float /*invStepCount*/);
|
||||
|
||||
private:
|
||||
void InitCallbacks(cpCollisionHandler* handler, Callback callbacks);
|
||||
|
||||
using PostStep = std::function<void(ChipmunkRigidBody2D* body)>;
|
||||
|
||||
void OnRigidBodyMoved(ChipmunkRigidBody2D* oldPointer, ChipmunkRigidBody2D* newPointer);
|
||||
void OnRigidBodyRelease(ChipmunkRigidBody2D* rigidBody);
|
||||
|
||||
void RegisterPostStep(ChipmunkRigidBody2D* rigidBody, PostStep&& func);
|
||||
|
||||
struct PostStepContainer
|
||||
{
|
||||
NazaraSlot(ChipmunkRigidBody2D, OnRigidBody2DMove, onMovedSlot);
|
||||
NazaraSlot(ChipmunkRigidBody2D, OnRigidBody2DRelease, onReleaseSlot);
|
||||
|
||||
std::vector<PostStep> funcs;
|
||||
};
|
||||
|
||||
static_assert(std::is_nothrow_move_constructible<PostStepContainer>::value, "PostStepContainer should be noexcept MoveConstructible");
|
||||
|
||||
std::size_t m_maxStepCount;
|
||||
std::unordered_map<cpCollisionHandler*, std::unique_ptr<Callback>> m_callbacks;
|
||||
std::unordered_map<ChipmunkRigidBody2D*, PostStepContainer> m_rigidPostSteps;
|
||||
cpSpace* m_handle;
|
||||
Time m_stepSize;
|
||||
Time m_timestepAccumulator;
|
||||
};
|
||||
}
|
||||
|
||||
#endif // NAZARA_CHIPMUNKPHYSICS2D_PHYSWORLD2D_HPP
|
||||
33
include/Nazara/ChipmunkPhysics2D/ChipmunkPhysics2D.hpp
Normal file
33
include/Nazara/ChipmunkPhysics2D/ChipmunkPhysics2D.hpp
Normal file
@@ -0,0 +1,33 @@
|
||||
// Copyright (C) 2023 Jérôme "Lynix" Leclercq (lynix680@gmail.com)
|
||||
// This file is part of the "Nazara Engine - Physics2D module"
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifndef NAZARA_CHIPMUNKPHYSICS2D_HPP
|
||||
#define NAZARA_CHIPMUNKPHYSICS2D_HPP
|
||||
|
||||
#include <NazaraUtils/Prerequisites.hpp>
|
||||
#include <Nazara/Core/Core.hpp>
|
||||
#include <Nazara/ChipmunkPhysics2D/Config.hpp>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
class NAZARA_CHIPMUNKPHYSICS2D_API ChipmunkPhysics2D : public ModuleBase<ChipmunkPhysics2D>
|
||||
{
|
||||
friend ModuleBase;
|
||||
|
||||
public:
|
||||
using Dependencies = TypeList<Core>;
|
||||
|
||||
struct Config {};
|
||||
|
||||
ChipmunkPhysics2D(Config /*config*/);
|
||||
~ChipmunkPhysics2D() = default;
|
||||
|
||||
private:
|
||||
static ChipmunkPhysics2D* s_instance;
|
||||
};
|
||||
}
|
||||
|
||||
#endif // NAZARA_CHIPMUNKPHYSICS2D_HPP
|
||||
143
include/Nazara/ChipmunkPhysics2D/ChipmunkRigidBody2D.hpp
Normal file
143
include/Nazara/ChipmunkPhysics2D/ChipmunkRigidBody2D.hpp
Normal file
@@ -0,0 +1,143 @@
|
||||
// Copyright (C) 2023 Jérôme "Lynix" Leclercq (lynix680@gmail.com)
|
||||
// This file is part of the "Nazara Engine - Physics2D module"
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifndef NAZARA_CHIPMUNKPHYSICS2D_RIGIDBODY2D_HPP
|
||||
#define NAZARA_CHIPMUNKPHYSICS2D_RIGIDBODY2D_HPP
|
||||
|
||||
#include <NazaraUtils/Prerequisites.hpp>
|
||||
#include <Nazara/Core/Enums.hpp>
|
||||
#include <Nazara/Math/Angle.hpp>
|
||||
#include <Nazara/Math/Rect.hpp>
|
||||
#include <Nazara/ChipmunkPhysics2D/ChipmunkCollider2D.hpp>
|
||||
#include <Nazara/ChipmunkPhysics2D/Config.hpp>
|
||||
#include <NazaraUtils/Signal.hpp>
|
||||
#include <functional>
|
||||
#include <limits>
|
||||
|
||||
struct cpBody;
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
class ChipmunkArbiter2D;
|
||||
class ChipmunkPhysWorld2D;
|
||||
|
||||
class NAZARA_CHIPMUNKPHYSICS2D_API ChipmunkRigidBody2D
|
||||
{
|
||||
public:
|
||||
using VelocityFunc = std::function<void(ChipmunkRigidBody2D& body2D, const Vector2f& gravity, float damping, float deltaTime)>;
|
||||
|
||||
ChipmunkRigidBody2D(ChipmunkPhysWorld2D* world, float mass);
|
||||
ChipmunkRigidBody2D(ChipmunkPhysWorld2D* world, float mass, std::shared_ptr<ChipmunkCollider2D> geom);
|
||||
ChipmunkRigidBody2D(const ChipmunkRigidBody2D& object);
|
||||
ChipmunkRigidBody2D(ChipmunkRigidBody2D&& object) noexcept;
|
||||
~ChipmunkRigidBody2D();
|
||||
|
||||
void AddForce(const Vector2f& force, CoordSys coordSys = CoordSys::Global);
|
||||
void AddForce(const Vector2f& force, const Vector2f& point, CoordSys coordSys = CoordSys::Global);
|
||||
void AddImpulse(const Vector2f& impulse, CoordSys coordSys = CoordSys::Global);
|
||||
void AddImpulse(const Vector2f& impulse, const Vector2f& point, CoordSys coordSys = CoordSys::Global);
|
||||
void AddTorque(const RadianAnglef& torque);
|
||||
|
||||
bool ClosestPointQuery(const Vector2f& position, Vector2f* closestPoint = nullptr, float* closestDistance = nullptr) const;
|
||||
|
||||
void EnableSimulation(bool simulation);
|
||||
|
||||
void ForEachArbiter(std::function<void(ChipmunkArbiter2D& /*arbiter*/)> callback);
|
||||
void ForceSleep();
|
||||
|
||||
Rectf GetAABB() const;
|
||||
inline float GetAngularDamping() const;
|
||||
RadianAnglef GetAngularVelocity() const;
|
||||
NAZARA_DEPRECATED("Name error, please use GetMassCenter")
|
||||
inline Vector2f GetCenterOfGravity(CoordSys coordSys = CoordSys::Local) const;
|
||||
float GetElasticity(std::size_t shapeIndex = 0) const;
|
||||
float GetFriction(std::size_t shapeIndex = 0) const;
|
||||
const std::shared_ptr<ChipmunkCollider2D>& GetGeom() const;
|
||||
cpBody* GetHandle() const;
|
||||
float GetMass() const;
|
||||
Vector2f GetMassCenter(CoordSys coordSys = CoordSys::Local) const;
|
||||
float GetMomentOfInertia() const;
|
||||
Vector2f GetPosition() const;
|
||||
inline const Vector2f& GetPositionOffset() const;
|
||||
RadianAnglef GetRotation() const;
|
||||
inline std::size_t GetShapeCount() const;
|
||||
std::size_t GetShapeIndex(cpShape* shape) const;
|
||||
Vector2f GetSurfaceVelocity(std::size_t shapeIndex = 0) const;
|
||||
void* GetUserdata() const;
|
||||
Vector2f GetVelocity() const;
|
||||
const VelocityFunc& GetVelocityFunction() const;
|
||||
ChipmunkPhysWorld2D* GetWorld() const;
|
||||
|
||||
bool IsKinematic() const;
|
||||
bool IsSimulationEnabled() const;
|
||||
bool IsSleeping() const;
|
||||
bool IsStatic() const;
|
||||
|
||||
void ResetVelocityFunction();
|
||||
|
||||
inline void SetAngularDamping(float angularDamping);
|
||||
void SetAngularVelocity(const RadianAnglef& angularVelocity);
|
||||
void SetElasticity(float elasticity);
|
||||
void SetElasticity(std::size_t shapeIndex, float elasticity);
|
||||
void SetFriction(float friction);
|
||||
void SetFriction(std::size_t shapeIndex, float friction);
|
||||
void SetGeom(std::shared_ptr<ChipmunkCollider2D> geom, bool recomputeMoment = true, bool recomputeMassCenter = true);
|
||||
void SetMass(float mass, bool recomputeMoment = true);
|
||||
void SetMassCenter(const Vector2f& center, CoordSys coordSys = CoordSys::Local);
|
||||
void SetMomentOfInertia(float moment);
|
||||
void SetPosition(const Vector2f& position);
|
||||
void SetPositionOffset(const Vector2f& offset);
|
||||
void SetRotation(const RadianAnglef& rotation);
|
||||
void SetSurfaceVelocity(const Vector2f& surfaceVelocity);
|
||||
void SetSurfaceVelocity(std::size_t shapeIndex, const Vector2f& surfaceVelocity);
|
||||
void SetStatic(bool setStaticBody = true);
|
||||
void SetUserdata(void* ud);
|
||||
void SetVelocity(const Vector2f& velocity);
|
||||
void SetVelocityFunction(VelocityFunc velocityFunc);
|
||||
|
||||
void TeleportTo(const Vector2f& position, const RadianAnglef& rotation);
|
||||
|
||||
void UpdateVelocity(const Vector2f& gravity, float damping, float deltaTime);
|
||||
|
||||
void Wakeup();
|
||||
|
||||
ChipmunkRigidBody2D& operator=(const ChipmunkRigidBody2D& object);
|
||||
ChipmunkRigidBody2D& operator=(ChipmunkRigidBody2D&& object);
|
||||
|
||||
NazaraSignal(OnRigidBody2DMove, ChipmunkRigidBody2D* /*oldPointer*/, ChipmunkRigidBody2D* /*newPointer*/);
|
||||
NazaraSignal(OnRigidBody2DRelease, ChipmunkRigidBody2D* /*rigidBody*/);
|
||||
|
||||
static constexpr std::size_t InvalidShapeIndex = std::numeric_limits<std::size_t>::max();
|
||||
|
||||
protected:
|
||||
void Destroy();
|
||||
|
||||
private:
|
||||
cpBody* Create(float mass = 1.f, float moment = 1.f);
|
||||
void RegisterToSpace();
|
||||
void UnregisterFromSpace();
|
||||
|
||||
static void CopyBodyData(cpBody* from, cpBody* to);
|
||||
static void CopyShapeData(cpShape* from, cpShape* to);
|
||||
|
||||
Vector2f m_positionOffset;
|
||||
VelocityFunc m_velocityFunc;
|
||||
std::vector<cpShape*> m_shapes;
|
||||
std::shared_ptr<ChipmunkCollider2D> m_geom;
|
||||
cpBody* m_handle;
|
||||
void* m_userData;
|
||||
ChipmunkPhysWorld2D* m_world;
|
||||
bool m_isRegistered;
|
||||
bool m_isSimulationEnabled;
|
||||
bool m_isStatic;
|
||||
float m_gravityFactor;
|
||||
float m_mass;
|
||||
};
|
||||
}
|
||||
|
||||
#include <Nazara/ChipmunkPhysics2D/ChipmunkRigidBody2D.inl>
|
||||
|
||||
#endif // NAZARA_CHIPMUNKPHYSICS2D_RIGIDBODY2D_HPP
|
||||
35
include/Nazara/ChipmunkPhysics2D/ChipmunkRigidBody2D.inl
Normal file
35
include/Nazara/ChipmunkPhysics2D/ChipmunkRigidBody2D.inl
Normal file
@@ -0,0 +1,35 @@
|
||||
// Copyright (C) 2023 Jérôme "Lynix" Leclercq (lynix680@gmail.com)
|
||||
// This file is part of the "Nazara Engine - Physics2D module"
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#include <Nazara/ChipmunkPhysics2D/Debug.hpp>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
inline float ChipmunkRigidBody2D::GetAngularDamping() const
|
||||
{
|
||||
return GetMomentOfInertia();
|
||||
}
|
||||
|
||||
inline Vector2f ChipmunkRigidBody2D::GetCenterOfGravity(CoordSys coordSys) const
|
||||
{
|
||||
return GetMassCenter(coordSys);
|
||||
}
|
||||
|
||||
inline const Vector2f& ChipmunkRigidBody2D::GetPositionOffset() const
|
||||
{
|
||||
return m_positionOffset;
|
||||
}
|
||||
|
||||
inline std::size_t ChipmunkRigidBody2D::GetShapeCount() const
|
||||
{
|
||||
return m_shapes.size();
|
||||
}
|
||||
|
||||
inline void ChipmunkRigidBody2D::SetAngularDamping(float angularDamping)
|
||||
{
|
||||
SetMomentOfInertia(angularDamping);
|
||||
}
|
||||
}
|
||||
|
||||
#include <Nazara/ChipmunkPhysics2D/DebugOff.hpp>
|
||||
34
include/Nazara/ChipmunkPhysics2D/Components.hpp
Normal file
34
include/Nazara/ChipmunkPhysics2D/Components.hpp
Normal file
@@ -0,0 +1,34 @@
|
||||
// this file was automatically generated and should not be edited
|
||||
|
||||
/*
|
||||
Nazara Engine - Physics2D module
|
||||
|
||||
Copyright (C) 2023 Jérôme "Lynix" Leclercq (lynix680@gmail.com)
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
||||
this software and associated documentation files (the "Software"), to deal in
|
||||
the Software without restriction, including without limitation the rights to
|
||||
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
|
||||
of the Software, and to permit persons to whom the Software is furnished to do
|
||||
so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifndef NAZARA_CHIPMUNKPHYSICS2D_COMPONENTS_HPP
|
||||
#define NAZARA_CHIPMUNKPHYSICS2D_COMPONENTS_HPP
|
||||
|
||||
#include <Nazara/ChipmunkPhysics2D/Components/ChipmunkRigidBody2DComponent.hpp>
|
||||
|
||||
#endif // NAZARA_CHIPMUNKPHYSICS2D_COMPONENTS_HPP
|
||||
@@ -0,0 +1,32 @@
|
||||
// Copyright (C) 2023 Jérôme "Lynix" Leclercq (lynix680@gmail.com)
|
||||
// This file is part of the "Nazara Engine - Physics2D module"
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifndef NAZARA_CHIPMUNKPHYSICS2D_COMPONENTS_RIGIDBODY2DCOMPONENT_HPP
|
||||
#define NAZARA_CHIPMUNKPHYSICS2D_COMPONENTS_RIGIDBODY2DCOMPONENT_HPP
|
||||
|
||||
#include <NazaraUtils/Prerequisites.hpp>
|
||||
#include <Nazara/ChipmunkPhysics2D/ChipmunkRigidBody2D.hpp>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
class NAZARA_CHIPMUNKPHYSICS2D_API ChipmunkRigidBody2DComponent : public ChipmunkRigidBody2D
|
||||
{
|
||||
friend class ChipmunkPhysics2DSystem;
|
||||
|
||||
public:
|
||||
using ChipmunkRigidBody2D::ChipmunkRigidBody2D;
|
||||
ChipmunkRigidBody2DComponent(const ChipmunkRigidBody2DComponent&) = default;
|
||||
ChipmunkRigidBody2DComponent(ChipmunkRigidBody2DComponent&&) noexcept = default;
|
||||
~ChipmunkRigidBody2DComponent() = default;
|
||||
|
||||
ChipmunkRigidBody2DComponent& operator=(const ChipmunkRigidBody2DComponent&) = default;
|
||||
ChipmunkRigidBody2DComponent& operator=(ChipmunkRigidBody2DComponent&&) noexcept = default;
|
||||
};
|
||||
}
|
||||
|
||||
#include <Nazara/ChipmunkPhysics2D/Components/ChipmunkRigidBody2DComponent.inl>
|
||||
|
||||
#endif // NAZARA_CHIPMUNKPHYSICS2D_COMPONENTS_RIGIDBODY2DCOMPONENT_HPP
|
||||
@@ -0,0 +1,11 @@
|
||||
// Copyright (C) 2023 Jérôme "Lynix" Leclercq (lynix680@gmail.com)
|
||||
// This file is part of the "Nazara Engine - Physics2D module"
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#include <Nazara/ChipmunkPhysics2D/Debug.hpp>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
}
|
||||
|
||||
#include <Nazara/ChipmunkPhysics2D/DebugOff.hpp>
|
||||
48
include/Nazara/ChipmunkPhysics2D/Config.hpp
Normal file
48
include/Nazara/ChipmunkPhysics2D/Config.hpp
Normal file
@@ -0,0 +1,48 @@
|
||||
/*
|
||||
Nazara Engine - Physics2D module
|
||||
|
||||
Copyright (C) 2023 Jérôme "Lynix" Leclercq (lynix680@gmail.com)
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
||||
this software and associated documentation files (the "Software"), to deal in
|
||||
the Software without restriction, including without limitation the rights to
|
||||
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
|
||||
of the Software, and to permit persons to whom the Software is furnished to do
|
||||
so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifndef NAZARA_CHIPMUNKPHYSICS2D_CONFIG_HPP
|
||||
#define NAZARA_CHIPMUNKPHYSICS2D_CONFIG_HPP
|
||||
|
||||
/// Chaque modification d'un paramètre du module nécessite une recompilation de celui-ci
|
||||
|
||||
// Active les tests de sécurité basés sur le code (Conseillé pour le développement)
|
||||
#define NAZARA_CHIPMUNKPHYSICS2D_SAFE 1
|
||||
|
||||
/// Vérification des valeurs et types de certaines constantes
|
||||
#include <Nazara/ChipmunkPhysics2D/ConfigCheck.hpp>
|
||||
|
||||
#if defined(NAZARA_STATIC)
|
||||
#define NAZARA_CHIPMUNKPHYSICS2D_API
|
||||
#else
|
||||
#ifdef NAZARA_CHIPMUNKPHYSICS2D_BUILD
|
||||
#define NAZARA_CHIPMUNKPHYSICS2D_API NAZARA_EXPORT
|
||||
#else
|
||||
#define NAZARA_CHIPMUNKPHYSICS2D_API NAZARA_IMPORT
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#endif // NAZARA_CHIPMUNKPHYSICS2D_CONFIG_HPP
|
||||
19
include/Nazara/ChipmunkPhysics2D/ConfigCheck.hpp
Normal file
19
include/Nazara/ChipmunkPhysics2D/ConfigCheck.hpp
Normal file
@@ -0,0 +1,19 @@
|
||||
// Copyright (C) 2023 Jérôme "Lynix" Leclercq (lynix680@gmail.com)
|
||||
// This file is part of the "Nazara Engine - Physics2D module"
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifndef NAZARA_CHIPMUNKPHYSICS2D_CONFIGCHECK_HPP
|
||||
#define NAZARA_CHIPMUNKPHYSICS2D_CONFIGCHECK_HPP
|
||||
|
||||
/// This file is used to check the constant values defined in Config.hpp
|
||||
|
||||
#include <type_traits>
|
||||
#define NazaraCheckTypeAndVal(name, type, op, val, err) static_assert(std::is_ ##type <decltype(name)>::value && name op val, #type err)
|
||||
|
||||
// config checks
|
||||
|
||||
#undef NazaraCheckTypeAndVal
|
||||
|
||||
#endif // NAZARA_CHIPMUNKPHYSICS2D_CONFIGCHECK_HPP
|
||||
5
include/Nazara/ChipmunkPhysics2D/Debug.hpp
Normal file
5
include/Nazara/ChipmunkPhysics2D/Debug.hpp
Normal file
@@ -0,0 +1,5 @@
|
||||
// Copyright (C) 2023 Jérôme "Lynix" Leclercq (lynix680@gmail.com)
|
||||
// This file is part of the "Nazara Engine - Physics2D module"
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
// no header guards
|
||||
5
include/Nazara/ChipmunkPhysics2D/DebugOff.hpp
Normal file
5
include/Nazara/ChipmunkPhysics2D/DebugOff.hpp
Normal file
@@ -0,0 +1,5 @@
|
||||
// Copyright (C) 2023 Jérôme "Lynix" Leclercq (lynix680@gmail.com)
|
||||
// This file is part of the "Nazara Engine - Physics2D module"
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
// no header guards
|
||||
25
include/Nazara/ChipmunkPhysics2D/Enums.hpp
Normal file
25
include/Nazara/ChipmunkPhysics2D/Enums.hpp
Normal file
@@ -0,0 +1,25 @@
|
||||
// Copyright (C) 2023 Jérôme "Lynix" Leclercq (lynix680@gmail.com)
|
||||
// This file is part of the "Nazara Engine - Physics2D module"
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifndef NAZARA_CHIPMUNKPHYSICS2D_ENUMS_HPP
|
||||
#define NAZARA_CHIPMUNKPHYSICS2D_ENUMS_HPP
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
enum class ChipmunkColliderType2D
|
||||
{
|
||||
Box,
|
||||
Compound,
|
||||
Convex,
|
||||
Circle,
|
||||
Null,
|
||||
Segment,
|
||||
|
||||
Max = Segment
|
||||
};
|
||||
}
|
||||
|
||||
#endif // NAZARA_CHIPMUNKPHYSICS2D_ENUMS_HPP
|
||||
34
include/Nazara/ChipmunkPhysics2D/Systems.hpp
Normal file
34
include/Nazara/ChipmunkPhysics2D/Systems.hpp
Normal file
@@ -0,0 +1,34 @@
|
||||
// this file was automatically generated and should not be edited
|
||||
|
||||
/*
|
||||
Nazara Engine - Physics2D module
|
||||
|
||||
Copyright (C) 2023 Jérôme "Lynix" Leclercq (lynix680@gmail.com)
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
||||
this software and associated documentation files (the "Software"), to deal in
|
||||
the Software without restriction, including without limitation the rights to
|
||||
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
|
||||
of the Software, and to permit persons to whom the Software is furnished to do
|
||||
so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifndef NAZARA_CHIPMUNKPHYSICS2D_SYSTEMS_HPP
|
||||
#define NAZARA_CHIPMUNKPHYSICS2D_SYSTEMS_HPP
|
||||
|
||||
#include <Nazara/ChipmunkPhysics2D/Systems/ChipmunkPhysics2DSystem.hpp>
|
||||
|
||||
#endif // NAZARA_CHIPMUNKPHYSICS2D_SYSTEMS_HPP
|
||||
@@ -0,0 +1,50 @@
|
||||
// Copyright (C) 2023 Jérôme "Lynix" Leclercq (lynix680@gmail.com)
|
||||
// This file is part of the "Nazara Engine - Physics2D module"
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifndef NAZARA_CHIPMUNKPHYSICS2D_SYSTEMS_PHYSICS2DSYSTEM_HPP
|
||||
#define NAZARA_CHIPMUNKPHYSICS2D_SYSTEMS_PHYSICS2DSYSTEM_HPP
|
||||
|
||||
#include <NazaraUtils/Prerequisites.hpp>
|
||||
#include <Nazara/Core/Time.hpp>
|
||||
#include <Nazara/ChipmunkPhysics2D/ChipmunkPhysWorld2D.hpp>
|
||||
#include <Nazara/ChipmunkPhysics2D/Components/ChipmunkRigidBody2DComponent.hpp>
|
||||
#include <NazaraUtils/TypeList.hpp>
|
||||
#include <entt/entt.hpp>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
class NAZARA_CHIPMUNKPHYSICS2D_API ChipmunkPhysics2DSystem
|
||||
{
|
||||
public:
|
||||
static constexpr Int64 ExecutionOrder = 0;
|
||||
using Components = TypeList<ChipmunkRigidBody2DComponent, class NodeComponent>;
|
||||
|
||||
ChipmunkPhysics2DSystem(entt::registry& registry);
|
||||
ChipmunkPhysics2DSystem(const ChipmunkPhysics2DSystem&) = delete;
|
||||
ChipmunkPhysics2DSystem(ChipmunkPhysics2DSystem&&) = delete;
|
||||
~ChipmunkPhysics2DSystem();
|
||||
|
||||
template<typename... Args> ChipmunkRigidBody2DComponent CreateRigidBody(Args&&... args);
|
||||
|
||||
inline ChipmunkPhysWorld2D& GetPhysWorld();
|
||||
inline const ChipmunkPhysWorld2D& GetPhysWorld() const;
|
||||
|
||||
void Update(Time elapsedTime);
|
||||
|
||||
ChipmunkPhysics2DSystem& operator=(const ChipmunkPhysics2DSystem&) = delete;
|
||||
ChipmunkPhysics2DSystem& operator=(ChipmunkPhysics2DSystem&&) = delete;
|
||||
|
||||
private:
|
||||
entt::registry& m_registry;
|
||||
entt::observer m_physicsConstructObserver;
|
||||
entt::scoped_connection m_constructConnection;
|
||||
ChipmunkPhysWorld2D m_physWorld;
|
||||
};
|
||||
}
|
||||
|
||||
#include <Nazara/ChipmunkPhysics2D/Systems/ChipmunkPhysics2DSystem.inl>
|
||||
|
||||
#endif // NAZARA_CHIPMUNKPHYSICS2D_SYSTEMS_PHYSICS2DSYSTEM_HPP
|
||||
@@ -0,0 +1,26 @@
|
||||
// Copyright (C) 2023 Jérôme "Lynix" Leclercq (lynix680@gmail.com)
|
||||
// This file is part of the "Nazara Engine - Physics2D module"
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#include <Nazara/ChipmunkPhysics2D/Debug.hpp>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
template<typename... Args>
|
||||
ChipmunkRigidBody2DComponent ChipmunkPhysics2DSystem::CreateRigidBody(Args&&... args)
|
||||
{
|
||||
return ChipmunkRigidBody2DComponent(&m_physWorld, std::forward<Args>(args)...);
|
||||
}
|
||||
|
||||
inline ChipmunkPhysWorld2D& ChipmunkPhysics2DSystem::GetPhysWorld()
|
||||
{
|
||||
return m_physWorld;
|
||||
}
|
||||
|
||||
inline const ChipmunkPhysWorld2D& ChipmunkPhysics2DSystem::GetPhysWorld() const
|
||||
{
|
||||
return m_physWorld;
|
||||
}
|
||||
}
|
||||
|
||||
#include <Nazara/ChipmunkPhysics2D/DebugOff.hpp>
|
||||
Reference in New Issue
Block a user