Add JoltPhysics3D for a performance test

This commit is contained in:
SirLynix
2023-03-15 13:44:58 +01:00
committed by Jérôme Leclercq
parent bd4c2d6ee7
commit c5ac142888
40 changed files with 2555 additions and 95 deletions

View File

@@ -26,16 +26,16 @@
#pragma once
#ifndef NAZARA_GLOBAL_PHYSICS3D_HPP
#define NAZARA_GLOBAL_PHYSICS3D_HPP
#ifndef NAZARA_GLOBAL_BULLETPHYSICS3D_HPP
#define NAZARA_GLOBAL_BULLETPHYSICS3D_HPP
#include <Nazara/BulletPhysics3D/BulletCollider3D.hpp>
#include <Nazara/BulletPhysics3D/Config.hpp>
#include <Nazara/BulletPhysics3D/BulletConstraint3D.hpp>
#include <Nazara/BulletPhysics3D/Enums.hpp>
#include <Nazara/BulletPhysics3D/BulletPhysics3D.hpp>
#include <Nazara/BulletPhysics3D/BulletPhysWorld3D.hpp>
#include <Nazara/BulletPhysics3D/BulletRigidBody3D.hpp>
#include <Nazara/BulletPhysics3D/Config.hpp>
#include <Nazara/BulletPhysics3D/Enums.hpp>
#ifdef NAZARA_ENTT
@@ -44,4 +44,4 @@
#endif
#endif // NAZARA_GLOBAL_PHYSICS3D_HPP
#endif // NAZARA_GLOBAL_BULLETPHYSICS3D_HPP

View File

