Rename ChipmunkPhysics2D and JoltPhysics3D to Physics[2D|3D]
This commit is contained in:
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>
|
||||
35
include/Nazara/Physics3D/Components.hpp
Normal file
35
include/Nazara/Physics3D/Components.hpp
Normal file
@@ -0,0 +1,35 @@
|
||||
// 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_PHYSICS3D_COMPONENTS_HPP
|
||||
#define NAZARA_PHYSICS3D_COMPONENTS_HPP
|
||||
|
||||
#include <Nazara/Physics3D/Components/PhysCharacter3DComponent.hpp>
|
||||
#include <Nazara/Physics3D/Components/RigidBody3DComponent.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>
|
||||
48
include/Nazara/Physics3D/Config.hpp
Normal file
48
include/Nazara/Physics3D/Config.hpp
Normal file
@@ -0,0 +1,48 @@
|
||||
/*
|
||||
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_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_PHYSICS3D_SAFE 1
|
||||
|
||||
/// Vérification des valeurs et types de certaines constantes
|
||||
#include <Nazara/Physics3D/ConfigCheck.hpp>
|
||||
|
||||
#if defined(NAZARA_STATIC)
|
||||
#define NAZARA_PHYSICS3D_API
|
||||
#else
|
||||
#ifdef NAZARA_PHYSICS3D_BUILD
|
||||
#define NAZARA_PHYSICS3D_API NAZARA_EXPORT
|
||||
#else
|
||||
#define NAZARA_PHYSICS3D_API NAZARA_IMPORT
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#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
|
||||
5
include/Nazara/Physics3D/Debug.hpp
Normal file
5
include/Nazara/Physics3D/Debug.hpp
Normal file
@@ -0,0 +1,5 @@
|
||||
// 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
|
||||
|
||||
// no header guards
|
||||
5
include/Nazara/Physics3D/DebugOff.hpp
Normal file
5
include/Nazara/Physics3D/DebugOff.hpp
Normal file
@@ -0,0 +1,5 @@
|
||||
// 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
|
||||
|
||||
// no header guards
|
||||
34
include/Nazara/Physics3D/Enums.hpp
Normal file
34
include/Nazara/Physics3D/Enums.hpp
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
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifndef NAZARA_PHYSICS3D_ENUMS_HPP
|
||||
#define NAZARA_PHYSICS3D_ENUMS_HPP
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
enum class ColliderType3D
|
||||
{
|
||||
Box,
|
||||
Capsule,
|
||||
Compound,
|
||||
Convex,
|
||||
Mesh,
|
||||
Sphere,
|
||||
|
||||
ScaleDecoration,
|
||||
TranslatedRotatedDecoration,
|
||||
|
||||
Max = TranslatedRotatedDecoration
|
||||
};
|
||||
|
||||
enum class PhysMotionQuality3D
|
||||
{
|
||||
Discrete,
|
||||
LinearCast
|
||||
};
|
||||
}
|
||||
|
||||
#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
|
||||
22
include/Nazara/Physics3D/PhysConstraint3D.inl
Normal file
22
include/Nazara/Physics3D/PhysConstraint3D.inl
Normal file
@@ -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
|
||||
{
|
||||
template<typename T>
|
||||
T* PhysConstraint3D::GetConstraint()
|
||||
{
|
||||
return SafeCast<T*>(m_constraint.get());
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
const T* PhysConstraint3D::GetConstraint() const
|
||||
{
|
||||
return SafeCast<const T*>(m_constraint.get());
|
||||
}
|
||||
}
|
||||
|
||||
#include <Nazara/Physics3D/DebugOff.hpp>
|
||||
137
include/Nazara/Physics3D/PhysWorld3D.hpp
Normal file
137
include/Nazara/Physics3D/PhysWorld3D.hpp
Normal file
@@ -0,0 +1,137 @@
|
||||
// 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_PHYSWORLD3D_HPP
|
||||
#define NAZARA_PHYSICS3D_PHYSWORLD3D_HPP
|
||||
|
||||
#include <NazaraUtils/Prerequisites.hpp>
|
||||
#include <Nazara/Core/Time.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>
|
||||
#include <optional>
|
||||
#include <vector>
|
||||
|
||||
namespace JPH
|
||||
{
|
||||
class BodyID;
|
||||
class PhysicsSystem;
|
||||
class Shape;
|
||||
}
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
class Physics3DBody;
|
||||
class PhysCharacter3D;
|
||||
class PhysCharacter3DImpl;
|
||||
class Collider3D;
|
||||
class Physiscs3DStepListener;
|
||||
class RigidBody3D;
|
||||
|
||||
class NAZARA_PHYSICS3D_API PhysWorld3D
|
||||
{
|
||||
friend PhysCharacter3D;
|
||||
friend RigidBody3D;
|
||||
|
||||
public:
|
||||
struct PointCollisionInfo;
|
||||
struct RaycastHit;
|
||||
struct ShapeCollisionInfo;
|
||||
|
||||
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 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;
|
||||
std::size_t GetMaxStepCount() const;
|
||||
JPH::PhysicsSystem* GetPhysicsSystem();
|
||||
Time GetStepSize() const;
|
||||
|
||||
inline bool IsBodyActive(UInt32 bodyIndex) const;
|
||||
inline bool IsBodyRegistered(UInt32 bodyIndex) const;
|
||||
|
||||
bool RaycastQuery(const Vector3f& from, const Vector3f& to, const FunctionRef<std::optional<float>(const RaycastHit& hitInfo)>& callback);
|
||||
bool RaycastQueryFirst(const Vector3f& from, const Vector3f& to, const FunctionRef<void(const RaycastHit& hitInfo)>& callback);
|
||||
|
||||
void RefreshBodies();
|
||||
|
||||
inline void RegisterStepListener(Physiscs3DStepListener* stepListener);
|
||||
|
||||
void SetGravity(const Vector3f& gravity);
|
||||
void SetMaxStepCount(std::size_t maxStepCount);
|
||||
void SetStepSize(Time stepSize);
|
||||
|
||||
bool Step(Time timestep);
|
||||
|
||||
inline void UnregisterStepListener(Physiscs3DStepListener* stepListener);
|
||||
|
||||
PhysWorld3D& operator=(const PhysWorld3D&) = delete;
|
||||
PhysWorld3D& operator=(PhysWorld3D&&) = delete;
|
||||
|
||||
struct PointCollisionInfo
|
||||
{
|
||||
Physics3DBody* hitBody = nullptr;
|
||||
};
|
||||
|
||||
struct RaycastHit
|
||||
{
|
||||
float fraction;
|
||||
Physics3DBody* hitBody = nullptr;
|
||||
Vector3f hitNormal;
|
||||
Vector3f hitPosition;
|
||||
};
|
||||
|
||||
struct ShapeCollisionInfo
|
||||
{
|
||||
Physics3DBody* hitBody = nullptr;
|
||||
Vector3f collisionPosition1;
|
||||
Vector3f collisionPosition2;
|
||||
Vector3f penetrationAxis;
|
||||
float penetrationDepth;
|
||||
};
|
||||
|
||||
private:
|
||||
class BodyActivationListener;
|
||||
friend BodyActivationListener;
|
||||
|
||||
class StepListener;
|
||||
friend StepListener;
|
||||
|
||||
struct JoltWorld;
|
||||
|
||||
std::shared_ptr<PhysCharacter3DImpl> GetDefaultCharacterImpl();
|
||||
const JPH::Shape* GetNullShape() const;
|
||||
|
||||
void OnPreStep(float deltatime);
|
||||
|
||||
void RegisterBody(const JPH::BodyID& bodyID, bool activate, bool removeFromDeactivationList);
|
||||
|
||||
void UnregisterBody(const JPH::BodyID& bodyID, bool destroy, bool removeFromRegisterList);
|
||||
|
||||
std::size_t m_maxStepCount;
|
||||
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<Physiscs3DStepListener*> m_stepListeners;
|
||||
Vector3f m_gravity;
|
||||
Time m_stepSize;
|
||||
Time m_timestepAccumulator;
|
||||
};
|
||||
}
|
||||
|
||||
#include <Nazara/Physics3D/PhysWorld3D.inl>
|
||||
|
||||
#endif // NAZARA_PHYSICS3D_PHYSWORLD3D_HPP
|
||||
39
include/Nazara/Physics3D/PhysWorld3D.inl
Normal file
39
include/Nazara/Physics3D/PhysWorld3D.inl
Normal file
@@ -0,0 +1,39 @@
|
||||
// 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 bool PhysWorld3D::IsBodyActive(UInt32 bodyIndex) const
|
||||
{
|
||||
UInt32 blockIndex = bodyIndex / 64;
|
||||
UInt32 localIndex = bodyIndex % 64;
|
||||
|
||||
return m_activeBodies[blockIndex] & (UInt64(1u) << localIndex);
|
||||
}
|
||||
|
||||
inline bool PhysWorld3D::IsBodyRegistered(UInt32 bodyIndex) const
|
||||
{
|
||||
UInt32 blockIndex = bodyIndex / 64;
|
||||
UInt32 localIndex = bodyIndex % 64;
|
||||
|
||||
return m_registeredBodies[blockIndex] & (UInt64(1u) << localIndex);
|
||||
}
|
||||
|
||||
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 PhysWorld3D::UnregisterStepListener(Physiscs3DStepListener* stepListener)
|
||||
{
|
||||
auto it = std::lower_bound(m_stepListeners.begin(), m_stepListeners.end(), stepListener);
|
||||
assert(*it == stepListener);
|
||||
m_stepListeners.erase(it);
|
||||
}
|
||||
}
|
||||
|
||||
#include <Nazara/Physics3D/DebugOff.hpp>
|
||||
44
include/Nazara/Physics3D/Physics3D.hpp
Normal file
44
include/Nazara/Physics3D/Physics3D.hpp
Normal file
@@ -0,0 +1,44 @@
|
||||
// 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_HPP
|
||||
#define NAZARA_PHYSICS3D_HPP
|
||||
|
||||
#include <NazaraUtils/Prerequisites.hpp>
|
||||
#include <Nazara/Core/Core.hpp>
|
||||
#include <Nazara/Physics3D/Config.hpp>
|
||||
#include <memory>
|
||||
|
||||
namespace JPH
|
||||
{
|
||||
class JobSystem;
|
||||
class JobSystemThreadPool;
|
||||
}
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
class NAZARA_PHYSICS3D_API Physics3D : public ModuleBase<Physics3D>
|
||||
{
|
||||
friend ModuleBase;
|
||||
|
||||
public:
|
||||
using Dependencies = TypeList<Core>;
|
||||
|
||||
struct Config {};
|
||||
|
||||
Physics3D(Config /*config*/);
|
||||
~Physics3D();
|
||||
|
||||
JPH::JobSystem& GetThreadPool();
|
||||
|
||||
private:
|
||||
std::unique_ptr<JPH::JobSystemThreadPool> m_threadPool;
|
||||
|
||||
static Physics3D* s_instance;
|
||||
};
|
||||
}
|
||||
|
||||
#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
|
||||
11
include/Nazara/Physics3D/Physics3DBody.inl
Normal file
11
include/Nazara/Physics3D/Physics3DBody.inl
Normal file
@@ -0,0 +1,11 @@
|
||||
// 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
|
||||
{
|
||||
}
|
||||
|
||||
#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
|
||||
11
include/Nazara/Physics3D/Physiscs3DStepListener.inl
Normal file
11
include/Nazara/Physics3D/Physiscs3DStepListener.inl
Normal file
@@ -0,0 +1,11 @@
|
||||
// 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
|
||||
{
|
||||
}
|
||||
|
||||
#include <Nazara/Physics3D/DebugOff.hpp>
|
||||
162
include/Nazara/Physics3D/RigidBody3D.hpp
Normal file
162
include/Nazara/Physics3D/RigidBody3D.hpp
Normal file
@@ -0,0 +1,162 @@
|
||||
// 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_RIGIDBODY3D_HPP
|
||||
#define NAZARA_PHYSICS3D_RIGIDBODY3D_HPP
|
||||
|
||||
#include <NazaraUtils/Prerequisites.hpp>
|
||||
#include <Nazara/Core/Enums.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
|
||||
{
|
||||
class Body;
|
||||
class BodyCreationSettings;
|
||||
}
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
class PhysWorld3D;
|
||||
|
||||
class NAZARA_PHYSICS3D_API RigidBody3D : public Physics3DBody
|
||||
{
|
||||
public:
|
||||
struct DynamicSettings;
|
||||
struct StaticSettings;
|
||||
|
||||
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);
|
||||
void AddTorque(const Vector3f& torque, CoordSys coordSys = CoordSys::Global);
|
||||
|
||||
inline void DisableSimulation();
|
||||
inline void DisableSleeping();
|
||||
void EnableSimulation(bool enable);
|
||||
void EnableSleeping(bool enable);
|
||||
|
||||
void FallAsleep();
|
||||
|
||||
Boxf GetAABB() const;
|
||||
float GetAngularDamping() const;
|
||||
Vector3f GetAngularVelocity() const;
|
||||
inline JPH::Body* GetBody();
|
||||
inline const JPH::Body* GetBody() const;
|
||||
UInt32 GetBodyIndex() const override;
|
||||
inline const std::shared_ptr<Collider3D>& GetGeom() const;
|
||||
float GetLinearDamping() const;
|
||||
Vector3f GetLinearVelocity() const;
|
||||
float GetMass() const;
|
||||
Matrix4f GetMatrix() const;
|
||||
Vector3f GetPosition() const;
|
||||
std::pair<Vector3f, Quaternionf> GetPositionAndRotation() const;
|
||||
Quaternionf GetRotation() const;
|
||||
inline PhysWorld3D& GetWorld() const;
|
||||
|
||||
inline bool IsSimulationEnabled() const;
|
||||
bool IsSleeping() const;
|
||||
bool IsSleepingEnabled() const;
|
||||
bool IsStatic() const;
|
||||
|
||||
void SetAngularDamping(float angularDamping);
|
||||
void SetAngularVelocity(const Vector3f& angularVelocity);
|
||||
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);
|
||||
void SetPosition(const Vector3f& position);
|
||||
void SetRotation(const Quaternionf& rotation);
|
||||
|
||||
void TeleportTo(const Vector3f& position, const Quaternionf& rotation);
|
||||
|
||||
Quaternionf ToLocal(const Quaternionf& worldRotation);
|
||||
Vector3f ToLocal(const Vector3f& worldPosition);
|
||||
Quaternionf ToWorld(const Quaternionf& localRotation);
|
||||
Vector3f ToWorld(const Vector3f& localPosition);
|
||||
|
||||
void WakeUp();
|
||||
|
||||
RigidBody3D& operator=(const RigidBody3D& object) = delete;
|
||||
RigidBody3D& operator=(RigidBody3D&& object) noexcept;
|
||||
|
||||
struct CommonSettings
|
||||
{
|
||||
std::shared_ptr<Collider3D> geom;
|
||||
Quaternionf rotation = Quaternionf::Identity();
|
||||
Vector3f position = Vector3f::Zero();
|
||||
bool initiallySleeping = false;
|
||||
bool isSimulationEnabled = true;
|
||||
bool isTrigger = false;
|
||||
};
|
||||
|
||||
struct DynamicSettings : CommonSettings
|
||||
{
|
||||
DynamicSettings() = default;
|
||||
DynamicSettings(std::shared_ptr<Collider3D> collider, float mass_) :
|
||||
mass(mass_)
|
||||
{
|
||||
geom = std::move(collider);
|
||||
}
|
||||
|
||||
// Default values from Jolt
|
||||
PhysMotionQuality3D motionQuality = PhysMotionQuality3D::Discrete;
|
||||
Vector3f angularVelocity = Vector3f::Zero();
|
||||
Vector3f linearVelocity = Vector3f::Zero();
|
||||
bool allowSleeping = true;
|
||||
float angularDamping = 0.05f;
|
||||
float friction = 0.2f;
|
||||
float gravityFactor = 1.f;
|
||||
float linearDamping = 0.05f;
|
||||
float mass = 1.f;
|
||||
float maxAngularVelocity = 0.25f * Pi<float> * 60.f;
|
||||
float maxLinearVelocity = 500.f;
|
||||
float restitution = 0.f;
|
||||
};
|
||||
|
||||
struct StaticSettings : CommonSettings
|
||||
{
|
||||
StaticSettings() = default;
|
||||
StaticSettings(std::shared_ptr<Collider3D> collider)
|
||||
{
|
||||
geom = std::move(collider);
|
||||
}
|
||||
};
|
||||
|
||||
protected:
|
||||
RigidBody3D() = default;
|
||||
void Create(PhysWorld3D& world, const DynamicSettings& settings);
|
||||
void Create(PhysWorld3D& world, const StaticSettings& settings);
|
||||
void Destroy(bool worldDestruction = false);
|
||||
|
||||
private:
|
||||
void BuildSettings(const CommonSettings& settings, JPH::BodyCreationSettings& creationSettings);
|
||||
void BuildSettings(const DynamicSettings& settings, JPH::BodyCreationSettings& creationSettings);
|
||||
void BuildSettings(const StaticSettings& settings, JPH::BodyCreationSettings& creationSettings);
|
||||
|
||||
bool ShouldActivate() const;
|
||||
|
||||
std::shared_ptr<Collider3D> m_geom;
|
||||
MovablePtr<JPH::Body> m_body;
|
||||
MovablePtr<PhysWorld3D> m_world;
|
||||
UInt32 m_bodyIndex;
|
||||
bool m_isSimulationEnabled;
|
||||
bool m_isTrigger;
|
||||
};
|
||||
}
|
||||
|
||||
#include <Nazara/Physics3D/RigidBody3D.inl>
|
||||
|
||||
#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>
|
||||
34
include/Nazara/Physics3D/Systems.hpp
Normal file
34
include/Nazara/Physics3D/Systems.hpp
Normal file
@@ -0,0 +1,34 @@
|
||||
// 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_PHYSICS3D_SYSTEMS_HPP
|
||||
#define NAZARA_PHYSICS3D_SYSTEMS_HPP
|
||||
|
||||
#include <Nazara/Physics3D/Systems/Physics3DSystem.hpp>
|
||||
|
||||
#endif // NAZARA_PHYSICS3D_SYSTEMS_HPP
|
||||
89
include/Nazara/Physics3D/Systems/Physics3DSystem.hpp
Normal file
89
include/Nazara/Physics3D/Systems/Physics3DSystem.hpp
Normal file
@@ -0,0 +1,89 @@
|
||||
// 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_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/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_PHYSICS3D_API Physics3DSystem
|
||||
{
|
||||
public:
|
||||
static constexpr Int64 ExecutionOrder = 0;
|
||||
using Components = TypeList<PhysCharacter3DComponent, RigidBody3DComponent, class NodeComponent>;
|
||||
|
||||
struct PointCollisionInfo;
|
||||
struct RaycastHit;
|
||||
struct ShapeCollisionInfo;
|
||||
|
||||
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 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 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);
|
||||
bool RaycastQueryFirst(const Vector3f& from, const Vector3f& to, const FunctionRef<void(const RaycastHit& hitInfo)>& callback);
|
||||
|
||||
void Update(Time elapsedTime);
|
||||
|
||||
Physics3DSystem& operator=(const Physics3DSystem&) = delete;
|
||||
Physics3DSystem& operator=(Physics3DSystem&&) = delete;
|
||||
|
||||
struct PointCollisionInfo : PhysWorld3D::PointCollisionInfo
|
||||
{
|
||||
entt::handle hitEntity;
|
||||
};
|
||||
|
||||
struct RaycastHit : PhysWorld3D::RaycastHit
|
||||
{
|
||||
entt::handle hitEntity;
|
||||
};
|
||||
|
||||
struct ShapeCollisionInfo : PhysWorld3D::ShapeCollisionInfo
|
||||
{
|
||||
entt::handle hitEntity;
|
||||
};
|
||||
|
||||
private:
|
||||
void OnBodyConstruct(entt::registry& registry, entt::entity entity);
|
||||
void OnBodyDestruct(entt::registry& registry, entt::entity entity);
|
||||
void OnCharacterConstruct(entt::registry& registry, entt::entity entity);
|
||||
void OnCharacterDestruct(entt::registry& registry, entt::entity entity);
|
||||
|
||||
std::size_t m_stepCount;
|
||||
std::vector<entt::entity> m_bodyIndicesToEntity;
|
||||
entt::registry& m_registry;
|
||||
entt::observer m_characterConstructObserver;
|
||||
entt::observer m_rigidBodyConstructObserver;
|
||||
entt::scoped_connection m_bodyConstructConnection;
|
||||
entt::scoped_connection m_bodyDestructConnection;
|
||||
entt::scoped_connection m_characterConstructConnection;
|
||||
entt::scoped_connection m_characterDestructConnection;
|
||||
PhysWorld3D m_physWorld;
|
||||
};
|
||||
}
|
||||
|
||||
#include <Nazara/Physics3D/Systems/Physics3DSystem.inl>
|
||||
|
||||
#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