Physics2D: Expose elasticity/friction/surface velocity
This commit is contained in:
@@ -47,6 +47,9 @@ namespace Nz
|
||||
inline UInt32 GetCollisionGroup() const;
|
||||
inline unsigned int GetCollisionId() const;
|
||||
inline UInt32 GetCollisionMask() const;
|
||||
inline float GetElasticity() const;
|
||||
inline float GetFriction() const;
|
||||
inline Vector2f GetSurfaceVelocity() const;
|
||||
|
||||
virtual ColliderType2D GetType() const = 0;
|
||||
|
||||
@@ -56,6 +59,9 @@ namespace Nz
|
||||
inline void SetCollisionGroup(UInt32 groupId);
|
||||
inline void SetCollisionId(unsigned int typeId);
|
||||
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);
|
||||
|
||||
Collider2D& operator=(const Collider2D&) = delete;
|
||||
@@ -67,11 +73,14 @@ namespace Nz
|
||||
protected:
|
||||
virtual std::size_t CreateShapes(RigidBody2D* body, std::vector<cpShape*>* shapes) const = 0;
|
||||
|
||||
bool m_trigger;
|
||||
UInt32 m_categoryMask;
|
||||
UInt32 m_collisionGroup;
|
||||
unsigned int m_collisionId;
|
||||
UInt32 m_collisionMask;
|
||||
Vector2f m_surfaceVelocity;
|
||||
bool m_trigger;
|
||||
float m_elasticity;
|
||||
float m_friction;
|
||||
unsigned int m_collisionId;
|
||||
|
||||
private:
|
||||
virtual std::size_t GenerateShapes(RigidBody2D* body, std::vector<cpShape*>* shapes) const;
|
||||
|
||||
@@ -9,11 +9,14 @@
|
||||
namespace Nz
|
||||
{
|
||||
inline Collider2D::Collider2D() :
|
||||
m_trigger(false),
|
||||
m_categoryMask(0xFFFFFFFF),
|
||||
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;
|
||||
}
|
||||
|
||||
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
|
||||
{
|
||||
return m_trigger;
|
||||
@@ -62,6 +80,21 @@ namespace Nz
|
||||
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)
|
||||
{
|
||||
m_trigger = trigger;
|
||||
|
||||
@@ -10,6 +10,7 @@
|
||||
#include <Nazara/Prerequisites.hpp>
|
||||
#include <Nazara/Core/Enums.hpp>
|
||||
#include <Nazara/Core/Signal.hpp>
|
||||
#include <Nazara/Math/Angle.hpp>
|
||||
#include <Nazara/Math/Rect.hpp>
|
||||
#include <Nazara/Physics2D/Config.hpp>
|
||||
#include <Nazara/Physics2D/Collider2D.hpp>
|
||||
@@ -42,17 +43,21 @@ namespace Nz
|
||||
|
||||
Rectf GetAABB() const;
|
||||
inline float GetAngularDamping() const;
|
||||
float GetAngularVelocity() const;
|
||||
RadianAnglef GetAngularVelocity() const;
|
||||
NAZARA_DEPRECATED("Name error, please use GetMassCenter")
|
||||
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;
|
||||
cpBody* GetHandle() const;
|
||||
float GetMass() const;
|
||||
Vector2f GetMassCenter(CoordSys coordSys = CoordSys_Local) const;
|
||||
float GetMomentOfInertia() const;
|
||||
Vector2f GetPosition() const;
|
||||
float GetRotation() const;
|
||||
RadianAnglef GetRotation() const;
|
||||
inline std::size_t GetShapeCount() const;
|
||||
std::size_t GetShapeIndex(cpShape* shape) const;
|
||||
Vector2f GetSurfaceVelocity(std::size_t shapeIndex = 0) const;
|
||||
void* GetUserdata() const;
|
||||
Vector2f GetVelocity() const;
|
||||
PhysWorld2D* GetWorld() const;
|
||||
@@ -63,14 +68,19 @@ namespace Nz
|
||||
bool IsStatic() const;
|
||||
|
||||
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 SetGeom(Collider2DRef geom, bool recomputeMoment = true);
|
||||
void SetMass(float mass, bool recomputeMoment = true);
|
||||
void SetMassCenter(const Vector2f& center, CoordSys coordSys = CoordSys_Local);
|
||||
void SetMomentOfInertia(float moment);
|
||||
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 SetUserdata(void* ud);
|
||||
void SetVelocity(const Vector2f& velocity);
|
||||
@@ -90,6 +100,7 @@ namespace Nz
|
||||
void UnregisterFromSpace();
|
||||
|
||||
static void CopyBodyData(cpBody* from, cpBody* to);
|
||||
static void CopyShapeData(cpShape* from, cpShape* to);
|
||||
|
||||
std::vector<cpShape*> m_shapes;
|
||||
Collider2DRef m_geom;
|
||||
|
||||
@@ -17,6 +17,11 @@ namespace Nz
|
||||
return GetMassCenter(coordSys);
|
||||
}
|
||||
|
||||
inline std::size_t RigidBody2D::GetShapeCount() const
|
||||
{
|
||||
return m_shapes.size();
|
||||
}
|
||||
|
||||
inline void RigidBody2D::SetAngularDamping(float angularDamping)
|
||||
{
|
||||
SetMomentOfInertia(angularDamping);
|
||||
|
||||
Reference in New Issue
Block a user