@@ -62,11 +62,11 @@ namespace Nz
static std::shared_ptr<BulletCollider3D> CreateGeomFromPrimitive(const Primitive& primitive);
};
class NAZARA_BULLETPHYSICS3D_API BoxCollider3D final : public BulletCollider3D
class NAZARA_BULLETPHYSICS3D_API BulletBoxCollider3D final : public BulletCollider3D
{
public:
BoxCollider3D(const Vector3f& lengths);
~BoxCollider3D();
BulletBoxCollider3D(const Vector3f& lengths);
~BulletBoxCollider3D();
void BuildDebugMesh(std::vector<Vector3f>& vertices, std::vector<UInt16>& indices, const Matrix4f& offsetMatrix) const override;
@@ -79,11 +79,11 @@ namespace Nz
Vector3f m_lengths;
};
class NAZARA_BULLETPHYSICS3D_API CapsuleCollider3D final : public BulletCollider3D
class NAZARA_BULLETPHYSICS3D_API BulletCapsuleCollider3D final : public BulletCollider3D
{
public:
CapsuleCollider3D(float length, float radius);
~CapsuleCollider3D();
BulletCapsuleCollider3D(float length, float radius);
~BulletCapsuleCollider3D();
void BuildDebugMesh(std::vector<Vector3f>& vertices, std::vector<UInt16>& indices, const Matrix4f& offsetMatrix) const override;
@@ -98,13 +98,13 @@ namespace Nz
float m_radius;
};
class NAZARA_BULLETPHYSICS3D_API CompoundCollider3D final : public BulletCollider3D
class NAZARA_BULLETPHYSICS3D_API BulletCompoundCollider3D final : public BulletCollider3D
{
public:
struct ChildCollider;
CompoundCollider3D(std::vector<ChildCollider> childs);
~CompoundCollider3D();
BulletCompoundCollider3D(std::vector<ChildCollider> childs);
~BulletCompoundCollider3D();
void BuildDebugMesh(std::vector<Vector3f>& vertices, std::vector<UInt16>& indices, const Matrix4f& offsetMatrix) const override;
@@ -123,11 +123,11 @@ namespace Nz
std::vector<ChildCollider> m_childs;
};
class NAZARA_BULLETPHYSICS3D_API ConeCollider3D final : public BulletCollider3D
class NAZARA_BULLETPHYSICS3D_API BulletConeCollider3D final : public BulletCollider3D
{
public:
ConeCollider3D(float length, float radius);
~ConeCollider3D();
BulletConeCollider3D(float length, float radius);
~BulletConeCollider3D();
void BuildDebugMesh(std::vector<Vector3f>& vertices, std::vector<UInt16>& indices, const Matrix4f& offsetMatrix) const override;
@@ -142,11 +142,11 @@ namespace Nz
float m_radius;
};
class NAZARA_BULLETPHYSICS3D_API ConvexCollider3D final : public BulletCollider3D
class NAZARA_BULLETPHYSICS3D_API BulletConvexCollider3D final : public BulletCollider3D
{
public:
ConvexCollider3D(SparsePtr<const Vector3f> vertices, unsigned int vertexCount);
~ConvexCollider3D();
BulletConvexCollider3D(SparsePtr<const Vector3f> vertices, unsigned int vertexCount);
~BulletConvexCollider3D();
void BuildDebugMesh(std::vector<Vector3f>& vertices, std::vector<UInt16>& indices, const Matrix4f& offsetMatrix) const override;
@@ -157,11 +157,11 @@ namespace Nz
std::unique_ptr<btConvexHullShape> m_shape;
};
class NAZARA_BULLETPHYSICS3D_API CylinderCollider3D final : public BulletCollider3D
class NAZARA_BULLETPHYSICS3D_API BulletCylinderCollider3D final : public BulletCollider3D
{
public:
CylinderCollider3D(float length, float radius);
~CylinderCollider3D();
BulletCylinderCollider3D(float length, float radius);
~BulletCylinderCollider3D();
void BuildDebugMesh(std::vector<Vector3f>& vertices, std::vector<UInt16>& indices, const Matrix4f& offsetMatrix) const override;
@@ -177,11 +177,11 @@ namespace Nz
float m_radius;
};
class NAZARA_BULLETPHYSICS3D_API NullCollider3D final : public BulletCollider3D
class NAZARA_BULLETPHYSICS3D_API BulletNullCollider3D final : public BulletCollider3D
{
public:
NullCollider3D();
~NullCollider3D();
BulletNullCollider3D();
~BulletNullCollider3D();
void BuildDebugMesh(std::vector<Vector3f>& vertices, std::vector<UInt16>& indices, const Matrix4f& offsetMatrix) const override;
@@ -194,11 +194,11 @@ namespace Nz
std::unique_ptr<btEmptyShape> m_shape;
};
class NAZARA_BULLETPHYSICS3D_API SphereCollider3D final : public BulletCollider3D
class NAZARA_BULLETPHYSICS3D_API BulletSphereCollider3D final : public BulletCollider3D
{
public:
SphereCollider3D(float radius);
~SphereCollider3D();
BulletSphereCollider3D(float radius);
~BulletSphereCollider3D();
void BuildDebugMesh(std::vector<Vector3f>& vertices, std::vector<UInt16>& indices, const Matrix4f& offsetMatrix) const override;

View File

@@ -67,6 +67,7 @@ namespace Nz
void SetMass(float mass);
void SetMassCenter(const Vector3f& center);
void SetPosition(const Vector3f& position);
void SetPositionAndRotation(const Vector3f& position, const Quaternionf& rotation);
void SetRotation(const Quaternionf& rotation);
Quaternionf ToLocal(const Quaternionf& worldRotation);

View File

@@ -8,6 +8,7 @@
#define NAZARA_BULLETPHYSICS3D_SYSTEMS_BULLETPHYSICS3DSYSTEM_HPP
#include <Nazara/Prerequisites.hpp>
#include <Nazara/Core/Clock.hpp>
#include <Nazara/BulletPhysics3D/BulletPhysWorld3D.hpp>
#include <Nazara/BulletPhysics3D/Components/BulletRigidBody3DComponent.hpp>
#include <Nazara/Core/Time.hpp>
@@ -32,6 +33,8 @@ namespace Nz
template<typename... Args> BulletRigidBody3DComponent CreateRigidBody(Args&&... args);
void Dump();
inline BulletPhysWorld3D& GetPhysWorld();
inline const BulletPhysWorld3D& GetPhysWorld() const;
@@ -51,12 +54,15 @@ namespace Nz
void OnConstruct(entt::registry& registry, entt::entity entity);
void OnDestruct(entt::registry& registry, entt::entity entity);
std::size_t m_stepCount;
std::vector<entt::entity> m_physicsEntities;
entt::registry& m_registry;
entt::observer m_physicsConstructObserver;
entt::scoped_connection m_constructConnection;
entt::scoped_connection m_destructConnection;
BulletPhysWorld3D m_physWorld;
Time m_physicsTime;
Time m_updateTime;
};
}

