Physics3D/RigidBody3D: Add [Get|Set][Angular|Linear]Damping

This commit is contained in:
Lynix 2017-11-30 12:04:33 +01:00
parent a9fc553bd5
commit 6d09abbc2c
5 changed files with 98 additions and 8 deletions

View File

@ -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);

View File

@ -3,6 +3,7 @@
// For conditions of distribution and use, see copyright notice in Prerequesites.hpp
#include <Nazara/Core/Error.hpp>
#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");

View File

@ -40,7 +40,7 @@ namespace Ndk
else
matrix.MakeIdentity();
m_object.reset(new Nz::RigidBody3D(&world, geom, matrix));
m_object = std::make_unique<Nz::RigidBody3D>(&world, geom, matrix);
m_object->SetMass(1.f);
}

View File

@ -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);

View File

@ -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)