Rename ChipmunkPhysics2D and JoltPhysics3D to Physics[2D|3D]
This commit is contained in:
@@ -1,48 +0,0 @@
|
||||
// this file was automatically generated and should not be edited
|
||||
|
||||
/*
|
||||
Nazara Engine - ChipmunkPhysics2D module
|
||||
|
||||
Copyright (C) 2024 Jérôme "SirLynix" 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_GLOBAL_CHIPMUNKPHYSICS2D_HPP
|
||||
#define NAZARA_GLOBAL_CHIPMUNKPHYSICS2D_HPP
|
||||
|
||||
#include <Nazara/ChipmunkPhysics2D/ChipmunkArbiter2D.hpp>
|
||||
#include <Nazara/ChipmunkPhysics2D/ChipmunkCollider2D.hpp>
|
||||
#include <Nazara/ChipmunkPhysics2D/ChipmunkConstraint2D.hpp>
|
||||
#include <Nazara/ChipmunkPhysics2D/ChipmunkPhysics2D.hpp>
|
||||
#include <Nazara/ChipmunkPhysics2D/ChipmunkPhysWorld2D.hpp>
|
||||
#include <Nazara/ChipmunkPhysics2D/ChipmunkRigidBody2D.hpp>
|
||||
#include <Nazara/ChipmunkPhysics2D/Config.hpp>
|
||||
#include <Nazara/ChipmunkPhysics2D/Enums.hpp>
|
||||
|
||||
#ifdef NAZARA_ENTT
|
||||
|
||||
#include <Nazara/ChipmunkPhysics2D/Components.hpp>
|
||||
#include <Nazara/ChipmunkPhysics2D/Systems.hpp>
|
||||
|
||||
#endif
|
||||
|
||||
#endif // NAZARA_GLOBAL_CHIPMUNKPHYSICS2D_HPP
|
||||
@@ -1,16 +0,0 @@
|
||||
// Copyright (C) 2024 Jérôme "SirLynix" Leclercq (lynix680@gmail.com)
|
||||
// This file is part of the "Nazara Engine - ChipmunkPhysics2D 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>
|
||||
@@ -1,196 +0,0 @@
|
||||
// Copyright (C) 2024 Jérôme "SirLynix" Leclercq (lynix680@gmail.com)
|
||||
// This file is part of the "Nazara Engine - ChipmunkPhysics2D 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>
|
||||
@@ -1,238 +0,0 @@
|
||||
// Copyright (C) 2024 Jérôme "SirLynix" Leclercq (lynix680@gmail.com)
|
||||
// This file is part of the "Nazara Engine - ChipmunkPhysics2D module"
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifndef NAZARA_CHIPMUNKPHYSICS2D_CHIPMUNKCONSTRAINT2D_HPP
|
||||
#define NAZARA_CHIPMUNKPHYSICS2D_CHIPMUNKCONSTRAINT2D_HPP
|
||||
|
||||
#include <NazaraUtils/Prerequisites.hpp>
|
||||
#include <Nazara/ChipmunkPhysics2D/ChipmunkPhysWorld2D.hpp>
|
||||
#include <Nazara/ChipmunkPhysics2D/ChipmunkRigidBody2D.hpp>
|
||||
#include <Nazara/ChipmunkPhysics2D/Config.hpp>
|
||||
#include <Nazara/Core/HandledObject.hpp>
|
||||
#include <Nazara/Core/ObjectHandle.hpp>
|
||||
#include <Nazara/Math/Angle.hpp>
|
||||
#include <NazaraUtils/MovablePtr.hpp>
|
||||
|
||||
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&& constraint) noexcept;
|
||||
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;
|
||||
bool IsSingleBody() const;
|
||||
|
||||
void SetErrorBias(float bias);
|
||||
void SetMaxBias(float bias);
|
||||
void SetMaxForce(float force);
|
||||
|
||||
ChipmunkConstraint2D& operator=(const ChipmunkConstraint2D&) = delete;
|
||||
ChipmunkConstraint2D& operator=(ChipmunkConstraint2D&& constraint) noexcept;
|
||||
|
||||
protected:
|
||||
ChipmunkConstraint2D(ChipmunkPhysWorld2D* world, cpConstraint* constraint);
|
||||
|
||||
MovablePtr<cpConstraint> m_constraint;
|
||||
|
||||
private:
|
||||
void Destroy();
|
||||
};
|
||||
|
||||
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& body, const Vector2f& anchor);
|
||||
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& body, const Vector2f& anchor);
|
||||
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_CHIPMUNKCONSTRAINT2D_HPP
|
||||
@@ -1,33 +0,0 @@
|
||||
// Copyright (C) 2024 Jérôme "SirLynix" Leclercq (lynix680@gmail.com)
|
||||
// This file is part of the "Nazara Engine - ChipmunkPhysics2D 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/ChipmunkPhysics2D/Config.hpp>
|
||||
#include <Nazara/Core/Core.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
|
||||
@@ -1,99 +0,0 @@
|
||||
// Copyright (C) 2024 Jérôme "SirLynix" Leclercq (lynix680@gmail.com)
|
||||
// This file is part of the "Nazara Engine - ChipmunkPhysics2D module"
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#include <Nazara/ChipmunkPhysics2D/Debug.hpp>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
inline ChipmunkRigidBody2D::ChipmunkRigidBody2D(ChipmunkPhysWorld2D& world, const DynamicSettings& settings)
|
||||
{
|
||||
Create(world, settings);
|
||||
}
|
||||
|
||||
inline ChipmunkRigidBody2D::ChipmunkRigidBody2D(ChipmunkPhysWorld2D& world, const StaticSettings& settings)
|
||||
{
|
||||
Create(world, settings);
|
||||
}
|
||||
|
||||
inline ChipmunkRigidBody2D::~ChipmunkRigidBody2D()
|
||||
{
|
||||
Destroy();
|
||||
}
|
||||
|
||||
inline void ChipmunkRigidBody2D::AddForce(const Vector2f& force, CoordSys coordSys)
|
||||
{
|
||||
return AddForce(force, GetMassCenter(coordSys), coordSys);
|
||||
}
|
||||
|
||||
inline void ChipmunkRigidBody2D::AddImpulse(const Vector2f& impulse, CoordSys coordSys)
|
||||
{
|
||||
return AddImpulse(impulse, GetMassCenter(coordSys), coordSys);
|
||||
}
|
||||
|
||||
inline UInt32 ChipmunkRigidBody2D::GetBodyIndex() const
|
||||
{
|
||||
return m_bodyIndex;
|
||||
}
|
||||
|
||||
inline const std::shared_ptr<ChipmunkCollider2D>& ChipmunkRigidBody2D::GetGeom() const
|
||||
{
|
||||
return m_geom;
|
||||
}
|
||||
|
||||
inline cpBody* ChipmunkRigidBody2D::GetHandle() const
|
||||
{
|
||||
return m_handle;
|
||||
}
|
||||
|
||||
inline float ChipmunkRigidBody2D::GetMass() const
|
||||
{
|
||||
return m_mass;
|
||||
}
|
||||
|
||||
inline const Vector2f& ChipmunkRigidBody2D::GetPositionOffset() const
|
||||
{
|
||||
return m_positionOffset;
|
||||
}
|
||||
|
||||
inline std::size_t ChipmunkRigidBody2D::GetShapeIndex(cpShape* shape) const
|
||||
{
|
||||
auto it = std::find(m_shapes.begin(), m_shapes.end(), shape);
|
||||
if (it == m_shapes.end())
|
||||
return InvalidShapeIndex;
|
||||
|
||||
return std::distance(m_shapes.begin(), it);
|
||||
}
|
||||
|
||||
inline std::size_t ChipmunkRigidBody2D::GetShapeCount() const
|
||||
{
|
||||
return m_shapes.size();
|
||||
}
|
||||
|
||||
inline const ChipmunkRigidBody2D::VelocityFunc& ChipmunkRigidBody2D::GetVelocityFunction() const
|
||||
{
|
||||
return m_velocityFunc;
|
||||
}
|
||||
|
||||
inline ChipmunkPhysWorld2D* ChipmunkRigidBody2D::GetWorld() const
|
||||
{
|
||||
return m_world;
|
||||
}
|
||||
|
||||
inline bool ChipmunkRigidBody2D::IsKinematic() const
|
||||
{
|
||||
return m_mass <= 0.f;
|
||||
}
|
||||
|
||||
inline bool ChipmunkRigidBody2D::IsSimulationEnabled() const
|
||||
{
|
||||
return m_isSimulationEnabled;
|
||||
}
|
||||
|
||||
inline bool ChipmunkRigidBody2D::IsStatic() const
|
||||
{
|
||||
return m_isStatic;
|
||||
}
|
||||
}
|
||||
|
||||
#include <Nazara/ChipmunkPhysics2D/DebugOff.hpp>
|
||||
@@ -1,40 +0,0 @@
|
||||
// Copyright (C) 2024 Jérôme "SirLynix" Leclercq (lynix680@gmail.com)
|
||||
// This file is part of the "Nazara Engine - ChipmunkPhysics2D module"
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifndef NAZARA_CHIPMUNKPHYSICS2D_COMPONENTS_CHIPMUNKRIGIDBODY2DCOMPONENT_HPP
|
||||
#define NAZARA_CHIPMUNKPHYSICS2D_COMPONENTS_CHIPMUNKRIGIDBODY2DCOMPONENT_HPP
|
||||
|
||||
#include <NazaraUtils/Prerequisites.hpp>
|
||||
#include <Nazara/ChipmunkPhysics2D/ChipmunkRigidBody2D.hpp>
|
||||
#include <variant>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
class NAZARA_CHIPMUNKPHYSICS2D_API ChipmunkRigidBody2DComponent : public ChipmunkRigidBody2D
|
||||
{
|
||||
friend class ChipmunkPhysics2DSystem;
|
||||
|
||||
public:
|
||||
inline ChipmunkRigidBody2DComponent(const ChipmunkRigidBody2D::DynamicSettings& settings);
|
||||
inline ChipmunkRigidBody2DComponent(const ChipmunkRigidBody2D::StaticSettings& settings);
|
||||
ChipmunkRigidBody2DComponent(const ChipmunkRigidBody2DComponent&) = delete;
|
||||
ChipmunkRigidBody2DComponent(ChipmunkRigidBody2DComponent&&) noexcept = default;
|
||||
~ChipmunkRigidBody2DComponent() = default;
|
||||
|
||||
ChipmunkRigidBody2DComponent& operator=(const ChipmunkRigidBody2DComponent&) = delete;
|
||||
ChipmunkRigidBody2DComponent& operator=(ChipmunkRigidBody2DComponent&&) noexcept = default;
|
||||
|
||||
private:
|
||||
inline void Construct(ChipmunkPhysWorld2D& world);
|
||||
|
||||
using Setting = std::variant<ChipmunkRigidBody2D::DynamicSettings, ChipmunkRigidBody2D::StaticSettings>;
|
||||
std::unique_ptr<Setting> m_settings;
|
||||
};
|
||||
}
|
||||
|
||||
#include <Nazara/ChipmunkPhysics2D/Components/ChipmunkRigidBody2DComponent.inl>
|
||||
|
||||
#endif // NAZARA_CHIPMUNKPHYSICS2D_COMPONENTS_CHIPMUNKRIGIDBODY2DCOMPONENT_HPP
|
||||
@@ -1,30 +0,0 @@
|
||||
// Copyright (C) 2024 Jérôme "SirLynix" Leclercq (lynix680@gmail.com)
|
||||
// This file is part of the "Nazara Engine - ChipmunkPhysics2D module"
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#include <Nazara/ChipmunkPhysics2D/Debug.hpp>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
inline ChipmunkRigidBody2DComponent::ChipmunkRigidBody2DComponent(const ChipmunkRigidBody2D::DynamicSettings& settings)
|
||||
{
|
||||
m_settings = std::make_unique<Setting>(settings);
|
||||
}
|
||||
|
||||
inline ChipmunkRigidBody2DComponent::ChipmunkRigidBody2DComponent(const ChipmunkRigidBody2D::StaticSettings& settings)
|
||||
{
|
||||
m_settings = std::make_unique<Setting>(settings);
|
||||
}
|
||||
|
||||
inline void ChipmunkRigidBody2DComponent::Construct(ChipmunkPhysWorld2D& world)
|
||||
{
|
||||
assert(m_settings);
|
||||
std::visit([&](auto&& arg)
|
||||
{
|
||||
Create(world, arg);
|
||||
}, *m_settings);
|
||||
m_settings.reset();
|
||||
}
|
||||
}
|
||||
|
||||
#include <Nazara/ChipmunkPhysics2D/DebugOff.hpp>
|
||||
@@ -1,50 +0,0 @@
|
||||
// this file was automatically generated and should not be edited
|
||||
|
||||
/*
|
||||
Nazara Engine - JoltPhysics3D module
|
||||
|
||||
Copyright (C) 2024 Jérôme "SirLynix" 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_GLOBAL_JOLTPHYSICS3D_HPP
|
||||
#define NAZARA_GLOBAL_JOLTPHYSICS3D_HPP
|
||||
|
||||
#include <Nazara/JoltPhysics3D/Config.hpp>
|
||||
#include <Nazara/JoltPhysics3D/Enums.hpp>
|
||||
#include <Nazara/JoltPhysics3D/JoltAbstractBody.hpp>
|
||||
#include <Nazara/JoltPhysics3D/JoltCharacter.hpp>
|
||||
#include <Nazara/JoltPhysics3D/JoltCollider3D.hpp>
|
||||
#include <Nazara/JoltPhysics3D/JoltConstraint3D.hpp>
|
||||
#include <Nazara/JoltPhysics3D/JoltPhysics3D.hpp>
|
||||
#include <Nazara/JoltPhysics3D/JoltPhysicsStepListener.hpp>
|
||||
#include <Nazara/JoltPhysics3D/JoltPhysWorld3D.hpp>
|
||||
#include <Nazara/JoltPhysics3D/JoltRigidBody3D.hpp>
|
||||
|
||||
#ifdef NAZARA_ENTT
|
||||
|
||||
#include <Nazara/JoltPhysics3D/Components.hpp>
|
||||
#include <Nazara/JoltPhysics3D/Systems.hpp>
|
||||
|
||||
#endif
|
||||
|
||||
#endif // NAZARA_GLOBAL_JOLTPHYSICS3D_HPP
|
||||
@@ -1,37 +0,0 @@
|
||||
// Copyright (C) 2024 Jérôme "SirLynix" Leclercq (lynix680@gmail.com)
|
||||
// This file is part of the "Nazara Engine - JoltPhysics3D module"
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifndef NAZARA_JOLTPHYSICS3D_COMPONENTS_JOLTCHARACTERCOMPONENT_HPP
|
||||
#define NAZARA_JOLTPHYSICS3D_COMPONENTS_JOLTCHARACTERCOMPONENT_HPP
|
||||
|
||||
#include <NazaraUtils/Prerequisites.hpp>
|
||||
#include <Nazara/JoltPhysics3D/JoltCharacter.hpp>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
class NAZARA_JOLTPHYSICS3D_API JoltCharacterComponent : public JoltCharacter
|
||||
{
|
||||
friend class JoltPhysics3DSystem;
|
||||
|
||||
public:
|
||||
inline JoltCharacterComponent(const JoltCharacter::Settings& settings);
|
||||
JoltCharacterComponent(const JoltCharacterComponent&) = default;
|
||||
JoltCharacterComponent(JoltCharacterComponent&&) noexcept = default;
|
||||
~JoltCharacterComponent() = default;
|
||||
|
||||
JoltCharacterComponent& operator=(const JoltCharacterComponent&) = default;
|
||||
JoltCharacterComponent& operator=(JoltCharacterComponent&&) noexcept = default;
|
||||
|
||||
private:
|
||||
inline void Construct(JoltPhysWorld3D& world);
|
||||
|
||||
std::unique_ptr<JoltCharacter::Settings> m_settings;
|
||||
};
|
||||
}
|
||||
|
||||
#include <Nazara/JoltPhysics3D/Components/JoltCharacterComponent.inl>
|
||||
|
||||
#endif // NAZARA_JOLTPHYSICS3D_COMPONENTS_JOLTCHARACTERCOMPONENT_HPP
|
||||
@@ -1,22 +0,0 @@
|
||||
// Copyright (C) 2024 Jérôme "SirLynix" Leclercq (lynix680@gmail.com)
|
||||
// This file is part of the "Nazara Engine - JoltPhysics3D module"
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#include <Nazara/JoltPhysics3D/Debug.hpp>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
inline JoltCharacterComponent::JoltCharacterComponent(const JoltCharacter::Settings& settings)
|
||||
{
|
||||
m_settings = std::make_unique<JoltCharacter::Settings>(settings);
|
||||
}
|
||||
|
||||
inline void JoltCharacterComponent::Construct(JoltPhysWorld3D& world)
|
||||
{
|
||||
assert(m_settings);
|
||||
Create(world, *m_settings);
|
||||
m_settings.reset();
|
||||
}
|
||||
}
|
||||
|
||||
#include <Nazara/JoltPhysics3D/DebugOff.hpp>
|
||||
@@ -1,40 +0,0 @@
|
||||
// Copyright (C) 2024 Jérôme "SirLynix" Leclercq (lynix680@gmail.com)
|
||||
// This file is part of the "Nazara Engine - JoltPhysics3D module"
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifndef NAZARA_JOLTPHYSICS3D_COMPONENTS_JOLTRIGIDBODY3DCOMPONENT_HPP
|
||||
#define NAZARA_JOLTPHYSICS3D_COMPONENTS_JOLTRIGIDBODY3DCOMPONENT_HPP
|
||||
|
||||
#include <NazaraUtils/Prerequisites.hpp>
|
||||
#include <Nazara/JoltPhysics3D/JoltRigidBody3D.hpp>
|
||||
#include <variant>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
class NAZARA_JOLTPHYSICS3D_API JoltRigidBody3DComponent : public JoltRigidBody3D
|
||||
{
|
||||
friend class JoltPhysics3DSystem;
|
||||
|
||||
public:
|
||||
inline JoltRigidBody3DComponent(const JoltRigidBody3D::DynamicSettings& settings);
|
||||
inline JoltRigidBody3DComponent(const JoltRigidBody3D::StaticSettings& settings);
|
||||
JoltRigidBody3DComponent(const JoltRigidBody3DComponent&) = default;
|
||||
JoltRigidBody3DComponent(JoltRigidBody3DComponent&&) noexcept = default;
|
||||
~JoltRigidBody3DComponent() = default;
|
||||
|
||||
JoltRigidBody3DComponent& operator=(const JoltRigidBody3DComponent&) = default;
|
||||
JoltRigidBody3DComponent& operator=(JoltRigidBody3DComponent&&) noexcept = default;
|
||||
|
||||
private:
|
||||
inline void Construct(JoltPhysWorld3D& world);
|
||||
|
||||
using Setting = std::variant<JoltRigidBody3D::DynamicSettings, JoltRigidBody3D::StaticSettings>;
|
||||
std::unique_ptr<Setting> m_settings;
|
||||
};
|
||||
}
|
||||
|
||||
#include <Nazara/JoltPhysics3D/Components/JoltRigidBody3DComponent.inl>
|
||||
|
||||
#endif // NAZARA_JOLTPHYSICS3D_COMPONENTS_JOLTRIGIDBODY3DCOMPONENT_HPP
|
||||
@@ -1,31 +0,0 @@
|
||||
// Copyright (C) 2024 Jérôme "SirLynix" Leclercq (lynix680@gmail.com)
|
||||
// This file is part of the "Nazara Engine - JoltPhysics3D module"
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#include <cassert>
|
||||
#include <Nazara/JoltPhysics3D/Debug.hpp>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
inline JoltRigidBody3DComponent::JoltRigidBody3DComponent(const JoltRigidBody3D::DynamicSettings& settings)
|
||||
{
|
||||
m_settings = std::make_unique<Setting>(settings);
|
||||
}
|
||||
|
||||
inline JoltRigidBody3DComponent::JoltRigidBody3DComponent(const JoltRigidBody3D::StaticSettings& settings)
|
||||
{
|
||||
m_settings = std::make_unique<Setting>(settings);
|
||||
}
|
||||
|
||||
inline void JoltRigidBody3DComponent::Construct(JoltPhysWorld3D& world)
|
||||
{
|
||||
assert(m_settings);
|
||||
std::visit([&](auto&& arg)
|
||||
{
|
||||
Create(world, arg);
|
||||
}, *m_settings);
|
||||
m_settings.reset();
|
||||
}
|
||||
}
|
||||
|
||||
#include <Nazara/JoltPhysics3D/DebugOff.hpp>
|
||||
@@ -1,10 +0,0 @@
|
||||
// Copyright (C) 2024 Jérôme "SirLynix" Leclercq (lynix680@gmail.com)
|
||||
// This file is part of the "Nazara Engine - JoltPhysics3D module"
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifndef NAZARA_JOLTPHYSICS3D_CONFIGCHECK_HPP
|
||||
#define NAZARA_JOLTPHYSICS3D_CONFIGCHECK_HPP
|
||||
|
||||
#endif // NAZARA_JOLTPHYSICS3D_CONFIGCHECK_HPP
|
||||
@@ -1,32 +0,0 @@
|
||||
// Copyright (C) 2024 Jérôme "SirLynix" Leclercq (lynix680@gmail.com)
|
||||
// This file is part of the "Nazara Engine - JoltPhysics3D module"
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifndef NAZARA_JOLTPHYSICS3D_JOLTABSTRACTBODY_HPP
|
||||
#define NAZARA_JOLTPHYSICS3D_JOLTABSTRACTBODY_HPP
|
||||
|
||||
#include <NazaraUtils/Prerequisites.hpp>
|
||||
#include <Nazara/JoltPhysics3D/Config.hpp>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
class NAZARA_JOLTPHYSICS3D_API JoltAbstractBody
|
||||
{
|
||||
public:
|
||||
JoltAbstractBody() = default;
|
||||
JoltAbstractBody(const JoltAbstractBody&) = delete;
|
||||
JoltAbstractBody(JoltAbstractBody&&) = delete;
|
||||
virtual ~JoltAbstractBody();
|
||||
|
||||
virtual UInt32 GetBodyIndex() const = 0;
|
||||
|
||||
JoltAbstractBody& operator=(const JoltAbstractBody&) = delete;
|
||||
JoltAbstractBody& operator=(JoltAbstractBody&&) = delete;
|
||||
};
|
||||
}
|
||||
|
||||
#include <Nazara/JoltPhysics3D/JoltAbstractBody.inl>
|
||||
|
||||
#endif // NAZARA_JOLTPHYSICS3D_JOLTABSTRACTBODY_HPP
|
||||
@@ -1,113 +0,0 @@
|
||||
// Copyright (C) 2024 Jérôme "SirLynix" Leclercq (lynix680@gmail.com)
|
||||
// This file is part of the "Nazara Engine - JoltPhysics3D module"
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifndef NAZARA_JOLTPHYSICS3D_JOLTCHARACTER_HPP
|
||||
#define NAZARA_JOLTPHYSICS3D_JOLTCHARACTER_HPP
|
||||
|
||||
#include <NazaraUtils/Prerequisites.hpp>
|
||||
#include <Nazara/JoltPhysics3D/Config.hpp>
|
||||
#include <Nazara/JoltPhysics3D/JoltAbstractBody.hpp>
|
||||
#include <Nazara/JoltPhysics3D/JoltPhysicsStepListener.hpp>
|
||||
#include <Nazara/Math/Quaternion.hpp>
|
||||
#include <Nazara/Math/Vector3.hpp>
|
||||
#include <NazaraUtils/MovablePtr.hpp>
|
||||
#include <memory>
|
||||
|
||||
namespace JPH
|
||||
{
|
||||
class Character;
|
||||
class Body;
|
||||
}
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
class JoltCharacterImpl;
|
||||
class JoltCollider3D;
|
||||
class JoltPhysWorld3D;
|
||||
|
||||
class NAZARA_JOLTPHYSICS3D_API JoltCharacter : public JoltAbstractBody, public JoltPhysicsStepListener
|
||||
{
|
||||
friend JoltPhysWorld3D;
|
||||
|
||||
public:
|
||||
struct Settings;
|
||||
|
||||
JoltCharacter(JoltPhysWorld3D& physWorld, const Settings& settings);
|
||||
JoltCharacter(const JoltCharacter&) = delete;
|
||||
JoltCharacter(JoltCharacter&& character) noexcept;
|
||||
~JoltCharacter();
|
||||
|
||||
inline void DisableSleeping();
|
||||
void EnableSleeping(bool enable);
|
||||
|
||||
UInt32 GetBodyIndex() const override;
|
||||
inline const std::shared_ptr<JoltCollider3D>& GetCollider() const;
|
||||
Vector3f GetLinearVelocity() const;
|
||||
inline JoltPhysWorld3D& GetPhysWorld();
|
||||
inline const JoltPhysWorld3D& GetPhysWorld() const;
|
||||
Vector3f GetPosition() const;
|
||||
std::pair<Vector3f, Quaternionf> GetPositionAndRotation() const;
|
||||
Quaternionf GetRotation() const;
|
||||
Vector3f GetUp() const;
|
||||
|
||||
bool IsOnGround() const;
|
||||
|
||||
void SetFriction(float friction);
|
||||
inline void SetImpl(std::shared_ptr<JoltCharacterImpl> characterImpl);
|
||||
void SetLinearVelocity(const Vector3f& linearVel);
|
||||
void SetRotation(const Quaternionf& rotation);
|
||||
void SetUp(const Vector3f& up);
|
||||
|
||||
void TeleportTo(const Vector3f& position, const Quaternionf& rotation);
|
||||
|
||||
void WakeUp();
|
||||
|
||||
JoltCharacter& operator=(const JoltCharacter&) = delete;
|
||||
JoltCharacter& operator=(JoltCharacter&& character) noexcept;
|
||||
|
||||
struct Settings
|
||||
{
|
||||
std::shared_ptr<JoltCollider3D> collider;
|
||||
Quaternionf rotation = Quaternionf::Identity();
|
||||
Vector3f position = Vector3f::Zero();
|
||||
};
|
||||
|
||||
protected:
|
||||
JoltCharacter();
|
||||
|
||||
void Create(JoltPhysWorld3D& physWorld, const Settings& settings);
|
||||
void Destroy();
|
||||
|
||||
private:
|
||||
void PostSimulate(float elapsedTime) override;
|
||||
void PreSimulate(float elapsedTime) override;
|
||||
|
||||
std::shared_ptr<JoltCharacterImpl> m_impl;
|
||||
std::shared_ptr<JoltCollider3D> m_collider;
|
||||
std::unique_ptr<JPH::Character> m_character;
|
||||
MovablePtr<JoltPhysWorld3D> m_world;
|
||||
UInt32 m_bodyIndex;
|
||||
};
|
||||
|
||||
class NAZARA_JOLTPHYSICS3D_API JoltCharacterImpl
|
||||
{
|
||||
public:
|
||||
JoltCharacterImpl() = default;
|
||||
JoltCharacterImpl(const JoltCharacterImpl&) = delete;
|
||||
JoltCharacterImpl(JoltCharacterImpl&&) = delete;
|
||||
virtual ~JoltCharacterImpl();
|
||||
|
||||
virtual void PostSimulate(JoltCharacter& character, float elapsedTime);
|
||||
virtual void PreSimulate(JoltCharacter& character, float elapsedTime);
|
||||
|
||||
JoltCharacterImpl& operator=(const JoltCharacterImpl&) = delete;
|
||||
JoltCharacterImpl& operator=(JoltCharacterImpl&&) = delete;
|
||||
};
|
||||
}
|
||||
|
||||
#include <Nazara/JoltPhysics3D/JoltCharacter.inl>
|
||||
|
||||
#endif // NAZARA_JOLTPHYSICS3D_JOLTCHARACTER_HPP
|
||||
@@ -1,35 +0,0 @@
|
||||
// Copyright (C) 2024 Jérôme "SirLynix" Leclercq (lynix680@gmail.com)
|
||||
// This file is part of the "Nazara Engine - JoltPhysics3D module"
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#include <Nazara/JoltPhysics3D/Debug.hpp>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
inline void JoltCharacter::DisableSleeping()
|
||||
{
|
||||
return EnableSleeping(false);
|
||||
}
|
||||
|
||||
inline const std::shared_ptr<JoltCollider3D>& JoltCharacter::GetCollider() const
|
||||
{
|
||||
return m_collider;
|
||||
}
|
||||
|
||||
inline JoltPhysWorld3D& JoltCharacter::GetPhysWorld()
|
||||
{
|
||||
return *m_world;
|
||||
}
|
||||
|
||||
inline const JoltPhysWorld3D& JoltCharacter::GetPhysWorld() const
|
||||
{
|
||||
return *m_world;
|
||||
}
|
||||
|
||||
inline void JoltCharacter::SetImpl(std::shared_ptr<JoltCharacterImpl> characterImpl)
|
||||
{
|
||||
m_impl = std::move(characterImpl);
|
||||
}
|
||||
}
|
||||
|
||||
#include <Nazara/JoltPhysics3D/DebugOff.hpp>
|
||||
@@ -1,172 +0,0 @@
|
||||
// Copyright (C) 2024 Jérôme "SirLynix" Leclercq (lynix680@gmail.com)
|
||||
// This file is part of the "Nazara Engine - JoltPhysics3D module"
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifndef NAZARA_JOLTPHYSICS3D_JOLTCOLLIDER3D_HPP
|
||||
#define NAZARA_JOLTPHYSICS3D_JOLTCOLLIDER3D_HPP
|
||||
|
||||
#include <NazaraUtils/Prerequisites.hpp>
|
||||
#include <Nazara/Core/ObjectLibrary.hpp>
|
||||
#include <Nazara/JoltPhysics3D/Config.hpp>
|
||||
#include <Nazara/JoltPhysics3D/Enums.hpp>
|
||||
#include <Nazara/Math/Box.hpp>
|
||||
#include <Nazara/Math/Quaternion.hpp>
|
||||
#include <Nazara/Math/Vector3.hpp>
|
||||
#include <NazaraUtils/Signal.hpp>
|
||||
#include <NazaraUtils/SparsePtr.hpp>
|
||||
#include <memory>
|
||||
|
||||
namespace JPH
|
||||
{
|
||||
class ShapeSettings;
|
||||
class BoxShapeSettings;
|
||||
}
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
class PrimitiveList;
|
||||
class StaticMesh;
|
||||
struct Primitive;
|
||||
|
||||
class NAZARA_JOLTPHYSICS3D_API JoltCollider3D
|
||||
{
|
||||
public:
|
||||
JoltCollider3D();
|
||||
JoltCollider3D(const JoltCollider3D&) = delete;
|
||||
JoltCollider3D(JoltCollider3D&&) = delete;
|
||||
virtual ~JoltCollider3D();
|
||||
|
||||
virtual void BuildDebugMesh(std::vector<Vector3f>& vertices, std::vector<UInt16>& indices, const Matrix4f& offsetMatrix = Matrix4f::Identity()) const = 0;
|
||||
|
||||
virtual std::shared_ptr<StaticMesh> GenerateDebugMesh() const;
|
||||
|
||||
inline JPH::ShapeSettings* GetShapeSettings() const;
|
||||
virtual JoltColliderType3D GetType() const = 0;
|
||||
|
||||
JoltCollider3D& operator=(const JoltCollider3D&) = delete;
|
||||
JoltCollider3D& operator=(JoltCollider3D&&) = delete;
|
||||
|
||||
static std::shared_ptr<JoltCollider3D> Build(const PrimitiveList& list);
|
||||
|
||||
protected:
|
||||
template<typename T> const T* GetShapeSettingsAs() const;
|
||||
void ResetShapeSettings();
|
||||
void SetupShapeSettings(std::unique_ptr<JPH::ShapeSettings>&& shapeSettings);
|
||||
|
||||
private:
|
||||
static std::shared_ptr<JoltCollider3D> CreateGeomFromPrimitive(const Primitive& primitive);
|
||||
|
||||
std::unique_ptr<JPH::ShapeSettings> m_shapeSettings;
|
||||
};
|
||||
|
||||
/*********************************** Shapes ******************************************/
|
||||
|
||||
class NAZARA_JOLTPHYSICS3D_API JoltBoxCollider3D final : public JoltCollider3D
|
||||
{
|
||||
public:
|
||||
JoltBoxCollider3D(const Vector3f& lengths, float convexRadius = 0.01f);
|
||||
~JoltBoxCollider3D() = default;
|
||||
|
||||
void BuildDebugMesh(std::vector<Vector3f>& vertices, std::vector<UInt16>& indices, const Matrix4f& offsetMatrix) const override;
|
||||
|
||||
Vector3f GetLengths() const;
|
||||
JoltColliderType3D GetType() const override;
|
||||
};
|
||||
|
||||
class NAZARA_JOLTPHYSICS3D_API JoltCapsuleCollider3D final : public JoltCollider3D
|
||||
{
|
||||
public:
|
||||
JoltCapsuleCollider3D(float height, float radius);
|
||||
~JoltCapsuleCollider3D() = default;
|
||||
|
||||
void BuildDebugMesh(std::vector<Vector3f>& vertices, std::vector<UInt16>& indices, const Matrix4f& offsetMatrix) const override;
|
||||
|
||||
float GetHeight() const;
|
||||
float GetRadius() const;
|
||||
JoltColliderType3D GetType() const override;
|
||||
};
|
||||
|
||||
class NAZARA_JOLTPHYSICS3D_API JoltCompoundCollider3D final : public JoltCollider3D
|
||||
{
|
||||
public:
|
||||
struct ChildCollider;
|
||||
|
||||
JoltCompoundCollider3D(std::vector<ChildCollider> childs);
|
||||
~JoltCompoundCollider3D();
|
||||
|
||||
void BuildDebugMesh(std::vector<Vector3f>& vertices, std::vector<UInt16>& indices, const Matrix4f& offsetMatrix) const override;
|
||||
|
||||
const std::vector<ChildCollider>& GetGeoms() const;
|
||||
JoltColliderType3D GetType() const override;
|
||||
|
||||
struct ChildCollider
|
||||
{
|
||||
std::shared_ptr<JoltCollider3D> collider;
|
||||
Quaternionf rotation = Quaternionf::Identity();
|
||||
Vector3f offset = Vector3f::Zero();
|
||||
};
|
||||
|
||||
private:
|
||||
std::vector<ChildCollider> m_childs;
|
||||
};
|
||||
|
||||
class NAZARA_JOLTPHYSICS3D_API JoltConvexHullCollider3D final : public JoltCollider3D
|
||||
{
|
||||
public:
|
||||
JoltConvexHullCollider3D(SparsePtr<const Vector3f> vertices, std::size_t vertexCount, float hullTolerance = 0.001f, float convexRadius = 0.f, float maxErrorConvexRadius = 0.05f);
|
||||
~JoltConvexHullCollider3D() = default;
|
||||
|
||||
void BuildDebugMesh(std::vector<Vector3f>& vertices, std::vector<UInt16>& indices, const Matrix4f& offsetMatrix) const override;
|
||||
|
||||
JoltColliderType3D GetType() const override;
|
||||
};
|
||||
|
||||
class NAZARA_JOLTPHYSICS3D_API JoltMeshCollider3D final : public JoltCollider3D
|
||||
{
|
||||
public:
|
||||
JoltMeshCollider3D(SparsePtr<const Vector3f> vertices, std::size_t vertexCount, SparsePtr<const UInt16> indices, std::size_t indexCount);
|
||||
JoltMeshCollider3D(SparsePtr<const Vector3f> vertices, std::size_t vertexCount, SparsePtr<const UInt32> indices, std::size_t indexCount);
|
||||
~JoltMeshCollider3D() = default;
|
||||
|
||||
void BuildDebugMesh(std::vector<Vector3f>& vertices, std::vector<UInt16>& indices, const Matrix4f& offsetMatrix) const override;
|
||||
|
||||
JoltColliderType3D GetType() const override;
|
||||
};
|
||||
|
||||
class NAZARA_JOLTPHYSICS3D_API JoltSphereCollider3D final : public JoltCollider3D
|
||||
{
|
||||
public:
|
||||
JoltSphereCollider3D(float radius);
|
||||
~JoltSphereCollider3D() = default;
|
||||
|
||||
void BuildDebugMesh(std::vector<Vector3f>& vertices, std::vector<UInt16>& indices, const Matrix4f& offsetMatrix) const override;
|
||||
|
||||
float GetRadius() const;
|
||||
JoltColliderType3D GetType() const override;
|
||||
};
|
||||
|
||||
/*********************************** Decorated ******************************************/
|
||||
|
||||
class NAZARA_JOLTPHYSICS3D_API JoltTranslatedRotatedCollider3D final : public JoltCollider3D
|
||||
{
|
||||
public:
|
||||
inline JoltTranslatedRotatedCollider3D(std::shared_ptr<JoltCollider3D> collider, const Vector3f& translation);
|
||||
inline JoltTranslatedRotatedCollider3D(std::shared_ptr<JoltCollider3D> collider, const Quaternionf& rotation);
|
||||
JoltTranslatedRotatedCollider3D(std::shared_ptr<JoltCollider3D> collider, const Vector3f& translation, const Quaternionf& rotation);
|
||||
~JoltTranslatedRotatedCollider3D();
|
||||
|
||||
void BuildDebugMesh(std::vector<Vector3f>& vertices, std::vector<UInt16>& indices, const Matrix4f& offsetMatrix) const override;
|
||||
|
||||
JoltColliderType3D GetType() const override;
|
||||
|
||||
private:
|
||||
std::shared_ptr<JoltCollider3D> m_collider;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#include <Nazara/JoltPhysics3D/JoltCollider3D.inl>
|
||||
|
||||
#endif // NAZARA_JOLTPHYSICS3D_JOLTCOLLIDER3D_HPP
|
||||
@@ -1,34 +0,0 @@
|
||||
// Copyright (C) 2024 Jérôme "SirLynix" Leclercq (lynix680@gmail.com)
|
||||
// This file is part of the "Nazara Engine - JoltPhysics3D module"
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#include <NazaraUtils/Algorithm.hpp>
|
||||
#include <memory>
|
||||
#include <Nazara/JoltPhysics3D/Debug.hpp>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
inline JPH::ShapeSettings* JoltCollider3D::GetShapeSettings() const
|
||||
{
|
||||
return m_shapeSettings.get();
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
const T* JoltCollider3D::GetShapeSettingsAs() const
|
||||
{
|
||||
return SafeCast<T*>(m_shapeSettings.get());
|
||||
}
|
||||
|
||||
|
||||
inline JoltTranslatedRotatedCollider3D::JoltTranslatedRotatedCollider3D(std::shared_ptr<JoltCollider3D> collider, const Vector3f& translation) :
|
||||
JoltTranslatedRotatedCollider3D(std::move(collider), translation, Quaternionf::Identity())
|
||||
{
|
||||
}
|
||||
|
||||
inline JoltTranslatedRotatedCollider3D::JoltTranslatedRotatedCollider3D(std::shared_ptr<JoltCollider3D> collider, const Quaternionf& rotation) :
|
||||
JoltTranslatedRotatedCollider3D(std::move(collider), Vector3f::Zero(), rotation)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
#include <Nazara/JoltPhysics3D/DebugOff.hpp>
|
||||
@@ -1,99 +0,0 @@
|
||||
// Copyright (C) 2024 Jérôme "SirLynix" Leclercq (lynix680@gmail.com)
|
||||
// This file is part of the "Nazara Engine - JoltPhysics3D module"
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifndef NAZARA_JOLTPHYSICS3D_JOLTCONSTRAINT3D_HPP
|
||||
#define NAZARA_JOLTPHYSICS3D_JOLTCONSTRAINT3D_HPP
|
||||
|
||||
#include <NazaraUtils/Prerequisites.hpp>
|
||||
#include <Nazara/Core/HandledObject.hpp>
|
||||
#include <Nazara/Core/ObjectHandle.hpp>
|
||||
#include <Nazara/JoltPhysics3D/Config.hpp>
|
||||
#include <Nazara/JoltPhysics3D/JoltPhysWorld3D.hpp>
|
||||
#include <Nazara/JoltPhysics3D/JoltRigidBody3D.hpp>
|
||||
|
||||
namespace JPH
|
||||
{
|
||||
class TwoBodyConstraint;
|
||||
}
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
class JoltConstraint3D;
|
||||
|
||||
using JoltConstraint3DHandle = ObjectHandle<JoltConstraint3D>;
|
||||
|
||||
class NAZARA_JOLTPHYSICS3D_API JoltConstraint3D : public HandledObject<JoltConstraint3D>
|
||||
{
|
||||
public:
|
||||
JoltConstraint3D(const JoltConstraint3D&) = delete;
|
||||
JoltConstraint3D(JoltConstraint3D&& constraint) noexcept;
|
||||
virtual ~JoltConstraint3D();
|
||||
|
||||
JoltRigidBody3D& GetBodyA();
|
||||
const JoltRigidBody3D& GetBodyA() const;
|
||||
JoltRigidBody3D& GetBodyB();
|
||||
const JoltRigidBody3D& GetBodyB() const;
|
||||
JoltPhysWorld3D& GetWorld();
|
||||
const JoltPhysWorld3D& GetWorld() const;
|
||||
|
||||
bool IsSingleBody() const;
|
||||
|
||||
JoltConstraint3D& operator=(const JoltConstraint3D&) = delete;
|
||||
JoltConstraint3D& operator=(JoltConstraint3D&& constraint) noexcept;
|
||||
|
||||
protected:
|
||||
JoltConstraint3D();
|
||||
|
||||
template<typename T> T* GetConstraint();
|
||||
template<typename T> const T* GetConstraint() const;
|
||||
|
||||
void SetupConstraint(std::unique_ptr<JPH::TwoBodyConstraint> constraint);
|
||||
|
||||
private:
|
||||
void Destroy();
|
||||
|
||||
std::unique_ptr<JPH::TwoBodyConstraint> m_constraint;
|
||||
};
|
||||
|
||||
class NAZARA_JOLTPHYSICS3D_API JoltDistanceConstraint3D : public JoltConstraint3D
|
||||
{
|
||||
public:
|
||||
JoltDistanceConstraint3D(JoltRigidBody3D& first, const Vector3f& pivot, float maxDist = -1.f, float minDist = -1.f);
|
||||
JoltDistanceConstraint3D(JoltRigidBody3D& first, JoltRigidBody3D& second, const Vector3f& pivot, float maxDist = -1.f, float minDist = -1.f);
|
||||
JoltDistanceConstraint3D(JoltRigidBody3D& first, JoltRigidBody3D& second, const Vector3f& firstAnchor, const Vector3f& secondAnchor, float maxDist = -1.f, float minDist = -1.f);
|
||||
~JoltDistanceConstraint3D() = default;
|
||||
|
||||
float GetDamping() const;
|
||||
float GetFrequency() const;
|
||||
float GetMaxDistance() const;
|
||||
float GetMinDistance() const;
|
||||
|
||||
void SetDamping(float damping);
|
||||
void SetDistance(float minDist, float maxDist);
|
||||
void SetFrequency(float frequency);
|
||||
void SetMaxDistance(float maxDist);
|
||||
void SetMinDistance(float minDist);
|
||||
};
|
||||
|
||||
class NAZARA_JOLTPHYSICS3D_API JoltPivotConstraint3D : public JoltConstraint3D
|
||||
{
|
||||
public:
|
||||
JoltPivotConstraint3D(JoltRigidBody3D& first, const Vector3f& pivot);
|
||||
JoltPivotConstraint3D(JoltRigidBody3D& first, JoltRigidBody3D& second, const Vector3f& pivot);
|
||||
JoltPivotConstraint3D(JoltRigidBody3D& first, JoltRigidBody3D& second, const Vector3f& firstAnchor, const Vector3f& secondAnchor);
|
||||
~JoltPivotConstraint3D() = default;
|
||||
|
||||
Vector3f GetFirstAnchor() const;
|
||||
Vector3f GetSecondAnchor() const;
|
||||
|
||||
void SetFirstAnchor(const Vector3f& firstAnchor);
|
||||
void SetSecondAnchor(const Vector3f& secondAnchor);
|
||||
};
|
||||
}
|
||||
|
||||
#include <Nazara/JoltPhysics3D/JoltConstraint3D.inl>
|
||||
|
||||
#endif // NAZARA_JOLTPHYSICS3D_JOLTCONSTRAINT3D_HPP
|
||||
@@ -1,33 +0,0 @@
|
||||
// Copyright (C) 2024 Jérôme "SirLynix" Leclercq (lynix680@gmail.com)
|
||||
// This file is part of the "Nazara Engine - JoltPhysics3D module"
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifndef NAZARA_JOLTPHYSICS3D_JOLTPHYSICSSTEPLISTENER_HPP
|
||||
#define NAZARA_JOLTPHYSICS3D_JOLTPHYSICSSTEPLISTENER_HPP
|
||||
|
||||
#include <NazaraUtils/Prerequisites.hpp>
|
||||
#include <Nazara/JoltPhysics3D/Config.hpp>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
class NAZARA_JOLTPHYSICS3D_API JoltPhysicsStepListener
|
||||
{
|
||||
public:
|
||||
JoltPhysicsStepListener() = default;
|
||||
JoltPhysicsStepListener(const JoltPhysicsStepListener&) = delete;
|
||||
JoltPhysicsStepListener(JoltPhysicsStepListener&&) = delete;
|
||||
virtual ~JoltPhysicsStepListener();
|
||||
|
||||
virtual void PostSimulate(float elapsedTime);
|
||||
virtual void PreSimulate(float elapsedTime);
|
||||
|
||||
JoltPhysicsStepListener& operator=(const JoltPhysicsStepListener&) = delete;
|
||||
JoltPhysicsStepListener& operator=(JoltPhysicsStepListener&&) = delete;
|
||||
};
|
||||
}
|
||||
|
||||
#include <Nazara/JoltPhysics3D/JoltPhysicsStepListener.inl>
|
||||
|
||||
#endif // NAZARA_JOLTPHYSICS3D_JOLTPHYSICSSTEPLISTENER_HPP
|
||||
@@ -1,55 +0,0 @@
|
||||
// Copyright (C) 2024 Jérôme "SirLynix" Leclercq (lynix680@gmail.com)
|
||||
// This file is part of the "Nazara Engine - JoltPhysics3D module"
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#include <Nazara/JoltPhysics3D/Debug.hpp>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
inline JoltRigidBody3D::JoltRigidBody3D(JoltPhysWorld3D& world, const DynamicSettings& settings)
|
||||
{
|
||||
Create(world, settings);
|
||||
}
|
||||
|
||||
inline JoltRigidBody3D::JoltRigidBody3D(JoltPhysWorld3D& world, const StaticSettings& settings)
|
||||
{
|
||||
Create(world, settings);
|
||||
}
|
||||
|
||||
inline void JoltRigidBody3D::DisableSimulation()
|
||||
{
|
||||
return EnableSimulation(false);
|
||||
}
|
||||
|
||||
inline void JoltRigidBody3D::DisableSleeping()
|
||||
{
|
||||
return EnableSleeping(false);
|
||||
}
|
||||
|
||||
inline JPH::Body* JoltRigidBody3D::GetBody()
|
||||
{
|
||||
return m_body;
|
||||
}
|
||||
|
||||
inline const JPH::Body* JoltRigidBody3D::GetBody() const
|
||||
{
|
||||
return m_body;
|
||||
}
|
||||
|
||||
inline const std::shared_ptr<JoltCollider3D>& JoltRigidBody3D::GetGeom() const
|
||||
{
|
||||
return m_geom;
|
||||
}
|
||||
|
||||
inline JoltPhysWorld3D& JoltRigidBody3D::GetWorld() const
|
||||
{
|
||||
return *m_world;
|
||||
}
|
||||
|
||||
inline bool JoltRigidBody3D::IsSimulationEnabled() const
|
||||
{
|
||||
return m_isSimulationEnabled;
|
||||
}
|
||||
}
|
||||
|
||||
#include <Nazara/JoltPhysics3D/DebugOff.hpp>
|
||||
@@ -1,25 +0,0 @@
|
||||
// Copyright (C) 2024 Jérôme "SirLynix" Leclercq (lynix680@gmail.com)
|
||||
// This file is part of the "Nazara Engine - JoltPhysics3D module"
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#include <Nazara/JoltPhysics3D/Debug.hpp>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
inline JoltPhysWorld3D& JoltPhysics3DSystem::GetPhysWorld()
|
||||
{
|
||||
return m_physWorld;
|
||||
}
|
||||
|
||||
inline const JoltPhysWorld3D& JoltPhysics3DSystem::GetPhysWorld() const
|
||||
{
|
||||
return m_physWorld;
|
||||
}
|
||||
|
||||
inline entt::handle JoltPhysics3DSystem::GetRigidBodyEntity(UInt32 bodyIndex) const
|
||||
{
|
||||
return entt::handle(m_registry, m_bodyIndicesToEntity[bodyIndex]);
|
||||
}
|
||||
}
|
||||
|
||||
#include <Nazara/JoltPhysics3D/DebugOff.hpp>
|
||||
48
include/Nazara/Physics2D.hpp
Normal file
48
include/Nazara/Physics2D.hpp
Normal file
@@ -0,0 +1,48 @@
|
||||
// this file was automatically generated and should not be edited
|
||||
|
||||
/*
|
||||
Nazara Engine - Physics2D module
|
||||
|
||||
Copyright (C) 2024 Jérôme "SirLynix" 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_GLOBAL_PHYSICS2D_HPP
|
||||
#define NAZARA_GLOBAL_PHYSICS2D_HPP
|
||||
|
||||
#include <Nazara/Physics2D/Collider2D.hpp>
|
||||
#include <Nazara/Physics2D/Config.hpp>
|
||||
#include <Nazara/Physics2D/Enums.hpp>
|
||||
#include <Nazara/Physics2D/PhysArbiter2D.hpp>
|
||||
#include <Nazara/Physics2D/PhysConstraint2D.hpp>
|
||||
#include <Nazara/Physics2D/Physics2D.hpp>
|
||||
#include <Nazara/Physics2D/PhysWorld2D.hpp>
|
||||
#include <Nazara/Physics2D/RigidBody2D.hpp>
|
||||
|
||||
#ifdef NAZARA_ENTT
|
||||
|
||||
#include <Nazara/Physics2D/Components.hpp>
|
||||
#include <Nazara/Physics2D/Systems.hpp>
|
||||
|
||||
#endif
|
||||
|
||||
#endif // NAZARA_GLOBAL_PHYSICS2D_HPP
|
||||
@@ -1,18 +1,18 @@
|
||||
// Copyright (C) 2024 Jérôme "SirLynix" Leclercq (lynix680@gmail.com)
|
||||
// This file is part of the "Nazara Engine - ChipmunkPhysics2D module"
|
||||
// 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_CHIPMUNKCOLLIDER2D_HPP
|
||||
#define NAZARA_CHIPMUNKPHYSICS2D_CHIPMUNKCOLLIDER2D_HPP
|
||||
#ifndef NAZARA_PHYSICS2D_COLLIDER2D_HPP
|
||||
#define NAZARA_PHYSICS2D_COLLIDER2D_HPP
|
||||
|
||||
#include <NazaraUtils/Prerequisites.hpp>
|
||||
#include <Nazara/ChipmunkPhysics2D/Config.hpp>
|
||||
#include <Nazara/ChipmunkPhysics2D/Enums.hpp>
|
||||
#include <Nazara/Core/ObjectLibrary.hpp>
|
||||
#include <Nazara/Math/Rect.hpp>
|
||||
#include <Nazara/Math/Vector2.hpp>
|
||||
#include <Nazara/Physics2D/Config.hpp>
|
||||
#include <Nazara/Physics2D/Enums.hpp>
|
||||
#include <NazaraUtils/FunctionRef.hpp>
|
||||
#include <NazaraUtils/Signal.hpp>
|
||||
#include <NazaraUtils/SparsePtr.hpp>
|
||||
@@ -23,18 +23,18 @@ struct cpShape;
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
class ChipmunkRigidBody2D;
|
||||
class RigidBody2D;
|
||||
|
||||
class NAZARA_CHIPMUNKPHYSICS2D_API ChipmunkCollider2D
|
||||
class NAZARA_PHYSICS2D_API Collider2D
|
||||
{
|
||||
friend ChipmunkRigidBody2D;
|
||||
friend class ChipmunkCompoundCollider2D; //< See CompoundCollider2D::CreateShapes
|
||||
friend RigidBody2D;
|
||||
friend class CompoundCollider2D; //< See CompoundCollider2D::CreateShapes
|
||||
|
||||
public:
|
||||
inline ChipmunkCollider2D();
|
||||
ChipmunkCollider2D(const ChipmunkCollider2D&) = delete;
|
||||
ChipmunkCollider2D(ChipmunkCollider2D&&) = delete;
|
||||
virtual ~ChipmunkCollider2D();
|
||||
inline Collider2D();
|
||||
Collider2D(const Collider2D&) = delete;
|
||||
Collider2D(Collider2D&&) = delete;
|
||||
virtual ~Collider2D();
|
||||
|
||||
virtual Vector2f ComputeCenterOfMass() const = 0;
|
||||
virtual float ComputeMomentOfInertia(float mass) const = 0;
|
||||
@@ -49,7 +49,7 @@ namespace Nz
|
||||
inline float GetFriction() const;
|
||||
inline Vector2f GetSurfaceVelocity() const;
|
||||
|
||||
virtual ChipmunkColliderType2D GetType() const = 0;
|
||||
virtual ColliderType2D GetType() const = 0;
|
||||
|
||||
inline bool IsTrigger() const;
|
||||
|
||||
@@ -62,11 +62,11 @@ namespace Nz
|
||||
inline void SetSurfaceVelocity(const Vector2f& surfaceVelocity);
|
||||
inline void SetTrigger(bool trigger);
|
||||
|
||||
ChipmunkCollider2D& operator=(const ChipmunkCollider2D&) = delete;
|
||||
ChipmunkCollider2D& operator=(ChipmunkCollider2D&&) = delete;
|
||||
Collider2D& operator=(const Collider2D&) = delete;
|
||||
Collider2D& operator=(Collider2D&&) = delete;
|
||||
|
||||
// Signals:
|
||||
NazaraSignal(OnColliderRelease, const ChipmunkCollider2D* /*collider*/);
|
||||
NazaraSignal(OnColliderRelease, const Collider2D* /*collider*/);
|
||||
|
||||
protected:
|
||||
virtual std::size_t CreateShapes(cpBody* body, std::vector<cpShape*>* shapes) const = 0;
|
||||
@@ -84,11 +84,11 @@ namespace Nz
|
||||
virtual std::size_t GenerateShapes(cpBody* body, std::vector<cpShape*>* shapes) const;
|
||||
};
|
||||
|
||||
class NAZARA_CHIPMUNKPHYSICS2D_API ChipmunkBoxCollider2D : public ChipmunkCollider2D
|
||||
class NAZARA_PHYSICS2D_API BoxCollider2D : public Collider2D
|
||||
{
|
||||
public:
|
||||
ChipmunkBoxCollider2D(const Vector2f& size, float radius = 0.f);
|
||||
ChipmunkBoxCollider2D(const Rectf& rect, float radius = 0.f);
|
||||
BoxCollider2D(const Vector2f& size, float radius = 0.f);
|
||||
BoxCollider2D(const Rectf& rect, float radius = 0.f);
|
||||
|
||||
Nz::Vector2f ComputeCenterOfMass() const override;
|
||||
float ComputeMomentOfInertia(float mass) const override;
|
||||
@@ -96,7 +96,7 @@ namespace Nz
|
||||
inline float GetRadius() const;
|
||||
inline const Rectf& GetRect() const;
|
||||
inline Vector2f GetSize() const;
|
||||
ChipmunkColliderType2D GetType() const override;
|
||||
ColliderType2D GetType() const override;
|
||||
|
||||
private:
|
||||
std::size_t CreateShapes(cpBody* body, std::vector<cpShape*>* shapes) const override;
|
||||
@@ -105,17 +105,17 @@ namespace Nz
|
||||
float m_radius;
|
||||
};
|
||||
|
||||
class NAZARA_CHIPMUNKPHYSICS2D_API ChipmunkCircleCollider2D : public ChipmunkCollider2D
|
||||
class NAZARA_PHYSICS2D_API CircleCollider2D : public Collider2D
|
||||
{
|
||||
public:
|
||||
ChipmunkCircleCollider2D(float radius, const Vector2f& offset = Vector2f::Zero());
|
||||
CircleCollider2D(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;
|
||||
ColliderType2D GetType() const override;
|
||||
|
||||
private:
|
||||
std::size_t CreateShapes(cpBody* body, std::vector<cpShape*>* shapes) const override;
|
||||
@@ -124,18 +124,18 @@ namespace Nz
|
||||
float m_radius;
|
||||
};
|
||||
|
||||
class NAZARA_CHIPMUNKPHYSICS2D_API ChipmunkCompoundCollider2D : public ChipmunkCollider2D
|
||||
class NAZARA_PHYSICS2D_API CompoundCollider2D : public Collider2D
|
||||
{
|
||||
public:
|
||||
ChipmunkCompoundCollider2D(std::vector<std::shared_ptr<ChipmunkCollider2D>> geoms);
|
||||
CompoundCollider2D(std::vector<std::shared_ptr<Collider2D>> 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 const std::vector<std::shared_ptr<Collider2D>>& GetGeoms() const;
|
||||
ColliderType2D GetType() const override;
|
||||
|
||||
inline void OverridesCollisionProperties(bool shouldOverride);
|
||||
|
||||
@@ -143,19 +143,19 @@ namespace Nz
|
||||
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;
|
||||
std::vector<std::shared_ptr<Collider2D>> m_geoms;
|
||||
bool m_doesOverrideCollisionProperties;
|
||||
};
|
||||
|
||||
class NAZARA_CHIPMUNKPHYSICS2D_API ChipmunkConvexCollider2D : public ChipmunkCollider2D
|
||||
class NAZARA_PHYSICS2D_API ConvexCollider2D : public Collider2D
|
||||
{
|
||||
public:
|
||||
ChipmunkConvexCollider2D(SparsePtr<const Vector2f> vertices, std::size_t vertexCount, float radius = 0.f);
|
||||
ConvexCollider2D(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;
|
||||
ColliderType2D GetType() const override;
|
||||
inline const std::vector<Vector2d>& GetVertices() const;
|
||||
|
||||
private:
|
||||
@@ -165,25 +165,25 @@ namespace Nz
|
||||
float m_radius;
|
||||
};
|
||||
|
||||
class NAZARA_CHIPMUNKPHYSICS2D_API ChipmunkNullCollider2D : public ChipmunkCollider2D
|
||||
class NAZARA_PHYSICS2D_API NullCollider2D : public Collider2D
|
||||
{
|
||||
public:
|
||||
ChipmunkNullCollider2D() = default;
|
||||
NullCollider2D() = default;
|
||||
|
||||
Nz::Vector2f ComputeCenterOfMass() const override;
|
||||
float ComputeMomentOfInertia(float mass) const override;
|
||||
|
||||
ChipmunkColliderType2D GetType() const override;
|
||||
ColliderType2D GetType() const override;
|
||||
|
||||
private:
|
||||
std::size_t CreateShapes(cpBody* body, std::vector<cpShape*>* shapes) const override;
|
||||
};
|
||||
|
||||
class NAZARA_CHIPMUNKPHYSICS2D_API ChipmunkSegmentCollider2D : public ChipmunkCollider2D
|
||||
class NAZARA_PHYSICS2D_API SegmentCollider2D : public Collider2D
|
||||
{
|
||||
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);
|
||||
inline SegmentCollider2D(const Vector2f& first, const Vector2f& second, float thickness = 1.f);
|
||||
inline SegmentCollider2D(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;
|
||||
@@ -194,7 +194,7 @@ namespace Nz
|
||||
inline const Vector2f& GetSecondPoint() const;
|
||||
inline const Vector2f& GetSecondPointNeighbor() const;
|
||||
inline float GetThickness() const;
|
||||
ChipmunkColliderType2D GetType() const override;
|
||||
ColliderType2D GetType() const override;
|
||||
|
||||
private:
|
||||
std::size_t CreateShapes(cpBody* body, std::vector<cpShape*>* shapes) const override;
|
||||
@@ -207,6 +207,6 @@ namespace Nz
|
||||
};
|
||||
}
|
||||
|
||||
#include <Nazara/ChipmunkPhysics2D/ChipmunkCollider2D.inl>
|
||||
#include <Nazara/Physics2D/Collider2D.inl>
|
||||
|
||||
#endif // NAZARA_CHIPMUNKPHYSICS2D_CHIPMUNKCOLLIDER2D_HPP
|
||||
#endif // NAZARA_PHYSICS2D_COLLIDER2D_HPP
|
||||
196
include/Nazara/Physics2D/Collider2D.inl
Normal file
196
include/Nazara/Physics2D/Collider2D.inl
Normal file
@@ -0,0 +1,196 @@
|
||||
// Copyright (C) 2024 Jérôme "SirLynix" 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/Physics2D/Debug.hpp>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
inline Collider2D::Collider2D() :
|
||||
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 Collider2D::GetCategoryMask() const
|
||||
{
|
||||
return m_categoryMask;
|
||||
}
|
||||
|
||||
inline UInt32 Collider2D::GetCollisionGroup() const
|
||||
{
|
||||
return m_collisionGroup;
|
||||
}
|
||||
|
||||
inline unsigned int Collider2D::GetCollisionId() const
|
||||
{
|
||||
return m_collisionId;
|
||||
}
|
||||
|
||||
inline UInt32 Collider2D::GetCollisionMask() const
|
||||
{
|
||||
return m_collisionMask;
|
||||
}
|
||||
|
||||
inline float Collider2D::GetElasticity() const
|
||||
{
|
||||
return m_elasticity;
|
||||
}
|
||||
|
||||
inline float Collider2D::GetFriction() const
|
||||
{
|
||||
return m_friction;
|
||||
}
|
||||
|
||||
inline Vector2f Collider2D::GetSurfaceVelocity() const
|
||||
{
|
||||
return m_surfaceVelocity;
|
||||
}
|
||||
|
||||
inline bool Collider2D::IsTrigger() const
|
||||
{
|
||||
return m_trigger;
|
||||
}
|
||||
|
||||
inline void Collider2D::SetCategoryMask(UInt32 categoryMask)
|
||||
{
|
||||
m_categoryMask = categoryMask;
|
||||
}
|
||||
|
||||
inline void Collider2D::SetCollisionGroup(UInt32 groupId)
|
||||
{
|
||||
m_collisionGroup = groupId;
|
||||
}
|
||||
|
||||
inline void Collider2D::SetCollisionId(unsigned int typeId)
|
||||
{
|
||||
m_collisionId = typeId;
|
||||
}
|
||||
|
||||
inline void Collider2D::SetCollisionMask(UInt32 mask)
|
||||
{
|
||||
m_collisionMask = mask;
|
||||
}
|
||||
|
||||
inline void Collider2D::SetElasticity(float elasticity)
|
||||
{
|
||||
m_elasticity = elasticity;
|
||||
}
|
||||
|
||||
inline void Collider2D::SetFriction(float friction)
|
||||
{
|
||||
m_friction = friction;
|
||||
}
|
||||
|
||||
inline void Collider2D::SetSurfaceVelocity(const Vector2f& surfaceVelocity)
|
||||
{
|
||||
m_surfaceVelocity = surfaceVelocity;
|
||||
}
|
||||
|
||||
inline void Collider2D::SetTrigger(bool trigger)
|
||||
{
|
||||
m_trigger = trigger;
|
||||
}
|
||||
|
||||
inline float BoxCollider2D::GetRadius() const
|
||||
{
|
||||
return m_radius;
|
||||
}
|
||||
|
||||
inline const Rectf& BoxCollider2D::GetRect() const
|
||||
{
|
||||
return m_rect;
|
||||
}
|
||||
|
||||
inline Vector2f BoxCollider2D::GetSize() const
|
||||
{
|
||||
return m_rect.GetLengths();
|
||||
}
|
||||
|
||||
|
||||
inline const Vector2f& CircleCollider2D::GetOffset() const
|
||||
{
|
||||
return m_offset;
|
||||
}
|
||||
|
||||
inline float CircleCollider2D::GetRadius() const
|
||||
{
|
||||
return m_radius;
|
||||
}
|
||||
|
||||
|
||||
inline bool Nz::CompoundCollider2D::DoesOverrideCollisionProperties() const
|
||||
{
|
||||
return m_doesOverrideCollisionProperties;
|
||||
}
|
||||
|
||||
inline const std::vector<std::shared_ptr<Collider2D>>& CompoundCollider2D::GetGeoms() const
|
||||
{
|
||||
return m_geoms;
|
||||
}
|
||||
|
||||
inline void Nz::CompoundCollider2D::OverridesCollisionProperties(bool shouldOverride)
|
||||
{
|
||||
m_doesOverrideCollisionProperties = shouldOverride;
|
||||
}
|
||||
|
||||
|
||||
inline const std::vector<Vector2d>& ConvexCollider2D::GetVertices() const
|
||||
{
|
||||
return m_vertices;
|
||||
}
|
||||
|
||||
|
||||
SegmentCollider2D::SegmentCollider2D(const Vector2f& first, const Vector2f& second, float thickness) :
|
||||
SegmentCollider2D(first, first, second, second, thickness)
|
||||
{
|
||||
}
|
||||
|
||||
inline SegmentCollider2D::SegmentCollider2D(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& SegmentCollider2D::GetFirstPoint() const
|
||||
{
|
||||
return m_first;
|
||||
}
|
||||
|
||||
inline const Vector2f& SegmentCollider2D::GetFirstPointNeighbor() const
|
||||
{
|
||||
return m_firstNeighbor;
|
||||
}
|
||||
|
||||
inline float SegmentCollider2D::GetLength() const
|
||||
{
|
||||
return m_first.Distance(m_second);
|
||||
}
|
||||
|
||||
inline const Vector2f& SegmentCollider2D::GetSecondPoint() const
|
||||
{
|
||||
return m_second;
|
||||
}
|
||||
|
||||
inline const Vector2f& SegmentCollider2D::GetSecondPointNeighbor() const
|
||||
{
|
||||
return m_secondNeighbor;
|
||||
}
|
||||
|
||||
inline float SegmentCollider2D::GetThickness() const
|
||||
{
|
||||
return m_thickness;
|
||||
}
|
||||
}
|
||||
|
||||
#include <Nazara/Physics2D/DebugOff.hpp>
|
||||
@@ -1,7 +1,7 @@
|
||||
// this file was automatically generated and should not be edited
|
||||
|
||||
/*
|
||||
Nazara Engine - ChipmunkPhysics2D module
|
||||
Nazara Engine - Physics2D module
|
||||
|
||||
Copyright (C) 2024 Jérôme "SirLynix" Leclercq (lynix680@gmail.com)
|
||||
|
||||
@@ -26,9 +26,9 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifndef NAZARA_CHIPMUNKPHYSICS2D_COMPONENTS_HPP
|
||||
#define NAZARA_CHIPMUNKPHYSICS2D_COMPONENTS_HPP
|
||||
#ifndef NAZARA_PHYSICS2D_COMPONENTS_HPP
|
||||
#define NAZARA_PHYSICS2D_COMPONENTS_HPP
|
||||
|
||||
#include <Nazara/ChipmunkPhysics2D/Components/ChipmunkRigidBody2DComponent.hpp>
|
||||
#include <Nazara/Physics2D/Components/RigidBody2DComponent.hpp>
|
||||
|
||||
#endif // NAZARA_CHIPMUNKPHYSICS2D_COMPONENTS_HPP
|
||||
#endif // NAZARA_PHYSICS2D_COMPONENTS_HPP
|
||||
40
include/Nazara/Physics2D/Components/RigidBody2DComponent.hpp
Normal file
40
include/Nazara/Physics2D/Components/RigidBody2DComponent.hpp
Normal file
@@ -0,0 +1,40 @@
|
||||
// Copyright (C) 2024 Jérôme "SirLynix" 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_PHYSICS2D_COMPONENTS_RIGIDBODY2DCOMPONENT_HPP
|
||||
#define NAZARA_PHYSICS2D_COMPONENTS_RIGIDBODY2DCOMPONENT_HPP
|
||||
|
||||
#include <NazaraUtils/Prerequisites.hpp>
|
||||
#include <Nazara/Physics2D/RigidBody2D.hpp>
|
||||
#include <variant>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
class NAZARA_PHYSICS2D_API RigidBody2DComponent : public RigidBody2D
|
||||
{
|
||||
friend class Physics2DSystem;
|
||||
|
||||
public:
|
||||
inline RigidBody2DComponent(const RigidBody2D::DynamicSettings& settings);
|
||||
inline RigidBody2DComponent(const RigidBody2D::StaticSettings& settings);
|
||||
RigidBody2DComponent(const RigidBody2DComponent&) = delete;
|
||||
RigidBody2DComponent(RigidBody2DComponent&&) noexcept = default;
|
||||
~RigidBody2DComponent() = default;
|
||||
|
||||
RigidBody2DComponent& operator=(const RigidBody2DComponent&) = delete;
|
||||
RigidBody2DComponent& operator=(RigidBody2DComponent&&) noexcept = default;
|
||||
|
||||
private:
|
||||
inline void Construct(PhysWorld2D& world);
|
||||
|
||||
using Setting = std::variant<RigidBody2D::DynamicSettings, RigidBody2D::StaticSettings>;
|
||||
std::unique_ptr<Setting> m_settings;
|
||||
};
|
||||
}
|
||||
|
||||
#include <Nazara/Physics2D/Components/RigidBody2DComponent.inl>
|
||||
|
||||
#endif // NAZARA_PHYSICS2D_COMPONENTS_RIGIDBODY2DCOMPONENT_HPP
|
||||
30
include/Nazara/Physics2D/Components/RigidBody2DComponent.inl
Normal file
30
include/Nazara/Physics2D/Components/RigidBody2DComponent.inl
Normal file
@@ -0,0 +1,30 @@
|
||||
// Copyright (C) 2024 Jérôme "SirLynix" 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/Physics2D/Debug.hpp>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
inline RigidBody2DComponent::RigidBody2DComponent(const RigidBody2D::DynamicSettings& settings)
|
||||
{
|
||||
m_settings = std::make_unique<Setting>(settings);
|
||||
}
|
||||
|
||||
inline RigidBody2DComponent::RigidBody2DComponent(const RigidBody2D::StaticSettings& settings)
|
||||
{
|
||||
m_settings = std::make_unique<Setting>(settings);
|
||||
}
|
||||
|
||||
inline void RigidBody2DComponent::Construct(PhysWorld2D& world)
|
||||
{
|
||||
assert(m_settings);
|
||||
std::visit([&](auto&& arg)
|
||||
{
|
||||
Create(world, arg);
|
||||
}, *m_settings);
|
||||
m_settings.reset();
|
||||
}
|
||||
}
|
||||
|
||||
#include <Nazara/Physics2D/DebugOff.hpp>
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
Nazara Engine - JoltPhysics3D module
|
||||
Nazara Engine - Physics2D module
|
||||
|
||||
Copyright (C) 2024 Jérôme "SirLynix" Leclercq (lynix680@gmail.com)
|
||||
|
||||
@@ -24,25 +24,25 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifndef NAZARA_JOLTPHYSICS3D_CONFIG_HPP
|
||||
#define NAZARA_JOLTPHYSICS3D_CONFIG_HPP
|
||||
#ifndef NAZARA_PHYSICS2D_CONFIG_HPP
|
||||
#define NAZARA_PHYSICS2D_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_JOLTPHYSICS3D_SAFE 1
|
||||
#define NAZARA_PHYSICS2D_SAFE 1
|
||||
|
||||
/// Vérification des valeurs et types de certaines constantes
|
||||
#include <Nazara/JoltPhysics3D/ConfigCheck.hpp>
|
||||
#include <Nazara/Physics2D/ConfigCheck.hpp>
|
||||
|
||||
#if defined(NAZARA_STATIC)
|
||||
#define NAZARA_JOLTPHYSICS3D_API
|
||||
#define NAZARA_PHYSICS2D_API
|
||||
#else
|
||||
#ifdef NAZARA_JOLTPHYSICS3D_BUILD
|
||||
#define NAZARA_JOLTPHYSICS3D_API NAZARA_EXPORT
|
||||
#ifdef NAZARA_PHYSICS2D_BUILD
|
||||
#define NAZARA_PHYSICS2D_API NAZARA_EXPORT
|
||||
#else
|
||||
#define NAZARA_JOLTPHYSICS3D_API NAZARA_IMPORT
|
||||
#define NAZARA_PHYSICS2D_API NAZARA_IMPORT
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#endif // NAZARA_JOLTPHYSICS3D_CONFIG_HPP
|
||||
#endif // NAZARA_PHYSICS2D_CONFIG_HPP
|
||||
@@ -1,11 +1,11 @@
|
||||
// Copyright (C) 2024 Jérôme "SirLynix" Leclercq (lynix680@gmail.com)
|
||||
// This file is part of the "Nazara Engine - ChipmunkPhysics2D module"
|
||||
// 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
|
||||
#ifndef NAZARA_PHYSICS2D_CONFIGCHECK_HPP
|
||||
#define NAZARA_PHYSICS2D_CONFIGCHECK_HPP
|
||||
|
||||
/// This file is used to check the constant values defined in Config.hpp
|
||||
|
||||
@@ -16,4 +16,4 @@
|
||||
|
||||
#undef NazaraCheckTypeAndVal
|
||||
|
||||
#endif // NAZARA_CHIPMUNKPHYSICS2D_CONFIGCHECK_HPP
|
||||
#endif // NAZARA_PHYSICS2D_CONFIGCHECK_HPP
|
||||
@@ -1,5 +1,5 @@
|
||||
// Copyright (C) 2024 Jérôme "SirLynix" Leclercq (lynix680@gmail.com)
|
||||
// This file is part of the "Nazara Engine - JoltPhysics3D module"
|
||||
// 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
|
||||
@@ -1,5 +1,5 @@
|
||||
// Copyright (C) 2024 Jérôme "SirLynix" Leclercq (lynix680@gmail.com)
|
||||
// This file is part of the "Nazara Engine - JoltPhysics3D module"
|
||||
// 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
|
||||
@@ -1,15 +1,15 @@
|
||||
// Copyright (C) 2024 Jérôme "SirLynix" Leclercq (lynix680@gmail.com)
|
||||
// This file is part of the "Nazara Engine - ChipmunkPhysics2D module"
|
||||
// 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
|
||||
#ifndef NAZARA_PHYSICS2D_ENUMS_HPP
|
||||
#define NAZARA_PHYSICS2D_ENUMS_HPP
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
enum class ChipmunkColliderType2D
|
||||
enum class ColliderType2D
|
||||
{
|
||||
Box,
|
||||
Compound,
|
||||
@@ -22,4 +22,4 @@ namespace Nz
|
||||
};
|
||||
}
|
||||
|
||||
#endif // NAZARA_CHIPMUNKPHYSICS2D_ENUMS_HPP
|
||||
#endif // NAZARA_PHYSICS2D_ENUMS_HPP
|
||||
@@ -1,35 +1,35 @@
|
||||
// Copyright (C) 2024 Jérôme "SirLynix" Leclercq (lynix680@gmail.com)
|
||||
// This file is part of the "Nazara Engine - ChipmunkPhysics2D module"
|
||||
// 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_CHIPMUNKARBITER2D_HPP
|
||||
#define NAZARA_CHIPMUNKPHYSICS2D_CHIPMUNKARBITER2D_HPP
|
||||
#ifndef NAZARA_PHYSICS2D_PHYSARBITER2D_HPP
|
||||
#define NAZARA_PHYSICS2D_PHYSARBITER2D_HPP
|
||||
|
||||
#include <NazaraUtils/Prerequisites.hpp>
|
||||
#include <Nazara/ChipmunkPhysics2D/Config.hpp>
|
||||
#include <Nazara/Math/Vector2.hpp>
|
||||
#include <Nazara/Physics2D/Config.hpp>
|
||||
#include <NazaraUtils/MovablePtr.hpp>
|
||||
|
||||
struct cpArbiter;
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
class ChipmunkRigidBody2D;
|
||||
class RigidBody2D;
|
||||
|
||||
class NAZARA_CHIPMUNKPHYSICS2D_API ChipmunkArbiter2D
|
||||
class NAZARA_PHYSICS2D_API PhysArbiter2D
|
||||
{
|
||||
public:
|
||||
inline ChipmunkArbiter2D(cpArbiter* arbiter);
|
||||
ChipmunkArbiter2D(const ChipmunkArbiter2D&) = delete;
|
||||
ChipmunkArbiter2D(ChipmunkArbiter2D&&) = default;
|
||||
~ChipmunkArbiter2D() = default;
|
||||
inline PhysArbiter2D(cpArbiter* arbiter);
|
||||
PhysArbiter2D(const PhysArbiter2D&) = delete;
|
||||
PhysArbiter2D(PhysArbiter2D&&) = default;
|
||||
~PhysArbiter2D() = default;
|
||||
|
||||
float ComputeTotalKinematicEnergy() const;
|
||||
Nz::Vector2f ComputeTotalImpulse() const;
|
||||
|
||||
std::pair<ChipmunkRigidBody2D*, ChipmunkRigidBody2D*> GetBodies() const;
|
||||
std::pair<RigidBody2D*, RigidBody2D*> GetBodies() const;
|
||||
|
||||
std::size_t GetContactCount() const;
|
||||
float GetContactDepth(std::size_t i) const;
|
||||
@@ -48,14 +48,14 @@ namespace Nz
|
||||
void SetFriction(float friction);
|
||||
void SetSurfaceVelocity(const Vector2f& surfaceVelocity);
|
||||
|
||||
ChipmunkArbiter2D& operator=(const ChipmunkArbiter2D&) = delete;
|
||||
ChipmunkArbiter2D& operator=(ChipmunkArbiter2D&&) = default;
|
||||
PhysArbiter2D& operator=(const PhysArbiter2D&) = delete;
|
||||
PhysArbiter2D& operator=(PhysArbiter2D&&) = default;
|
||||
|
||||
private:
|
||||
MovablePtr<cpArbiter> m_arbiter;
|
||||
};
|
||||
}
|
||||
|
||||
#include <Nazara/ChipmunkPhysics2D/ChipmunkArbiter2D.inl>
|
||||
#include <Nazara/Physics2D/PhysArbiter2D.inl>
|
||||
|
||||
#endif // NAZARA_CHIPMUNKPHYSICS2D_CHIPMUNKARBITER2D_HPP
|
||||
#endif // NAZARA_PHYSICS2D_PHYSARBITER2D_HPP
|
||||
16
include/Nazara/Physics2D/PhysArbiter2D.inl
Normal file
16
include/Nazara/Physics2D/PhysArbiter2D.inl
Normal file
@@ -0,0 +1,16 @@
|
||||
// Copyright (C) 2024 Jérôme "SirLynix" 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/Physics2D/Debug.hpp>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
inline PhysArbiter2D::PhysArbiter2D(cpArbiter* arbiter) :
|
||||
m_arbiter(arbiter)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
#include <Nazara/Physics2D/DebugOff.hpp>
|
||||
238
include/Nazara/Physics2D/PhysConstraint2D.hpp
Normal file
238
include/Nazara/Physics2D/PhysConstraint2D.hpp
Normal file
@@ -0,0 +1,238 @@
|
||||
// Copyright (C) 2024 Jérôme "SirLynix" 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_PHYSICS2D_PHYSCONSTRAINT2D_HPP
|
||||
#define NAZARA_PHYSICS2D_PHYSCONSTRAINT2D_HPP
|
||||
|
||||
#include <NazaraUtils/Prerequisites.hpp>
|
||||
#include <Nazara/Core/HandledObject.hpp>
|
||||
#include <Nazara/Core/ObjectHandle.hpp>
|
||||
#include <Nazara/Math/Angle.hpp>
|
||||
#include <Nazara/Physics2D/Config.hpp>
|
||||
#include <Nazara/Physics2D/PhysWorld2D.hpp>
|
||||
#include <Nazara/Physics2D/RigidBody2D.hpp>
|
||||
#include <NazaraUtils/MovablePtr.hpp>
|
||||
|
||||
struct cpConstraint;
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
class PhysConstraint2D;
|
||||
|
||||
using PhysConstraint2DHandle = ObjectHandle<PhysConstraint2D>;
|
||||
|
||||
class NAZARA_PHYSICS2D_API PhysConstraint2D : public HandledObject<PhysConstraint2D>
|
||||
{
|
||||
public:
|
||||
PhysConstraint2D(const PhysConstraint2D&) = delete;
|
||||
PhysConstraint2D(PhysConstraint2D&& constraint) noexcept;
|
||||
virtual ~PhysConstraint2D();
|
||||
|
||||
void EnableBodyCollision(bool enable);
|
||||
|
||||
RigidBody2D& GetBodyA();
|
||||
const RigidBody2D& GetBodyA() const;
|
||||
RigidBody2D& GetBodyB();
|
||||
const RigidBody2D& GetBodyB() const;
|
||||
float GetErrorBias() const;
|
||||
float GetLastImpulse() const;
|
||||
float GetMaxBias() const;
|
||||
float GetMaxForce() const;
|
||||
PhysWorld2D& GetWorld();
|
||||
const PhysWorld2D& GetWorld() const;
|
||||
|
||||
bool IsBodyCollisionEnabled() const;
|
||||
bool IsSingleBody() const;
|
||||
|
||||
void SetErrorBias(float bias);
|
||||
void SetMaxBias(float bias);
|
||||
void SetMaxForce(float force);
|
||||
|
||||
PhysConstraint2D& operator=(const PhysConstraint2D&) = delete;
|
||||
PhysConstraint2D& operator=(PhysConstraint2D&& constraint) noexcept;
|
||||
|
||||
protected:
|
||||
PhysConstraint2D(PhysWorld2D* world, cpConstraint* constraint);
|
||||
|
||||
MovablePtr<cpConstraint> m_constraint;
|
||||
|
||||
private:
|
||||
void Destroy();
|
||||
};
|
||||
|
||||
class PhysDampedSpringConstraint2D;
|
||||
|
||||
using PhysDampedSpringConstraint2DHandle = ObjectHandle<PhysDampedSpringConstraint2D>;
|
||||
|
||||
class NAZARA_PHYSICS2D_API PhysDampedSpringConstraint2D : public PhysConstraint2D
|
||||
{
|
||||
public:
|
||||
PhysDampedSpringConstraint2D(RigidBody2D& first, RigidBody2D& second, const Vector2f& firstAnchor, const Vector2f& secondAnchor, float restLength, float stiffness, float damping);
|
||||
~PhysDampedSpringConstraint2D() = 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 PhysDampedRotarySpringConstraint2D;
|
||||
|
||||
using PhysDampedRotarySpringConstraint2DHandle = ObjectHandle<PhysDampedRotarySpringConstraint2D>;
|
||||
|
||||
class NAZARA_PHYSICS2D_API PhysDampedRotarySpringConstraint2D : public PhysConstraint2D
|
||||
{
|
||||
public:
|
||||
PhysDampedRotarySpringConstraint2D(RigidBody2D& first, RigidBody2D& second, const RadianAnglef& restAngle, float stiffness, float damping);
|
||||
~PhysDampedRotarySpringConstraint2D() = default;
|
||||
|
||||
float GetDamping() const;
|
||||
RadianAnglef GetRestAngle() const;
|
||||
float GetStiffness() const;
|
||||
|
||||
void SetDamping(float newDamping);
|
||||
void SetRestAngle(const RadianAnglef& newAngle);
|
||||
void SetStiffness(float newStiffness);
|
||||
};
|
||||
|
||||
class PhysGearConstraint2D;
|
||||
|
||||
using PhysGearConstraint2DHandle = ObjectHandle<PhysGearConstraint2D>;
|
||||
|
||||
class NAZARA_PHYSICS2D_API PhysGearConstraint2D : public PhysConstraint2D
|
||||
{
|
||||
public:
|
||||
PhysGearConstraint2D(RigidBody2D& first, RigidBody2D& second, float phase, float ratio);
|
||||
~PhysGearConstraint2D() = default;
|
||||
|
||||
float GetPhase() const;
|
||||
float GetRatio() const;
|
||||
|
||||
void SetPhase(float phase);
|
||||
void SetRatio(float ratio);
|
||||
};
|
||||
|
||||
class PhysMotorConstraint2D;
|
||||
|
||||
using PhysMotorConstraint2DHandle = ObjectHandle<PhysMotorConstraint2D>;
|
||||
|
||||
class NAZARA_PHYSICS2D_API PhysMotorConstraint2D : public PhysConstraint2D
|
||||
{
|
||||
public:
|
||||
PhysMotorConstraint2D(RigidBody2D& first, RigidBody2D& second, float rate);
|
||||
~PhysMotorConstraint2D() = default;
|
||||
|
||||
float GetRate() const;
|
||||
void SetRate(float rate);
|
||||
};
|
||||
|
||||
class PhysPinConstraint2D;
|
||||
|
||||
using PhysPinConstraint2DHandle = ObjectHandle<PhysPinConstraint2D>;
|
||||
|
||||
class NAZARA_PHYSICS2D_API PhysPinConstraint2D : public PhysConstraint2D
|
||||
{
|
||||
public:
|
||||
PhysPinConstraint2D(RigidBody2D& body, const Vector2f& anchor);
|
||||
PhysPinConstraint2D(RigidBody2D& first, RigidBody2D& second, const Vector2f& firstAnchor, const Vector2f& secondAnchor);
|
||||
~PhysPinConstraint2D() = 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 PhysPivotConstraint2D;
|
||||
|
||||
using PhysPivotConstraint2DHandle = ObjectHandle<PhysPivotConstraint2D>;
|
||||
|
||||
class NAZARA_PHYSICS2D_API PhysPivotConstraint2D : public PhysConstraint2D
|
||||
{
|
||||
public:
|
||||
PhysPivotConstraint2D(RigidBody2D& body, const Vector2f& anchor);
|
||||
PhysPivotConstraint2D(RigidBody2D& first, RigidBody2D& second, const Vector2f& anchor);
|
||||
PhysPivotConstraint2D(RigidBody2D& first, RigidBody2D& second, const Vector2f& firstAnchor, const Vector2f& secondAnchor);
|
||||
~PhysPivotConstraint2D() = default;
|
||||
|
||||
Vector2f GetFirstAnchor() const;
|
||||
Vector2f GetSecondAnchor() const;
|
||||
|
||||
void SetFirstAnchor(const Vector2f& firstAnchor);
|
||||
void SetSecondAnchor(const Vector2f& firstAnchor);
|
||||
};
|
||||
|
||||
class PhysRatchetConstraint2D;
|
||||
|
||||
using PhysRatchetConstraint2DHandle = ObjectHandle<PhysRatchetConstraint2D>;
|
||||
|
||||
class NAZARA_PHYSICS2D_API PhysRatchetConstraint2D : public PhysConstraint2D
|
||||
{
|
||||
public:
|
||||
PhysRatchetConstraint2D(RigidBody2D& first, RigidBody2D& second, float phase, float ratchet);
|
||||
~PhysRatchetConstraint2D() = default;
|
||||
|
||||
RadianAnglef GetAngle() const;
|
||||
float GetPhase() const;
|
||||
float GetRatchet() const;
|
||||
|
||||
void SetAngle(const RadianAnglef& angle);
|
||||
void SetPhase(float phase);
|
||||
void SetRatchet(float ratchet);
|
||||
};
|
||||
|
||||
class PhysRotaryLimitConstraint2D;
|
||||
|
||||
using PhysRotaryLimitConstraint2DHandle = ObjectHandle<PhysRotaryLimitConstraint2D>;
|
||||
|
||||
class NAZARA_PHYSICS2D_API PhysRotaryLimitConstraint2D : public PhysConstraint2D
|
||||
{
|
||||
public:
|
||||
PhysRotaryLimitConstraint2D(RigidBody2D& first, RigidBody2D& second, const RadianAnglef& minAngle, const RadianAnglef& maxAngle);
|
||||
~PhysRotaryLimitConstraint2D() = default;
|
||||
|
||||
RadianAnglef GetMaxAngle() const;
|
||||
RadianAnglef GetMinAngle() const;
|
||||
|
||||
void SetMaxAngle(const RadianAnglef& maxAngle);
|
||||
void SetMinAngle(const RadianAnglef& minAngle);
|
||||
};
|
||||
|
||||
class PhysSlideConstraint2D;
|
||||
|
||||
using PhysSlideConstraint2DHandle = ObjectHandle<PhysSlideConstraint2D>;
|
||||
|
||||
class NAZARA_PHYSICS2D_API PhysSlideConstraint2D : public PhysConstraint2D
|
||||
{
|
||||
public:
|
||||
PhysSlideConstraint2D(RigidBody2D& first, RigidBody2D& second, const Vector2f& firstAnchor, const Vector2f& secondAnchor, float min, float max);
|
||||
~PhysSlideConstraint2D() = 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/Physics2D/PhysConstraint2D.inl>
|
||||
|
||||
#endif // NAZARA_PHYSICS2D_PHYSCONSTRAINT2D_HPP
|
||||
@@ -1,12 +1,12 @@
|
||||
// Copyright (C) 2024 Jérôme "SirLynix" Leclercq (lynix680@gmail.com)
|
||||
// This file is part of the "Nazara Engine - ChipmunkPhysics2D module"
|
||||
// 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>
|
||||
#include <Nazara/Physics2D/Debug.hpp>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
}
|
||||
|
||||
#include <Nazara/ChipmunkPhysics2D/DebugOff.hpp>
|
||||
#include <Nazara/Physics2D/DebugOff.hpp>
|
||||
@@ -1,19 +1,19 @@
|
||||
// Copyright (C) 2024 Jérôme "SirLynix" Leclercq (lynix680@gmail.com)
|
||||
// This file is part of the "Nazara Engine - ChipmunkPhysics2D module"
|
||||
// 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_CHIPMUNKPHYSWORLD2D_HPP
|
||||
#define NAZARA_CHIPMUNKPHYSICS2D_CHIPMUNKPHYSWORLD2D_HPP
|
||||
#ifndef NAZARA_PHYSICS2D_PHYSWORLD2D_HPP
|
||||
#define NAZARA_PHYSICS2D_PHYSWORLD2D_HPP
|
||||
|
||||
#include <NazaraUtils/Prerequisites.hpp>
|
||||
#include <Nazara/ChipmunkPhysics2D/ChipmunkRigidBody2D.hpp>
|
||||
#include <Nazara/ChipmunkPhysics2D/Config.hpp>
|
||||
#include <Nazara/Core/Color.hpp>
|
||||
#include <Nazara/Core/Time.hpp>
|
||||
#include <Nazara/Math/Angle.hpp>
|
||||
#include <Nazara/Math/Vector2.hpp>
|
||||
#include <Nazara/Physics2D/Config.hpp>
|
||||
#include <Nazara/Physics2D/RigidBody2D.hpp>
|
||||
#include <NazaraUtils/Bitset.hpp>
|
||||
#include <NazaraUtils/FunctionRef.hpp>
|
||||
#include <NazaraUtils/Signal.hpp>
|
||||
@@ -27,23 +27,23 @@ struct cpSpace;
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
class ChipmunkArbiter2D;
|
||||
class PhysArbiter2D;
|
||||
|
||||
class NAZARA_CHIPMUNKPHYSICS2D_API ChipmunkPhysWorld2D
|
||||
class NAZARA_PHYSICS2D_API PhysWorld2D
|
||||
{
|
||||
friend ChipmunkRigidBody2D;
|
||||
friend RigidBody2D;
|
||||
|
||||
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 ContactEndCallback = std::function<void(PhysWorld2D& world, PhysArbiter2D& arbiter, RigidBody2D& bodyA, RigidBody2D& bodyB, void* userdata)>;
|
||||
using ContactPreSolveCallback = std::function<bool(PhysWorld2D& world, PhysArbiter2D& arbiter, RigidBody2D& bodyA, RigidBody2D& bodyB, void* userdata)>;
|
||||
using ContactPostSolveCallback = std::function<void(PhysWorld2D& world, PhysArbiter2D& arbiter, RigidBody2D& bodyA, RigidBody2D& bodyB, void* userdata)>;
|
||||
using ContactStartCallback = std::function<bool(PhysWorld2D& world, PhysArbiter2D& arbiter, RigidBody2D& bodyA, RigidBody2D& 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)>;
|
||||
using DebugDrawGetColorCallback = std::function<Color(RigidBody2D& body, std::size_t shapeIndex, void* userdata)>;
|
||||
|
||||
public:
|
||||
struct ContactCallbacks;
|
||||
@@ -51,10 +51,10 @@ namespace Nz
|
||||
struct NearestQueryResult;
|
||||
struct RaycastHit;
|
||||
|
||||
ChipmunkPhysWorld2D();
|
||||
ChipmunkPhysWorld2D(const ChipmunkPhysWorld2D&) = delete;
|
||||
ChipmunkPhysWorld2D(ChipmunkPhysWorld2D&&) = delete;
|
||||
~ChipmunkPhysWorld2D();
|
||||
PhysWorld2D();
|
||||
PhysWorld2D(const PhysWorld2D&) = delete;
|
||||
PhysWorld2D(PhysWorld2D&&) = delete;
|
||||
~PhysWorld2D();
|
||||
|
||||
void DebugDraw(const DebugDrawOptions& options, bool drawShapes = true, bool drawConstraints = true, bool drawCollisions = true) const;
|
||||
|
||||
@@ -65,15 +65,15 @@ namespace Nz
|
||||
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, RigidBody2D** 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 RegionQuery(const Rectf& boundingBox, UInt32 collisionGroup, UInt32 categoryMask, UInt32 collisionMask, const FunctionRef<void(RigidBody2D*)>& callback);
|
||||
void RegionQuery(const Rectf& boundingBox, UInt32 collisionGroup, UInt32 categoryMask, UInt32 collisionMask, std::vector<RigidBody2D*>* bodies);
|
||||
|
||||
void RegisterCallbacks(unsigned int collisionId, ContactCallbacks callbacks);
|
||||
void RegisterCallbacks(unsigned int collisionIdA, unsigned int collisionIdB, ContactCallbacks callbacks);
|
||||
@@ -89,8 +89,8 @@ namespace Nz
|
||||
|
||||
void UseSpatialHash(float cellSize, std::size_t entityCount);
|
||||
|
||||
ChipmunkPhysWorld2D& operator=(const ChipmunkPhysWorld2D&) = delete;
|
||||
ChipmunkPhysWorld2D& operator=(ChipmunkPhysWorld2D&&) = delete;
|
||||
PhysWorld2D& operator=(const PhysWorld2D&) = delete;
|
||||
PhysWorld2D& operator=(PhysWorld2D&&) = delete;
|
||||
|
||||
struct ContactCallbacks
|
||||
{
|
||||
@@ -119,7 +119,7 @@ namespace Nz
|
||||
|
||||
struct NearestQueryResult
|
||||
{
|
||||
ChipmunkRigidBody2D* nearestBody;
|
||||
RigidBody2D* nearestBody;
|
||||
Vector2f closestPoint;
|
||||
Vector2f fraction;
|
||||
float distance;
|
||||
@@ -127,30 +127,30 @@ namespace Nz
|
||||
|
||||
struct RaycastHit
|
||||
{
|
||||
ChipmunkRigidBody2D* nearestBody;
|
||||
RigidBody2D* nearestBody;
|
||||
Vector2f hitPos;
|
||||
Vector2f hitNormal;
|
||||
float fraction;
|
||||
};
|
||||
|
||||
NazaraSignal(OnPhysWorld2DPreStep, const ChipmunkPhysWorld2D* /*physWorld*/, float /*invStepCount*/);
|
||||
NazaraSignal(OnPhysWorld2DPostStep, const ChipmunkPhysWorld2D* /*physWorld*/, float /*invStepCount*/);
|
||||
NazaraSignal(OnPhysWorld2DPreStep, const PhysWorld2D* /*physWorld*/, float /*invStepCount*/);
|
||||
NazaraSignal(OnPhysWorld2DPostStep, const PhysWorld2D* /*physWorld*/, float /*invStepCount*/);
|
||||
|
||||
private:
|
||||
using PostStep = std::function<void(ChipmunkRigidBody2D* body)>;
|
||||
using PostStep = std::function<void(RigidBody2D* body)>;
|
||||
|
||||
static constexpr std::size_t FreeBodyIdGrowRate = 256;
|
||||
|
||||
void DeferBodyAction(ChipmunkRigidBody2D& rigidBody, PostStep&& func);
|
||||
void DeferBodyAction(RigidBody2D& rigidBody, PostStep&& func);
|
||||
void InitCallbacks(cpCollisionHandler* handler, ContactCallbacks callbacks);
|
||||
inline UInt32 RegisterBody(ChipmunkRigidBody2D& rigidBody);
|
||||
inline UInt32 RegisterBody(RigidBody2D& rigidBody);
|
||||
inline void UnregisterBody(UInt32 bodyIndex);
|
||||
inline void UpdateBodyPointer(ChipmunkRigidBody2D& rigidBody);
|
||||
inline void UpdateBodyPointer(RigidBody2D& rigidBody);
|
||||
|
||||
std::size_t m_maxStepCount;
|
||||
std::unordered_map<cpCollisionHandler*, std::unique_ptr<ContactCallbacks>> m_callbacks;
|
||||
std::unordered_map<UInt32, std::vector<PostStep>> m_rigidBodyPostSteps;
|
||||
std::vector<ChipmunkRigidBody2D*> m_bodies;
|
||||
std::vector<RigidBody2D*> m_bodies;
|
||||
cpSpace* m_handle;
|
||||
Bitset<UInt64> m_freeBodyIndices;
|
||||
Time m_stepSize;
|
||||
@@ -158,6 +158,6 @@ namespace Nz
|
||||
};
|
||||
}
|
||||
|
||||
#include <Nazara/ChipmunkPhysics2D/ChipmunkPhysWorld2D.inl>
|
||||
#include <Nazara/Physics2D/PhysWorld2D.inl>
|
||||
|
||||
#endif // NAZARA_CHIPMUNKPHYSICS2D_CHIPMUNKPHYSWORLD2D_HPP
|
||||
#endif // NAZARA_PHYSICS2D_PHYSWORLD2D_HPP
|
||||
@@ -1,13 +1,13 @@
|
||||
// Copyright (C) 2024 Jérôme "SirLynix" Leclercq (lynix680@gmail.com)
|
||||
// This file is part of the "Nazara Engine - ChipmunkPhysics2D module"
|
||||
// This file is part of the "Nazara Engine - Physics2D module"
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#include <cassert>
|
||||
#include <Nazara/ChipmunkPhysics2D/Debug.hpp>
|
||||
#include <Nazara/Physics2D/Debug.hpp>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
inline UInt32 ChipmunkPhysWorld2D::RegisterBody(ChipmunkRigidBody2D& rigidBody)
|
||||
inline UInt32 PhysWorld2D::RegisterBody(RigidBody2D& rigidBody)
|
||||
{
|
||||
std::size_t bodyIndex = m_freeBodyIndices.FindFirst();
|
||||
if (bodyIndex == m_freeBodyIndices.npos)
|
||||
@@ -26,7 +26,7 @@ namespace Nz
|
||||
return SafeCast<UInt32>(bodyIndex);
|
||||
}
|
||||
|
||||
inline void ChipmunkPhysWorld2D::UnregisterBody(UInt32 bodyIndex)
|
||||
inline void PhysWorld2D::UnregisterBody(UInt32 bodyIndex)
|
||||
{
|
||||
assert(!m_freeBodyIndices.Test(bodyIndex));
|
||||
m_freeBodyIndices.Set(bodyIndex, true);
|
||||
@@ -36,7 +36,7 @@ namespace Nz
|
||||
m_rigidBodyPostSteps.erase(bodyIndex);
|
||||
}
|
||||
|
||||
inline void ChipmunkPhysWorld2D::UpdateBodyPointer(ChipmunkRigidBody2D& rigidBody)
|
||||
inline void PhysWorld2D::UpdateBodyPointer(RigidBody2D& rigidBody)
|
||||
{
|
||||
UInt32 bodyIndex = rigidBody.GetBodyIndex();
|
||||
assert(m_bodies[bodyIndex]);
|
||||
@@ -44,4 +44,4 @@ namespace Nz
|
||||
}
|
||||
}
|
||||
|
||||
#include <Nazara/ChipmunkPhysics2D/DebugOff.hpp>
|
||||
#include <Nazara/Physics2D/DebugOff.hpp>
|
||||
33
include/Nazara/Physics2D/Physics2D.hpp
Normal file
33
include/Nazara/Physics2D/Physics2D.hpp
Normal file
@@ -0,0 +1,33 @@
|
||||
// Copyright (C) 2024 Jérôme "SirLynix" 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_PHYSICS2D_HPP
|
||||
#define NAZARA_PHYSICS2D_HPP
|
||||
|
||||
#include <NazaraUtils/Prerequisites.hpp>
|
||||
#include <Nazara/Core/Core.hpp>
|
||||
#include <Nazara/Physics2D/Config.hpp>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
class NAZARA_PHYSICS2D_API Physics2D : public ModuleBase<Physics2D>
|
||||
{
|
||||
friend ModuleBase;
|
||||
|
||||
public:
|
||||
using Dependencies = TypeList<Core>;
|
||||
|
||||
struct Config {};
|
||||
|
||||
Physics2D(Config /*config*/);
|
||||
~Physics2D() = default;
|
||||
|
||||
private:
|
||||
static Physics2D* s_instance;
|
||||
};
|
||||
}
|
||||
|
||||
#endif // NAZARA_PHYSICS2D_HPP
|
||||
@@ -1,18 +1,18 @@
|
||||
// Copyright (C) 2024 Jérôme "SirLynix" Leclercq (lynix680@gmail.com)
|
||||
// This file is part of the "Nazara Engine - ChipmunkPhysics2D module"
|
||||
// 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_CHIPMUNKRIGIDBODY2D_HPP
|
||||
#define NAZARA_CHIPMUNKPHYSICS2D_CHIPMUNKRIGIDBODY2D_HPP
|
||||
#ifndef NAZARA_PHYSICS2D_RIGIDBODY2D_HPP
|
||||
#define NAZARA_PHYSICS2D_RIGIDBODY2D_HPP
|
||||
|
||||
#include <NazaraUtils/Prerequisites.hpp>
|
||||
#include <Nazara/ChipmunkPhysics2D/ChipmunkCollider2D.hpp>
|
||||
#include <Nazara/ChipmunkPhysics2D/Config.hpp>
|
||||
#include <Nazara/Core/Enums.hpp>
|
||||
#include <Nazara/Math/Angle.hpp>
|
||||
#include <Nazara/Math/Rect.hpp>
|
||||
#include <Nazara/Physics2D/Collider2D.hpp>
|
||||
#include <Nazara/Physics2D/Config.hpp>
|
||||
#include <NazaraUtils/Signal.hpp>
|
||||
#include <functional>
|
||||
#include <limits>
|
||||
@@ -21,22 +21,22 @@ struct cpBody;
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
class ChipmunkArbiter2D;
|
||||
class ChipmunkPhysWorld2D;
|
||||
class PhysArbiter2D;
|
||||
class PhysWorld2D;
|
||||
|
||||
class NAZARA_CHIPMUNKPHYSICS2D_API ChipmunkRigidBody2D
|
||||
class NAZARA_PHYSICS2D_API RigidBody2D
|
||||
{
|
||||
public:
|
||||
struct DynamicSettings;
|
||||
struct StaticSettings;
|
||||
|
||||
using VelocityFunc = std::function<void(ChipmunkRigidBody2D& body2D, const Vector2f& gravity, float damping, float deltaTime)>;
|
||||
using VelocityFunc = std::function<void(RigidBody2D& body2D, const Vector2f& gravity, float damping, float deltaTime)>;
|
||||
|
||||
inline ChipmunkRigidBody2D(ChipmunkPhysWorld2D& world, const DynamicSettings& settings);
|
||||
inline ChipmunkRigidBody2D(ChipmunkPhysWorld2D& world, const StaticSettings& settings);
|
||||
ChipmunkRigidBody2D(const ChipmunkRigidBody2D& object);
|
||||
ChipmunkRigidBody2D(ChipmunkRigidBody2D&& object) noexcept;
|
||||
inline ~ChipmunkRigidBody2D();
|
||||
inline RigidBody2D(PhysWorld2D& world, const DynamicSettings& settings);
|
||||
inline RigidBody2D(PhysWorld2D& world, const StaticSettings& settings);
|
||||
RigidBody2D(const RigidBody2D& object);
|
||||
RigidBody2D(RigidBody2D&& object) noexcept;
|
||||
inline ~RigidBody2D();
|
||||
|
||||
inline void AddForce(const Vector2f& force, CoordSys coordSys = CoordSys::Global);
|
||||
void AddForce(const Vector2f& force, const Vector2f& point, CoordSys coordSys = CoordSys::Global);
|
||||
@@ -48,7 +48,7 @@ namespace Nz
|
||||
|
||||
void EnableSimulation(bool simulation);
|
||||
|
||||
void ForEachArbiter(const FunctionRef<void(ChipmunkArbiter2D& /*arbiter*/)>& callback);
|
||||
void ForEachArbiter(const FunctionRef<void(PhysArbiter2D& /*arbiter*/)>& callback);
|
||||
void ForceSleep();
|
||||
|
||||
Rectf GetAABB() const;
|
||||
@@ -56,7 +56,7 @@ namespace Nz
|
||||
inline UInt32 GetBodyIndex() const;
|
||||
float GetElasticity(std::size_t shapeIndex = 0) const;
|
||||
float GetFriction(std::size_t shapeIndex = 0) const;
|
||||
inline const std::shared_ptr<ChipmunkCollider2D>& GetGeom() const;
|
||||
inline const std::shared_ptr<Collider2D>& GetGeom() const;
|
||||
inline cpBody* GetHandle() const;
|
||||
inline float GetMass() const;
|
||||
Vector2f GetMassCenter(CoordSys coordSys = CoordSys::Local) const;
|
||||
@@ -69,7 +69,7 @@ namespace Nz
|
||||
Vector2f GetSurfaceVelocity(std::size_t shapeIndex = 0) const;
|
||||
Vector2f GetVelocity() const;
|
||||
inline const VelocityFunc& GetVelocityFunction() const;
|
||||
inline ChipmunkPhysWorld2D* GetWorld() const;
|
||||
inline PhysWorld2D* GetWorld() const;
|
||||
|
||||
inline bool IsKinematic() const;
|
||||
inline bool IsSimulationEnabled() const;
|
||||
@@ -83,7 +83,7 @@ namespace Nz
|
||||
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 SetGeom(std::shared_ptr<Collider2D> 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);
|
||||
@@ -107,15 +107,15 @@ namespace Nz
|
||||
|
||||
void Wakeup();
|
||||
|
||||
ChipmunkRigidBody2D& operator=(const ChipmunkRigidBody2D& object);
|
||||
ChipmunkRigidBody2D& operator=(ChipmunkRigidBody2D&& object) noexcept;
|
||||
RigidBody2D& operator=(const RigidBody2D& object);
|
||||
RigidBody2D& operator=(RigidBody2D&& object) noexcept;
|
||||
|
||||
static constexpr UInt32 InvalidBodyIndex = std::numeric_limits<UInt32>::max();
|
||||
static constexpr std::size_t InvalidShapeIndex = std::numeric_limits<std::size_t>::max();
|
||||
|
||||
struct CommonSettings
|
||||
{
|
||||
std::shared_ptr<ChipmunkCollider2D> geom;
|
||||
std::shared_ptr<Collider2D> geom;
|
||||
RadianAnglef rotation = RadianAnglef::Zero();
|
||||
Vector2f position = Vector2f::Zero();
|
||||
bool initiallySleeping = false;
|
||||
@@ -125,7 +125,7 @@ namespace Nz
|
||||
struct DynamicSettings : CommonSettings
|
||||
{
|
||||
DynamicSettings() = default;
|
||||
DynamicSettings(std::shared_ptr<ChipmunkCollider2D> collider, float mass_) :
|
||||
DynamicSettings(std::shared_ptr<Collider2D> collider, float mass_) :
|
||||
mass(mass_)
|
||||
{
|
||||
geom = std::move(collider);
|
||||
@@ -140,16 +140,16 @@ namespace Nz
|
||||
struct StaticSettings : CommonSettings
|
||||
{
|
||||
StaticSettings() = default;
|
||||
StaticSettings(std::shared_ptr<ChipmunkCollider2D> collider)
|
||||
StaticSettings(std::shared_ptr<Collider2D> collider)
|
||||
{
|
||||
geom = std::move(collider);
|
||||
}
|
||||
};
|
||||
|
||||
protected:
|
||||
ChipmunkRigidBody2D() = default;
|
||||
void Create(ChipmunkPhysWorld2D& world, const DynamicSettings& settings);
|
||||
void Create(ChipmunkPhysWorld2D& world, const StaticSettings& settings);
|
||||
RigidBody2D() = default;
|
||||
void Create(PhysWorld2D& world, const DynamicSettings& settings);
|
||||
void Create(PhysWorld2D& world, const StaticSettings& settings);
|
||||
void Destroy();
|
||||
|
||||
private:
|
||||
@@ -161,9 +161,9 @@ namespace Nz
|
||||
static void CopyShapeData(cpShape* from, cpShape* to);
|
||||
|
||||
std::vector<cpShape*> m_shapes;
|
||||
std::shared_ptr<ChipmunkCollider2D> m_geom;
|
||||
std::shared_ptr<Collider2D> m_geom;
|
||||
MovablePtr<cpBody> m_handle;
|
||||
MovablePtr<ChipmunkPhysWorld2D> m_world;
|
||||
MovablePtr<PhysWorld2D> m_world;
|
||||
UInt32 m_bodyIndex;
|
||||
Vector2f m_positionOffset;
|
||||
VelocityFunc m_velocityFunc;
|
||||
@@ -175,6 +175,6 @@ namespace Nz
|
||||
};
|
||||
}
|
||||
|
||||
#include <Nazara/ChipmunkPhysics2D/ChipmunkRigidBody2D.inl>
|
||||
#include <Nazara/Physics2D/RigidBody2D.inl>
|
||||
|
||||
#endif // NAZARA_CHIPMUNKPHYSICS2D_CHIPMUNKRIGIDBODY2D_HPP
|
||||
#endif // NAZARA_PHYSICS2D_RIGIDBODY2D_HPP
|
||||
99
include/Nazara/Physics2D/RigidBody2D.inl
Normal file
99
include/Nazara/Physics2D/RigidBody2D.inl
Normal file
@@ -0,0 +1,99 @@
|
||||
// Copyright (C) 2024 Jérôme "SirLynix" 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/Physics2D/Debug.hpp>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
inline RigidBody2D::RigidBody2D(PhysWorld2D& world, const DynamicSettings& settings)
|
||||
{
|
||||
Create(world, settings);
|
||||
}
|
||||
|
||||
inline RigidBody2D::RigidBody2D(PhysWorld2D& world, const StaticSettings& settings)
|
||||
{
|
||||
Create(world, settings);
|
||||
}
|
||||
|
||||
inline RigidBody2D::~RigidBody2D()
|
||||
{
|
||||
Destroy();
|
||||
}
|
||||
|
||||
inline void RigidBody2D::AddForce(const Vector2f& force, CoordSys coordSys)
|
||||
{
|
||||
return AddForce(force, GetMassCenter(coordSys), coordSys);
|
||||
}
|
||||
|
||||
inline void RigidBody2D::AddImpulse(const Vector2f& impulse, CoordSys coordSys)
|
||||
{
|
||||
return AddImpulse(impulse, GetMassCenter(coordSys), coordSys);
|
||||
}
|
||||
|
||||
inline UInt32 RigidBody2D::GetBodyIndex() const
|
||||
{
|
||||
return m_bodyIndex;
|
||||
}
|
||||
|
||||
inline const std::shared_ptr<Collider2D>& RigidBody2D::GetGeom() const
|
||||
{
|
||||
return m_geom;
|
||||
}
|
||||
|
||||
inline cpBody* RigidBody2D::GetHandle() const
|
||||
{
|
||||
return m_handle;
|
||||
}
|
||||
|
||||
inline float RigidBody2D::GetMass() const
|
||||
{
|
||||
return m_mass;
|
||||
}
|
||||
|
||||
inline const Vector2f& RigidBody2D::GetPositionOffset() const
|
||||
{
|
||||
return m_positionOffset;
|
||||
}
|
||||
|
||||
inline std::size_t RigidBody2D::GetShapeIndex(cpShape* shape) const
|
||||
{
|
||||
auto it = std::find(m_shapes.begin(), m_shapes.end(), shape);
|
||||
if (it == m_shapes.end())
|
||||
return InvalidShapeIndex;
|
||||
|
||||
return std::distance(m_shapes.begin(), it);
|
||||
}
|
||||
|
||||
inline std::size_t RigidBody2D::GetShapeCount() const
|
||||
{
|
||||
return m_shapes.size();
|
||||
}
|
||||
|
||||
inline const RigidBody2D::VelocityFunc& RigidBody2D::GetVelocityFunction() const
|
||||
{
|
||||
return m_velocityFunc;
|
||||
}
|
||||
|
||||
inline PhysWorld2D* RigidBody2D::GetWorld() const
|
||||
{
|
||||
return m_world;
|
||||
}
|
||||
|
||||
inline bool RigidBody2D::IsKinematic() const
|
||||
{
|
||||
return m_mass <= 0.f;
|
||||
}
|
||||
|
||||
inline bool RigidBody2D::IsSimulationEnabled() const
|
||||
{
|
||||
return m_isSimulationEnabled;
|
||||
}
|
||||
|
||||
inline bool RigidBody2D::IsStatic() const
|
||||
{
|
||||
return m_isStatic;
|
||||
}
|
||||
}
|
||||
|
||||
#include <Nazara/Physics2D/DebugOff.hpp>
|
||||
@@ -1,7 +1,7 @@
|
||||
// this file was automatically generated and should not be edited
|
||||
|
||||
/*
|
||||
Nazara Engine - JoltPhysics3D module
|
||||
Nazara Engine - Physics2D module
|
||||
|
||||
Copyright (C) 2024 Jérôme "SirLynix" Leclercq (lynix680@gmail.com)
|
||||
|
||||
@@ -26,9 +26,9 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifndef NAZARA_JOLTPHYSICS3D_SYSTEMS_HPP
|
||||
#define NAZARA_JOLTPHYSICS3D_SYSTEMS_HPP
|
||||
#ifndef NAZARA_PHYSICS2D_SYSTEMS_HPP
|
||||
#define NAZARA_PHYSICS2D_SYSTEMS_HPP
|
||||
|
||||
#include <Nazara/JoltPhysics3D/Systems/JoltPhysics3DSystem.hpp>
|
||||
#include <Nazara/Physics2D/Systems/Physics2DSystem.hpp>
|
||||
|
||||
#endif // NAZARA_JOLTPHYSICS3D_SYSTEMS_HPP
|
||||
#endif // NAZARA_PHYSICS2D_SYSTEMS_HPP
|
||||
@@ -1,43 +1,43 @@
|
||||
// Copyright (C) 2024 Jérôme "SirLynix" Leclercq (lynix680@gmail.com)
|
||||
// This file is part of the "Nazara Engine - ChipmunkPhysics2D module"
|
||||
// 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_CHIPMUNKPHYSICS2DSYSTEM_HPP
|
||||
#define NAZARA_CHIPMUNKPHYSICS2D_SYSTEMS_CHIPMUNKPHYSICS2DSYSTEM_HPP
|
||||
#ifndef NAZARA_PHYSICS2D_SYSTEMS_PHYSICS2DSYSTEM_HPP
|
||||
#define NAZARA_PHYSICS2D_SYSTEMS_PHYSICS2DSYSTEM_HPP
|
||||
|
||||
#include <NazaraUtils/Prerequisites.hpp>
|
||||
#include <Nazara/ChipmunkPhysics2D/ChipmunkPhysWorld2D.hpp>
|
||||
#include <Nazara/ChipmunkPhysics2D/Components/ChipmunkRigidBody2DComponent.hpp>
|
||||
#include <Nazara/Core/Time.hpp>
|
||||
#include <Nazara/Physics2D/PhysWorld2D.hpp>
|
||||
#include <Nazara/Physics2D/Components/RigidBody2DComponent.hpp>
|
||||
#include <NazaraUtils/TypeList.hpp>
|
||||
#include <entt/entt.hpp>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
class NAZARA_CHIPMUNKPHYSICS2D_API ChipmunkPhysics2DSystem
|
||||
class NAZARA_PHYSICS2D_API Physics2DSystem
|
||||
{
|
||||
using ContactEndCallback = std::function<void(ChipmunkPhysWorld2D& world, ChipmunkArbiter2D& arbiter, entt::handle entityA, entt::handle entityB, void* userdata)>;
|
||||
using ContactPostSolveCallback = std::function<void(ChipmunkPhysWorld2D& world, ChipmunkArbiter2D& arbiter, entt::handle entityA, entt::handle entityB, void* userdata)>;
|
||||
using ContactPreSolveCallback = std::function<bool(ChipmunkPhysWorld2D& world, ChipmunkArbiter2D& arbiter, entt::handle entityA, entt::handle entityB, void* userdata)>;
|
||||
using ContactStartCallback = std::function<bool(ChipmunkPhysWorld2D& world, ChipmunkArbiter2D& arbiter, entt::handle entityA, entt::handle entityB, void* userdata)>;
|
||||
using ContactEndCallback = std::function<void(PhysWorld2D& world, PhysArbiter2D& arbiter, entt::handle entityA, entt::handle entityB, void* userdata)>;
|
||||
using ContactPostSolveCallback = std::function<void(PhysWorld2D& world, PhysArbiter2D& arbiter, entt::handle entityA, entt::handle entityB, void* userdata)>;
|
||||
using ContactPreSolveCallback = std::function<bool(PhysWorld2D& world, PhysArbiter2D& arbiter, entt::handle entityA, entt::handle entityB, void* userdata)>;
|
||||
using ContactStartCallback = std::function<bool(PhysWorld2D& world, PhysArbiter2D& arbiter, entt::handle entityA, entt::handle entityB, void* userdata)>;
|
||||
|
||||
public:
|
||||
static constexpr Int64 ExecutionOrder = 0;
|
||||
using Components = TypeList<ChipmunkRigidBody2DComponent, class NodeComponent>;
|
||||
using Components = TypeList<RigidBody2DComponent, class NodeComponent>;
|
||||
|
||||
struct ContactCallbacks;
|
||||
struct NearestQueryResult;
|
||||
struct RaycastHit;
|
||||
|
||||
ChipmunkPhysics2DSystem(entt::registry& registry);
|
||||
ChipmunkPhysics2DSystem(const ChipmunkPhysics2DSystem&) = delete;
|
||||
ChipmunkPhysics2DSystem(ChipmunkPhysics2DSystem&&) = delete;
|
||||
~ChipmunkPhysics2DSystem();
|
||||
Physics2DSystem(entt::registry& registry);
|
||||
Physics2DSystem(const Physics2DSystem&) = delete;
|
||||
Physics2DSystem(Physics2DSystem&&) = delete;
|
||||
~Physics2DSystem();
|
||||
|
||||
inline ChipmunkPhysWorld2D& GetPhysWorld();
|
||||
inline const ChipmunkPhysWorld2D& GetPhysWorld() const;
|
||||
inline PhysWorld2D& GetPhysWorld();
|
||||
inline const PhysWorld2D& GetPhysWorld() const;
|
||||
inline entt::handle GetRigidBodyEntity(UInt32 bodyIndex) const;
|
||||
|
||||
inline bool NearestBodyQuery(const Vector2f& from, float maxDistance, UInt32 collisionGroup, UInt32 categoryMask, UInt32 collisionMask, entt::handle* nearestEntity = nullptr);
|
||||
@@ -55,8 +55,8 @@ namespace Nz
|
||||
|
||||
void Update(Time elapsedTime);
|
||||
|
||||
ChipmunkPhysics2DSystem& operator=(const ChipmunkPhysics2DSystem&) = delete;
|
||||
ChipmunkPhysics2DSystem& operator=(ChipmunkPhysics2DSystem&&) = delete;
|
||||
Physics2DSystem& operator=(const Physics2DSystem&) = delete;
|
||||
Physics2DSystem& operator=(Physics2DSystem&&) = delete;
|
||||
|
||||
struct ContactCallbacks
|
||||
{
|
||||
@@ -67,12 +67,12 @@ namespace Nz
|
||||
void* userdata = nullptr;
|
||||
};
|
||||
|
||||
struct NearestQueryResult : ChipmunkPhysWorld2D::NearestQueryResult
|
||||
struct NearestQueryResult : PhysWorld2D::NearestQueryResult
|
||||
{
|
||||
entt::handle nearestEntity;
|
||||
};
|
||||
|
||||
struct RaycastHit : ChipmunkPhysWorld2D::RaycastHit
|
||||
struct RaycastHit : PhysWorld2D::RaycastHit
|
||||
{
|
||||
entt::handle nearestEntity;
|
||||
};
|
||||
@@ -80,17 +80,17 @@ namespace Nz
|
||||
private:
|
||||
void OnBodyConstruct(entt::registry& registry, entt::entity entity);
|
||||
void OnBodyDestruct(entt::registry& registry, entt::entity entity);
|
||||
ChipmunkPhysWorld2D::ContactCallbacks SetupContactCallbacks(ContactCallbacks callbacks);
|
||||
PhysWorld2D::ContactCallbacks SetupContactCallbacks(ContactCallbacks callbacks);
|
||||
|
||||
std::vector<entt::entity> m_bodyIndicesToEntity;
|
||||
entt::registry& m_registry;
|
||||
entt::observer m_physicsConstructObserver;
|
||||
entt::scoped_connection m_bodyConstructConnection;
|
||||
entt::scoped_connection m_bodyDestructConnection;
|
||||
ChipmunkPhysWorld2D m_physWorld;
|
||||
PhysWorld2D m_physWorld;
|
||||
};
|
||||
}
|
||||
|
||||
#include <Nazara/ChipmunkPhysics2D/Systems/ChipmunkPhysics2DSystem.inl>
|
||||
#include <Nazara/Physics2D/Systems/Physics2DSystem.inl>
|
||||
|
||||
#endif // NAZARA_CHIPMUNKPHYSICS2D_SYSTEMS_CHIPMUNKPHYSICS2DSYSTEM_HPP
|
||||
#endif // NAZARA_PHYSICS2D_SYSTEMS_PHYSICS2DSYSTEM_HPP
|
||||
@@ -1,29 +1,29 @@
|
||||
// Copyright (C) 2024 Jérôme "SirLynix" Leclercq (lynix680@gmail.com)
|
||||
// This file is part of the "Nazara Engine - ChipmunkPhysics2D module"
|
||||
// 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>
|
||||
#include <Nazara/Physics2D/Debug.hpp>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
inline ChipmunkPhysWorld2D& ChipmunkPhysics2DSystem::GetPhysWorld()
|
||||
inline PhysWorld2D& Physics2DSystem::GetPhysWorld()
|
||||
{
|
||||
return m_physWorld;
|
||||
}
|
||||
|
||||
inline const ChipmunkPhysWorld2D& ChipmunkPhysics2DSystem::GetPhysWorld() const
|
||||
inline const PhysWorld2D& Physics2DSystem::GetPhysWorld() const
|
||||
{
|
||||
return m_physWorld;
|
||||
}
|
||||
|
||||
inline entt::handle ChipmunkPhysics2DSystem::GetRigidBodyEntity(UInt32 bodyIndex) const
|
||||
inline entt::handle Physics2DSystem::GetRigidBodyEntity(UInt32 bodyIndex) const
|
||||
{
|
||||
return entt::handle(m_registry, m_bodyIndicesToEntity[bodyIndex]);
|
||||
}
|
||||
|
||||
inline bool ChipmunkPhysics2DSystem::NearestBodyQuery(const Vector2f& from, float maxDistance, UInt32 collisionGroup, UInt32 categoryMask, UInt32 collisionMask, entt::handle* nearestEntity)
|
||||
inline bool Physics2DSystem::NearestBodyQuery(const Vector2f& from, float maxDistance, UInt32 collisionGroup, UInt32 categoryMask, UInt32 collisionMask, entt::handle* nearestEntity)
|
||||
{
|
||||
ChipmunkRigidBody2D* nearestBody;
|
||||
RigidBody2D* nearestBody;
|
||||
if (!m_physWorld.NearestBodyQuery(from, maxDistance, collisionGroup, categoryMask, collisionMask, &nearestBody))
|
||||
return false;
|
||||
|
||||
@@ -38,7 +38,7 @@ namespace Nz
|
||||
return true;
|
||||
}
|
||||
|
||||
inline bool ChipmunkPhysics2DSystem::NearestBodyQuery(const Vector2f& from, float maxDistance, UInt32 collisionGroup, UInt32 categoryMask, UInt32 collisionMask, NearestQueryResult* result)
|
||||
inline bool Physics2DSystem::NearestBodyQuery(const Vector2f& from, float maxDistance, UInt32 collisionGroup, UInt32 categoryMask, UInt32 collisionMask, NearestQueryResult* result)
|
||||
{
|
||||
if (!m_physWorld.NearestBodyQuery(from, maxDistance, collisionGroup, categoryMask, collisionMask, result))
|
||||
return false;
|
||||
@@ -54,12 +54,12 @@ namespace Nz
|
||||
return true;
|
||||
}
|
||||
|
||||
inline void ChipmunkPhysics2DSystem::RaycastQuery(const Vector2f& from, const Vector2f& to, float radius, UInt32 collisionGroup, UInt32 categoryMask, UInt32 collisionMask, const FunctionRef<void(const RaycastHit&)>& callback)
|
||||
inline void Physics2DSystem::RaycastQuery(const Vector2f& from, const Vector2f& to, float radius, UInt32 collisionGroup, UInt32 categoryMask, UInt32 collisionMask, const FunctionRef<void(const RaycastHit&)>& callback)
|
||||
{
|
||||
return m_physWorld.RaycastQuery(from, to, radius, collisionGroup, categoryMask, collisionMask, [&](const ChipmunkPhysWorld2D::RaycastHit& hitInfo)
|
||||
return m_physWorld.RaycastQuery(from, to, radius, collisionGroup, categoryMask, collisionMask, [&](const PhysWorld2D::RaycastHit& hitInfo)
|
||||
{
|
||||
RaycastHit extendedHitInfo;
|
||||
static_cast<ChipmunkPhysWorld2D::RaycastHit&>(extendedHitInfo) = hitInfo;
|
||||
static_cast<PhysWorld2D::RaycastHit&>(extendedHitInfo) = hitInfo;
|
||||
|
||||
if (extendedHitInfo.nearestBody)
|
||||
extendedHitInfo.nearestEntity = GetRigidBodyEntity(extendedHitInfo.nearestBody->GetBodyIndex());
|
||||
@@ -68,7 +68,7 @@ namespace Nz
|
||||
});
|
||||
}
|
||||
|
||||
inline bool ChipmunkPhysics2DSystem::RaycastQuery(const Vector2f& from, const Vector2f& to, float radius, UInt32 collisionGroup, UInt32 categoryMask, UInt32 collisionMask, std::vector<RaycastHit>* hitInfos)
|
||||
inline bool Physics2DSystem::RaycastQuery(const Vector2f& from, const Vector2f& to, float radius, UInt32 collisionGroup, UInt32 categoryMask, UInt32 collisionMask, std::vector<RaycastHit>* hitInfos)
|
||||
{
|
||||
NazaraAssert(hitInfos, "invalid output pointer");
|
||||
|
||||
@@ -82,7 +82,7 @@ namespace Nz
|
||||
return hitInfos->size() != originalSize;
|
||||
}
|
||||
|
||||
inline bool ChipmunkPhysics2DSystem::RaycastQueryFirst(const Vector2f& from, const Vector2f& to, float radius, UInt32 collisionGroup, UInt32 categoryMask, UInt32 collisionMask, RaycastHit* hitInfo)
|
||||
inline bool Physics2DSystem::RaycastQueryFirst(const Vector2f& from, const Vector2f& to, float radius, UInt32 collisionGroup, UInt32 categoryMask, UInt32 collisionMask, RaycastHit* hitInfo)
|
||||
{
|
||||
if (!m_physWorld.RaycastQueryFirst(from, to, radius, collisionGroup, categoryMask, collisionMask, hitInfo))
|
||||
return false;
|
||||
@@ -98,33 +98,33 @@ namespace Nz
|
||||
return true;
|
||||
}
|
||||
|
||||
inline void ChipmunkPhysics2DSystem::RegionQuery(const Rectf& boundingBox, UInt32 collisionGroup, UInt32 categoryMask, UInt32 collisionMask, const FunctionRef<void(entt::handle)>& callback)
|
||||
inline void Physics2DSystem::RegionQuery(const Rectf& boundingBox, UInt32 collisionGroup, UInt32 categoryMask, UInt32 collisionMask, const FunctionRef<void(entt::handle)>& callback)
|
||||
{
|
||||
return m_physWorld.RegionQuery(boundingBox, collisionGroup, categoryMask, collisionMask, [&](ChipmunkRigidBody2D* body)
|
||||
return m_physWorld.RegionQuery(boundingBox, collisionGroup, categoryMask, collisionMask, [&](RigidBody2D* body)
|
||||
{
|
||||
callback(GetRigidBodyEntity(body->GetBodyIndex()));
|
||||
});
|
||||
}
|
||||
|
||||
inline void ChipmunkPhysics2DSystem::RegionQuery(const Rectf& boundingBox, UInt32 collisionGroup, UInt32 categoryMask, UInt32 collisionMask, std::vector<entt::handle>* bodies)
|
||||
inline void Physics2DSystem::RegionQuery(const Rectf& boundingBox, UInt32 collisionGroup, UInt32 categoryMask, UInt32 collisionMask, std::vector<entt::handle>* bodies)
|
||||
{
|
||||
NazaraAssert(bodies, "invalid output pointer");
|
||||
|
||||
return m_physWorld.RegionQuery(boundingBox, collisionGroup, categoryMask, collisionMask, [&](ChipmunkRigidBody2D* body)
|
||||
return m_physWorld.RegionQuery(boundingBox, collisionGroup, categoryMask, collisionMask, [&](RigidBody2D* body)
|
||||
{
|
||||
bodies->emplace_back(GetRigidBodyEntity(body->GetBodyIndex()));
|
||||
});
|
||||
}
|
||||
|
||||
inline void ChipmunkPhysics2DSystem::RegisterCallbacks(unsigned int collisionId, ContactCallbacks callbacks)
|
||||
inline void Physics2DSystem::RegisterCallbacks(unsigned int collisionId, ContactCallbacks callbacks)
|
||||
{
|
||||
return m_physWorld.RegisterCallbacks(collisionId, SetupContactCallbacks(std::move(callbacks)));
|
||||
}
|
||||
|
||||
inline void ChipmunkPhysics2DSystem::RegisterCallbacks(unsigned int collisionIdA, unsigned int collisionIdB, ContactCallbacks callbacks)
|
||||
inline void Physics2DSystem::RegisterCallbacks(unsigned int collisionIdA, unsigned int collisionIdB, ContactCallbacks callbacks)
|
||||
{
|
||||
return m_physWorld.RegisterCallbacks(collisionIdA, collisionIdB, SetupContactCallbacks(std::move(callbacks)));
|
||||
}
|
||||
}
|
||||
|
||||
#include <Nazara/ChipmunkPhysics2D/DebugOff.hpp>
|
||||
#include <Nazara/Physics2D/DebugOff.hpp>
|
||||
50
include/Nazara/Physics3D.hpp
Normal file
50
include/Nazara/Physics3D.hpp
Normal file
@@ -0,0 +1,50 @@
|
||||
// this file was automatically generated and should not be edited
|
||||
|
||||
/*
|
||||
Nazara Engine - Physics3D module
|
||||
|
||||
Copyright (C) 2024 Jérôme "SirLynix" 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_GLOBAL_PHYSICS3D_HPP
|
||||
#define NAZARA_GLOBAL_PHYSICS3D_HPP
|
||||
|
||||
#include <Nazara/Physics3D/Collider3D.hpp>
|
||||
#include <Nazara/Physics3D/Config.hpp>
|
||||
#include <Nazara/Physics3D/Enums.hpp>
|
||||
#include <Nazara/Physics3D/PhysCharacter3D.hpp>
|
||||
#include <Nazara/Physics3D/PhysConstraint3D.hpp>
|
||||
#include <Nazara/Physics3D/Physics3D.hpp>
|
||||
#include <Nazara/Physics3D/Physics3DBody.hpp>
|
||||
#include <Nazara/Physics3D/Physiscs3DStepListener.hpp>
|
||||
#include <Nazara/Physics3D/PhysWorld3D.hpp>
|
||||
#include <Nazara/Physics3D/RigidBody3D.hpp>
|
||||
|
||||
#ifdef NAZARA_ENTT
|
||||
|
||||
#include <Nazara/Physics3D/Components.hpp>
|
||||
#include <Nazara/Physics3D/Systems.hpp>
|
||||
|
||||
#endif
|
||||
|
||||
#endif // NAZARA_GLOBAL_PHYSICS3D_HPP
|
||||
172
include/Nazara/Physics3D/Collider3D.hpp
Normal file
172
include/Nazara/Physics3D/Collider3D.hpp
Normal file
@@ -0,0 +1,172 @@
|
||||
// Copyright (C) 2024 Jérôme "SirLynix" Leclercq (lynix680@gmail.com)
|
||||
// This file is part of the "Nazara Engine - Physics3D module"
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifndef NAZARA_PHYSICS3D_COLLIDER3D_HPP
|
||||
#define NAZARA_PHYSICS3D_COLLIDER3D_HPP
|
||||
|
||||
#include <NazaraUtils/Prerequisites.hpp>
|
||||
#include <Nazara/Core/ObjectLibrary.hpp>
|
||||
#include <Nazara/Math/Box.hpp>
|
||||
#include <Nazara/Math/Quaternion.hpp>
|
||||
#include <Nazara/Math/Vector3.hpp>
|
||||
#include <Nazara/Physics3D/Config.hpp>
|
||||
#include <Nazara/Physics3D/Enums.hpp>
|
||||
#include <NazaraUtils/Signal.hpp>
|
||||
#include <NazaraUtils/SparsePtr.hpp>
|
||||
#include <memory>
|
||||
|
||||
namespace JPH
|
||||
{
|
||||
class ShapeSettings;
|
||||
class BoxShapeSettings;
|
||||
}
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
class PrimitiveList;
|
||||
class StaticMesh;
|
||||
struct Primitive;
|
||||
|
||||
class NAZARA_PHYSICS3D_API Collider3D
|
||||
{
|
||||
public:
|
||||
Collider3D();
|
||||
Collider3D(const Collider3D&) = delete;
|
||||
Collider3D(Collider3D&&) = delete;
|
||||
virtual ~Collider3D();
|
||||
|
||||
virtual void BuildDebugMesh(std::vector<Vector3f>& vertices, std::vector<UInt16>& indices, const Matrix4f& offsetMatrix = Matrix4f::Identity()) const = 0;
|
||||
|
||||
virtual std::shared_ptr<StaticMesh> GenerateDebugMesh() const;
|
||||
|
||||
inline JPH::ShapeSettings* GetShapeSettings() const;
|
||||
virtual ColliderType3D GetType() const = 0;
|
||||
|
||||
Collider3D& operator=(const Collider3D&) = delete;
|
||||
Collider3D& operator=(Collider3D&&) = delete;
|
||||
|
||||
static std::shared_ptr<Collider3D> Build(const PrimitiveList& list);
|
||||
|
||||
protected:
|
||||
template<typename T> const T* GetShapeSettingsAs() const;
|
||||
void ResetShapeSettings();
|
||||
void SetupShapeSettings(std::unique_ptr<JPH::ShapeSettings>&& shapeSettings);
|
||||
|
||||
private:
|
||||
static std::shared_ptr<Collider3D> CreateGeomFromPrimitive(const Primitive& primitive);
|
||||
|
||||
std::unique_ptr<JPH::ShapeSettings> m_shapeSettings;
|
||||
};
|
||||
|
||||
/*********************************** Shapes ******************************************/
|
||||
|
||||
class NAZARA_PHYSICS3D_API BoxCollider3D final : public Collider3D
|
||||
{
|
||||
public:
|
||||
BoxCollider3D(const Vector3f& lengths, float convexRadius = 0.01f);
|
||||
~BoxCollider3D() = default;
|
||||
|
||||
void BuildDebugMesh(std::vector<Vector3f>& vertices, std::vector<UInt16>& indices, const Matrix4f& offsetMatrix) const override;
|
||||
|
||||
Vector3f GetLengths() const;
|
||||
ColliderType3D GetType() const override;
|
||||
};
|
||||
|
||||
class NAZARA_PHYSICS3D_API CapsuleCollider3D final : public Collider3D
|
||||
{
|
||||
public:
|
||||
CapsuleCollider3D(float height, float radius);
|
||||
~CapsuleCollider3D() = default;
|
||||
|
||||
void BuildDebugMesh(std::vector<Vector3f>& vertices, std::vector<UInt16>& indices, const Matrix4f& offsetMatrix) const override;
|
||||
|
||||
float GetHeight() const;
|
||||
float GetRadius() const;
|
||||
ColliderType3D GetType() const override;
|
||||
};
|
||||
|
||||
class NAZARA_PHYSICS3D_API CompoundCollider3D final : public Collider3D
|
||||
{
|
||||
public:
|
||||
struct ChildCollider;
|
||||
|
||||
CompoundCollider3D(std::vector<ChildCollider> childs);
|
||||
~CompoundCollider3D();
|
||||
|
||||
void BuildDebugMesh(std::vector<Vector3f>& vertices, std::vector<UInt16>& indices, const Matrix4f& offsetMatrix) const override;
|
||||
|
||||
const std::vector<ChildCollider>& GetGeoms() const;
|
||||
ColliderType3D GetType() const override;
|
||||
|
||||
struct ChildCollider
|
||||
{
|
||||
std::shared_ptr<Collider3D> collider;
|
||||
Quaternionf rotation = Quaternionf::Identity();
|
||||
Vector3f offset = Vector3f::Zero();
|
||||
};
|
||||
|
||||
private:
|
||||
std::vector<ChildCollider> m_childs;
|
||||
};
|
||||
|
||||
class NAZARA_PHYSICS3D_API ConvexHullCollider3D final : public Collider3D
|
||||
{
|
||||
public:
|
||||
ConvexHullCollider3D(SparsePtr<const Vector3f> vertices, std::size_t vertexCount, float hullTolerance = 0.001f, float convexRadius = 0.f, float maxErrorConvexRadius = 0.05f);
|
||||
~ConvexHullCollider3D() = default;
|
||||
|
||||
void BuildDebugMesh(std::vector<Vector3f>& vertices, std::vector<UInt16>& indices, const Matrix4f& offsetMatrix) const override;
|
||||
|
||||
ColliderType3D GetType() const override;
|
||||
};
|
||||
|
||||
class NAZARA_PHYSICS3D_API MeshCollider3D final : public Collider3D
|
||||
{
|
||||
public:
|
||||
MeshCollider3D(SparsePtr<const Vector3f> vertices, std::size_t vertexCount, SparsePtr<const UInt16> indices, std::size_t indexCount);
|
||||
MeshCollider3D(SparsePtr<const Vector3f> vertices, std::size_t vertexCount, SparsePtr<const UInt32> indices, std::size_t indexCount);
|
||||
~MeshCollider3D() = default;
|
||||
|
||||
void BuildDebugMesh(std::vector<Vector3f>& vertices, std::vector<UInt16>& indices, const Matrix4f& offsetMatrix) const override;
|
||||
|
||||
ColliderType3D GetType() const override;
|
||||
};
|
||||
|
||||
class NAZARA_PHYSICS3D_API SphereCollider3D final : public Collider3D
|
||||
{
|
||||
public:
|
||||
SphereCollider3D(float radius);
|
||||
~SphereCollider3D() = default;
|
||||
|
||||
void BuildDebugMesh(std::vector<Vector3f>& vertices, std::vector<UInt16>& indices, const Matrix4f& offsetMatrix) const override;
|
||||
|
||||
float GetRadius() const;
|
||||
ColliderType3D GetType() const override;
|
||||
};
|
||||
|
||||
/*********************************** Decorated ******************************************/
|
||||
|
||||
class NAZARA_PHYSICS3D_API TranslatedRotatedCollider3D final : public Collider3D
|
||||
{
|
||||
public:
|
||||
inline TranslatedRotatedCollider3D(std::shared_ptr<Collider3D> collider, const Vector3f& translation);
|
||||
inline TranslatedRotatedCollider3D(std::shared_ptr<Collider3D> collider, const Quaternionf& rotation);
|
||||
TranslatedRotatedCollider3D(std::shared_ptr<Collider3D> collider, const Vector3f& translation, const Quaternionf& rotation);
|
||||
~TranslatedRotatedCollider3D();
|
||||
|
||||
void BuildDebugMesh(std::vector<Vector3f>& vertices, std::vector<UInt16>& indices, const Matrix4f& offsetMatrix) const override;
|
||||
|
||||
ColliderType3D GetType() const override;
|
||||
|
||||
private:
|
||||
std::shared_ptr<Collider3D> m_collider;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#include <Nazara/Physics3D/Collider3D.inl>
|
||||
|
||||
#endif // NAZARA_PHYSICS3D_COLLIDER3D_HPP
|
||||
34
include/Nazara/Physics3D/Collider3D.inl
Normal file
34
include/Nazara/Physics3D/Collider3D.inl
Normal file
@@ -0,0 +1,34 @@
|
||||
// Copyright (C) 2024 Jérôme "SirLynix" Leclercq (lynix680@gmail.com)
|
||||
// This file is part of the "Nazara Engine - Physics3D module"
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#include <NazaraUtils/Algorithm.hpp>
|
||||
#include <memory>
|
||||
#include <Nazara/Physics3D/Debug.hpp>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
inline JPH::ShapeSettings* Collider3D::GetShapeSettings() const
|
||||
{
|
||||
return m_shapeSettings.get();
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
const T* Collider3D::GetShapeSettingsAs() const
|
||||
{
|
||||
return SafeCast<T*>(m_shapeSettings.get());
|
||||
}
|
||||
|
||||
|
||||
inline TranslatedRotatedCollider3D::TranslatedRotatedCollider3D(std::shared_ptr<Collider3D> collider, const Vector3f& translation) :
|
||||
TranslatedRotatedCollider3D(std::move(collider), translation, Quaternionf::Identity())
|
||||
{
|
||||
}
|
||||
|
||||
inline TranslatedRotatedCollider3D::TranslatedRotatedCollider3D(std::shared_ptr<Collider3D> collider, const Quaternionf& rotation) :
|
||||
TranslatedRotatedCollider3D(std::move(collider), Vector3f::Zero(), rotation)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
#include <Nazara/Physics3D/DebugOff.hpp>
|
||||
@@ -1,7 +1,7 @@
|
||||
// this file was automatically generated and should not be edited
|
||||
|
||||
/*
|
||||
Nazara Engine - JoltPhysics3D module
|
||||
Nazara Engine - Physics3D module
|
||||
|
||||
Copyright (C) 2024 Jérôme "SirLynix" Leclercq (lynix680@gmail.com)
|
||||
|
||||
@@ -26,10 +26,10 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifndef NAZARA_JOLTPHYSICS3D_COMPONENTS_HPP
|
||||
#define NAZARA_JOLTPHYSICS3D_COMPONENTS_HPP
|
||||
#ifndef NAZARA_PHYSICS3D_COMPONENTS_HPP
|
||||
#define NAZARA_PHYSICS3D_COMPONENTS_HPP
|
||||
|
||||
#include <Nazara/JoltPhysics3D/Components/JoltCharacterComponent.hpp>
|
||||
#include <Nazara/JoltPhysics3D/Components/JoltRigidBody3DComponent.hpp>
|
||||
#include <Nazara/Physics3D/Components/PhysCharacter3DComponent.hpp>
|
||||
#include <Nazara/Physics3D/Components/RigidBody3DComponent.hpp>
|
||||
|
||||
#endif // NAZARA_JOLTPHYSICS3D_COMPONENTS_HPP
|
||||
#endif // NAZARA_PHYSICS3D_COMPONENTS_HPP
|
||||
@@ -0,0 +1,37 @@
|
||||
// Copyright (C) 2024 Jérôme "SirLynix" Leclercq (lynix680@gmail.com)
|
||||
// This file is part of the "Nazara Engine - Physics3D module"
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifndef NAZARA_PHYSICS3D_COMPONENTS_PHYSCHARACTER3DCOMPONENT_HPP
|
||||
#define NAZARA_PHYSICS3D_COMPONENTS_PHYSCHARACTER3DCOMPONENT_HPP
|
||||
|
||||
#include <NazaraUtils/Prerequisites.hpp>
|
||||
#include <Nazara/Physics3D/PhysCharacter3D.hpp>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
class NAZARA_PHYSICS3D_API PhysCharacter3DComponent : public PhysCharacter3D
|
||||
{
|
||||
friend class Physics3DSystem;
|
||||
|
||||
public:
|
||||
inline PhysCharacter3DComponent(const PhysCharacter3D::Settings& settings);
|
||||
PhysCharacter3DComponent(const PhysCharacter3DComponent&) = default;
|
||||
PhysCharacter3DComponent(PhysCharacter3DComponent&&) noexcept = default;
|
||||
~PhysCharacter3DComponent() = default;
|
||||
|
||||
PhysCharacter3DComponent& operator=(const PhysCharacter3DComponent&) = default;
|
||||
PhysCharacter3DComponent& operator=(PhysCharacter3DComponent&&) noexcept = default;
|
||||
|
||||
private:
|
||||
inline void Construct(PhysWorld3D& world);
|
||||
|
||||
std::unique_ptr<PhysCharacter3D::Settings> m_settings;
|
||||
};
|
||||
}
|
||||
|
||||
#include <Nazara/Physics3D/Components/PhysCharacter3DComponent.inl>
|
||||
|
||||
#endif // NAZARA_PHYSICS3D_COMPONENTS_PHYSCHARACTER3DCOMPONENT_HPP
|
||||
@@ -0,0 +1,22 @@
|
||||
// Copyright (C) 2024 Jérôme "SirLynix" Leclercq (lynix680@gmail.com)
|
||||
// This file is part of the "Nazara Engine - Physics3D module"
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#include <Nazara/Physics3D/Debug.hpp>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
inline PhysCharacter3DComponent::PhysCharacter3DComponent(const PhysCharacter3D::Settings& settings)
|
||||
{
|
||||
m_settings = std::make_unique<PhysCharacter3D::Settings>(settings);
|
||||
}
|
||||
|
||||
inline void PhysCharacter3DComponent::Construct(PhysWorld3D& world)
|
||||
{
|
||||
assert(m_settings);
|
||||
Create(world, *m_settings);
|
||||
m_settings.reset();
|
||||
}
|
||||
}
|
||||
|
||||
#include <Nazara/Physics3D/DebugOff.hpp>
|
||||
40
include/Nazara/Physics3D/Components/RigidBody3DComponent.hpp
Normal file
40
include/Nazara/Physics3D/Components/RigidBody3DComponent.hpp
Normal file
@@ -0,0 +1,40 @@
|
||||
// Copyright (C) 2024 Jérôme "SirLynix" Leclercq (lynix680@gmail.com)
|
||||
// This file is part of the "Nazara Engine - Physics3D module"
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifndef NAZARA_PHYSICS3D_COMPONENTS_RIGIDBODY3DCOMPONENT_HPP
|
||||
#define NAZARA_PHYSICS3D_COMPONENTS_RIGIDBODY3DCOMPONENT_HPP
|
||||
|
||||
#include <NazaraUtils/Prerequisites.hpp>
|
||||
#include <Nazara/Physics3D/RigidBody3D.hpp>
|
||||
#include <variant>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
class NAZARA_PHYSICS3D_API RigidBody3DComponent : public RigidBody3D
|
||||
{
|
||||
friend class Physics3DSystem;
|
||||
|
||||
public:
|
||||
inline RigidBody3DComponent(const RigidBody3D::DynamicSettings& settings);
|
||||
inline RigidBody3DComponent(const RigidBody3D::StaticSettings& settings);
|
||||
RigidBody3DComponent(const RigidBody3DComponent&) = default;
|
||||
RigidBody3DComponent(RigidBody3DComponent&&) noexcept = default;
|
||||
~RigidBody3DComponent() = default;
|
||||
|
||||
RigidBody3DComponent& operator=(const RigidBody3DComponent&) = default;
|
||||
RigidBody3DComponent& operator=(RigidBody3DComponent&&) noexcept = default;
|
||||
|
||||
private:
|
||||
inline void Construct(PhysWorld3D& world);
|
||||
|
||||
using Setting = std::variant<RigidBody3D::DynamicSettings, RigidBody3D::StaticSettings>;
|
||||
std::unique_ptr<Setting> m_settings;
|
||||
};
|
||||
}
|
||||
|
||||
#include <Nazara/Physics3D/Components/RigidBody3DComponent.inl>
|
||||
|
||||
#endif // NAZARA_PHYSICS3D_COMPONENTS_RIGIDBODY3DCOMPONENT_HPP
|
||||
31
include/Nazara/Physics3D/Components/RigidBody3DComponent.inl
Normal file
31
include/Nazara/Physics3D/Components/RigidBody3DComponent.inl
Normal file
@@ -0,0 +1,31 @@
|
||||
// Copyright (C) 2024 Jérôme "SirLynix" Leclercq (lynix680@gmail.com)
|
||||
// This file is part of the "Nazara Engine - Physics3D module"
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#include <cassert>
|
||||
#include <Nazara/Physics3D/Debug.hpp>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
inline RigidBody3DComponent::RigidBody3DComponent(const RigidBody3D::DynamicSettings& settings)
|
||||
{
|
||||
m_settings = std::make_unique<Setting>(settings);
|
||||
}
|
||||
|
||||
inline RigidBody3DComponent::RigidBody3DComponent(const RigidBody3D::StaticSettings& settings)
|
||||
{
|
||||
m_settings = std::make_unique<Setting>(settings);
|
||||
}
|
||||
|
||||
inline void RigidBody3DComponent::Construct(PhysWorld3D& world)
|
||||
{
|
||||
assert(m_settings);
|
||||
std::visit([&](auto&& arg)
|
||||
{
|
||||
Create(world, arg);
|
||||
}, *m_settings);
|
||||
m_settings.reset();
|
||||
}
|
||||
}
|
||||
|
||||
#include <Nazara/Physics3D/DebugOff.hpp>
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
Nazara Engine - ChipmunkPhysics2D module
|
||||
Nazara Engine - Physics3D module
|
||||
|
||||
Copyright (C) 2024 Jérôme "SirLynix" Leclercq (lynix680@gmail.com)
|
||||
|
||||
@@ -24,25 +24,25 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifndef NAZARA_CHIPMUNKPHYSICS2D_CONFIG_HPP
|
||||
#define NAZARA_CHIPMUNKPHYSICS2D_CONFIG_HPP
|
||||
#ifndef NAZARA_PHYSICS3D_CONFIG_HPP
|
||||
#define NAZARA_PHYSICS3D_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
|
||||
#define NAZARA_PHYSICS3D_SAFE 1
|
||||
|
||||
/// Vérification des valeurs et types de certaines constantes
|
||||
#include <Nazara/ChipmunkPhysics2D/ConfigCheck.hpp>
|
||||
#include <Nazara/Physics3D/ConfigCheck.hpp>
|
||||
|
||||
#if defined(NAZARA_STATIC)
|
||||
#define NAZARA_CHIPMUNKPHYSICS2D_API
|
||||
#define NAZARA_PHYSICS3D_API
|
||||
#else
|
||||
#ifdef NAZARA_CHIPMUNKPHYSICS2D_BUILD
|
||||
#define NAZARA_CHIPMUNKPHYSICS2D_API NAZARA_EXPORT
|
||||
#ifdef NAZARA_PHYSICS3D_BUILD
|
||||
#define NAZARA_PHYSICS3D_API NAZARA_EXPORT
|
||||
#else
|
||||
#define NAZARA_CHIPMUNKPHYSICS2D_API NAZARA_IMPORT
|
||||
#define NAZARA_PHYSICS3D_API NAZARA_IMPORT
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#endif // NAZARA_CHIPMUNKPHYSICS2D_CONFIG_HPP
|
||||
#endif // NAZARA_PHYSICS3D_CONFIG_HPP
|
||||
10
include/Nazara/Physics3D/ConfigCheck.hpp
Normal file
10
include/Nazara/Physics3D/ConfigCheck.hpp
Normal file
@@ -0,0 +1,10 @@
|
||||
// Copyright (C) 2024 Jérôme "SirLynix" Leclercq (lynix680@gmail.com)
|
||||
// This file is part of the "Nazara Engine - Physics3D module"
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifndef NAZARA_PHYSICS3D_CONFIGCHECK_HPP
|
||||
#define NAZARA_PHYSICS3D_CONFIGCHECK_HPP
|
||||
|
||||
#endif // NAZARA_PHYSICS3D_CONFIGCHECK_HPP
|
||||
@@ -1,5 +1,5 @@
|
||||
// Copyright (C) 2024 Jérôme "SirLynix" Leclercq (lynix680@gmail.com)
|
||||
// This file is part of the "Nazara Engine - ChipmunkPhysics2D module"
|
||||
// This file is part of the "Nazara Engine - Physics3D module"
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
// no header guards
|
||||
@@ -1,5 +1,5 @@
|
||||
// Copyright (C) 2024 Jérôme "SirLynix" Leclercq (lynix680@gmail.com)
|
||||
// This file is part of the "Nazara Engine - ChipmunkPhysics2D module"
|
||||
// This file is part of the "Nazara Engine - Physics3D module"
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
// no header guards
|
||||
@@ -1,15 +1,15 @@
|
||||
// Copyright (C) 2024 Jérôme "SirLynix" Leclercq (lynix680@gmail.com)
|
||||
// This file is part of the "Nazara Engine - JoltPhysics3D module"
|
||||
// This file is part of the "Nazara Engine - Physics3D module"
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifndef NAZARA_JOLTPHYSICS3D_ENUMS_HPP
|
||||
#define NAZARA_JOLTPHYSICS3D_ENUMS_HPP
|
||||
#ifndef NAZARA_PHYSICS3D_ENUMS_HPP
|
||||
#define NAZARA_PHYSICS3D_ENUMS_HPP
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
enum class JoltColliderType3D
|
||||
enum class ColliderType3D
|
||||
{
|
||||
Box,
|
||||
Capsule,
|
||||
@@ -24,11 +24,11 @@ namespace Nz
|
||||
Max = TranslatedRotatedDecoration
|
||||
};
|
||||
|
||||
enum class JoltMotionQuality
|
||||
enum class PhysMotionQuality3D
|
||||
{
|
||||
Discrete,
|
||||
LinearCast
|
||||
};
|
||||
}
|
||||
|
||||
#endif // NAZARA_JOLTPHYSICS3D_ENUMS_HPP
|
||||
#endif // NAZARA_PHYSICS3D_ENUMS_HPP
|
||||
113
include/Nazara/Physics3D/PhysCharacter3D.hpp
Normal file
113
include/Nazara/Physics3D/PhysCharacter3D.hpp
Normal file
@@ -0,0 +1,113 @@
|
||||
// Copyright (C) 2024 Jérôme "SirLynix" Leclercq (lynix680@gmail.com)
|
||||
// This file is part of the "Nazara Engine - Physics3D module"
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifndef NAZARA_PHYSICS3D_PHYSCHARACTER3D_HPP
|
||||
#define NAZARA_PHYSICS3D_PHYSCHARACTER3D_HPP
|
||||
|
||||
#include <NazaraUtils/Prerequisites.hpp>
|
||||
#include <Nazara/Math/Quaternion.hpp>
|
||||
#include <Nazara/Math/Vector3.hpp>
|
||||
#include <Nazara/Physics3D/Config.hpp>
|
||||
#include <Nazara/Physics3D/Physics3DBody.hpp>
|
||||
#include <Nazara/Physics3D/Physiscs3DStepListener.hpp>
|
||||
#include <NazaraUtils/MovablePtr.hpp>
|
||||
#include <memory>
|
||||
|
||||
namespace JPH
|
||||
{
|
||||
class Character;
|
||||
class Body;
|
||||
}
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
class PhysCharacter3DImpl;
|
||||
class Collider3D;
|
||||
class PhysWorld3D;
|
||||
|
||||
class NAZARA_PHYSICS3D_API PhysCharacter3D : public Physics3DBody, public Physiscs3DStepListener
|
||||
{
|
||||
friend PhysWorld3D;
|
||||
|
||||
public:
|
||||
struct Settings;
|
||||
|
||||
PhysCharacter3D(PhysWorld3D& physWorld, const Settings& settings);
|
||||
PhysCharacter3D(const PhysCharacter3D&) = delete;
|
||||
PhysCharacter3D(PhysCharacter3D&& character) noexcept;
|
||||
~PhysCharacter3D();
|
||||
|
||||
inline void DisableSleeping();
|
||||
void EnableSleeping(bool enable);
|
||||
|
||||
UInt32 GetBodyIndex() const override;
|
||||
inline const std::shared_ptr<Collider3D>& GetCollider() const;
|
||||
Vector3f GetLinearVelocity() const;
|
||||
inline PhysWorld3D& GetPhysWorld();
|
||||
inline const PhysWorld3D& GetPhysWorld() const;
|
||||
Vector3f GetPosition() const;
|
||||
std::pair<Vector3f, Quaternionf> GetPositionAndRotation() const;
|
||||
Quaternionf GetRotation() const;
|
||||
Vector3f GetUp() const;
|
||||
|
||||
bool IsOnGround() const;
|
||||
|
||||
void SetFriction(float friction);
|
||||
inline void SetImpl(std::shared_ptr<PhysCharacter3DImpl> characterImpl);
|
||||
void SetLinearVelocity(const Vector3f& linearVel);
|
||||
void SetRotation(const Quaternionf& rotation);
|
||||
void SetUp(const Vector3f& up);
|
||||
|
||||
void TeleportTo(const Vector3f& position, const Quaternionf& rotation);
|
||||
|
||||
void WakeUp();
|
||||
|
||||
PhysCharacter3D& operator=(const PhysCharacter3D&) = delete;
|
||||
PhysCharacter3D& operator=(PhysCharacter3D&& character) noexcept;
|
||||
|
||||
struct Settings
|
||||
{
|
||||
std::shared_ptr<Collider3D> collider;
|
||||
Quaternionf rotation = Quaternionf::Identity();
|
||||
Vector3f position = Vector3f::Zero();
|
||||
};
|
||||
|
||||
protected:
|
||||
PhysCharacter3D();
|
||||
|
||||
void Create(PhysWorld3D& physWorld, const Settings& settings);
|
||||
void Destroy();
|
||||
|
||||
private:
|
||||
void PostSimulate(float elapsedTime) override;
|
||||
void PreSimulate(float elapsedTime) override;
|
||||
|
||||
std::shared_ptr<PhysCharacter3DImpl> m_impl;
|
||||
std::shared_ptr<Collider3D> m_collider;
|
||||
std::unique_ptr<JPH::Character> m_character;
|
||||
MovablePtr<PhysWorld3D> m_world;
|
||||
UInt32 m_bodyIndex;
|
||||
};
|
||||
|
||||
class NAZARA_PHYSICS3D_API PhysCharacter3DImpl
|
||||
{
|
||||
public:
|
||||
PhysCharacter3DImpl() = default;
|
||||
PhysCharacter3DImpl(const PhysCharacter3DImpl&) = delete;
|
||||
PhysCharacter3DImpl(PhysCharacter3DImpl&&) = delete;
|
||||
virtual ~PhysCharacter3DImpl();
|
||||
|
||||
virtual void PostSimulate(PhysCharacter3D& character, float elapsedTime);
|
||||
virtual void PreSimulate(PhysCharacter3D& character, float elapsedTime);
|
||||
|
||||
PhysCharacter3DImpl& operator=(const PhysCharacter3DImpl&) = delete;
|
||||
PhysCharacter3DImpl& operator=(PhysCharacter3DImpl&&) = delete;
|
||||
};
|
||||
}
|
||||
|
||||
#include <Nazara/Physics3D/PhysCharacter3D.inl>
|
||||
|
||||
#endif // NAZARA_PHYSICS3D_PHYSCHARACTER3D_HPP
|
||||
35
include/Nazara/Physics3D/PhysCharacter3D.inl
Normal file
35
include/Nazara/Physics3D/PhysCharacter3D.inl
Normal file
@@ -0,0 +1,35 @@
|
||||
// Copyright (C) 2024 Jérôme "SirLynix" Leclercq (lynix680@gmail.com)
|
||||
// This file is part of the "Nazara Engine - Physics3D module"
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#include <Nazara/Physics3D/Debug.hpp>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
inline void PhysCharacter3D::DisableSleeping()
|
||||
{
|
||||
return EnableSleeping(false);
|
||||
}
|
||||
|
||||
inline const std::shared_ptr<Collider3D>& PhysCharacter3D::GetCollider() const
|
||||
{
|
||||
return m_collider;
|
||||
}
|
||||
|
||||
inline PhysWorld3D& PhysCharacter3D::GetPhysWorld()
|
||||
{
|
||||
return *m_world;
|
||||
}
|
||||
|
||||
inline const PhysWorld3D& PhysCharacter3D::GetPhysWorld() const
|
||||
{
|
||||
return *m_world;
|
||||
}
|
||||
|
||||
inline void PhysCharacter3D::SetImpl(std::shared_ptr<PhysCharacter3DImpl> characterImpl)
|
||||
{
|
||||
m_impl = std::move(characterImpl);
|
||||
}
|
||||
}
|
||||
|
||||
#include <Nazara/Physics3D/DebugOff.hpp>
|
||||
99
include/Nazara/Physics3D/PhysConstraint3D.hpp
Normal file
99
include/Nazara/Physics3D/PhysConstraint3D.hpp
Normal file
@@ -0,0 +1,99 @@
|
||||
// Copyright (C) 2024 Jérôme "SirLynix" Leclercq (lynix680@gmail.com)
|
||||
// This file is part of the "Nazara Engine - Physics3D module"
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifndef NAZARA_PHYSICS3D_PHYSCONSTRAINT3D_HPP
|
||||
#define NAZARA_PHYSICS3D_PHYSCONSTRAINT3D_HPP
|
||||
|
||||
#include <NazaraUtils/Prerequisites.hpp>
|
||||
#include <Nazara/Core/HandledObject.hpp>
|
||||
#include <Nazara/Core/ObjectHandle.hpp>
|
||||
#include <Nazara/Physics3D/Config.hpp>
|
||||
#include <Nazara/Physics3D/PhysWorld3D.hpp>
|
||||
#include <Nazara/Physics3D/RigidBody3D.hpp>
|
||||
|
||||
namespace JPH
|
||||
{
|
||||
class TwoBodyConstraint;
|
||||
}
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
class PhysConstraint3D;
|
||||
|
||||
using PhysConstraint3DHandle = ObjectHandle<PhysConstraint3D>;
|
||||
|
||||
class NAZARA_PHYSICS3D_API PhysConstraint3D : public HandledObject<PhysConstraint3D>
|
||||
{
|
||||
public:
|
||||
PhysConstraint3D(const PhysConstraint3D&) = delete;
|
||||
PhysConstraint3D(PhysConstraint3D&& constraint) noexcept;
|
||||
virtual ~PhysConstraint3D();
|
||||
|
||||
RigidBody3D& GetBodyA();
|
||||
const RigidBody3D& GetBodyA() const;
|
||||
RigidBody3D& GetBodyB();
|
||||
const RigidBody3D& GetBodyB() const;
|
||||
PhysWorld3D& GetWorld();
|
||||
const PhysWorld3D& GetWorld() const;
|
||||
|
||||
bool IsSingleBody() const;
|
||||
|
||||
PhysConstraint3D& operator=(const PhysConstraint3D&) = delete;
|
||||
PhysConstraint3D& operator=(PhysConstraint3D&& constraint) noexcept;
|
||||
|
||||
protected:
|
||||
PhysConstraint3D();
|
||||
|
||||
template<typename T> T* GetConstraint();
|
||||
template<typename T> const T* GetConstraint() const;
|
||||
|
||||
void SetupConstraint(std::unique_ptr<JPH::TwoBodyConstraint> constraint);
|
||||
|
||||
private:
|
||||
void Destroy();
|
||||
|
||||
std::unique_ptr<JPH::TwoBodyConstraint> m_constraint;
|
||||
};
|
||||
|
||||
class NAZARA_PHYSICS3D_API PhysDistanceConstraint3D : public PhysConstraint3D
|
||||
{
|
||||
public:
|
||||
PhysDistanceConstraint3D(RigidBody3D& first, const Vector3f& pivot, float maxDist = -1.f, float minDist = -1.f);
|
||||
PhysDistanceConstraint3D(RigidBody3D& first, RigidBody3D& second, const Vector3f& pivot, float maxDist = -1.f, float minDist = -1.f);
|
||||
PhysDistanceConstraint3D(RigidBody3D& first, RigidBody3D& second, const Vector3f& firstAnchor, const Vector3f& secondAnchor, float maxDist = -1.f, float minDist = -1.f);
|
||||
~PhysDistanceConstraint3D() = default;
|
||||
|
||||
float GetDamping() const;
|
||||
float GetFrequency() const;
|
||||
float GetMaxDistance() const;
|
||||
float GetMinDistance() const;
|
||||
|
||||
void SetDamping(float damping);
|
||||
void SetDistance(float minDist, float maxDist);
|
||||
void SetFrequency(float frequency);
|
||||
void SetMaxDistance(float maxDist);
|
||||
void SetMinDistance(float minDist);
|
||||
};
|
||||
|
||||
class NAZARA_PHYSICS3D_API PhysPivotConstraint3D : public PhysConstraint3D
|
||||
{
|
||||
public:
|
||||
PhysPivotConstraint3D(RigidBody3D& first, const Vector3f& pivot);
|
||||
PhysPivotConstraint3D(RigidBody3D& first, RigidBody3D& second, const Vector3f& pivot);
|
||||
PhysPivotConstraint3D(RigidBody3D& first, RigidBody3D& second, const Vector3f& firstAnchor, const Vector3f& secondAnchor);
|
||||
~PhysPivotConstraint3D() = default;
|
||||
|
||||
Vector3f GetFirstAnchor() const;
|
||||
Vector3f GetSecondAnchor() const;
|
||||
|
||||
void SetFirstAnchor(const Vector3f& firstAnchor);
|
||||
void SetSecondAnchor(const Vector3f& secondAnchor);
|
||||
};
|
||||
}
|
||||
|
||||
#include <Nazara/Physics3D/PhysConstraint3D.inl>
|
||||
|
||||
#endif // NAZARA_PHYSICS3D_PHYSCONSTRAINT3D_HPP
|
||||
@@ -1,22 +1,22 @@
|
||||
// Copyright (C) 2024 Jérôme "SirLynix" Leclercq (lynix680@gmail.com)
|
||||
// This file is part of the "Nazara Engine - JoltPhysics3D module"
|
||||
// This file is part of the "Nazara Engine - Physics3D module"
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#include <Nazara/JoltPhysics3D/Debug.hpp>
|
||||
#include <Nazara/Physics3D/Debug.hpp>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
template<typename T>
|
||||
T* JoltConstraint3D::GetConstraint()
|
||||
T* PhysConstraint3D::GetConstraint()
|
||||
{
|
||||
return SafeCast<T*>(m_constraint.get());
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
const T* JoltConstraint3D::GetConstraint() const
|
||||
const T* PhysConstraint3D::GetConstraint() const
|
||||
{
|
||||
return SafeCast<const T*>(m_constraint.get());
|
||||
}
|
||||
}
|
||||
|
||||
#include <Nazara/JoltPhysics3D/DebugOff.hpp>
|
||||
#include <Nazara/Physics3D/DebugOff.hpp>
|
||||
@@ -1,17 +1,17 @@
|
||||
// Copyright (C) 2024 Jérôme "SirLynix" Leclercq (lynix680@gmail.com)
|
||||
// This file is part of the "Nazara Engine - JoltPhysics3D module"
|
||||
// This file is part of the "Nazara Engine - Physics3D module"
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifndef NAZARA_JOLTPHYSICS3D_JOLTPHYSWORLD3D_HPP
|
||||
#define NAZARA_JOLTPHYSICS3D_JOLTPHYSWORLD3D_HPP
|
||||
#ifndef NAZARA_PHYSICS3D_PHYSWORLD3D_HPP
|
||||
#define NAZARA_PHYSICS3D_PHYSWORLD3D_HPP
|
||||
|
||||
#include <NazaraUtils/Prerequisites.hpp>
|
||||
#include <Nazara/Core/Time.hpp>
|
||||
#include <Nazara/JoltPhysics3D/Config.hpp>
|
||||
#include <Nazara/Math/Box.hpp>
|
||||
#include <Nazara/Math/Vector3.hpp>
|
||||
#include <Nazara/Physics3D/Config.hpp>
|
||||
#include <NazaraUtils/FunctionRef.hpp>
|
||||
#include <NazaraUtils/MovablePtr.hpp>
|
||||
#include <atomic>
|
||||
@@ -27,31 +27,31 @@ namespace JPH
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
class JoltAbstractBody;
|
||||
class JoltCharacter;
|
||||
class JoltCharacterImpl;
|
||||
class JoltCollider3D;
|
||||
class JoltPhysicsStepListener;
|
||||
class JoltRigidBody3D;
|
||||
class Physics3DBody;
|
||||
class PhysCharacter3D;
|
||||
class PhysCharacter3DImpl;
|
||||
class Collider3D;
|
||||
class Physiscs3DStepListener;
|
||||
class RigidBody3D;
|
||||
|
||||
class NAZARA_JOLTPHYSICS3D_API JoltPhysWorld3D
|
||||
class NAZARA_PHYSICS3D_API PhysWorld3D
|
||||
{
|
||||
friend JoltCharacter;
|
||||
friend JoltRigidBody3D;
|
||||
friend PhysCharacter3D;
|
||||
friend RigidBody3D;
|
||||
|
||||
public:
|
||||
struct PointCollisionInfo;
|
||||
struct RaycastHit;
|
||||
struct ShapeCollisionInfo;
|
||||
|
||||
JoltPhysWorld3D();
|
||||
JoltPhysWorld3D(const JoltPhysWorld3D&) = delete;
|
||||
JoltPhysWorld3D(JoltPhysWorld3D&& ph) = delete;
|
||||
~JoltPhysWorld3D();
|
||||
PhysWorld3D();
|
||||
PhysWorld3D(const PhysWorld3D&) = delete;
|
||||
PhysWorld3D(PhysWorld3D&& ph) = delete;
|
||||
~PhysWorld3D();
|
||||
|
||||
bool CollisionQuery(const Vector3f& point, const FunctionRef<std::optional<float>(const PointCollisionInfo& collisionInfo)>& callback);
|
||||
bool CollisionQuery(const JoltCollider3D& collider, const Matrix4f& colliderTransform, const FunctionRef<std::optional<float>(const ShapeCollisionInfo& hitInfo)>& callback);
|
||||
bool CollisionQuery(const JoltCollider3D& collider, const Matrix4f& colliderTransform, const Vector3f& colliderScale, const FunctionRef<std::optional<float>(const ShapeCollisionInfo& hitInfo)>& callback);
|
||||
bool CollisionQuery(const Collider3D& collider, const Matrix4f& colliderTransform, const FunctionRef<std::optional<float>(const ShapeCollisionInfo& hitInfo)>& callback);
|
||||
bool CollisionQuery(const Collider3D& collider, const Matrix4f& colliderTransform, const Vector3f& colliderScale, const FunctionRef<std::optional<float>(const ShapeCollisionInfo& hitInfo)>& callback);
|
||||
|
||||
UInt32 GetActiveBodyCount() const;
|
||||
Vector3f GetGravity() const;
|
||||
@@ -67,7 +67,7 @@ namespace Nz
|
||||
|
||||
void RefreshBodies();
|
||||
|
||||
inline void RegisterStepListener(JoltPhysicsStepListener* stepListener);
|
||||
inline void RegisterStepListener(Physiscs3DStepListener* stepListener);
|
||||
|
||||
void SetGravity(const Vector3f& gravity);
|
||||
void SetMaxStepCount(std::size_t maxStepCount);
|
||||
@@ -75,27 +75,27 @@ namespace Nz
|
||||
|
||||
bool Step(Time timestep);
|
||||
|
||||
inline void UnregisterStepListener(JoltPhysicsStepListener* stepListener);
|
||||
inline void UnregisterStepListener(Physiscs3DStepListener* stepListener);
|
||||
|
||||
JoltPhysWorld3D& operator=(const JoltPhysWorld3D&) = delete;
|
||||
JoltPhysWorld3D& operator=(JoltPhysWorld3D&&) = delete;
|
||||
PhysWorld3D& operator=(const PhysWorld3D&) = delete;
|
||||
PhysWorld3D& operator=(PhysWorld3D&&) = delete;
|
||||
|
||||
struct PointCollisionInfo
|
||||
{
|
||||
JoltAbstractBody* hitBody = nullptr;
|
||||
Physics3DBody* hitBody = nullptr;
|
||||
};
|
||||
|
||||
struct RaycastHit
|
||||
{
|
||||
float fraction;
|
||||
JoltAbstractBody* hitBody = nullptr;
|
||||
Physics3DBody* hitBody = nullptr;
|
||||
Vector3f hitNormal;
|
||||
Vector3f hitPosition;
|
||||
};
|
||||
|
||||
struct ShapeCollisionInfo
|
||||
{
|
||||
JoltAbstractBody* hitBody = nullptr;
|
||||
Physics3DBody* hitBody = nullptr;
|
||||
Vector3f collisionPosition1;
|
||||
Vector3f collisionPosition2;
|
||||
Vector3f penetrationAxis;
|
||||
@@ -111,7 +111,7 @@ namespace Nz
|
||||
|
||||
struct JoltWorld;
|
||||
|
||||
std::shared_ptr<JoltCharacterImpl> GetDefaultCharacterImpl();
|
||||
std::shared_ptr<PhysCharacter3DImpl> GetDefaultCharacterImpl();
|
||||
const JPH::Shape* GetNullShape() const;
|
||||
|
||||
void OnPreStep(float deltatime);
|
||||
@@ -121,17 +121,17 @@ namespace Nz
|
||||
void UnregisterBody(const JPH::BodyID& bodyID, bool destroy, bool removeFromRegisterList);
|
||||
|
||||
std::size_t m_maxStepCount;
|
||||
std::shared_ptr<JoltCharacterImpl> m_defaultCharacterImpl;
|
||||
std::shared_ptr<PhysCharacter3DImpl> m_defaultCharacterImpl;
|
||||
std::unique_ptr<std::atomic_uint64_t[]> m_activeBodies;
|
||||
std::unique_ptr<std::uint64_t[]> m_registeredBodies;
|
||||
std::unique_ptr<JoltWorld> m_world;
|
||||
std::vector<JoltPhysicsStepListener*> m_stepListeners;
|
||||
std::vector<Physiscs3DStepListener*> m_stepListeners;
|
||||
Vector3f m_gravity;
|
||||
Time m_stepSize;
|
||||
Time m_timestepAccumulator;
|
||||
};
|
||||
}
|
||||
|
||||
#include <Nazara/JoltPhysics3D/JoltPhysWorld3D.inl>
|
||||
#include <Nazara/Physics3D/PhysWorld3D.inl>
|
||||
|
||||
#endif // NAZARA_JOLTPHYSICS3D_JOLTPHYSWORLD3D_HPP
|
||||
#endif // NAZARA_PHYSICS3D_PHYSWORLD3D_HPP
|
||||
@@ -1,12 +1,12 @@
|
||||
// Copyright (C) 2024 Jérôme "SirLynix" Leclercq (lynix680@gmail.com)
|
||||
// This file is part of the "Nazara Engine - JoltPhysics3D module"
|
||||
// This file is part of the "Nazara Engine - Physics3D module"
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#include <Nazara/JoltPhysics3D/Debug.hpp>
|
||||
#include <Nazara/Physics3D/Debug.hpp>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
inline bool JoltPhysWorld3D::IsBodyActive(UInt32 bodyIndex) const
|
||||
inline bool PhysWorld3D::IsBodyActive(UInt32 bodyIndex) const
|
||||
{
|
||||
UInt32 blockIndex = bodyIndex / 64;
|
||||
UInt32 localIndex = bodyIndex % 64;
|
||||
@@ -14,7 +14,7 @@ namespace Nz
|
||||
return m_activeBodies[blockIndex] & (UInt64(1u) << localIndex);
|
||||
}
|
||||
|
||||
inline bool JoltPhysWorld3D::IsBodyRegistered(UInt32 bodyIndex) const
|
||||
inline bool PhysWorld3D::IsBodyRegistered(UInt32 bodyIndex) const
|
||||
{
|
||||
UInt32 blockIndex = bodyIndex / 64;
|
||||
UInt32 localIndex = bodyIndex % 64;
|
||||
@@ -22,13 +22,13 @@ namespace Nz
|
||||
return m_registeredBodies[blockIndex] & (UInt64(1u) << localIndex);
|
||||
}
|
||||
|
||||
inline void JoltPhysWorld3D::RegisterStepListener(JoltPhysicsStepListener* stepListener)
|
||||
inline void PhysWorld3D::RegisterStepListener(Physiscs3DStepListener* stepListener)
|
||||
{
|
||||
auto it = std::lower_bound(m_stepListeners.begin(), m_stepListeners.end(), stepListener);
|
||||
m_stepListeners.insert(it, stepListener);
|
||||
}
|
||||
|
||||
inline void JoltPhysWorld3D::UnregisterStepListener(JoltPhysicsStepListener* stepListener)
|
||||
inline void PhysWorld3D::UnregisterStepListener(Physiscs3DStepListener* stepListener)
|
||||
{
|
||||
auto it = std::lower_bound(m_stepListeners.begin(), m_stepListeners.end(), stepListener);
|
||||
assert(*it == stepListener);
|
||||
@@ -36,4 +36,4 @@ namespace Nz
|
||||
}
|
||||
}
|
||||
|
||||
#include <Nazara/JoltPhysics3D/DebugOff.hpp>
|
||||
#include <Nazara/Physics3D/DebugOff.hpp>
|
||||
@@ -1,15 +1,15 @@
|
||||
// Copyright (C) 2024 Jérôme "SirLynix" Leclercq (lynix680@gmail.com)
|
||||
// This file is part of the "Nazara Engine - JoltPhysics3D module"
|
||||
// This file is part of the "Nazara Engine - Physics3D module"
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifndef NAZARA_JOLTPHYSICS3D_HPP
|
||||
#define NAZARA_JOLTPHYSICS3D_HPP
|
||||
#ifndef NAZARA_PHYSICS3D_HPP
|
||||
#define NAZARA_PHYSICS3D_HPP
|
||||
|
||||
#include <NazaraUtils/Prerequisites.hpp>
|
||||
#include <Nazara/Core/Core.hpp>
|
||||
#include <Nazara/JoltPhysics3D/Config.hpp>
|
||||
#include <Nazara/Physics3D/Config.hpp>
|
||||
#include <memory>
|
||||
|
||||
namespace JPH
|
||||
@@ -20,7 +20,7 @@ namespace JPH
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
class NAZARA_JOLTPHYSICS3D_API JoltPhysics3D : public ModuleBase<JoltPhysics3D>
|
||||
class NAZARA_PHYSICS3D_API Physics3D : public ModuleBase<Physics3D>
|
||||
{
|
||||
friend ModuleBase;
|
||||
|
||||
@@ -29,16 +29,16 @@ namespace Nz
|
||||
|
||||
struct Config {};
|
||||
|
||||
JoltPhysics3D(Config /*config*/);
|
||||
~JoltPhysics3D();
|
||||
Physics3D(Config /*config*/);
|
||||
~Physics3D();
|
||||
|
||||
JPH::JobSystem& GetThreadPool();
|
||||
|
||||
private:
|
||||
std::unique_ptr<JPH::JobSystemThreadPool> m_threadPool;
|
||||
|
||||
static JoltPhysics3D* s_instance;
|
||||
static Physics3D* s_instance;
|
||||
};
|
||||
}
|
||||
|
||||
#endif // NAZARA_JOLTPHYSICS3D_HPP
|
||||
#endif // NAZARA_PHYSICS3D_HPP
|
||||
32
include/Nazara/Physics3D/Physics3DBody.hpp
Normal file
32
include/Nazara/Physics3D/Physics3DBody.hpp
Normal file
@@ -0,0 +1,32 @@
|
||||
// Copyright (C) 2024 Jérôme "SirLynix" Leclercq (lynix680@gmail.com)
|
||||
// This file is part of the "Nazara Engine - Physics3D module"
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifndef NAZARA_PHYSICS3D_PHYSICS3DBODY_HPP
|
||||
#define NAZARA_PHYSICS3D_PHYSICS3DBODY_HPP
|
||||
|
||||
#include <NazaraUtils/Prerequisites.hpp>
|
||||
#include <Nazara/Physics3D/Config.hpp>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
class NAZARA_PHYSICS3D_API Physics3DBody
|
||||
{
|
||||
public:
|
||||
Physics3DBody() = default;
|
||||
Physics3DBody(const Physics3DBody&) = delete;
|
||||
Physics3DBody(Physics3DBody&&) = delete;
|
||||
virtual ~Physics3DBody();
|
||||
|
||||
virtual UInt32 GetBodyIndex() const = 0;
|
||||
|
||||
Physics3DBody& operator=(const Physics3DBody&) = delete;
|
||||
Physics3DBody& operator=(Physics3DBody&&) = delete;
|
||||
};
|
||||
}
|
||||
|
||||
#include <Nazara/Physics3D/Physics3DBody.inl>
|
||||
|
||||
#endif // NAZARA_PHYSICS3D_PHYSICS3DBODY_HPP
|
||||
@@ -1,11 +1,11 @@
|
||||
// Copyright (C) 2024 Jérôme "SirLynix" Leclercq (lynix680@gmail.com)
|
||||
// This file is part of the "Nazara Engine - JoltPhysics3D module"
|
||||
// This file is part of the "Nazara Engine - Physics3D module"
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#include <Nazara/JoltPhysics3D/Debug.hpp>
|
||||
#include <Nazara/Physics3D/Debug.hpp>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
}
|
||||
|
||||
#include <Nazara/JoltPhysics3D/DebugOff.hpp>
|
||||
#include <Nazara/Physics3D/DebugOff.hpp>
|
||||
33
include/Nazara/Physics3D/Physiscs3DStepListener.hpp
Normal file
33
include/Nazara/Physics3D/Physiscs3DStepListener.hpp
Normal file
@@ -0,0 +1,33 @@
|
||||
// Copyright (C) 2024 Jérôme "SirLynix" Leclercq (lynix680@gmail.com)
|
||||
// This file is part of the "Nazara Engine - Physics3D module"
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifndef NAZARA_PHYSICS3D_PHYSISCS3DSTEPLISTENER_HPP
|
||||
#define NAZARA_PHYSICS3D_PHYSISCS3DSTEPLISTENER_HPP
|
||||
|
||||
#include <NazaraUtils/Prerequisites.hpp>
|
||||
#include <Nazara/Physics3D/Config.hpp>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
class NAZARA_PHYSICS3D_API Physiscs3DStepListener
|
||||
{
|
||||
public:
|
||||
Physiscs3DStepListener() = default;
|
||||
Physiscs3DStepListener(const Physiscs3DStepListener&) = delete;
|
||||
Physiscs3DStepListener(Physiscs3DStepListener&&) = delete;
|
||||
virtual ~Physiscs3DStepListener();
|
||||
|
||||
virtual void PostSimulate(float elapsedTime);
|
||||
virtual void PreSimulate(float elapsedTime);
|
||||
|
||||
Physiscs3DStepListener& operator=(const Physiscs3DStepListener&) = delete;
|
||||
Physiscs3DStepListener& operator=(Physiscs3DStepListener&&) = delete;
|
||||
};
|
||||
}
|
||||
|
||||
#include <Nazara/Physics3D/Physiscs3DStepListener.inl>
|
||||
|
||||
#endif // NAZARA_PHYSICS3D_PHYSISCS3DSTEPLISTENER_HPP
|
||||
@@ -1,11 +1,11 @@
|
||||
// Copyright (C) 2024 Jérôme "SirLynix" Leclercq (lynix680@gmail.com)
|
||||
// This file is part of the "Nazara Engine - JoltPhysics3D module"
|
||||
// This file is part of the "Nazara Engine - Physics3D module"
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#include <Nazara/JoltPhysics3D/Debug.hpp>
|
||||
#include <Nazara/Physics3D/Debug.hpp>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
}
|
||||
|
||||
#include <Nazara/JoltPhysics3D/DebugOff.hpp>
|
||||
#include <Nazara/Physics3D/DebugOff.hpp>
|
||||
@@ -1,20 +1,20 @@
|
||||
// Copyright (C) 2024 Jérôme "SirLynix" Leclercq (lynix680@gmail.com)
|
||||
// This file is part of the "Nazara Engine - JoltPhysics3D module"
|
||||
// This file is part of the "Nazara Engine - Physics3D module"
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifndef NAZARA_JOLTPHYSICS3D_JOLTRIGIDBODY3D_HPP
|
||||
#define NAZARA_JOLTPHYSICS3D_JOLTRIGIDBODY3D_HPP
|
||||
#ifndef NAZARA_PHYSICS3D_RIGIDBODY3D_HPP
|
||||
#define NAZARA_PHYSICS3D_RIGIDBODY3D_HPP
|
||||
|
||||
#include <NazaraUtils/Prerequisites.hpp>
|
||||
#include <Nazara/Core/Enums.hpp>
|
||||
#include <Nazara/JoltPhysics3D/Config.hpp>
|
||||
#include <Nazara/JoltPhysics3D/JoltAbstractBody.hpp>
|
||||
#include <Nazara/JoltPhysics3D/JoltCollider3D.hpp>
|
||||
#include <Nazara/Math/Matrix4.hpp>
|
||||
#include <Nazara/Math/Quaternion.hpp>
|
||||
#include <Nazara/Math/Vector3.hpp>
|
||||
#include <Nazara/Physics3D/Collider3D.hpp>
|
||||
#include <Nazara/Physics3D/Config.hpp>
|
||||
#include <Nazara/Physics3D/Physics3DBody.hpp>
|
||||
#include <NazaraUtils/MovablePtr.hpp>
|
||||
|
||||
namespace JPH
|
||||
@@ -25,19 +25,19 @@ namespace JPH
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
class JoltPhysWorld3D;
|
||||
class PhysWorld3D;
|
||||
|
||||
class NAZARA_JOLTPHYSICS3D_API JoltRigidBody3D : public JoltAbstractBody
|
||||
class NAZARA_PHYSICS3D_API RigidBody3D : public Physics3DBody
|
||||
{
|
||||
public:
|
||||
struct DynamicSettings;
|
||||
struct StaticSettings;
|
||||
|
||||
inline JoltRigidBody3D(JoltPhysWorld3D& world, const DynamicSettings& settings);
|
||||
inline JoltRigidBody3D(JoltPhysWorld3D& world, const StaticSettings& settings);
|
||||
JoltRigidBody3D(const JoltRigidBody3D& object) = delete;
|
||||
JoltRigidBody3D(JoltRigidBody3D&& object) noexcept;
|
||||
~JoltRigidBody3D();
|
||||
inline RigidBody3D(PhysWorld3D& world, const DynamicSettings& settings);
|
||||
inline RigidBody3D(PhysWorld3D& world, const StaticSettings& settings);
|
||||
RigidBody3D(const RigidBody3D& object) = delete;
|
||||
RigidBody3D(RigidBody3D&& object) noexcept;
|
||||
~RigidBody3D();
|
||||
|
||||
void AddForce(const Vector3f& force, CoordSys coordSys = CoordSys::Global);
|
||||
void AddForce(const Vector3f& force, const Vector3f& point, CoordSys coordSys = CoordSys::Global);
|
||||
@@ -56,7 +56,7 @@ namespace Nz
|
||||
inline JPH::Body* GetBody();
|
||||
inline const JPH::Body* GetBody() const;
|
||||
UInt32 GetBodyIndex() const override;
|
||||
inline const std::shared_ptr<JoltCollider3D>& GetGeom() const;
|
||||
inline const std::shared_ptr<Collider3D>& GetGeom() const;
|
||||
float GetLinearDamping() const;
|
||||
Vector3f GetLinearVelocity() const;
|
||||
float GetMass() const;
|
||||
@@ -64,7 +64,7 @@ namespace Nz
|
||||
Vector3f GetPosition() const;
|
||||
std::pair<Vector3f, Quaternionf> GetPositionAndRotation() const;
|
||||
Quaternionf GetRotation() const;
|
||||
inline JoltPhysWorld3D& GetWorld() const;
|
||||
inline PhysWorld3D& GetWorld() const;
|
||||
|
||||
inline bool IsSimulationEnabled() const;
|
||||
bool IsSleeping() const;
|
||||
@@ -73,7 +73,7 @@ namespace Nz
|
||||
|
||||
void SetAngularDamping(float angularDamping);
|
||||
void SetAngularVelocity(const Vector3f& angularVelocity);
|
||||
void SetGeom(std::shared_ptr<JoltCollider3D> geom, bool recomputeInertia = true);
|
||||
void SetGeom(std::shared_ptr<Collider3D> geom, bool recomputeInertia = true);
|
||||
void SetLinearDamping(float damping);
|
||||
void SetLinearVelocity(const Vector3f& velocity);
|
||||
void SetMass(float mass, bool recomputeInertia = true);
|
||||
@@ -89,12 +89,12 @@ namespace Nz
|
||||
|
||||
void WakeUp();
|
||||
|
||||
JoltRigidBody3D& operator=(const JoltRigidBody3D& object) = delete;
|
||||
JoltRigidBody3D& operator=(JoltRigidBody3D&& object) noexcept;
|
||||
RigidBody3D& operator=(const RigidBody3D& object) = delete;
|
||||
RigidBody3D& operator=(RigidBody3D&& object) noexcept;
|
||||
|
||||
struct CommonSettings
|
||||
{
|
||||
std::shared_ptr<JoltCollider3D> geom;
|
||||
std::shared_ptr<Collider3D> geom;
|
||||
Quaternionf rotation = Quaternionf::Identity();
|
||||
Vector3f position = Vector3f::Zero();
|
||||
bool initiallySleeping = false;
|
||||
@@ -105,14 +105,14 @@ namespace Nz
|
||||
struct DynamicSettings : CommonSettings
|
||||
{
|
||||
DynamicSettings() = default;
|
||||
DynamicSettings(std::shared_ptr<JoltCollider3D> collider, float mass_) :
|
||||
DynamicSettings(std::shared_ptr<Collider3D> collider, float mass_) :
|
||||
mass(mass_)
|
||||
{
|
||||
geom = std::move(collider);
|
||||
}
|
||||
|
||||
// Default values from Jolt
|
||||
JoltMotionQuality motionQuality = JoltMotionQuality::Discrete;
|
||||
PhysMotionQuality3D motionQuality = PhysMotionQuality3D::Discrete;
|
||||
Vector3f angularVelocity = Vector3f::Zero();
|
||||
Vector3f linearVelocity = Vector3f::Zero();
|
||||
bool allowSleeping = true;
|
||||
@@ -129,16 +129,16 @@ namespace Nz
|
||||
struct StaticSettings : CommonSettings
|
||||
{
|
||||
StaticSettings() = default;
|
||||
StaticSettings(std::shared_ptr<JoltCollider3D> collider)
|
||||
StaticSettings(std::shared_ptr<Collider3D> collider)
|
||||
{
|
||||
geom = std::move(collider);
|
||||
}
|
||||
};
|
||||
|
||||
protected:
|
||||
JoltRigidBody3D() = default;
|
||||
void Create(JoltPhysWorld3D& world, const DynamicSettings& settings);
|
||||
void Create(JoltPhysWorld3D& world, const StaticSettings& settings);
|
||||
RigidBody3D() = default;
|
||||
void Create(PhysWorld3D& world, const DynamicSettings& settings);
|
||||
void Create(PhysWorld3D& world, const StaticSettings& settings);
|
||||
void Destroy(bool worldDestruction = false);
|
||||
|
||||
private:
|
||||
@@ -148,15 +148,15 @@ namespace Nz
|
||||
|
||||
bool ShouldActivate() const;
|
||||
|
||||
std::shared_ptr<JoltCollider3D> m_geom;
|
||||
std::shared_ptr<Collider3D> m_geom;
|
||||
MovablePtr<JPH::Body> m_body;
|
||||
MovablePtr<JoltPhysWorld3D> m_world;
|
||||
MovablePtr<PhysWorld3D> m_world;
|
||||
UInt32 m_bodyIndex;
|
||||
bool m_isSimulationEnabled;
|
||||
bool m_isTrigger;
|
||||
};
|
||||
}
|
||||
|
||||
#include <Nazara/JoltPhysics3D/JoltRigidBody3D.inl>
|
||||
#include <Nazara/Physics3D/RigidBody3D.inl>
|
||||
|
||||
#endif // NAZARA_JOLTPHYSICS3D_JOLTRIGIDBODY3D_HPP
|
||||
#endif // NAZARA_PHYSICS3D_RIGIDBODY3D_HPP
|
||||
55
include/Nazara/Physics3D/RigidBody3D.inl
Normal file
55
include/Nazara/Physics3D/RigidBody3D.inl
Normal file
@@ -0,0 +1,55 @@
|
||||
// Copyright (C) 2024 Jérôme "SirLynix" Leclercq (lynix680@gmail.com)
|
||||
// This file is part of the "Nazara Engine - Physics3D module"
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#include <Nazara/Physics3D/Debug.hpp>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
inline RigidBody3D::RigidBody3D(PhysWorld3D& world, const DynamicSettings& settings)
|
||||
{
|
||||
Create(world, settings);
|
||||
}
|
||||
|
||||
inline RigidBody3D::RigidBody3D(PhysWorld3D& world, const StaticSettings& settings)
|
||||
{
|
||||
Create(world, settings);
|
||||
}
|
||||
|
||||
inline void RigidBody3D::DisableSimulation()
|
||||
{
|
||||
return EnableSimulation(false);
|
||||
}
|
||||
|
||||
inline void RigidBody3D::DisableSleeping()
|
||||
{
|
||||
return EnableSleeping(false);
|
||||
}
|
||||
|
||||
inline JPH::Body* RigidBody3D::GetBody()
|
||||
{
|
||||
return m_body;
|
||||
}
|
||||
|
||||
inline const JPH::Body* RigidBody3D::GetBody() const
|
||||
{
|
||||
return m_body;
|
||||
}
|
||||
|
||||
inline const std::shared_ptr<Collider3D>& RigidBody3D::GetGeom() const
|
||||
{
|
||||
return m_geom;
|
||||
}
|
||||
|
||||
inline PhysWorld3D& RigidBody3D::GetWorld() const
|
||||
{
|
||||
return *m_world;
|
||||
}
|
||||
|
||||
inline bool RigidBody3D::IsSimulationEnabled() const
|
||||
{
|
||||
return m_isSimulationEnabled;
|
||||
}
|
||||
}
|
||||
|
||||
#include <Nazara/Physics3D/DebugOff.hpp>
|
||||
@@ -1,7 +1,7 @@
|
||||
// this file was automatically generated and should not be edited
|
||||
|
||||
/*
|
||||
Nazara Engine - ChipmunkPhysics2D module
|
||||
Nazara Engine - Physics3D module
|
||||
|
||||
Copyright (C) 2024 Jérôme "SirLynix" Leclercq (lynix680@gmail.com)
|
||||
|
||||
@@ -26,9 +26,9 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifndef NAZARA_CHIPMUNKPHYSICS2D_SYSTEMS_HPP
|
||||
#define NAZARA_CHIPMUNKPHYSICS2D_SYSTEMS_HPP
|
||||
#ifndef NAZARA_PHYSICS3D_SYSTEMS_HPP
|
||||
#define NAZARA_PHYSICS3D_SYSTEMS_HPP
|
||||
|
||||
#include <Nazara/ChipmunkPhysics2D/Systems/ChipmunkPhysics2DSystem.hpp>
|
||||
#include <Nazara/Physics3D/Systems/Physics3DSystem.hpp>
|
||||
|
||||
#endif // NAZARA_CHIPMUNKPHYSICS2D_SYSTEMS_HPP
|
||||
#endif // NAZARA_PHYSICS3D_SYSTEMS_HPP
|
||||
@@ -1,45 +1,45 @@
|
||||
// Copyright (C) 2024 Jérôme "SirLynix" Leclercq (lynix680@gmail.com)
|
||||
// This file is part of the "Nazara Engine - JoltPhysics3D module"
|
||||
// This file is part of the "Nazara Engine - Physics3D module"
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifndef NAZARA_JOLTPHYSICS3D_SYSTEMS_JOLTPHYSICS3DSYSTEM_HPP
|
||||
#define NAZARA_JOLTPHYSICS3D_SYSTEMS_JOLTPHYSICS3DSYSTEM_HPP
|
||||
#ifndef NAZARA_PHYSICS3D_SYSTEMS_PHYSICS3DSYSTEM_HPP
|
||||
#define NAZARA_PHYSICS3D_SYSTEMS_PHYSICS3DSYSTEM_HPP
|
||||
|
||||
#include <NazaraUtils/Prerequisites.hpp>
|
||||
#include <Nazara/Core/Clock.hpp>
|
||||
#include <Nazara/Core/Time.hpp>
|
||||
#include <Nazara/JoltPhysics3D/JoltPhysWorld3D.hpp>
|
||||
#include <Nazara/JoltPhysics3D/Components/JoltCharacterComponent.hpp>
|
||||
#include <Nazara/JoltPhysics3D/Components/JoltRigidBody3DComponent.hpp>
|
||||
#include <Nazara/Physics3D/PhysWorld3D.hpp>
|
||||
#include <Nazara/Physics3D/Components/PhysCharacter3DComponent.hpp>
|
||||
#include <Nazara/Physics3D/Components/RigidBody3DComponent.hpp>
|
||||
#include <NazaraUtils/TypeList.hpp>
|
||||
#include <entt/entt.hpp>
|
||||
#include <vector>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
class NAZARA_JOLTPHYSICS3D_API JoltPhysics3DSystem
|
||||
class NAZARA_PHYSICS3D_API Physics3DSystem
|
||||
{
|
||||
public:
|
||||
static constexpr Int64 ExecutionOrder = 0;
|
||||
using Components = TypeList<JoltCharacterComponent, JoltRigidBody3DComponent, class NodeComponent>;
|
||||
using Components = TypeList<PhysCharacter3DComponent, RigidBody3DComponent, class NodeComponent>;
|
||||
|
||||
struct PointCollisionInfo;
|
||||
struct RaycastHit;
|
||||
struct ShapeCollisionInfo;
|
||||
|
||||
JoltPhysics3DSystem(entt::registry& registry);
|
||||
JoltPhysics3DSystem(const JoltPhysics3DSystem&) = delete;
|
||||
JoltPhysics3DSystem(JoltPhysics3DSystem&&) = delete;
|
||||
~JoltPhysics3DSystem();
|
||||
Physics3DSystem(entt::registry& registry);
|
||||
Physics3DSystem(const Physics3DSystem&) = delete;
|
||||
Physics3DSystem(Physics3DSystem&&) = delete;
|
||||
~Physics3DSystem();
|
||||
|
||||
bool CollisionQuery(const Vector3f& point, const FunctionRef<std::optional<float>(const PointCollisionInfo& collisionInfo)>& callback);
|
||||
bool CollisionQuery(const JoltCollider3D& collider, const Matrix4f& colliderTransform, const FunctionRef<std::optional<float>(const ShapeCollisionInfo& hitInfo)>& callback);
|
||||
bool CollisionQuery(const JoltCollider3D& collider, const Matrix4f& colliderTransform, const Vector3f& colliderScale, const FunctionRef<std::optional<float>(const ShapeCollisionInfo& hitInfo)>& callback);
|
||||
bool CollisionQuery(const Collider3D& collider, const Matrix4f& colliderTransform, const FunctionRef<std::optional<float>(const ShapeCollisionInfo& hitInfo)>& callback);
|
||||
bool CollisionQuery(const Collider3D& collider, const Matrix4f& colliderTransform, const Vector3f& colliderScale, const FunctionRef<std::optional<float>(const ShapeCollisionInfo& hitInfo)>& callback);
|
||||
|
||||
inline JoltPhysWorld3D& GetPhysWorld();
|
||||
inline const JoltPhysWorld3D& GetPhysWorld() const;
|
||||
inline PhysWorld3D& GetPhysWorld();
|
||||
inline const PhysWorld3D& GetPhysWorld() const;
|
||||
inline entt::handle GetRigidBodyEntity(UInt32 bodyIndex) const;
|
||||
|
||||
bool RaycastQuery(const Vector3f& from, const Vector3f& to, const FunctionRef<std::optional<float>(const RaycastHit& hitInfo)>& callback);
|
||||
@@ -47,20 +47,20 @@ namespace Nz
|
||||
|
||||
void Update(Time elapsedTime);
|
||||
|
||||
JoltPhysics3DSystem& operator=(const JoltPhysics3DSystem&) = delete;
|
||||
JoltPhysics3DSystem& operator=(JoltPhysics3DSystem&&) = delete;
|
||||
Physics3DSystem& operator=(const Physics3DSystem&) = delete;
|
||||
Physics3DSystem& operator=(Physics3DSystem&&) = delete;
|
||||
|
||||
struct PointCollisionInfo : JoltPhysWorld3D::PointCollisionInfo
|
||||
struct PointCollisionInfo : PhysWorld3D::PointCollisionInfo
|
||||
{
|
||||
entt::handle hitEntity;
|
||||
};
|
||||
|
||||
struct RaycastHit : JoltPhysWorld3D::RaycastHit
|
||||
struct RaycastHit : PhysWorld3D::RaycastHit
|
||||
{
|
||||
entt::handle hitEntity;
|
||||
};
|
||||
|
||||
struct ShapeCollisionInfo : JoltPhysWorld3D::ShapeCollisionInfo
|
||||
struct ShapeCollisionInfo : PhysWorld3D::ShapeCollisionInfo
|
||||
{
|
||||
entt::handle hitEntity;
|
||||
};
|
||||
@@ -80,10 +80,10 @@ namespace Nz
|
||||
entt::scoped_connection m_bodyDestructConnection;
|
||||
entt::scoped_connection m_characterConstructConnection;
|
||||
entt::scoped_connection m_characterDestructConnection;
|
||||
JoltPhysWorld3D m_physWorld;
|
||||
PhysWorld3D m_physWorld;
|
||||
};
|
||||
}
|
||||
|
||||
#include <Nazara/JoltPhysics3D/Systems/JoltPhysics3DSystem.inl>
|
||||
#include <Nazara/Physics3D/Systems/Physics3DSystem.inl>
|
||||
|
||||
#endif // NAZARA_JOLTPHYSICS3D_SYSTEMS_JOLTPHYSICS3DSYSTEM_HPP
|
||||
#endif // NAZARA_PHYSICS3D_SYSTEMS_PHYSICS3DSYSTEM_HPP
|
||||
25
include/Nazara/Physics3D/Systems/Physics3DSystem.inl
Normal file
25
include/Nazara/Physics3D/Systems/Physics3DSystem.inl
Normal file
@@ -0,0 +1,25 @@
|
||||
// Copyright (C) 2024 Jérôme "SirLynix" Leclercq (lynix680@gmail.com)
|
||||
// This file is part of the "Nazara Engine - Physics3D module"
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#include <Nazara/Physics3D/Debug.hpp>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
inline PhysWorld3D& Physics3DSystem::GetPhysWorld()
|
||||
{
|
||||
return m_physWorld;
|
||||
}
|
||||
|
||||
inline const PhysWorld3D& Physics3DSystem::GetPhysWorld() const
|
||||
{
|
||||
return m_physWorld;
|
||||
}
|
||||
|
||||
inline entt::handle Physics3DSystem::GetRigidBodyEntity(UInt32 bodyIndex) const
|
||||
{
|
||||
return entt::handle(m_registry, m_bodyIndicesToEntity[bodyIndex]);
|
||||
}
|
||||
}
|
||||
|
||||
#include <Nazara/Physics3D/DebugOff.hpp>
|
||||
Reference in New Issue
Block a user