View File

@@ -0,0 +1,47 @@
// this file was automatically generated and should not be edited
/*
Nazara Engine - BulletPhysics3D module
Copyright (C) 2023 Jérôme "Lynix" Leclercq (lynix680@gmail.com)
Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
of the Software, and to permit persons to whom the Software is furnished to do
so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
#pragma once
#ifndef NAZARA_GLOBAL_JOLTPHYSICS3D_HPP
#define NAZARA_GLOBAL_JOLTPHYSICS3D_HPP
#include <Nazara/JoltPhysics3D/Config.hpp>
#include <Nazara/JoltPhysics3D/Enums.hpp>
#include <Nazara/JoltPhysics3D/JoltCollider3D.hpp>
#include <Nazara/JoltPhysics3D/JoltConstraint3D.hpp>
#include <Nazara/JoltPhysics3D/JoltPhysics3D.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

View File

@@ -0,0 +1,34 @@
// this file was automatically generated and should not be edited
/*
Nazara Engine - BulletPhysics3D module
Copyright (C) 2023 Jérôme "Lynix" Leclercq (lynix680@gmail.com)
Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
of the Software, and to permit persons to whom the Software is furnished to do
so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
#pragma once
#ifndef NAZARA_JOLTPHYSICS3D_COMPONENTS_HPP
#define NAZARA_JOLTPHYSICS3D_COMPONENTS_HPP
#include <Nazara/JoltPhysics3D/Components/JoltRigidBody3DComponent.hpp>
#endif // NAZARA_JOLTPHYSICS3D_COMPONENTS_HPP

View File

@@ -0,0 +1,32 @@
// Copyright (C) 2023 Jérôme "Lynix" 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 <Nazara/Prerequisites.hpp>
#include <Nazara/JoltPhysics3D/JoltRigidBody3D.hpp>
namespace Nz
{
class NAZARA_JOLTPHYSICS3D_API JoltRigidBody3DComponent : public JoltRigidBody3D
{
friend class JoltPhysics3DSystem;
public:
using JoltRigidBody3D::JoltRigidBody3D;
JoltRigidBody3DComponent(const JoltRigidBody3DComponent&) = default;
JoltRigidBody3DComponent(JoltRigidBody3DComponent&&) noexcept = default;
~JoltRigidBody3DComponent() = default;
JoltRigidBody3DComponent& operator=(const JoltRigidBody3DComponent&) = default;
JoltRigidBody3DComponent& operator=(JoltRigidBody3DComponent&&) noexcept = default;
};
}
#include <Nazara/JoltPhysics3D/Components/JoltRigidBody3DComponent.inl>
#endif // NAZARA_JOLTPHYSICS3D_COMPONENTS_JOLTRIGIDBODY3DCOMPONENT_HPP

View File

@@ -0,0 +1,11 @@
// Copyright (C) 2023 Jérôme "Lynix" 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
{
}
#include <Nazara/JoltPhysics3D/DebugOff.hpp>

View File

@@ -0,0 +1,48 @@
/*
Nazara Engine - BulletPhysics3D module
Copyright (C) 2023 Jérôme "Lynix" Leclercq (lynix680@gmail.com)
Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
of the Software, and to permit persons to whom the Software is furnished to do
so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
#pragma once
#ifndef NAZARA_JOLTPHYSICS3D_CONFIG_HPP
#define NAZARA_JOLTPHYSICS3D_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
/// Vérification des valeurs et types de certaines constantes
#include <Nazara/JoltPhysics3D/ConfigCheck.hpp>
#if defined(NAZARA_STATIC)
#define NAZARA_JOLTPHYSICS3D_API
#else
#ifdef NAZARA_JOLTPHYSICS3D_BUILD
#define NAZARA_JOLTPHYSICS3D_API NAZARA_EXPORT
#else
#define NAZARA_JOLTPHYSICS3D_API NAZARA_IMPORT
#endif
#endif
#endif // NAZARA_JOLTPHYSICS3D_CONFIG_HPP

View File

@@ -0,0 +1,10 @@
// Copyright (C) 2023 Jérôme "Lynix" 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

View File

@@ -0,0 +1,5 @@
// Copyright (C) 2023 Jérôme "Lynix" 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
// no header guards

View File

@@ -0,0 +1,5 @@
// Copyright (C) 2023 Jérôme "Lynix" 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
// no header guards

View File

@@ -0,0 +1,22 @@
// Copyright (C) 2023 Jérôme "Lynix" 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_ENUMS_HPP
#define NAZARA_JOLTPHYSICS3D_ENUMS_HPP
namespace Nz
{
enum class JoltColliderType3D
{
Box,
Compound,
Sphere,
Max = Sphere
};
}
#endif // NAZARA_JOLTPHYSICS3D_ENUMS_HPP

View File

@@ -0,0 +1,123 @@
// Copyright (C) 2023 Jérôme "Lynix" 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 <Nazara/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 <Nazara/Utils/Signal.hpp>
#include <Nazara/Utils/SparsePtr.hpp>
#include <memory>
namespace JPH
{
class ShapeSettings;
class BoxShapeSettings;
class CompoundShapeSettings;
class SphereShapeSettings;
}
namespace Nz
{
class PrimitiveList;
class StaticMesh;
struct Primitive;
class NAZARA_JOLTPHYSICS3D_API JoltCollider3D
{
public:
JoltCollider3D() = default;
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;
virtual JPH::ShapeSettings* GetShapeSettings() const = 0;
virtual JoltColliderType3D GetType() const = 0;
JoltCollider3D& operator=(const JoltCollider3D&) = delete;
JoltCollider3D& operator=(JoltCollider3D&&) = delete;
static std::shared_ptr<JoltCollider3D> Build(const PrimitiveList& list);
private:
static std::shared_ptr<JoltCollider3D> CreateGeomFromPrimitive(const Primitive& primitive);
};
class NAZARA_JOLTPHYSICS3D_API JoltBoxCollider3D final : public JoltCollider3D
{
public:
JoltBoxCollider3D(const Vector3f& lengths, float convexRadius = 0.f);
~JoltBoxCollider3D();
void BuildDebugMesh(std::vector<Vector3f>& vertices, std::vector<UInt16>& indices, const Matrix4f& offsetMatrix) const override;
Vector3f GetLengths() const;
JPH::ShapeSettings* GetShapeSettings() const override;
JoltColliderType3D GetType() const override;
private:
std::unique_ptr<JPH::BoxShapeSettings> m_shapeSettings;
Vector3f m_lengths;
};
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;
JPH::ShapeSettings* GetShapeSettings() const override;
JoltColliderType3D GetType() const override;
struct ChildCollider
{
std::shared_ptr<JoltCollider3D> collider;
Quaternionf rotation = Quaternionf::Identity();
Vector3f offset = Vector3f::Zero();
};
private:
std::unique_ptr<JPH::CompoundShapeSettings> m_shapeSettings;
std::vector<ChildCollider> m_childs;
};
class NAZARA_JOLTPHYSICS3D_API JoltSphereCollider3D final : public JoltCollider3D
{
public:
JoltSphereCollider3D(float radius);
~JoltSphereCollider3D();
void BuildDebugMesh(std::vector<Vector3f>& vertices, std::vector<UInt16>& indices, const Matrix4f& offsetMatrix) const override;
float GetRadius() const;
JPH::ShapeSettings* GetShapeSettings() const override;
JoltColliderType3D GetType() const override;
private:
std::unique_ptr<JPH::SphereShapeSettings> m_shapeSettings;
Vector3f m_position;
float m_radius;
};
}
#include <Nazara/JoltPhysics3D/JoltCollider3D.inl>
#endif // NAZARA_JOLTPHYSICS3D_JOLTCOLLIDER3D_HPP

View File

@@ -0,0 +1,12 @@
// Copyright (C) 2023 Jérôme "Lynix" 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 <memory>
#include <Nazara/JoltPhysics3D/Debug.hpp>
namespace Nz
{
}
#include <Nazara/JoltPhysics3D/DebugOff.hpp>

View File

@@ -0,0 +1,75 @@
// Copyright (C) 2023 Jérôme "Lynix" 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
#if 0
#ifndef NAZARA_JOLTPHYSICS3D_JOLTCONSTRAINT3D_HPP
#define NAZARA_JOLTPHYSICS3D_JOLTCONSTRAINT3D_HPP
#include <Nazara/Prerequisites.hpp>
#include <Nazara/BulletPhysics3D/BulletPhysWorld3D.hpp>
#include <Nazara/BulletPhysics3D/BulletRigidBody3D.hpp>
#include <Nazara/BulletPhysics3D/Config.hpp>
#include <Nazara/Core/HandledObject.hpp>
#include <Nazara/Core/ObjectHandle.hpp>
class btTypedConstraint;
namespace Nz
{
class BulletConstraint3D;
using BulletConstraint3DHandle = ObjectHandle<BulletConstraint3D>;
class NAZARA_BULLETPHYSICS3D_API BulletConstraint3D : public HandledObject<BulletConstraint3D>
{
public:
BulletConstraint3D(const BulletConstraint3D&) = delete;
BulletConstraint3D(BulletConstraint3D&& constraint) noexcept;
virtual ~BulletConstraint3D();
BulletRigidBody3D& GetBodyA();
const BulletRigidBody3D& GetBodyA() const;
BulletRigidBody3D& GetBodyB();
const BulletRigidBody3D& GetBodyB() const;
BulletPhysWorld3D& GetWorld();
const BulletPhysWorld3D& GetWorld() const;
inline bool IsBodyCollisionEnabled() const;
bool IsSingleBody() const;
BulletConstraint3D& operator=(const BulletConstraint3D&) = delete;
BulletConstraint3D& operator=(BulletConstraint3D&& constraint) noexcept;
protected:
BulletConstraint3D(std::unique_ptr<btTypedConstraint> constraint, bool disableCollisions = false);
template<typename T> T* GetConstraint();
template<typename T> const T* GetConstraint() const;
private:
std::unique_ptr<btTypedConstraint> m_constraint;
bool m_bodyCollisionEnabled;
};
class NAZARA_BULLETPHYSICS3D_API BulletPivotConstraint3D : public BulletConstraint3D
{
public:
BulletPivotConstraint3D(BulletRigidBody3D& first, const Vector3f& pivot);
BulletPivotConstraint3D(BulletRigidBody3D& first, BulletRigidBody3D& second, const Vector3f& pivot, bool disableCollisions = false);
BulletPivotConstraint3D(BulletRigidBody3D& first, BulletRigidBody3D& second, const Vector3f& firstAnchor, const Vector3f& secondAnchor, bool disableCollisions = false);
~BulletPivotConstraint3D() = default;
Vector3f GetFirstAnchor() const;
Vector3f GetSecondAnchor() const;
void SetFirstAnchor(const Vector3f& firstAnchor);
void SetSecondAnchor(const Vector3f& secondAnchor);
};
}
#include <Nazara/BulletPhysics3D/BulletConstraint3D.inl>
#endif // NAZARA_BULLETPHYSICS3D_BULLETCONSTRAINT3D_HPP
#endif // NAZARA_JOLTPHYSICS3D_JOLTCONSTRAINT3D_HPP

View File

@@ -0,0 +1,27 @@
// Copyright (C) 2023 Jérôme "Lynix" 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 bool BulletConstraint3D::IsBodyCollisionEnabled() const
{
return m_bodyCollisionEnabled;
}
template<typename T>
T* BulletConstraint3D::GetConstraint()
{
return SafeCast<T*>(m_constraint.get());
}
template<typename T>
const T* BulletConstraint3D::GetConstraint() const
{
return SafeCast<const T*>(m_constraint.get());
}
}
#include <Nazara/JoltPhysics3D/DebugOff.hpp>

View File

@@ -0,0 +1,72 @@
// Copyright (C) 2023 Jérôme "Lynix" 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_JOLTPHYSWORLD3D_HPP
#define NAZARA_JOLTPHYSICS3D_JOLTPHYSWORLD3D_HPP
#include <Nazara/Prerequisites.hpp>
#include <Nazara/JoltPhysics3D/Config.hpp>
#include <Nazara/Core/Time.hpp>
#include <Nazara/Math/Box.hpp>
#include <Nazara/Math/Vector3.hpp>
#include <Nazara/Utils/FunctionRef.hpp>
#include <Nazara/Utils/MovablePtr.hpp>
namespace JPH
{
class PhysicsSystem;
}
namespace Nz
{
class JoltRigidBody3D;
class NAZARA_JOLTPHYSICS3D_API JoltPhysWorld3D
{
public:
struct RaycastHit;
JoltPhysWorld3D();
JoltPhysWorld3D(const JoltPhysWorld3D&) = delete;
JoltPhysWorld3D(JoltPhysWorld3D&& ph) = delete;
~JoltPhysWorld3D();
Vector3f GetGravity() const;
std::size_t GetMaxStepCount() const;
JPH::PhysicsSystem* GetPhysicsSystem();
Time GetStepSize() const;
bool RaycastQueryFirst(const Vector3f& from, const Vector3f& to, RaycastHit* hitInfo = nullptr);
void SetGravity(const Vector3f& gravity);
void SetMaxStepCount(std::size_t maxStepCount);
void SetStepSize(Time stepSize);
void Step(Time timestep);
JoltPhysWorld3D& operator=(const JoltPhysWorld3D&) = delete;
JoltPhysWorld3D& operator=(JoltPhysWorld3D&&) = delete;
struct RaycastHit
{
float fraction;
JoltRigidBody3D* hitBody = nullptr;
Vector3f hitPosition;
Vector3f hitNormal;
};
private:
struct JoltWorld;
std::size_t m_maxStepCount;
std::unique_ptr<JoltWorld> m_world;
Vector3f m_gravity;
Time m_stepSize;
Time m_timestepAccumulator;
};
}
#endif // NAZARA_JOLTPHYSICS3D_JOLTPHYSWORLD3D_HPP

View File

@@ -0,0 +1,44 @@
// Copyright (C) 2023 Jérôme "Lynix" 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_HPP
#define NAZARA_JOLTPHYSICS3D_HPP
#include <Nazara/Prerequisites.hpp>
#include <Nazara/JoltPhysics3D/Config.hpp>
#include <Nazara/Core/Core.hpp>
#include <memory>
namespace JPH
{
class JobSystem;
class JobSystemThreadPool;
}
namespace Nz
{
class NAZARA_JOLTPHYSICS3D_API JoltPhysics3D : public ModuleBase<JoltPhysics3D>
{
friend ModuleBase;
public:
using Dependencies = TypeList<Core>;
struct Config {};
JoltPhysics3D(Config /*config*/);
~JoltPhysics3D();
JPH::JobSystem& GetThreadPool();
private:
std::unique_ptr<JPH::JobSystemThreadPool> m_threadPool;
static JoltPhysics3D* s_instance;
};
}
#endif // NAZARA_JOLTPHYSICS3D_HPP

View File

@@ -0,0 +1,90 @@
// Copyright (C) 2023 Jérôme "Lynix" 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_JOLTRIGIDBODY3D_HPP
#define NAZARA_JOLTPHYSICS3D_JOLTRIGIDBODY3D_HPP
#include <Nazara/Prerequisites.hpp>
#include <Nazara/JoltPhysics3D/JoltCollider3D.hpp>
#include <Nazara/JoltPhysics3D/Config.hpp>
#include <Nazara/Core/Enums.hpp>
#include <Nazara/Math/Matrix4.hpp>
#include <Nazara/Math/Quaternion.hpp>
#include <Nazara/Math/Vector3.hpp>
#include <Nazara/Utils/MovablePtr.hpp>
namespace Nz
{
class JoltPhysWorld3D;
class NAZARA_JOLTPHYSICS3D_API JoltRigidBody3D
{
public:
JoltRigidBody3D(JoltPhysWorld3D* world, const Matrix4f& mat = Matrix4f::Identity());
JoltRigidBody3D(JoltPhysWorld3D* world, std::shared_ptr<JoltCollider3D> geom, const Matrix4f& mat = Matrix4f::Identity());
JoltRigidBody3D(const JoltRigidBody3D& object) = delete;
JoltRigidBody3D(JoltRigidBody3D&& object) noexcept;
~JoltRigidBody3D();
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 DisableSleeping();
void EnableSleeping(bool enable);
void FallAsleep();
Boxf GetAABB() const;
float GetAngularDamping() const;
Vector3f GetAngularVelocity() const;
inline const std::shared_ptr<JoltCollider3D>& GetGeom() const;
float GetLinearDamping() const;
Vector3f GetLinearVelocity() const;
float GetMass() const;
Vector3f GetMassCenter(CoordSys coordSys = CoordSys::Local) const;
Matrix4f GetMatrix() const;
Vector3f GetPosition() const;
Quaternionf GetRotation() const;
inline JoltPhysWorld3D* GetWorld() const;
bool IsSimulationEnabled() const;
bool IsSleeping() const;
bool IsSleepingEnabled() const;
void SetAngularDamping(float angularDamping);
void SetAngularVelocity(const Vector3f& angularVelocity);
void SetGeom(std::shared_ptr<JoltCollider3D> geom, bool recomputeInertia = true);
void SetLinearDamping(float damping);
void SetLinearVelocity(const Vector3f& velocity);
void SetMass(float mass);
void SetMassCenter(const Vector3f& center);
void SetPosition(const Vector3f& position);
void SetRotation(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();
JoltRigidBody3D& operator=(const JoltRigidBody3D& object) = delete;
JoltRigidBody3D& operator=(JoltRigidBody3D&& object) noexcept;
protected:
void Destroy();
private:
std::shared_ptr<JoltCollider3D> m_geom;
JoltPhysWorld3D* m_world;
UInt32 m_bodyIndex;
};
}
#include <Nazara/JoltPhysics3D/JoltRigidBody3D.inl>
#endif // NAZARA_JOLTPHYSICS3D_JOLTRIGIDBODY3D_HPP

View File

@@ -0,0 +1,25 @@
// Copyright (C) 2023 Jérôme "Lynix" 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 JoltRigidBody3D::DisableSleeping()
{
return EnableSleeping(false);
}
inline const std::shared_ptr<JoltCollider3D>& JoltRigidBody3D::GetGeom() const
{
return m_geom;
}
inline JoltPhysWorld3D* JoltRigidBody3D::GetWorld() const
{
return m_world;
}
}
#include <Nazara/JoltPhysics3D/DebugOff.hpp>

