Rename Physics3D to BulletPhysics3D
This commit is contained in:
committed by
Jérôme Leclercq
parent
5cbc435e1a
commit
bd4c2d6ee7
218
include/Nazara/BulletPhysics3D/BulletCollider3D.hpp
Normal file
218
include/Nazara/BulletPhysics3D/BulletCollider3D.hpp
Normal file
@@ -0,0 +1,218 @@
|
||||
// Copyright (C) 2023 Jérôme "Lynix" Leclercq (lynix680@gmail.com)
|
||||
// This file is part of the "Nazara Engine - BulletPhysics3D module"
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifndef NAZARA_BULLETPHYSICS3D_BULLETCOLLIDER3D_HPP
|
||||
#define NAZARA_BULLETPHYSICS3D_BULLETCOLLIDER3D_HPP
|
||||
|
||||
#include <NazaraUtils/Prerequisites.hpp>
|
||||
#include <Nazara/BulletPhysics3D/Config.hpp>
|
||||
#include <Nazara/BulletPhysics3D/Enums.hpp>
|
||||
#include <Nazara/Core/ObjectLibrary.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>
|
||||
|
||||
class btBoxShape;
|
||||
class btCapsuleShape;
|
||||
class btCompoundShape;
|
||||
class btCollisionShape;
|
||||
class btConeShape;
|
||||
class btConvexHullShape;
|
||||
class btCylinderShape;
|
||||
class btEmptyShape;
|
||||
class btSphereShape;
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
class PrimitiveList;
|
||||
class StaticMesh;
|
||||
struct Primitive;
|
||||
|
||||
class NAZARA_BULLETPHYSICS3D_API BulletCollider3D
|
||||
{
|
||||
public:
|
||||
BulletCollider3D() = default;
|
||||
BulletCollider3D(const BulletCollider3D&) = delete;
|
||||
BulletCollider3D(BulletCollider3D&&) = delete;
|
||||
virtual ~BulletCollider3D();
|
||||
|
||||
virtual void BuildDebugMesh(std::vector<Vector3f>& vertices, std::vector<UInt16>& indices, const Matrix4f& offsetMatrix = Matrix4f::Identity()) const = 0;
|
||||
|
||||
Boxf ComputeAABB(const Vector3f& translation, const Quaternionf& rotation, const Vector3f& scale) const;
|
||||
virtual Boxf ComputeAABB(const Matrix4f& offsetMatrix = Matrix4f::Identity(), const Vector3f& scale = Vector3f::Unit()) const;
|
||||
virtual void ComputeInertia(float mass, Vector3f* inertia) const;
|
||||
|
||||
virtual std::shared_ptr<StaticMesh> GenerateDebugMesh() const;
|
||||
|
||||
virtual btCollisionShape* GetShape() const = 0;
|
||||
virtual ColliderType3D GetType() const = 0;
|
||||
|
||||
BulletCollider3D& operator=(const BulletCollider3D&) = delete;
|
||||
BulletCollider3D& operator=(BulletCollider3D&&) = delete;
|
||||
|
||||
static std::shared_ptr<BulletCollider3D> Build(const PrimitiveList& list);
|
||||
|
||||
private:
|
||||
static std::shared_ptr<BulletCollider3D> CreateGeomFromPrimitive(const Primitive& primitive);
|
||||
};
|
||||
|
||||
class NAZARA_BULLETPHYSICS3D_API BoxCollider3D final : public BulletCollider3D
|
||||
{
|
||||
public:
|
||||
BoxCollider3D(const Vector3f& lengths);
|
||||
~BoxCollider3D();
|
||||
|
||||
void BuildDebugMesh(std::vector<Vector3f>& vertices, std::vector<UInt16>& indices, const Matrix4f& offsetMatrix) const override;
|
||||
|
||||
Vector3f GetLengths() const;
|
||||
btCollisionShape* GetShape() const override;
|
||||
ColliderType3D GetType() const override;
|
||||
|
||||
private:
|
||||
std::unique_ptr<btBoxShape> m_shape;
|
||||
Vector3f m_lengths;
|
||||
};
|
||||
|
||||
class NAZARA_BULLETPHYSICS3D_API CapsuleCollider3D final : public BulletCollider3D
|
||||
{
|
||||
public:
|
||||
CapsuleCollider3D(float length, float radius);
|
||||
~CapsuleCollider3D();
|
||||
|
||||
void BuildDebugMesh(std::vector<Vector3f>& vertices, std::vector<UInt16>& indices, const Matrix4f& offsetMatrix) const override;
|
||||
|
||||
float GetLength() const;
|
||||
float GetRadius() const;
|
||||
btCollisionShape* GetShape() const override;
|
||||
ColliderType3D GetType() const override;
|
||||
|
||||
private:
|
||||
std::unique_ptr<btCapsuleShape> m_shape;
|
||||
float m_length;
|
||||
float m_radius;
|
||||
};
|
||||
|
||||
class NAZARA_BULLETPHYSICS3D_API CompoundCollider3D final : public BulletCollider3D
|
||||
{
|
||||
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;
|
||||
btCollisionShape* GetShape() const override;
|
||||
ColliderType3D GetType() const override;
|
||||
|
||||
struct ChildCollider
|
||||
{
|
||||
std::shared_ptr<BulletCollider3D> collider;
|
||||
Matrix4f offsetMatrix;
|
||||
};
|
||||
|
||||
private:
|
||||
std::unique_ptr<btCompoundShape> m_shape;
|
||||
std::vector<ChildCollider> m_childs;
|
||||
};
|
||||
|
||||
class NAZARA_BULLETPHYSICS3D_API ConeCollider3D final : public BulletCollider3D
|
||||
{
|
||||
public:
|
||||
ConeCollider3D(float length, float radius);
|
||||
~ConeCollider3D();
|
||||
|
||||
void BuildDebugMesh(std::vector<Vector3f>& vertices, std::vector<UInt16>& indices, const Matrix4f& offsetMatrix) const override;
|
||||
|
||||
float GetLength() const;
|
||||
float GetRadius() const;
|
||||
btCollisionShape* GetShape() const override;
|
||||
ColliderType3D GetType() const override;
|
||||
|
||||
private:
|
||||
std::unique_ptr<btConeShape> m_shape;
|
||||
float m_length;
|
||||
float m_radius;
|
||||
};
|
||||
|
||||
class NAZARA_BULLETPHYSICS3D_API ConvexCollider3D final : public BulletCollider3D
|
||||
{
|
||||
public:
|
||||
ConvexCollider3D(SparsePtr<const Vector3f> vertices, unsigned int vertexCount);
|
||||
~ConvexCollider3D();
|
||||
|
||||
void BuildDebugMesh(std::vector<Vector3f>& vertices, std::vector<UInt16>& indices, const Matrix4f& offsetMatrix) const override;
|
||||
|
||||
btCollisionShape* GetShape() const override;
|
||||
ColliderType3D GetType() const override;
|
||||
|
||||
private:
|
||||
std::unique_ptr<btConvexHullShape> m_shape;
|
||||
};
|
||||
|
||||
class NAZARA_BULLETPHYSICS3D_API CylinderCollider3D final : public BulletCollider3D
|
||||
{
|
||||
public:
|
||||
CylinderCollider3D(float length, float radius);
|
||||
~CylinderCollider3D();
|
||||
|
||||
void BuildDebugMesh(std::vector<Vector3f>& vertices, std::vector<UInt16>& indices, const Matrix4f& offsetMatrix) const override;
|
||||
|
||||
float GetLength() const;
|
||||
float GetRadius() const;
|
||||
btCollisionShape* GetShape() const override;
|
||||
ColliderType3D GetType() const override;
|
||||
|
||||
private:
|
||||
std::unique_ptr<btCylinderShape> m_shape;
|
||||
Matrix4f m_matrix;
|
||||
float m_length;
|
||||
float m_radius;
|
||||
};
|
||||
|
||||
class NAZARA_BULLETPHYSICS3D_API NullCollider3D final : public BulletCollider3D
|
||||
{
|
||||
public:
|
||||
NullCollider3D();
|
||||
~NullCollider3D();
|
||||
|
||||
void BuildDebugMesh(std::vector<Vector3f>& vertices, std::vector<UInt16>& indices, const Matrix4f& offsetMatrix) const override;
|
||||
|
||||
void ComputeInertia(float mass, Vector3f* inertia) const override;
|
||||
|
||||
btCollisionShape* GetShape() const override;
|
||||
ColliderType3D GetType() const override;
|
||||
|
||||
private:
|
||||
std::unique_ptr<btEmptyShape> m_shape;
|
||||
};
|
||||
|
||||
class NAZARA_BULLETPHYSICS3D_API SphereCollider3D final : public BulletCollider3D
|
||||
{
|
||||
public:
|
||||
SphereCollider3D(float radius);
|
||||
~SphereCollider3D();
|
||||
|
||||
void BuildDebugMesh(std::vector<Vector3f>& vertices, std::vector<UInt16>& indices, const Matrix4f& offsetMatrix) const override;
|
||||
|
||||
float GetRadius() const;
|
||||
btCollisionShape* GetShape() const override;
|
||||
ColliderType3D GetType() const override;
|
||||
|
||||
private:
|
||||
std::unique_ptr<btSphereShape> m_shape;
|
||||
Vector3f m_position;
|
||||
float m_radius;
|
||||
};
|
||||
}
|
||||
|
||||
#include <Nazara/BulletPhysics3D/BulletCollider3D.inl>
|
||||
|
||||
#endif // NAZARA_BULLETPHYSICS3D_BULLETCOLLIDER3D_HPP
|
||||
12
include/Nazara/BulletPhysics3D/BulletCollider3D.inl
Normal file
12
include/Nazara/BulletPhysics3D/BulletCollider3D.inl
Normal file
@@ -0,0 +1,12 @@
|
||||
// Copyright (C) 2023 Jérôme "Lynix" Leclercq (lynix680@gmail.com)
|
||||
// This file is part of the "Nazara Engine - BulletPhysics3D module"
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#include <memory>
|
||||
#include <Nazara/BulletPhysics3D/Debug.hpp>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
}
|
||||
|
||||
#include <Nazara/BulletPhysics3D/DebugOff.hpp>
|
||||
74
include/Nazara/BulletPhysics3D/BulletConstraint3D.hpp
Normal file
74
include/Nazara/BulletPhysics3D/BulletConstraint3D.hpp
Normal file
@@ -0,0 +1,74 @@
|
||||
// Copyright (C) 2023 Jérôme "Lynix" Leclercq (lynix680@gmail.com)
|
||||
// This file is part of the "Nazara Engine - BulletPhysics3D module"
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifndef NAZARA_BULLETPHYSICS3D_BULLETCONSTRAINT3D_HPP
|
||||
#define NAZARA_BULLETPHYSICS3D_BULLETCONSTRAINT3D_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
|
||||
27
include/Nazara/BulletPhysics3D/BulletConstraint3D.inl
Normal file
27
include/Nazara/BulletPhysics3D/BulletConstraint3D.inl
Normal file
@@ -0,0 +1,27 @@
|
||||
// Copyright (C) 2023 Jérôme "Lynix" Leclercq (lynix680@gmail.com)
|
||||
// This file is part of the "Nazara Engine - BulletPhysics3D module"
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#include <Nazara/BulletPhysics3D/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/BulletPhysics3D/DebugOff.hpp>
|
||||
75
include/Nazara/BulletPhysics3D/BulletPhysWorld3D.hpp
Normal file
75
include/Nazara/BulletPhysics3D/BulletPhysWorld3D.hpp
Normal file
@@ -0,0 +1,75 @@
|
||||
// Copyright (C) 2023 Jérôme "Lynix" Leclercq (lynix680@gmail.com)
|
||||
// This file is part of the "Nazara Engine - BulletPhysics3D module"
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifndef NAZARA_BULLETPHYSICS3D_BULLETPHYSWORLD3D_HPP
|
||||
#define NAZARA_BULLETPHYSICS3D_BULLETPHYSWORLD3D_HPP
|
||||
|
||||
#include <NazaraUtils/Prerequisites.hpp>
|
||||
#include <Nazara/BulletPhysics3D/Config.hpp>
|
||||
#include <Nazara/Core/Time.hpp>
|
||||
#include <Nazara/Math/Box.hpp>
|
||||
#include <Nazara/Math/Vector3.hpp>
|
||||
#include <NazaraUtils/FunctionRef.hpp>
|
||||
#include <NazaraUtils/MovablePtr.hpp>
|
||||
|
||||
class btDynamicsWorld;
|
||||
class btRigidBody;
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
class BulletRigidBody3D;
|
||||
|
||||
class NAZARA_BULLETPHYSICS3D_API BulletPhysWorld3D
|
||||
{
|
||||
friend BulletRigidBody3D;
|
||||
|
||||
public:
|
||||
struct RaycastHit;
|
||||
|
||||
BulletPhysWorld3D();
|
||||
BulletPhysWorld3D(const BulletPhysWorld3D&) = delete;
|
||||
BulletPhysWorld3D(BulletPhysWorld3D&& ph) = delete;
|
||||
~BulletPhysWorld3D();
|
||||
|
||||
btDynamicsWorld* GetDynamicsWorld();
|
||||
Vector3f GetGravity() const;
|
||||
std::size_t GetMaxStepCount() const;
|
||||
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);
|
||||
|
||||
BulletPhysWorld3D& operator=(const BulletPhysWorld3D&) = delete;
|
||||
BulletPhysWorld3D& operator=(BulletPhysWorld3D&&) = delete;
|
||||
|
||||
struct RaycastHit
|
||||
{
|
||||
float fraction;
|
||||
BulletRigidBody3D* hitBody = nullptr;
|
||||
Vector3f hitPosition;
|
||||
Vector3f hitNormal;
|
||||
};
|
||||
|
||||
private:
|
||||
btRigidBody* AddRigidBody(std::size_t& rigidBodyIndex, FunctionRef<void(btRigidBody* body)> constructor);
|
||||
void RemoveRigidBody(btRigidBody* rigidBody, std::size_t rigidBodyIndex);
|
||||
|
||||
struct BulletWorld;
|
||||
|
||||
std::size_t m_maxStepCount;
|
||||
std::unique_ptr<BulletWorld> m_world;
|
||||
Vector3f m_gravity;
|
||||
Time m_stepSize;
|
||||
Time m_timestepAccumulator;
|
||||
};
|
||||
}
|
||||
|
||||
#endif // NAZARA_BULLETPHYSICS3D_BULLETPHYSWORLD3D_HPP
|
||||
33
include/Nazara/BulletPhysics3D/BulletPhysics3D.hpp
Normal file
33
include/Nazara/BulletPhysics3D/BulletPhysics3D.hpp
Normal file
@@ -0,0 +1,33 @@
|
||||
// Copyright (C) 2023 Jérôme "Lynix" Leclercq (lynix680@gmail.com)
|
||||
// This file is part of the "Nazara Engine - BulletPhysics3D module"
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifndef NAZARA_BULLETPHYSICS3D_HPP
|
||||
#define NAZARA_BULLETPHYSICS3D_HPP
|
||||
|
||||
#include <Nazara/Prerequisites.hpp>
|
||||
#include <Nazara/BulletPhysics3D/Config.hpp>
|
||||
#include <Nazara/Core/Core.hpp>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
class NAZARA_BULLETPHYSICS3D_API BulletPhysics3D : public ModuleBase<BulletPhysics3D>
|
||||
{
|
||||
friend ModuleBase;
|
||||
|
||||
public:
|
||||
using Dependencies = TypeList<Core>;
|
||||
|
||||
struct Config {};
|
||||
|
||||
BulletPhysics3D(Config /*config*/);
|
||||
~BulletPhysics3D() = default;
|
||||
|
||||
private:
|
||||
static BulletPhysics3D* s_instance;
|
||||
};
|
||||
}
|
||||
|
||||
#endif // NAZARA_BULLETPHYSICS3D_HPP
|
||||
95
include/Nazara/BulletPhysics3D/BulletRigidBody3D.hpp
Normal file
95
include/Nazara/BulletPhysics3D/BulletRigidBody3D.hpp
Normal file
@@ -0,0 +1,95 @@
|
||||
// Copyright (C) 2023 Jérôme "Lynix" Leclercq (lynix680@gmail.com)
|
||||
// This file is part of the "Nazara Engine - BulletPhysics3D module"
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifndef NAZARA_BULLETPHYSICS3D_BULLETRIGIDBODY3D_HPP
|
||||
#define NAZARA_BULLETPHYSICS3D_BULLETRIGIDBODY3D_HPP
|
||||
|
||||
#include <NazaraUtils/Prerequisites.hpp>
|
||||
#include <Nazara/BulletPhysics3D/BulletCollider3D.hpp>
|
||||
#include <Nazara/BulletPhysics3D/Config.hpp>
|
||||
#include <Nazara/Core/Enums.hpp>
|
||||
#include <Nazara/Math/Matrix4.hpp>
|
||||
#include <Nazara/Math/Quaternion.hpp>
|
||||
#include <Nazara/Math/Vector3.hpp>
|
||||
#include <NazaraUtils/MovablePtr.hpp>
|
||||
|
||||
class btRigidBody;
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
class BulletPhysWorld3D;
|
||||
|
||||
class NAZARA_BULLETPHYSICS3D_API BulletRigidBody3D
|
||||
{
|
||||
public:
|
||||
BulletRigidBody3D(BulletPhysWorld3D* world, const Matrix4f& mat = Matrix4f::Identity());
|
||||
BulletRigidBody3D(BulletPhysWorld3D* world, std::shared_ptr<BulletCollider3D> geom, const Matrix4f& mat = Matrix4f::Identity());
|
||||
BulletRigidBody3D(const BulletRigidBody3D& object) = delete;
|
||||
BulletRigidBody3D(BulletRigidBody3D&& object) noexcept;
|
||||
~BulletRigidBody3D();
|
||||
|
||||
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<BulletCollider3D>& GetGeom() const;
|
||||
float GetLinearDamping() const;
|
||||
Vector3f GetLinearVelocity() const;
|
||||
float GetMass() const;
|
||||
Vector3f GetMassCenter(CoordSys coordSys = CoordSys::Local) const;
|
||||
Matrix4f GetMatrix() const;
|
||||
Vector3f GetPosition() const;
|
||||
inline btRigidBody* GetRigidBody() const;
|
||||
Quaternionf GetRotation() const;
|
||||
inline std::size_t GetUniqueIndex() const;
|
||||
inline BulletPhysWorld3D* 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<BulletCollider3D> 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();
|
||||
|
||||
BulletRigidBody3D& operator=(const BulletRigidBody3D& object) = delete;
|
||||
BulletRigidBody3D& operator=(BulletRigidBody3D&& object) noexcept;
|
||||
|
||||
protected:
|
||||
void Destroy();
|
||||
|
||||
private:
|
||||
std::shared_ptr<BulletCollider3D> m_geom;
|
||||
std::size_t m_bodyPoolIndex;
|
||||
btRigidBody* m_body;
|
||||
BulletPhysWorld3D* m_world;
|
||||
};
|
||||
}
|
||||
|
||||
#include <Nazara/BulletPhysics3D/BulletRigidBody3D.inl>
|
||||
|
||||
#endif // NAZARA_BULLETPHYSICS3D_BULLETRIGIDBODY3D_HPP
|
||||
34
include/Nazara/BulletPhysics3D/BulletRigidBody3D.inl
Normal file
34
include/Nazara/BulletPhysics3D/BulletRigidBody3D.inl
Normal file
@@ -0,0 +1,34 @@
|
||||
// Copyright (C) 2023 Jérôme "Lynix" Leclercq (lynix680@gmail.com)
|
||||
// This file is part of the "Nazara Engine - BulletPhysics3D module"
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#include <Nazara/BulletPhysics3D/Debug.hpp>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
inline void BulletRigidBody3D::DisableSleeping()
|
||||
{
|
||||
return EnableSleeping(false);
|
||||
}
|
||||
|
||||
inline const std::shared_ptr<BulletCollider3D>& BulletRigidBody3D::GetGeom() const
|
||||
{
|
||||
return m_geom;
|
||||
}
|
||||
|
||||
inline btRigidBody* BulletRigidBody3D::GetRigidBody() const
|
||||
{
|
||||
return m_body;
|
||||
}
|
||||
inline std::size_t BulletRigidBody3D::GetUniqueIndex() const
|
||||
{
|
||||
return m_bodyPoolIndex;
|
||||
}
|
||||
|
||||
inline BulletPhysWorld3D* BulletRigidBody3D::GetWorld() const
|
||||
{
|
||||
return m_world;
|
||||
}
|
||||
}
|
||||
|
||||
#include <Nazara/BulletPhysics3D/DebugOff.hpp>
|
||||
34
include/Nazara/BulletPhysics3D/Components.hpp
Normal file
34
include/Nazara/BulletPhysics3D/Components.hpp
Normal 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_BULLETPHYSICS3D_COMPONENTS_HPP
|
||||
#define NAZARA_BULLETPHYSICS3D_COMPONENTS_HPP
|
||||
|
||||
#include <Nazara/BulletPhysics3D/Components/BulletRigidBody3DComponent.hpp>
|
||||
|
||||
#endif // NAZARA_BULLETPHYSICS3D_COMPONENTS_HPP
|
||||
@@ -0,0 +1,32 @@
|
||||
// Copyright (C) 2023 Jérôme "Lynix" Leclercq (lynix680@gmail.com)
|
||||
// This file is part of the "Nazara Engine - BulletPhysics3D module"
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifndef NAZARA_BULLETPHYSICS3D_COMPONENTS_BULLETRIGIDBODY3DCOMPONENT_HPP
|
||||
#define NAZARA_BULLETPHYSICS3D_COMPONENTS_BULLETRIGIDBODY3DCOMPONENT_HPP
|
||||
|
||||
#include <Nazara/Prerequisites.hpp>
|
||||
#include <Nazara/BulletPhysics3D/BulletRigidBody3D.hpp>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
class NAZARA_BULLETPHYSICS3D_API BulletRigidBody3DComponent : public BulletRigidBody3D
|
||||
{
|
||||
friend class BulletPhysics3DSystem;
|
||||
|
||||
public:
|
||||
using BulletRigidBody3D::BulletRigidBody3D;
|
||||
BulletRigidBody3DComponent(const BulletRigidBody3DComponent&) = default;
|
||||
BulletRigidBody3DComponent(BulletRigidBody3DComponent&&) noexcept = default;
|
||||
~BulletRigidBody3DComponent() = default;
|
||||
|
||||
BulletRigidBody3DComponent& operator=(const BulletRigidBody3DComponent&) = default;
|
||||
BulletRigidBody3DComponent& operator=(BulletRigidBody3DComponent&&) noexcept = default;
|
||||
};
|
||||
}
|
||||
|
||||
#include <Nazara/BulletPhysics3D/Components/BulletRigidBody3DComponent.inl>
|
||||
|
||||
#endif // NAZARA_BULLETPHYSICS3D_COMPONENTS_BULLETRIGIDBODY3DCOMPONENT_HPP
|
||||
@@ -0,0 +1,11 @@
|
||||
// Copyright (C) 2023 Jérôme "Lynix" Leclercq (lynix680@gmail.com)
|
||||
// This file is part of the "Nazara Engine - BulletPhysics3D module"
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#include <Nazara/BulletPhysics3D/Debug.hpp>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
}
|
||||
|
||||
#include <Nazara/BulletPhysics3D/DebugOff.hpp>
|
||||
48
include/Nazara/BulletPhysics3D/Config.hpp
Normal file
48
include/Nazara/BulletPhysics3D/Config.hpp
Normal 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_BULLETPHYSICS3D_CONFIG_HPP
|
||||
#define NAZARA_BULLETPHYSICS3D_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_BULLETPHYSICS3D_SAFE 1
|
||||
|
||||
/// Vérification des valeurs et types de certaines constantes
|
||||
#include <Nazara/BulletPhysics3D/ConfigCheck.hpp>
|
||||
|
||||
#if defined(NAZARA_STATIC)
|
||||
#define NAZARA_BULLETPHYSICS3D_API
|
||||
#else
|
||||
#ifdef NAZARA_BULLETPHYSICS3D_BUILD
|
||||
#define NAZARA_BULLETPHYSICS3D_API NAZARA_EXPORT
|
||||
#else
|
||||
#define NAZARA_BULLETPHYSICS3D_API NAZARA_IMPORT
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#endif // NAZARA_BULLETPHYSICS3D_CONFIG_HPP
|
||||
10
include/Nazara/BulletPhysics3D/ConfigCheck.hpp
Normal file
10
include/Nazara/BulletPhysics3D/ConfigCheck.hpp
Normal file
@@ -0,0 +1,10 @@
|
||||
// Copyright (C) 2023 Jérôme "Lynix" Leclercq (lynix680@gmail.com)
|
||||
// This file is part of the "Nazara Engine - BulletPhysics3D module"
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifndef NAZARA_BULLETPHYSICS3D_CONFIGCHECK_HPP
|
||||
#define NAZARA_BULLETPHYSICS3D_CONFIGCHECK_HPP
|
||||
|
||||
#endif // NAZARA_BULLETPHYSICS3D_CONFIGCHECK_HPP
|
||||
5
include/Nazara/BulletPhysics3D/Debug.hpp
Normal file
5
include/Nazara/BulletPhysics3D/Debug.hpp
Normal file
@@ -0,0 +1,5 @@
|
||||
// Copyright (C) 2023 Jérôme "Lynix" Leclercq (lynix680@gmail.com)
|
||||
// This file is part of the "Nazara Engine - BulletPhysics3D module"
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
// no header guards
|
||||
5
include/Nazara/BulletPhysics3D/DebugOff.hpp
Normal file
5
include/Nazara/BulletPhysics3D/DebugOff.hpp
Normal file
@@ -0,0 +1,5 @@
|
||||
// Copyright (C) 2023 Jérôme "Lynix" Leclercq (lynix680@gmail.com)
|
||||
// This file is part of the "Nazara Engine - BulletPhysics3D module"
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
// no header guards
|
||||
30
include/Nazara/BulletPhysics3D/Enums.hpp
Normal file
30
include/Nazara/BulletPhysics3D/Enums.hpp
Normal file
@@ -0,0 +1,30 @@
|
||||
// Copyright (C) 2023 Jérôme "Lynix" Leclercq (lynix680@gmail.com)
|
||||
// This file is part of the "Nazara Engine - BulletPhysics3D module"
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifndef NAZARA_BULLETPHYSICS3D_ENUMS_HPP
|
||||
#define NAZARA_BULLETPHYSICS3D_ENUMS_HPP
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
enum class ColliderType3D
|
||||
{
|
||||
Box,
|
||||
Capsule,
|
||||
Cone,
|
||||
Compound,
|
||||
ConvexHull,
|
||||
Cylinder,
|
||||
Heightfield,
|
||||
Null,
|
||||
Scene,
|
||||
Sphere,
|
||||
Tree,
|
||||
|
||||
Max = Tree
|
||||
};
|
||||
}
|
||||
|
||||
#endif // NAZARA_BULLETPHYSICS3D_ENUMS_HPP
|
||||
34
include/Nazara/BulletPhysics3D/Systems.hpp
Normal file
34
include/Nazara/BulletPhysics3D/Systems.hpp
Normal 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_BULLETPHYSICS3D_SYSTEMS_HPP
|
||||
#define NAZARA_BULLETPHYSICS3D_SYSTEMS_HPP
|
||||
|
||||
#include <Nazara/BulletPhysics3D/Systems/BulletPhysics3DSystem.hpp>
|
||||
|
||||
#endif // NAZARA_BULLETPHYSICS3D_SYSTEMS_HPP
|
||||
@@ -0,0 +1,65 @@
|
||||
// Copyright (C) 2023 Jérôme "Lynix" Leclercq (lynix680@gmail.com)
|
||||
// This file is part of the "Nazara Engine - BulletPhysics3D module"
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifndef NAZARA_BULLETPHYSICS3D_SYSTEMS_BULLETPHYSICS3DSYSTEM_HPP
|
||||
#define NAZARA_BULLETPHYSICS3D_SYSTEMS_BULLETPHYSICS3DSYSTEM_HPP
|
||||
|
||||
#include <Nazara/Prerequisites.hpp>
|
||||
#include <Nazara/BulletPhysics3D/BulletPhysWorld3D.hpp>
|
||||
#include <Nazara/BulletPhysics3D/Components/BulletRigidBody3DComponent.hpp>
|
||||
#include <Nazara/Core/Time.hpp>
|
||||
#include <Nazara/Utils/TypeList.hpp>
|
||||
#include <entt/entt.hpp>
|
||||
#include <vector>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
class NAZARA_BULLETPHYSICS3D_API BulletPhysics3DSystem
|
||||
{
|
||||
public:
|
||||
static constexpr Int64 ExecutionOrder = 0;
|
||||
using Components = TypeList<BulletRigidBody3DComponent, class NodeComponent>;
|
||||
|
||||
struct RaycastHit;
|
||||
|
||||
BulletPhysics3DSystem(entt::registry& registry);
|
||||
BulletPhysics3DSystem(const BulletPhysics3DSystem&) = delete;
|
||||
BulletPhysics3DSystem(BulletPhysics3DSystem&&) = delete;
|
||||
~BulletPhysics3DSystem();
|
||||
|
||||
template<typename... Args> BulletRigidBody3DComponent CreateRigidBody(Args&&... args);
|
||||
|
||||
inline BulletPhysWorld3D& GetPhysWorld();
|
||||
inline const BulletPhysWorld3D& GetPhysWorld() const;
|
||||
|
||||
bool RaycastQueryFirst(const Vector3f& from, const Vector3f& to, RaycastHit* hitInfo = nullptr);
|
||||
|
||||
void Update(Time elapsedTime);
|
||||
|
||||
BulletPhysics3DSystem& operator=(const BulletPhysics3DSystem&) = delete;
|
||||
BulletPhysics3DSystem& operator=(BulletPhysics3DSystem&&) = delete;
|
||||
|
||||
struct RaycastHit : BulletPhysWorld3D::RaycastHit
|
||||
{
|
||||
entt::handle hitEntity;
|
||||
};
|
||||
|
||||
private:
|
||||
void OnConstruct(entt::registry& registry, entt::entity entity);
|
||||
void OnDestruct(entt::registry& registry, entt::entity entity);
|
||||
|
||||
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;
|
||||
};
|
||||
}
|
||||
|
||||
#include <Nazara/BulletPhysics3D/Systems/BulletPhysics3DSystem.inl>
|
||||
|
||||
#endif // NAZARA_BULLETPHYSICS3D_SYSTEMS_BULLETPHYSICS3DSYSTEM_HPP
|
||||
@@ -0,0 +1,26 @@
|
||||
// Copyright (C) 2023 Jérôme "Lynix" Leclercq (lynix680@gmail.com)
|
||||
// This file is part of the "Nazara Engine - BulletPhysics3D module"
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#include <Nazara/BulletPhysics3D/Debug.hpp>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
template<typename... Args>
|
||||
BulletRigidBody3DComponent BulletPhysics3DSystem::CreateRigidBody(Args&&... args)
|
||||
{
|
||||
return BulletRigidBody3DComponent(&m_physWorld, std::forward<Args>(args)...);
|
||||
}
|
||||
|
||||
inline BulletPhysWorld3D& BulletPhysics3DSystem::GetPhysWorld()
|
||||
{
|
||||
return m_physWorld;
|
||||
}
|
||||
|
||||
inline const BulletPhysWorld3D& BulletPhysics3DSystem::GetPhysWorld() const
|
||||
{
|
||||
return m_physWorld;
|
||||
}
|
||||
}
|
||||
|
||||
#include <Nazara/BulletPhysics3D/DebugOff.hpp>
|
||||
Reference in New Issue
Block a user