diff --git a/SDK/include/NDK/Components/PhysicsComponent3D.hpp b/SDK/include/NDK/Components/PhysicsComponent3D.hpp index 610b8e1df..495b17a43 100644 --- a/SDK/include/NDK/Components/PhysicsComponent3D.hpp +++ b/SDK/include/NDK/Components/PhysicsComponent3D.hpp @@ -30,8 +30,10 @@ namespace Ndk void EnableAutoSleep(bool autoSleep); Nz::Boxf GetAABB() const; + Nz::Vector3f GetAngularDamping() const; Nz::Vector3f GetAngularVelocity() const; float GetGravityFactor() const; + float GetLinearDamping() const; float GetMass() const; Nz::Vector3f GetMassCenter(Nz::CoordSys coordSys = Nz::CoordSys_Local) const; const Nz::Matrix4f& GetMatrix() const; @@ -43,8 +45,10 @@ namespace Ndk bool IsMoveable() const; bool IsSleeping() const; + void SetAngularDamping(const Nz::Vector3f& angularDamping); void SetAngularVelocity(const Nz::Vector3f& angularVelocity); void SetGravityFactor(float gravityFactor); + void SetLinearDamping(float damping); void SetMass(float mass); void SetMassCenter(const Nz::Vector3f& center); void SetPosition(const Nz::Vector3f& position); diff --git a/SDK/include/NDK/Components/PhysicsComponent3D.inl b/SDK/include/NDK/Components/PhysicsComponent3D.inl index 72646e16a..939f5c75b 100644 --- a/SDK/include/NDK/Components/PhysicsComponent3D.inl +++ b/SDK/include/NDK/Components/PhysicsComponent3D.inl @@ -3,6 +3,7 @@ // For conditions of distribution and use, see copyright notice in Prerequesites.hpp #include +#include "PhysicsComponent3D.hpp" namespace Ndk { @@ -88,7 +89,6 @@ namespace Ndk * * \remark Produces a NazaraAssert if the physics object is invalid */ - inline Nz::Boxf PhysicsComponent3D::GetAABB() const { NazaraAssert(m_object, "Invalid physics object"); @@ -96,13 +96,23 @@ namespace Ndk return m_object->GetAABB(); } + /*! + * \brief Gets the angular damping of the physics object + * \return Angular damping of the object + * + * \remark Produces a NazaraAssert if the physics object is invalid + */ + inline Nz::Vector3f PhysicsComponent3D::GetAngularDamping() const + { + return m_object->GetAngularDamping(); + } + /*! * \brief Gets the angular velocity of the physics object * \return Angular velocity of the object * * \remark Produces a NazaraAssert if the physics object is invalid */ - inline Nz::Vector3f PhysicsComponent3D::GetAngularVelocity() const { NazaraAssert(m_object, "Invalid physics object"); @@ -116,7 +126,6 @@ namespace Ndk * * \remark Produces a NazaraAssert if the physics object is invalid */ - inline float PhysicsComponent3D::GetGravityFactor() const { NazaraAssert(m_object, "Invalid physics object"); @@ -124,6 +133,19 @@ namespace Ndk return m_object->GetGravityFactor(); } + /*! + * \brief Gets the linear damping of the physics object + * \return Linear damping of the object + * + * \remark Produces a NazaraAssert if the physics object is invalid + */ + inline float PhysicsComponent3D::GetLinearDamping() const + { + NazaraAssert(m_object, "Invalid physics object"); + + return m_object->GetLinearDamping(); + } + /*! * \brief Gets the mass of the physics object * \return Mass of the object @@ -216,7 +238,6 @@ namespace Ndk * * \remark Produces a NazaraAssert if the physics object is invalid */ - inline bool PhysicsComponent3D::IsAutoSleepEnabled() const { NazaraAssert(m_object, "Invalid physics object"); @@ -224,6 +245,19 @@ namespace Ndk return m_object->IsAutoSleepEnabled(); } + /*! + * \brief Checks whether the object is moveable + * \return true If it is the case + * + * \remark Produces a NazaraAssert if the physics object is invalid + */ + inline bool PhysicsComponent3D::IsMoveable() const + { + NazaraAssert(m_object, "Invalid physics object"); + + return m_object->IsMoveable(); + } + /*! * \brief Checks whether the entity is currently sleeping * \return true If it is the case @@ -238,6 +272,20 @@ namespace Ndk return m_object->IsSleeping(); } + /*! + * \brief Sets the angular damping of the physics object + * + * \param angularDamping Angular damping of the object + * + * \remark Produces a NazaraAssert if the physics object is invalid + */ + inline void PhysicsComponent3D::SetAngularDamping(const Nz::Vector3f& angularDamping) + { + NazaraAssert(m_object, "Invalid physics object"); + + m_object->SetAngularDamping(angularDamping); + } + /*! * \brief Sets the angular velocity of the physics object * @@ -245,7 +293,6 @@ namespace Ndk * * \remark Produces a NazaraAssert if the physics object is invalid */ - inline void PhysicsComponent3D::SetAngularVelocity(const Nz::Vector3f& angularVelocity) { NazaraAssert(m_object, "Invalid physics object"); @@ -260,7 +307,6 @@ namespace Ndk * * \remark Produces a NazaraAssert if the physics object is invalid */ - inline void PhysicsComponent3D::SetGravityFactor(float gravityFactor) { NazaraAssert(m_object, "Invalid physics object"); @@ -268,6 +314,20 @@ namespace Ndk m_object->SetGravityFactor(gravityFactor); } + /*! + * \brief Sets the linear damping of the physics object + * + * \param damping Linear damping of the object + * + * \remark Produces a NazaraAssert if the physics object is invalid + */ + inline void PhysicsComponent3D::SetLinearDamping(float damping) + { + NazaraAssert(m_object, "Invalid physics object"); + + m_object->SetLinearDamping(damping); + } + /*! * \brief Sets the mass of the physics object * @@ -276,7 +336,6 @@ namespace Ndk * \remark Produces a NazaraAssert if the physics object is invalid * \remark Produces a NazaraAssert if the mass is negative */ - inline void PhysicsComponent3D::SetMass(float mass) { NazaraAssert(m_object, "Invalid physics object"); diff --git a/SDK/src/NDK/Components/PhysicsComponent3D.cpp b/SDK/src/NDK/Components/PhysicsComponent3D.cpp index 1e6ccf0c7..09b323d2c 100644 --- a/SDK/src/NDK/Components/PhysicsComponent3D.cpp +++ b/SDK/src/NDK/Components/PhysicsComponent3D.cpp @@ -40,7 +40,7 @@ namespace Ndk else matrix.MakeIdentity(); - m_object.reset(new Nz::RigidBody3D(&world, geom, matrix)); + m_object = std::make_unique(&world, geom, matrix); m_object->SetMass(1.f); } diff --git a/include/Nazara/Physics3D/RigidBody3D.hpp b/include/Nazara/Physics3D/RigidBody3D.hpp index bc7f668b0..7307fa61e 100644 --- a/include/Nazara/Physics3D/RigidBody3D.hpp +++ b/include/Nazara/Physics3D/RigidBody3D.hpp @@ -37,10 +37,12 @@ namespace Nz void EnableAutoSleep(bool autoSleep); Boxf GetAABB() const; + Vector3f GetAngularDamping() const; Vector3f GetAngularVelocity() const; const Collider3DRef& GetGeom() const; float GetGravityFactor() const; NewtonBody* GetHandle() const; + float GetLinearDamping() const; float GetMass() const; Vector3f GetMassCenter(CoordSys coordSys = CoordSys_Local) const; const Matrix4f& GetMatrix() const; @@ -53,9 +55,11 @@ namespace Nz bool IsMoveable() const; bool IsSleeping() const; + void SetAngularDamping(const Nz::Vector3f& angularDamping); void SetAngularVelocity(const Vector3f& angularVelocity); void SetGeom(Collider3DRef geom); void SetGravityFactor(float gravityFactor); + void SetLinearDamping(float damping); void SetMass(float mass); void SetMassCenter(const Vector3f& center); void SetPosition(const Vector3f& position); diff --git a/src/Nazara/Physics3D/RigidBody3D.cpp b/src/Nazara/Physics3D/RigidBody3D.cpp index af4b91a32..ec747ec54 100644 --- a/src/Nazara/Physics3D/RigidBody3D.cpp +++ b/src/Nazara/Physics3D/RigidBody3D.cpp @@ -133,6 +133,14 @@ namespace Nz return Boxf(min, max); } + Vector3f RigidBody3D::GetAngularDamping() const + { + Vector3f angularDamping; + NewtonBodyGetAngularDamping(m_body, angularDamping); + + return angularDamping; + } + Vector3f RigidBody3D::GetAngularVelocity() const { Vector3f angularVelocity; @@ -156,6 +164,11 @@ namespace Nz return m_body; } + float RigidBody3D::GetLinearDamping() const + { + return NewtonBodyGetLinearDamping(m_body); + } + float RigidBody3D::GetMass() const { return m_mass; @@ -222,6 +235,11 @@ namespace Nz return NewtonBodyGetSleepState(m_body) != 0; } + void RigidBody3D::SetAngularDamping(const Nz::Vector3f& angularDamping) + { + NewtonBodySetAngularDamping(m_body, angularDamping); + } + void RigidBody3D::SetAngularVelocity(const Vector3f& angularVelocity) { NewtonBodySetOmega(m_body, angularVelocity); @@ -245,6 +263,11 @@ namespace Nz m_gravityFactor = gravityFactor; } + void RigidBody3D::SetLinearDamping(float damping) + { + NewtonBodySetLinearDamping(m_body, damping); + } + void RigidBody3D::SetMass(float mass) { if (m_mass > 0.f)