View File

@@ -0,0 +1,34 @@
// this file was automatically generated and should not be edited
/*
Nazara Engine - BulletPhysics3D module
Copyright (C) 2023 Jérôme "Lynix" Leclercq (lynix680@gmail.com)
Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
of the Software, and to permit persons to whom the Software is furnished to do
so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
#pragma once
#ifndef NAZARA_JOLTPHYSICS3D_SYSTEMS_HPP
#define NAZARA_JOLTPHYSICS3D_SYSTEMS_HPP
#include <Nazara/JoltPhysics3D/Systems/JoltPhysics3DSystem.hpp>
#endif // NAZARA_JOLTPHYSICS3D_SYSTEMS_HPP

View File

@@ -0,0 +1,71 @@
// Copyright (C) 2023 Jérôme "Lynix" 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_SYSTEMS_JOLTPHYSICS3DSYSTEM_HPP
#define NAZARA_JOLTPHYSICS3D_SYSTEMS_JOLTPHYSICS3DSYSTEM_HPP
#include <Nazara/Prerequisites.hpp>
#include <Nazara/Core/Clock.hpp>
#include <Nazara/JoltPhysics3D/JoltPhysWorld3D.hpp>
#include <Nazara/JoltPhysics3D/Components/JoltRigidBody3DComponent.hpp>
#include <Nazara/Core/Time.hpp>
#include <Nazara/Utils/TypeList.hpp>
#include <entt/entt.hpp>
#include <vector>
namespace Nz
{
class NAZARA_JOLTPHYSICS3D_API JoltPhysics3DSystem
{
public:
static constexpr Int64 ExecutionOrder = 0;
using Components = TypeList<JoltRigidBody3DComponent, class NodeComponent>;
struct RaycastHit;
JoltPhysics3DSystem(entt::registry& registry);
JoltPhysics3DSystem(const JoltPhysics3DSystem&) = delete;
JoltPhysics3DSystem(JoltPhysics3DSystem&&) = delete;
~JoltPhysics3DSystem();
template<typename... Args> JoltRigidBody3DComponent CreateRigidBody(Args&&... args);
void Dump();
inline JoltPhysWorld3D& GetPhysWorld();
inline const JoltPhysWorld3D& GetPhysWorld() const;
bool RaycastQueryFirst(const Vector3f& from, const Vector3f& to, RaycastHit* hitInfo = nullptr);
void Update(Time elapsedTime);
JoltPhysics3DSystem& operator=(const JoltPhysics3DSystem&) = delete;
JoltPhysics3DSystem& operator=(JoltPhysics3DSystem&&) = delete;
struct RaycastHit : JoltPhysWorld3D::RaycastHit
{
entt::handle hitEntity;
};
private:
void OnConstruct(entt::registry& registry, entt::entity entity);
void OnDestruct(entt::registry& registry, entt::entity entity);
std::size_t m_stepCount;
std::vector<entt::entity> m_physicsEntities;
entt::registry& m_registry;
entt::observer m_physicsConstructObserver;
entt::scoped_connection m_constructConnection;
entt::scoped_connection m_destructConnection;
JoltPhysWorld3D m_physWorld;
Time m_physicsTime;
Time m_updateTime;
};
}
#include <Nazara/JoltPhysics3D/Systems/JoltPhysics3DSystem.inl>
#endif // NAZARA_JOLTPHYSICS3D_SYSTEMS_JOLTPHYSICS3DSYSTEM_HPP

View File

@@ -0,0 +1,26 @@
// Copyright (C) 2023 Jérôme "Lynix" 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
{
template<typename... Args>
JoltRigidBody3DComponent JoltPhysics3DSystem::CreateRigidBody(Args&&... args)
{
return JoltRigidBody3DComponent(&m_physWorld, std::forward<Args>(args)...);
}
inline JoltPhysWorld3D& JoltPhysics3DSystem::GetPhysWorld()
{
return m_physWorld;
}
inline const JoltPhysWorld3D& JoltPhysics3DSystem::GetPhysWorld() const
{
return m_physWorld;
}
}
#include <Nazara/JoltPhysics3D/DebugOff.hpp>