Physics2D: Expose elasticity/friction/surface velocity
This commit is contained in:
parent
dc6fbfc90f
commit
30348525d7
|
|
@ -41,22 +41,32 @@ namespace Ndk
|
||||||
inline Nz::RadianAnglef GetAngularVelocity() const;
|
inline Nz::RadianAnglef GetAngularVelocity() const;
|
||||||
NAZARA_DEPRECATED("Name error, please use GetMassCenter")
|
NAZARA_DEPRECATED("Name error, please use GetMassCenter")
|
||||||
inline Nz::Vector2f GetCenterOfGravity(Nz::CoordSys coordSys = Nz::CoordSys_Local) const;
|
inline Nz::Vector2f GetCenterOfGravity(Nz::CoordSys coordSys = Nz::CoordSys_Local) const;
|
||||||
|
inline float GetElasticity(std::size_t shapeIndex = 0) const;
|
||||||
|
inline float GetFriction(std::size_t shapeIndex = 0) const;
|
||||||
inline float GetMass() const;
|
inline float GetMass() const;
|
||||||
inline Nz::Vector2f GetMassCenter(Nz::CoordSys coordSys = Nz::CoordSys_Local) const;
|
inline Nz::Vector2f GetMassCenter(Nz::CoordSys coordSys = Nz::CoordSys_Local) const;
|
||||||
inline float GetMomentOfInertia() const;
|
inline float GetMomentOfInertia() const;
|
||||||
inline Nz::Vector2f GetPosition() const;
|
inline Nz::Vector2f GetPosition() const;
|
||||||
inline Nz::RadianAnglef GetRotation() const;
|
inline Nz::RadianAnglef GetRotation() const;
|
||||||
|
inline Nz::Vector2f GetSurfaceVelocity(std::size_t shapeIndex = 0) const;
|
||||||
|
inline std::size_t GetShapeCount() const;
|
||||||
inline Nz::Vector2f GetVelocity() const;
|
inline Nz::Vector2f GetVelocity() const;
|
||||||
|
|
||||||
inline bool IsSleeping() const;
|
inline bool IsSleeping() const;
|
||||||
|
|
||||||
inline void SetAngularDamping(float angularDamping);
|
inline void SetAngularDamping(float angularDamping);
|
||||||
inline void SetAngularVelocity(const Nz::RadianAnglef& angularVelocity);
|
inline void SetAngularVelocity(const Nz::RadianAnglef& angularVelocity);
|
||||||
|
inline void SetElasticity(float elasticity);
|
||||||
|
inline void SetElasticity(std::size_t shapeIndex, float friction);
|
||||||
|
inline void SetFriction(float friction);
|
||||||
|
inline void SetFriction(std::size_t shapeIndex, float friction);
|
||||||
inline void SetMass(float mass);
|
inline void SetMass(float mass);
|
||||||
inline void SetMassCenter(const Nz::Vector2f& center, Nz::CoordSys coordSys = Nz::CoordSys_Local);
|
inline void SetMassCenter(const Nz::Vector2f& center, Nz::CoordSys coordSys = Nz::CoordSys_Local);
|
||||||
inline void SetMomentOfInertia(float moment);
|
inline void SetMomentOfInertia(float moment);
|
||||||
inline void SetPosition(const Nz::Vector2f& position);
|
inline void SetPosition(const Nz::Vector2f& position);
|
||||||
inline void SetRotation(const Nz::RadianAnglef& rotation);
|
inline void SetRotation(const Nz::RadianAnglef& rotation);
|
||||||
|
inline void SetSurfaceVelocity(const Nz::Vector2f& velocity);
|
||||||
|
inline void SetSurfaceVelocity(std::size_t shapeIndex, const Nz::Vector2f& velocity);
|
||||||
inline void SetVelocity(const Nz::Vector2f& velocity);
|
inline void SetVelocity(const Nz::Vector2f& velocity);
|
||||||
|
|
||||||
static ComponentIndex componentIndex;
|
static ComponentIndex componentIndex;
|
||||||
|
|
|
||||||
|
|
@ -174,6 +174,36 @@ namespace Ndk
|
||||||
return m_object->GetMassCenter(coordSys);
|
return m_object->GetMassCenter(coordSys);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*!
|
||||||
|
* \brief Gets the elasticity of a shape belonging to this physics object
|
||||||
|
* \return Elasticity of the shape
|
||||||
|
*
|
||||||
|
* \param shapeIndex Shape index of the collider we're interested
|
||||||
|
*
|
||||||
|
* \remark Produces a NazaraAssert if the physics object is invalid
|
||||||
|
*/
|
||||||
|
inline float PhysicsComponent2D::GetElasticity(std::size_t shapeIndex) const
|
||||||
|
{
|
||||||
|
NazaraAssert(m_object, "Invalid physics object");
|
||||||
|
|
||||||
|
return m_object->GetElasticity(shapeIndex);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*!
|
||||||
|
* \brief Gets the friction of a shape belonging to this physics object
|
||||||
|
* \return Friction of the shape
|
||||||
|
*
|
||||||
|
* \param shapeIndex Shape index of the collider we're interested
|
||||||
|
*
|
||||||
|
* \remark Produces a NazaraAssert if the physics object is invalid
|
||||||
|
*/
|
||||||
|
inline float PhysicsComponent2D::GetFriction(std::size_t shapeIndex) const
|
||||||
|
{
|
||||||
|
NazaraAssert(m_object, "Invalid physics object");
|
||||||
|
|
||||||
|
return m_object->GetFriction(shapeIndex);
|
||||||
|
}
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
* \brief Gets the mass of the physics object
|
* \brief Gets the mass of the physics object
|
||||||
* \return Mass of the object
|
* \return Mass of the object
|
||||||
|
|
@ -246,6 +276,30 @@ namespace Ndk
|
||||||
return m_object->GetRotation();
|
return m_object->GetRotation();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*!
|
||||||
|
* \brief Gets the surface velocity of a shape belonging to this physics object
|
||||||
|
* \return Surface velocity of the shape
|
||||||
|
*
|
||||||
|
* \param shapeIndex Shape index of the collider we're interested
|
||||||
|
*
|
||||||
|
* \remark Produces a NazaraAssert if the physics object is invalid
|
||||||
|
*/
|
||||||
|
inline Nz::Vector2f PhysicsComponent2D::GetSurfaceVelocity(std::size_t shapeIndex) const
|
||||||
|
{
|
||||||
|
return m_object->GetSurfaceVelocity(shapeIndex);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*!
|
||||||
|
* \brief Gets the rotation of the physics object
|
||||||
|
* \return Shape count of the object
|
||||||
|
*
|
||||||
|
* \remark Produces a NazaraAssert if the physics object is invalid
|
||||||
|
*/
|
||||||
|
inline std::size_t PhysicsComponent2D::GetShapeCount() const
|
||||||
|
{
|
||||||
|
return m_object->GetShapeCount();
|
||||||
|
}
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
* \brief Gets the velocity of the physics object
|
* \brief Gets the velocity of the physics object
|
||||||
* \return Velocity of the object
|
* \return Velocity of the object
|
||||||
|
|
@ -305,6 +359,72 @@ namespace Ndk
|
||||||
m_object->SetAngularVelocity(angularVelocity);
|
m_object->SetAngularVelocity(angularVelocity);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*!
|
||||||
|
* \brief Sets the elasticity of the whole physics object
|
||||||
|
*
|
||||||
|
* Overrides all shapes elasticity with a single value
|
||||||
|
*
|
||||||
|
* \param elasticity Elasticity to be applied
|
||||||
|
*
|
||||||
|
* \remark Elasticity must be positive or zero
|
||||||
|
*/
|
||||||
|
inline void PhysicsComponent2D::SetElasticity(float elasticity)
|
||||||
|
{
|
||||||
|
NazaraAssert(m_object, "Invalid physics object");
|
||||||
|
NazaraAssert(elasticity >= 0.f, "Friction must be positive");
|
||||||
|
|
||||||
|
m_object->SetElasticity(elasticity);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*!
|
||||||
|
* \brief Sets the elasticity of a single shape of the physics object
|
||||||
|
*
|
||||||
|
* \param shapeIndex Target shape index
|
||||||
|
* \param elasticity Elasticity to be applied
|
||||||
|
*
|
||||||
|
* \remark Elasticity must be positive or zero
|
||||||
|
*/
|
||||||
|
inline void PhysicsComponent2D::SetElasticity(std::size_t shapeIndex, float elasticity)
|
||||||
|
{
|
||||||
|
NazaraAssert(m_object, "Invalid physics object");
|
||||||
|
NazaraAssert(elasticity >= 0.f, "Friction must be positive");
|
||||||
|
|
||||||
|
m_object->SetElasticity(shapeIndex, elasticity);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*!
|
||||||
|
* \brief Sets the friction of the whole physics object
|
||||||
|
*
|
||||||
|
* Overrides all shapes friction with a single value
|
||||||
|
*
|
||||||
|
* \param friction Friction to be applied
|
||||||
|
*
|
||||||
|
* \remark Friction must be positive or zero
|
||||||
|
*/
|
||||||
|
inline void PhysicsComponent2D::SetFriction(float friction)
|
||||||
|
{
|
||||||
|
NazaraAssert(m_object, "Invalid physics object");
|
||||||
|
NazaraAssert(friction >= 0.f, "Friction must be positive");
|
||||||
|
|
||||||
|
m_object->SetFriction(friction);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*!
|
||||||
|
* \brief Sets the friction of a single shape of the physics object
|
||||||
|
*
|
||||||
|
* \param shapeIndex Target shape index
|
||||||
|
* \param friction Friction to be applied
|
||||||
|
*
|
||||||
|
* \remark Friction must be positive or zero
|
||||||
|
*/
|
||||||
|
inline void PhysicsComponent2D::SetFriction(std::size_t shapeIndex, float friction)
|
||||||
|
{
|
||||||
|
NazaraAssert(m_object, "Invalid physics object");
|
||||||
|
NazaraAssert(friction >= 0.f, "Friction must be positive");
|
||||||
|
|
||||||
|
m_object->SetFriction(shapeIndex, friction);
|
||||||
|
}
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
* \brief Sets the mass of the physics object
|
* \brief Sets the mass of the physics object
|
||||||
*
|
*
|
||||||
|
|
@ -378,14 +498,38 @@ namespace Ndk
|
||||||
m_object->SetRotation(rotation);
|
m_object->SetRotation(rotation);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*!
|
||||||
|
* \brief Sets the surface velocity of the whole physics object
|
||||||
|
*
|
||||||
|
* Overrides all shapes surface velocity with a single value
|
||||||
|
*
|
||||||
|
* \param velocity Surface velocity to be applied
|
||||||
|
*/
|
||||||
|
inline void PhysicsComponent2D::SetSurfaceVelocity(const Nz::Vector2f& velocity)
|
||||||
|
{
|
||||||
|
NazaraAssert(m_object, "Invalid physics object");
|
||||||
|
|
||||||
|
m_object->SetSurfaceVelocity(velocity);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*!
|
||||||
|
* \brief Sets the surface velocity of a single shape of the physics object
|
||||||
|
*
|
||||||
|
* \param shapeIndex Target shape index
|
||||||
|
* \param velocity Surface velocity to be applied
|
||||||
|
*/
|
||||||
|
inline void PhysicsComponent2D::SetSurfaceVelocity(std::size_t shapeIndex, const Nz::Vector2f& velocity)
|
||||||
|
{
|
||||||
|
NazaraAssert(m_object, "Invalid physics object");
|
||||||
|
|
||||||
|
m_object->SetSurfaceVelocity(shapeIndex, velocity);
|
||||||
|
}
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
* \brief Sets the velocity of the physics object
|
* \brief Sets the velocity of the physics object
|
||||||
*
|
*
|
||||||
* \param velocity Velocity of the object
|
* \param velocity Velocity of the object
|
||||||
*
|
|
||||||
* \remark Produces a NazaraAssert if the physics object is invalid
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
inline void PhysicsComponent2D::SetVelocity(const Nz::Vector2f& velocity)
|
inline void PhysicsComponent2D::SetVelocity(const Nz::Vector2f& velocity)
|
||||||
{
|
{
|
||||||
NazaraAssert(m_object, "Invalid physics object");
|
NazaraAssert(m_object, "Invalid physics object");
|
||||||
|
|
|
||||||
|
|
@ -47,6 +47,9 @@ namespace Nz
|
||||||
inline UInt32 GetCollisionGroup() const;
|
inline UInt32 GetCollisionGroup() const;
|
||||||
inline unsigned int GetCollisionId() const;
|
inline unsigned int GetCollisionId() const;
|
||||||
inline UInt32 GetCollisionMask() const;
|
inline UInt32 GetCollisionMask() const;
|
||||||
|
inline float GetElasticity() const;
|
||||||
|
inline float GetFriction() const;
|
||||||
|
inline Vector2f GetSurfaceVelocity() const;
|
||||||
|
|
||||||
virtual ColliderType2D GetType() const = 0;
|
virtual ColliderType2D GetType() const = 0;
|
||||||
|
|
||||||
|
|
@ -56,6 +59,9 @@ namespace Nz
|
||||||
inline void SetCollisionGroup(UInt32 groupId);
|
inline void SetCollisionGroup(UInt32 groupId);
|
||||||
inline void SetCollisionId(unsigned int typeId);
|
inline void SetCollisionId(unsigned int typeId);
|
||||||
inline void SetCollisionMask(UInt32 mask);
|
inline void SetCollisionMask(UInt32 mask);
|
||||||
|
inline void SetElasticity(float elasticity);
|
||||||
|
inline void SetFriction(float friction);
|
||||||
|
inline void SetSurfaceVelocity(const Vector2f& surfaceVelocity);
|
||||||
inline void SetTrigger(bool trigger);
|
inline void SetTrigger(bool trigger);
|
||||||
|
|
||||||
Collider2D& operator=(const Collider2D&) = delete;
|
Collider2D& operator=(const Collider2D&) = delete;
|
||||||
|
|
@ -67,11 +73,14 @@ namespace Nz
|
||||||
protected:
|
protected:
|
||||||
virtual std::size_t CreateShapes(RigidBody2D* body, std::vector<cpShape*>* shapes) const = 0;
|
virtual std::size_t CreateShapes(RigidBody2D* body, std::vector<cpShape*>* shapes) const = 0;
|
||||||
|
|
||||||
bool m_trigger;
|
|
||||||
UInt32 m_categoryMask;
|
UInt32 m_categoryMask;
|
||||||
UInt32 m_collisionGroup;
|
UInt32 m_collisionGroup;
|
||||||
unsigned int m_collisionId;
|
|
||||||
UInt32 m_collisionMask;
|
UInt32 m_collisionMask;
|
||||||
|
Vector2f m_surfaceVelocity;
|
||||||
|
bool m_trigger;
|
||||||
|
float m_elasticity;
|
||||||
|
float m_friction;
|
||||||
|
unsigned int m_collisionId;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
virtual std::size_t GenerateShapes(RigidBody2D* body, std::vector<cpShape*>* shapes) const;
|
virtual std::size_t GenerateShapes(RigidBody2D* body, std::vector<cpShape*>* shapes) const;
|
||||||
|
|
|
||||||
|
|
@ -9,11 +9,14 @@
|
||||||
namespace Nz
|
namespace Nz
|
||||||
{
|
{
|
||||||
inline Collider2D::Collider2D() :
|
inline Collider2D::Collider2D() :
|
||||||
m_trigger(false),
|
|
||||||
m_categoryMask(0xFFFFFFFF),
|
m_categoryMask(0xFFFFFFFF),
|
||||||
m_collisionGroup(0),
|
m_collisionGroup(0),
|
||||||
m_collisionId(0),
|
m_collisionMask(0xFFFFFFFF),
|
||||||
m_collisionMask(0xFFFFFFFF)
|
m_trigger(false),
|
||||||
|
m_elasticity(0.f),
|
||||||
|
m_friction(0.f),
|
||||||
|
m_surfaceVelocity(Vector2f::Zero()),
|
||||||
|
m_collisionId(0)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -37,6 +40,21 @@ namespace Nz
|
||||||
return m_collisionMask;
|
return m_collisionMask;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
inline float Collider2D::GetElasticity() const
|
||||||
|
{
|
||||||
|
return m_elasticity;
|
||||||
|
}
|
||||||
|
|
||||||
|
inline float Collider2D::GetFriction() const
|
||||||
|
{
|
||||||
|
return m_friction;
|
||||||
|
}
|
||||||
|
|
||||||
|
inline Vector2f Collider2D::GetSurfaceVelocity() const
|
||||||
|
{
|
||||||
|
return m_surfaceVelocity;
|
||||||
|
}
|
||||||
|
|
||||||
inline bool Collider2D::IsTrigger() const
|
inline bool Collider2D::IsTrigger() const
|
||||||
{
|
{
|
||||||
return m_trigger;
|
return m_trigger;
|
||||||
|
|
@ -62,6 +80,21 @@ namespace Nz
|
||||||
m_collisionMask = mask;
|
m_collisionMask = mask;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
inline void Collider2D::SetElasticity(float elasticity)
|
||||||
|
{
|
||||||
|
m_elasticity = elasticity;
|
||||||
|
}
|
||||||
|
|
||||||
|
inline void Collider2D::SetFriction(float friction)
|
||||||
|
{
|
||||||
|
m_friction = friction;
|
||||||
|
}
|
||||||
|
|
||||||
|
inline void Collider2D::SetSurfaceVelocity(const Vector2f& surfaceVelocity)
|
||||||
|
{
|
||||||
|
m_surfaceVelocity = surfaceVelocity;
|
||||||
|
}
|
||||||
|
|
||||||
inline void Collider2D::SetTrigger(bool trigger)
|
inline void Collider2D::SetTrigger(bool trigger)
|
||||||
{
|
{
|
||||||
m_trigger = trigger;
|
m_trigger = trigger;
|
||||||
|
|
|
||||||
|
|
@ -10,6 +10,7 @@
|
||||||
#include <Nazara/Prerequisites.hpp>
|
#include <Nazara/Prerequisites.hpp>
|
||||||
#include <Nazara/Core/Enums.hpp>
|
#include <Nazara/Core/Enums.hpp>
|
||||||
#include <Nazara/Core/Signal.hpp>
|
#include <Nazara/Core/Signal.hpp>
|
||||||
|
#include <Nazara/Math/Angle.hpp>
|
||||||
#include <Nazara/Math/Rect.hpp>
|
#include <Nazara/Math/Rect.hpp>
|
||||||
#include <Nazara/Physics2D/Config.hpp>
|
#include <Nazara/Physics2D/Config.hpp>
|
||||||
#include <Nazara/Physics2D/Collider2D.hpp>
|
#include <Nazara/Physics2D/Collider2D.hpp>
|
||||||
|
|
@ -42,17 +43,21 @@ namespace Nz
|
||||||
|
|
||||||
Rectf GetAABB() const;
|
Rectf GetAABB() const;
|
||||||
inline float GetAngularDamping() const;
|
inline float GetAngularDamping() const;
|
||||||
float GetAngularVelocity() const;
|
RadianAnglef GetAngularVelocity() const;
|
||||||
NAZARA_DEPRECATED("Name error, please use GetMassCenter")
|
NAZARA_DEPRECATED("Name error, please use GetMassCenter")
|
||||||
inline Vector2f GetCenterOfGravity(CoordSys coordSys = CoordSys_Local) const;
|
inline Vector2f GetCenterOfGravity(CoordSys coordSys = CoordSys_Local) const;
|
||||||
|
float GetElasticity(std::size_t shapeIndex = 0) const;
|
||||||
|
float GetFriction(std::size_t shapeIndex = 0) const;
|
||||||
const Collider2DRef& GetGeom() const;
|
const Collider2DRef& GetGeom() const;
|
||||||
cpBody* GetHandle() const;
|
cpBody* GetHandle() const;
|
||||||
float GetMass() const;
|
float GetMass() const;
|
||||||
Vector2f GetMassCenter(CoordSys coordSys = CoordSys_Local) const;
|
Vector2f GetMassCenter(CoordSys coordSys = CoordSys_Local) const;
|
||||||
float GetMomentOfInertia() const;
|
float GetMomentOfInertia() const;
|
||||||
Vector2f GetPosition() const;
|
Vector2f GetPosition() const;
|
||||||
float GetRotation() const;
|
RadianAnglef GetRotation() const;
|
||||||
|
inline std::size_t GetShapeCount() const;
|
||||||
std::size_t GetShapeIndex(cpShape* shape) const;
|
std::size_t GetShapeIndex(cpShape* shape) const;
|
||||||
|
Vector2f GetSurfaceVelocity(std::size_t shapeIndex = 0) const;
|
||||||
void* GetUserdata() const;
|
void* GetUserdata() const;
|
||||||
Vector2f GetVelocity() const;
|
Vector2f GetVelocity() const;
|
||||||
PhysWorld2D* GetWorld() const;
|
PhysWorld2D* GetWorld() const;
|
||||||
|
|
@ -63,14 +68,19 @@ namespace Nz
|
||||||
bool IsStatic() const;
|
bool IsStatic() const;
|
||||||
|
|
||||||
inline void SetAngularDamping(float angularDamping);
|
inline void SetAngularDamping(float angularDamping);
|
||||||
void SetAngularVelocity(float angularVelocity);
|
void SetAngularVelocity(const RadianAnglef& angularVelocity);
|
||||||
|
void SetElasticity(float elasticity);
|
||||||
|
void SetElasticity(std::size_t shapeIndex, float elasticity);
|
||||||
|
void SetFriction(float friction);
|
||||||
void SetFriction(std::size_t shapeIndex, float friction);
|
void SetFriction(std::size_t shapeIndex, float friction);
|
||||||
void SetGeom(Collider2DRef geom, bool recomputeMoment = true);
|
void SetGeom(Collider2DRef geom, bool recomputeMoment = true);
|
||||||
void SetMass(float mass, bool recomputeMoment = true);
|
void SetMass(float mass, bool recomputeMoment = true);
|
||||||
void SetMassCenter(const Vector2f& center, CoordSys coordSys = CoordSys_Local);
|
void SetMassCenter(const Vector2f& center, CoordSys coordSys = CoordSys_Local);
|
||||||
void SetMomentOfInertia(float moment);
|
void SetMomentOfInertia(float moment);
|
||||||
void SetPosition(const Vector2f& position);
|
void SetPosition(const Vector2f& position);
|
||||||
void SetRotation(float rotation);
|
void SetRotation(const RadianAnglef& rotation);
|
||||||
|
void SetSurfaceVelocity(const Vector2f& surfaceVelocity);
|
||||||
|
void SetSurfaceVelocity(std::size_t shapeIndex, const Vector2f& surfaceVelocity);
|
||||||
void SetStatic(bool setStaticBody = true);
|
void SetStatic(bool setStaticBody = true);
|
||||||
void SetUserdata(void* ud);
|
void SetUserdata(void* ud);
|
||||||
void SetVelocity(const Vector2f& velocity);
|
void SetVelocity(const Vector2f& velocity);
|
||||||
|
|
@ -90,6 +100,7 @@ namespace Nz
|
||||||
void UnregisterFromSpace();
|
void UnregisterFromSpace();
|
||||||
|
|
||||||
static void CopyBodyData(cpBody* from, cpBody* to);
|
static void CopyBodyData(cpBody* from, cpBody* to);
|
||||||
|
static void CopyShapeData(cpShape* from, cpShape* to);
|
||||||
|
|
||||||
std::vector<cpShape*> m_shapes;
|
std::vector<cpShape*> m_shapes;
|
||||||
Collider2DRef m_geom;
|
Collider2DRef m_geom;
|
||||||
|
|
|
||||||
|
|
@ -17,6 +17,11 @@ namespace Nz
|
||||||
return GetMassCenter(coordSys);
|
return GetMassCenter(coordSys);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
inline std::size_t RigidBody2D::GetShapeCount() const
|
||||||
|
{
|
||||||
|
return m_shapes.size();
|
||||||
|
}
|
||||||
|
|
||||||
inline void RigidBody2D::SetAngularDamping(float angularDamping)
|
inline void RigidBody2D::SetAngularDamping(float angularDamping)
|
||||||
{
|
{
|
||||||
SetMomentOfInertia(angularDamping);
|
SetMomentOfInertia(angularDamping);
|
||||||
|
|
|
||||||
|
|
@ -20,9 +20,12 @@ namespace Nz
|
||||||
{
|
{
|
||||||
cpShape* shape = (*shapes)[i];
|
cpShape* shape = (*shapes)[i];
|
||||||
|
|
||||||
|
cpShapeSetCollisionType(shape, cpFloat(m_collisionId));
|
||||||
|
cpShapeSetElasticity(shape, cpFloat(m_elasticity));
|
||||||
cpShapeSetFilter(shape, filter);
|
cpShapeSetFilter(shape, filter);
|
||||||
cpShapeSetCollisionType(shape, m_collisionId);
|
cpShapeSetFriction(shape, cpFloat(m_friction));
|
||||||
cpShapeSetSensor(shape, (m_trigger) ? cpTrue : cpFalse);
|
cpShapeSetSensor(shape, (m_trigger) ? cpTrue : cpFalse);
|
||||||
|
cpShapeSetSurfaceVelocity(shape, cpv(cpFloat(m_surfaceVelocity.x), cpFloat(m_surfaceVelocity.y)));
|
||||||
}
|
}
|
||||||
|
|
||||||
return shapeCount;
|
return shapeCount;
|
||||||
|
|
|
||||||
|
|
@ -52,8 +52,11 @@ namespace Nz
|
||||||
CopyBodyData(object.GetHandle(), m_handle);
|
CopyBodyData(object.GetHandle(), m_handle);
|
||||||
|
|
||||||
for (std::size_t i = 0; i < m_shapes.size(); ++i)
|
for (std::size_t i = 0; i < m_shapes.size(); ++i)
|
||||||
|
{
|
||||||
|
CopyShapeData(object.m_shapes[i], m_shapes[i]);
|
||||||
m_shapes[i]->bb = cpShapeCacheBB(object.m_shapes[i]);
|
m_shapes[i]->bb = cpShapeCacheBB(object.m_shapes[i]);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
RigidBody2D::RigidBody2D(RigidBody2D&& object) :
|
RigidBody2D::RigidBody2D(RigidBody2D&& object) :
|
||||||
OnRigidBody2DMove(std::move(object.OnRigidBody2DMove)),
|
OnRigidBody2DMove(std::move(object.OnRigidBody2DMove)),
|
||||||
|
|
@ -186,8 +189,20 @@ namespace Nz
|
||||||
}
|
}
|
||||||
|
|
||||||
RadianAnglef RigidBody2D::GetAngularVelocity() const
|
RadianAnglef RigidBody2D::GetAngularVelocity() const
|
||||||
return float(cpBodyGetAngularVelocity(m_handle));
|
|
||||||
{
|
{
|
||||||
|
return float(cpBodyGetAngularVelocity(m_handle));
|
||||||
|
}
|
||||||
|
|
||||||
|
float Nz::RigidBody2D::GetElasticity(std::size_t shapeIndex) const
|
||||||
|
{
|
||||||
|
assert(shapeIndex < m_shapes.size());
|
||||||
|
return float(cpShapeGetElasticity(m_shapes[shapeIndex]));
|
||||||
|
}
|
||||||
|
|
||||||
|
float Nz::RigidBody2D::GetFriction(std::size_t shapeIndex) const
|
||||||
|
{
|
||||||
|
assert(shapeIndex < m_shapes.size());
|
||||||
|
return float(cpShapeGetFriction(m_shapes[shapeIndex]));
|
||||||
}
|
}
|
||||||
|
|
||||||
const Collider2DRef& RigidBody2D::GetGeom() const
|
const Collider2DRef& RigidBody2D::GetGeom() const
|
||||||
|
|
@ -247,6 +262,13 @@ namespace Nz
|
||||||
return std::distance(m_shapes.begin(), it);
|
return std::distance(m_shapes.begin(), it);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Vector2f Nz::RigidBody2D::GetSurfaceVelocity(std::size_t shapeIndex) const
|
||||||
|
{
|
||||||
|
assert(shapeIndex < m_shapes.size());
|
||||||
|
cpVect vel = cpShapeGetSurfaceVelocity(m_shapes[shapeIndex]);
|
||||||
|
return Vector2f(static_cast<float>(vel.x), static_cast<float>(vel.y));
|
||||||
|
}
|
||||||
|
|
||||||
void* RigidBody2D::GetUserdata() const
|
void* RigidBody2D::GetUserdata() const
|
||||||
{
|
{
|
||||||
return m_userData;
|
return m_userData;
|
||||||
|
|
@ -286,8 +308,32 @@ namespace Nz
|
||||||
void RigidBody2D::SetAngularVelocity(const RadianAnglef& angularVelocity)
|
void RigidBody2D::SetAngularVelocity(const RadianAnglef& angularVelocity)
|
||||||
{
|
{
|
||||||
cpBodySetAngularVelocity(m_handle, angularVelocity.angle);
|
cpBodySetAngularVelocity(m_handle, angularVelocity.angle);
|
||||||
|
}
|
||||||
|
|
||||||
|
void RigidBody2D::SetElasticity(float friction)
|
||||||
|
{
|
||||||
|
cpFloat frict(friction);
|
||||||
|
for (cpShape* shape : m_shapes)
|
||||||
|
cpShapeSetElasticity(shape, frict);
|
||||||
|
}
|
||||||
|
|
||||||
|
void RigidBody2D::SetElasticity(std::size_t shapeIndex, float friction)
|
||||||
{
|
{
|
||||||
assert(shapeIndex < m_shapes.size());
|
assert(shapeIndex < m_shapes.size());
|
||||||
|
cpShapeSetElasticity(m_shapes[shapeIndex], cpFloat(friction));
|
||||||
|
}
|
||||||
|
|
||||||
|
void RigidBody2D::SetFriction(float friction)
|
||||||
|
{
|
||||||
|
cpFloat frict(friction);
|
||||||
|
for (cpShape* shape : m_shapes)
|
||||||
|
cpShapeSetFriction(shape, frict);
|
||||||
|
}
|
||||||
|
|
||||||
|
void RigidBody2D::SetFriction(std::size_t shapeIndex, float friction)
|
||||||
|
{
|
||||||
|
assert(shapeIndex < m_shapes.size());
|
||||||
|
cpShapeSetFriction(m_shapes[shapeIndex], cpFloat(friction));
|
||||||
}
|
}
|
||||||
|
|
||||||
void RigidBody2D::SetGeom(Collider2DRef geom, bool recomputeMoment)
|
void RigidBody2D::SetGeom(Collider2DRef geom, bool recomputeMoment)
|
||||||
|
|
@ -414,6 +460,19 @@ namespace Nz
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void RigidBody2D::SetSurfaceVelocity(const Vector2f& surfaceVelocity)
|
||||||
|
{
|
||||||
|
Vector2<cpFloat> velocity(surfaceVelocity.x, surfaceVelocity.y);
|
||||||
|
for (cpShape* shape : m_shapes)
|
||||||
|
cpShapeSetSurfaceVelocity(shape, cpv(velocity.x, velocity.y));
|
||||||
|
}
|
||||||
|
|
||||||
|
void RigidBody2D::SetSurfaceVelocity(std::size_t shapeIndex, const Vector2f& surfaceVelocity)
|
||||||
|
{
|
||||||
|
assert(shapeIndex < m_shapes.size());
|
||||||
|
cpShapeSetSurfaceVelocity(m_shapes[shapeIndex], cpv(cpFloat(surfaceVelocity.x), cpFloat(surfaceVelocity.y)));
|
||||||
|
}
|
||||||
|
|
||||||
void RigidBody2D::SetStatic(bool setStaticBody)
|
void RigidBody2D::SetStatic(bool setStaticBody)
|
||||||
{
|
{
|
||||||
m_isStatic = setStaticBody;
|
m_isStatic = setStaticBody;
|
||||||
|
|
@ -549,4 +608,10 @@ namespace Nz
|
||||||
cpBodySetVelocity(to, cpBodyGetVelocity(from));
|
cpBodySetVelocity(to, cpBodyGetVelocity(from));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void RigidBody2D::CopyShapeData(cpShape* from, cpShape* to)
|
||||||
|
{
|
||||||
|
cpShapeSetElasticity(to, cpShapeGetElasticity(from));
|
||||||
|
cpShapeSetFriction(to, cpShapeGetFriction(from));
|
||||||
|
cpShapeSetSurfaceVelocity(to, cpShapeGetSurfaceVelocity(from));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue