From 0df70dcb168df911648913352db93aab5e30b88d Mon Sep 17 00:00:00 2001 From: Lynix Date: Sun, 10 Dec 2017 12:09:36 +0100 Subject: [PATCH] Physics3D/RigidBody3D: Rename [Get|Set]Velocity to [Get|Set]LinearVelocity --- ChangeLog.md | 2 + .../NDK/Components/PhysicsComponent3D.hpp | 4 +- .../NDK/Components/PhysicsComponent3D.inl | 57 +++++++++---------- SDK/src/NDK/Systems/PhysicsSystem3D.cpp | 4 +- include/Nazara/Physics3D/RigidBody3D.hpp | 4 +- src/Nazara/Physics3D/RigidBody3D.cpp | 26 ++++----- 6 files changed, 49 insertions(+), 48 deletions(-) diff --git a/ChangeLog.md b/ChangeLog.md index 830a0dadb..b8b59925c 100644 --- a/ChangeLog.md +++ b/ChangeLog.md @@ -35,6 +35,7 @@ Nazara Engine: - Fix default directory permission (now created with 777) - Add linear and angular damping accessor to RigidBody3D - Fix MemoryStream::WriteBlock "Invalid buffer" assertion triggering when writing a zero-sized block +- ⚠️ Rename RigidBody3D::[Get|Set]Velocity to [Get|Set]LinearVelocity Nazara Development Kit: - Added ImageWidget (#139) @@ -59,6 +60,7 @@ Nazara Development Kit: - Fix GraphicsComponent::Clear method now clearing reflective states - Add linear and angular damping accessor to PhysicsComponent3D - Fix GraphicsComponent cloning not copying renderable local matrices +- ⚠️ Rename PhysicsComponent3D::[Get|Set]Velocity to [Get|Set]LinearVelocity # 0.4: diff --git a/SDK/include/NDK/Components/PhysicsComponent3D.hpp b/SDK/include/NDK/Components/PhysicsComponent3D.hpp index 495b17a43..b989f17ee 100644 --- a/SDK/include/NDK/Components/PhysicsComponent3D.hpp +++ b/SDK/include/NDK/Components/PhysicsComponent3D.hpp @@ -34,12 +34,12 @@ namespace Ndk Nz::Vector3f GetAngularVelocity() const; float GetGravityFactor() const; float GetLinearDamping() const; + Nz::Vector3f GetLinearVelocity() const; float GetMass() const; Nz::Vector3f GetMassCenter(Nz::CoordSys coordSys = Nz::CoordSys_Local) const; const Nz::Matrix4f& GetMatrix() const; Nz::Vector3f GetPosition() const; Nz::Quaternionf GetRotation() const; - Nz::Vector3f GetVelocity() const; bool IsAutoSleepEnabled() const; bool IsMoveable() const; @@ -49,11 +49,11 @@ namespace Ndk void SetAngularVelocity(const Nz::Vector3f& angularVelocity); void SetGravityFactor(float gravityFactor); void SetLinearDamping(float damping); + void SetLinearVelocity(const Nz::Vector3f& velocity); void SetMass(float mass); void SetMassCenter(const Nz::Vector3f& center); void SetPosition(const Nz::Vector3f& position); void SetRotation(const Nz::Quaternionf& rotation); - void SetVelocity(const Nz::Vector3f& velocity); static ComponentIndex componentIndex; diff --git a/SDK/include/NDK/Components/PhysicsComponent3D.inl b/SDK/include/NDK/Components/PhysicsComponent3D.inl index 939f5c75b..741655387 100644 --- a/SDK/include/NDK/Components/PhysicsComponent3D.inl +++ b/SDK/include/NDK/Components/PhysicsComponent3D.inl @@ -146,6 +146,20 @@ namespace Ndk return m_object->GetLinearDamping(); } + /*! + * \brief Gets the linear velocity of the physics object + * \return Linear velocity of the object + * + * \remark Produces a NazaraAssert if the physics object is invalid + */ + + inline Nz::Vector3f PhysicsComponent3D::GetLinearVelocity() const + { + NazaraAssert(m_object, "Invalid physics object"); + + return m_object->GetLinearVelocity(); + } + /*! * \brief Gets the mass of the physics object * \return Mass of the object @@ -218,20 +232,6 @@ namespace Ndk return m_object->GetRotation(); } - /*! - * \brief Gets the velocity of the physics object - * \return Velocity of the object - * - * \remark Produces a NazaraAssert if the physics object is invalid - */ - - inline Nz::Vector3f PhysicsComponent3D::GetVelocity() const - { - NazaraAssert(m_object, "Invalid physics object"); - - return m_object->GetVelocity(); - } - /*! * \brief Checks whether the auto sleep is enabled * \return true If it is the case @@ -328,6 +328,20 @@ namespace Ndk m_object->SetLinearDamping(damping); } + /*! + * \brief Sets the linear velocity of the physics object + * + * \param velocity New linear velocity of the object + * + * \remark Produces a NazaraAssert if the physics object is invalid + */ + inline void PhysicsComponent3D::SetLinearVelocity(const Nz::Vector3f& velocity) + { + NazaraAssert(m_object, "Invalid physics object"); + + m_object->SetLinearVelocity(velocity); + } + /*! * \brief Sets the mass of the physics object * @@ -389,21 +403,6 @@ namespace Ndk m_object->SetRotation(rotation); } - /*! - * \brief Sets the velocity of the physics object - * - * \param velocity Velocity of the object - * - * \remark Produces a NazaraAssert if the physics object is invalid - */ - - inline void PhysicsComponent3D::SetVelocity(const Nz::Vector3f& velocity) - { - NazaraAssert(m_object, "Invalid physics object"); - - m_object->SetVelocity(velocity); - } - /*! * \brief Gets the underlying physics object * \return A reference to the physics object diff --git a/SDK/src/NDK/Systems/PhysicsSystem3D.cpp b/SDK/src/NDK/Systems/PhysicsSystem3D.cpp index 9026c5a1d..efb2a0554 100644 --- a/SDK/src/NDK/Systems/PhysicsSystem3D.cpp +++ b/SDK/src/NDK/Systems/PhysicsSystem3D.cpp @@ -103,10 +103,10 @@ namespace Ndk if (newPosition != oldPosition) { physObj->SetPosition(newPosition); - physObj->SetVelocity((newPosition - oldPosition) * invElapsedTime); + physObj->SetLinearVelocity((newPosition - oldPosition) * invElapsedTime); } else - physObj->SetVelocity(Nz::Vector3f::Zero()); + physObj->SetLinearVelocity(Nz::Vector3f::Zero()); if (newRotation != oldRotation) { diff --git a/include/Nazara/Physics3D/RigidBody3D.hpp b/include/Nazara/Physics3D/RigidBody3D.hpp index 7307fa61e..06c617405 100644 --- a/include/Nazara/Physics3D/RigidBody3D.hpp +++ b/include/Nazara/Physics3D/RigidBody3D.hpp @@ -43,12 +43,12 @@ namespace Nz float GetGravityFactor() const; NewtonBody* GetHandle() const; float GetLinearDamping() const; + Vector3f GetLinearVelocity() const; float GetMass() const; Vector3f GetMassCenter(CoordSys coordSys = CoordSys_Local) const; const Matrix4f& GetMatrix() const; Vector3f GetPosition() const; Quaternionf GetRotation() const; - Vector3f GetVelocity() const; PhysWorld3D* GetWorld() const; bool IsAutoSleepEnabled() const; @@ -60,11 +60,11 @@ namespace Nz void SetGeom(Collider3DRef geom); void SetGravityFactor(float gravityFactor); 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); - void SetVelocity(const Vector3f& velocity); RigidBody3D& operator=(const RigidBody3D& object); RigidBody3D& operator=(RigidBody3D&& object); diff --git a/src/Nazara/Physics3D/RigidBody3D.cpp b/src/Nazara/Physics3D/RigidBody3D.cpp index ec747ec54..d3926bb68 100644 --- a/src/Nazara/Physics3D/RigidBody3D.cpp +++ b/src/Nazara/Physics3D/RigidBody3D.cpp @@ -169,6 +169,14 @@ namespace Nz return NewtonBodyGetLinearDamping(m_body); } + Vector3f RigidBody3D::GetLinearVelocity() const + { + Vector3f velocity; + NewtonBodyGetVelocity(m_body, velocity); + + return velocity; + } + float RigidBody3D::GetMass() const { return m_mass; @@ -207,14 +215,6 @@ namespace Nz return m_matrix.GetRotation(); } - Vector3f RigidBody3D::GetVelocity() const - { - Vector3f velocity; - NewtonBodyGetVelocity(m_body, velocity); - - return velocity; - } - PhysWorld3D* RigidBody3D::GetWorld() const { return m_world; @@ -268,6 +268,11 @@ namespace Nz NewtonBodySetLinearDamping(m_body, damping); } + void RigidBody3D::SetLinearVelocity(const Vector3f& velocity) + { + NewtonBodySetVelocity(m_body, velocity); + } + void RigidBody3D::SetMass(float mass) { if (m_mass > 0.f) @@ -313,11 +318,6 @@ namespace Nz UpdateBody(); } - void RigidBody3D::SetVelocity(const Vector3f& velocity) - { - NewtonBodySetVelocity(m_body, velocity); - } - RigidBody3D& RigidBody3D::operator=(const RigidBody3D& object) { RigidBody3D physObj(object);