From 3efd422e8619ed4273bb2258ad298f1e524c64ea Mon Sep 17 00:00:00 2001 From: SirLynix Date: Thu, 23 Mar 2023 13:10:00 +0100 Subject: [PATCH] BulletPhysics3D: Add StaticPlaneCollider3D --- .../BulletPhysics3D/BulletCollider3D.hpp | 22 ++++++++++ include/Nazara/BulletPhysics3D/Enums.hpp | 4 +- .../BulletPhysics3D/BulletCollider3D.cpp | 41 +++++++++++++++++++ 3 files changed, 65 insertions(+), 2 deletions(-) diff --git a/include/Nazara/BulletPhysics3D/BulletCollider3D.hpp b/include/Nazara/BulletPhysics3D/BulletCollider3D.hpp index 2fe58cae5..070ff7456 100644 --- a/include/Nazara/BulletPhysics3D/BulletCollider3D.hpp +++ b/include/Nazara/BulletPhysics3D/BulletCollider3D.hpp @@ -13,6 +13,7 @@ #include #include #include +#include #include #include #include @@ -27,6 +28,7 @@ class btConvexHullShape; class btCylinderShape; class btEmptyShape; class btSphereShape; +class btStaticPlaneShape; namespace Nz { @@ -211,6 +213,26 @@ namespace Nz Vector3f m_position; float m_radius; }; + + class NAZARA_BULLETPHYSICS3D_API BulletStaticPlaneCollider3D final : public BulletCollider3D + { + public: + BulletStaticPlaneCollider3D(const Planef& plane); + BulletStaticPlaneCollider3D(const Vector3f& normal, float distance); + ~BulletStaticPlaneCollider3D(); + + void BuildDebugMesh(std::vector& vertices, std::vector& indices, const Matrix4f& offsetMatrix) const override; + + float GetDistance() const; + const Vector3f& GetNormal() const; + btCollisionShape* GetShape() const override; + ColliderType3D GetType() const override; + + private: + std::unique_ptr m_shape; + Vector3f m_normal; + float m_distance; + }; } #include diff --git a/include/Nazara/BulletPhysics3D/Enums.hpp b/include/Nazara/BulletPhysics3D/Enums.hpp index 6d650bf1f..f864f61a9 100644 --- a/include/Nazara/BulletPhysics3D/Enums.hpp +++ b/include/Nazara/BulletPhysics3D/Enums.hpp @@ -21,9 +21,9 @@ namespace Nz Null, Scene, Sphere, - Tree, + StaticPlane, - Max = Tree + Max = StaticPlane }; } diff --git a/src/Nazara/BulletPhysics3D/BulletCollider3D.cpp b/src/Nazara/BulletPhysics3D/BulletCollider3D.cpp index e5215076e..3187783f1 100644 --- a/src/Nazara/BulletPhysics3D/BulletCollider3D.cpp +++ b/src/Nazara/BulletPhysics3D/BulletCollider3D.cpp @@ -20,6 +20,7 @@ #include #include #include +#include #include namespace Nz @@ -426,4 +427,44 @@ namespace Nz { return ColliderType3D::Sphere; } + + /******************************** StaticPlaneCollider3D *********************************/ + + StaticPlaneCollider3D::StaticPlaneCollider3D(const Planef& plane) : + StaticPlaneCollider3D(plane.normal, plane.distance) + { + } + + StaticPlaneCollider3D::StaticPlaneCollider3D(const Vector3f& normal, float distance) : + m_normal(normal), + m_distance(distance) + { + m_shape = std::make_unique(ToBullet(m_normal), m_distance); + } + + StaticPlaneCollider3D::~StaticPlaneCollider3D() = default; + + void StaticPlaneCollider3D::BuildDebugMesh(std::vector& vertices, std::vector& indices, const Matrix4f& offsetMatrix) const + { + } + + float StaticPlaneCollider3D::GetDistance() const + { + return m_distance; + } + + const Vector3f& StaticPlaneCollider3D::GetNormal() const + { + return m_normal; + } + + btCollisionShape* StaticPlaneCollider3D::GetShape() const + { + return m_shape.get(); + } + + ColliderType3D StaticPlaneCollider3D::GetType() const + { + return ColliderType3D::StaticPlane; + } }