Constraint 2D (#147)

* Rename all Constraint by [name]Constraint3D

* Create Refs and Libraries for Constraint2D

* Remove ref to PhysWorld in Constraints ctors

* Update Constraint2d ctor to have RigiBodies first

* Add New static function for all constraints and fix an oopsie

* Add Contraint Library and remove all library useless aliases

* Add ConstraintComponent2D

* remove useless definition of Constraint2D library

* Fix : getting the world of the constraint before having created it

* Make the GetStaticBody function return a ref

* Remove : Useless AddJoint Fonction and Update CreateJoint function

* Update PhysicsSystem3D because GetStaticBody return now a ref

* Oops

* Having done something with the 3D and i was needing 2D

* Add ConstraintComponent as friend of Collision and PhysicsComponent

* Update all the Get[Static/Rigid]Body function so they return a pointer

* fix the bugs caused by the commit before

* update : CreateConstraint lambda for the nullptr case

* remove the useless  use of const pointer

* Update : CreateConstraint function

* Update ChangeLog.md
This commit is contained in:
Faymoon 2018-01-13 11:03:03 +01:00 committed by Jérôme Leclercq
parent 48b9203cb1
commit 4f6bf30f24
18 changed files with 344 additions and 117 deletions

View File

@ -51,6 +51,7 @@ Nazara Engine:
- Calling PlacementDestroy on a null pointer is now a no-op (was triggering an undefined behavior)
- Fix OBJParser relative offsets handling
- Add JPEG image saver
- Update Constraint2Ds classes (Add : Ref, Library, ConstRef, New function and Update : ctors)
Nazara Development Kit:
- Added ImageWidget (#139)
@ -81,6 +82,7 @@ Nazara Development Kit:
- It is now possible to disable synchronization between a PhysicsComponent3D and the NodeComponent
- Fix PhysicsComponent3D copy which was not copying physics state (such as mass, mass center, damping values, gravity factor and auto-sleep mode)
- Fix TextAreaWidget::Clear crash
- Add ConstraintComponent2D class
# 0.4:

View File

@ -17,5 +17,6 @@
#include <NDK/Components/PhysicsComponent2D.hpp>
#include <NDK/Components/PhysicsComponent3D.hpp>
#include <NDK/Components/VelocityComponent.hpp>
#include <NDK/Components/ConstraintComponent2D.hpp>
#endif // NDK_COMPONENTS_GLOBAL_HPP

View File

@ -17,6 +17,7 @@ namespace Ndk
class NDK_API CollisionComponent2D : public Component<CollisionComponent2D>
{
friend class PhysicsSystem2D;
friend class ConstraintComponent2D;
public:
CollisionComponent2D(Nz::Collider2DRef geom = Nz::Collider2DRef());

View File

@ -0,0 +1,34 @@
#pragma once
#ifndef NDK_COMPONENTS_CONSTRAINTCOMPONENT2D_HPP
#define NDK_COMPONENTS_CONSTRAINTCOMPONENT2D_HPP
#include <NDK/Component.hpp>
#include <Nazara/Physics2D/Constraint2D.hpp>
#include <Nazara/Math/Vector3.hpp>
#include <vector>
#include <memory>
namespace Ndk
{
class NDK_API ConstraintComponent2D : public Component<ConstraintComponent2D>
{
public:
ConstraintComponent2D() = default;
ConstraintComponent2D(const ConstraintComponent2D& joint) = default;
ConstraintComponent2D(ConstraintComponent2D&& joint) = default;
template<typename T, typename... Args> inline Nz::ObjectRef<T> CreateConstraint(const Ndk::EntityHandle first, const Ndk::EntityHandle second, Args&&... args);
static ComponentIndex componentIndex;
private:
std::vector<Nz::Constraint2DRef> m_constraints;
};
}
#include <NDK/Components/ConstraintComponent2D.inl>
#endif// NDK_COMPONENTS_CONSTRAINTCOMPONENT2D_HPP

View File

@ -0,0 +1,29 @@
#include <NDK/Components/ConstraintComponent2D.hpp>
#include <NDK/Components/PhysicsComponent2D.hpp>
#include <NDK/Components/CollisionComponent2D.hpp>
namespace Ndk
{
template<typename T, typename ...Args>
inline Nz::ObjectRef<T> ConstraintComponent2D::CreateConstraint(const Ndk::EntityHandle first, const Ndk::EntityHandle second, Args && ...args)
{
auto QueryBody = [](const Ndk::EntityHandle& entity) -> Nz::RigidBody2D*
{
if (entity->HasComponent<Ndk::PhysicsComponent2D>())
return entity->GetComponent<Ndk::PhysicsComponent2D>().GetRigidBody();
else if (entity->HasComponent<Ndk::CollisionComponent2D>())
return entity->GetComponent<Ndk::CollisionComponent2D>().GetStaticBody();
return nullptr;
};
Nz::RigidBody2D* body_first{ QueryBody(first) }, body_second{ QueryBody(second) };
NazaraAssert(body_first && body_second, "RigidBodies of CollisionComponent2D or PhysicsComponent2D must be valid");
Nz::ObjectRef<T> constraint = T::New(*body_first, *body_second, std::forward<Args>(args)...);
m_constraints.push_back(constraint);
return constraint;
}
}

View File

@ -17,6 +17,7 @@ namespace Ndk
{
friend class CollisionComponent2D;
friend class PhysicsSystem2D;
friend class ConstraintComponent2D;
public:
PhysicsComponent2D() = default;
@ -49,7 +50,7 @@ namespace Ndk
static ComponentIndex componentIndex;
private:
Nz::RigidBody2D& GetRigidBody();
Nz::RigidBody2D* GetRigidBody();
void OnAttached() override;
void OnComponentAttached(BaseComponent& component) override;

View File

@ -307,8 +307,8 @@ namespace Ndk
* \return A reference to the physics object
*/
inline Nz::RigidBody2D& PhysicsComponent2D::GetRigidBody()
inline Nz::RigidBody2D* PhysicsComponent2D::GetRigidBody()
{
return *m_object.get();
return m_object.get();
}
}

View File

@ -62,7 +62,7 @@ namespace Ndk
private:
void ApplyPhysicsState(Nz::RigidBody3D& rigidBody) const;
void CopyPhysicsState(const Nz::RigidBody3D& rigidBody);
Nz::RigidBody3D& GetRigidBody();
Nz::RigidBody3D* GetRigidBody();
const Nz::RigidBody3D& GetRigidBody() const;
void OnAttached() override;

View File

@ -461,9 +461,9 @@ namespace Ndk
* \brief Gets the underlying physics object
* \return A reference to the physics object
*/
inline Nz::RigidBody3D& PhysicsComponent3D::GetRigidBody()
inline Nz::RigidBody3D* PhysicsComponent3D::GetRigidBody()
{
return *m_object.get();
return m_object.get();
}
/*!

View File

@ -33,7 +33,7 @@ namespace Ndk
{
// We update the geometry of the PhysiscsObject linked to the PhysicsComponent2D
PhysicsComponent2D& physComponent = m_entity->GetComponent<PhysicsComponent2D>();
physComponent.GetRigidBody().SetGeom(m_geom);
physComponent.GetRigidBody()->SetGeom(m_geom);
}
else
{

View File

@ -32,7 +32,7 @@ namespace Ndk
{
// We update the geometry of the PhysiscsObject linked to the PhysicsComponent3D
PhysicsComponent3D& physComponent = m_entity->GetComponent<PhysicsComponent3D>();
physComponent.GetRigidBody().SetGeom(m_geom);
physComponent.GetRigidBody()->SetGeom(m_geom);
}
else
{

View File

@ -0,0 +1,6 @@
#include <NDK/Components/ConstraintComponent2D.hpp>
namespace Ndk
{
ComponentIndex ConstraintComponent2D::componentIndex;
}

View File

@ -21,6 +21,7 @@
#include <NDK/Components/PhysicsComponent2D.hpp>
#include <NDK/Components/PhysicsComponent3D.hpp>
#include <NDK/Components/VelocityComponent.hpp>
#include <NDK/Components/ConstraintComponent2D.hpp>
#include <NDK/Systems/PhysicsSystem2D.hpp>
#include <NDK/Systems/PhysicsSystem3D.hpp>
#include <NDK/Systems/VelocitySystem.hpp>
@ -89,6 +90,7 @@ namespace Ndk
InitializeComponent<PhysicsComponent2D>("NdkPhys2");
InitializeComponent<PhysicsComponent3D>("NdkPhys3");
InitializeComponent<VelocityComponent>("NdkVeloc");
InitializeComponent<VelocityComponent>("NdkCons2");
#ifndef NDK_SERVER
// Client components

View File

@ -80,9 +80,9 @@ namespace Ndk
NodeComponent& node = entity->GetComponent<NodeComponent>();
PhysicsComponent2D& phys = entity->GetComponent<PhysicsComponent2D>();
Nz::RigidBody2D& body = phys.GetRigidBody();
node.SetRotation(Nz::EulerAnglesf(0.f, 0.f, body.GetRotation()), Nz::CoordSys_Global);
node.SetPosition(Nz::Vector3f(body.GetPosition(), node.GetPosition(Nz::CoordSys_Global).z), Nz::CoordSys_Global);
Nz::RigidBody2D* body = phys.GetRigidBody();
node.SetRotation(Nz::EulerAnglesf(0.f, 0.f, body->GetRotation()), Nz::CoordSys_Global);
node.SetPosition(Nz::Vector3f(body->GetPosition(), node.GetPosition(Nz::CoordSys_Global).z), Nz::CoordSys_Global);
}
float invElapsedTime = 1.f / elapsedTime;

View File

@ -84,9 +84,9 @@ namespace Ndk
NodeComponent& node = entity->GetComponent<NodeComponent>();
PhysicsComponent3D& phys = entity->GetComponent<PhysicsComponent3D>();
Nz::RigidBody3D& physObj = phys.GetRigidBody();
node.SetRotation(physObj.GetRotation(), Nz::CoordSys_Global);
node.SetPosition(physObj.GetPosition(), Nz::CoordSys_Global);
Nz::RigidBody3D* physObj = phys.GetRigidBody();
node.SetRotation(physObj->GetRotation(), Nz::CoordSys_Global);
node.SetPosition(physObj->GetPosition(), Nz::CoordSys_Global);
}
float invElapsedTime = 1.f / elapsedTime;

View File

@ -18,7 +18,13 @@ struct cpConstraint;
namespace Nz
{
class NAZARA_PHYSICS2D_API Constraint2D
class Constraint2D;
using Constraint2DConstRef = ObjectRef<const Constraint2D>;
using Constraint2DLibrary = ObjectLibrary<Constraint2D>;
using Constraint2DRef = ObjectRef<Constraint2D>;
class NAZARA_PHYSICS2D_API Constraint2D : public RefCounted
{
public:
Constraint2D(const Constraint2D&) = delete;
@ -47,16 +53,24 @@ namespace Nz
Constraint2D& operator=(Constraint2D&& rhs);
protected:
Constraint2D(PhysWorld2D& world, cpConstraint* constraint);
Constraint2D(Nz::PhysWorld2D* world, cpConstraint* constraint);
MovablePtr<cpConstraint> m_constraint;
private:
static Constraint2DLibrary s_library;
};
class DampedSpringConstraint2D;
using DampedSpringConstraint2DConstRef = ObjectRef<const DampedSpringConstraint2D>;
using DampedSpringConstraint2DRef = ObjectRef<DampedSpringConstraint2D>;
class NAZARA_PHYSICS2D_API DampedSpring2D : public Constraint2D
class NAZARA_PHYSICS2D_API DampedSpringConstraint2D : public Constraint2D
{
public:
DampedSpring2D(PhysWorld2D& world, RigidBody2D& first, const Vector2f& firstAnchor, RigidBody2D& second, const Vector2f& secondAnchor, float restLength, float stiffness, float damping);
~DampedSpring2D() = default;
DampedSpringConstraint2D(RigidBody2D& first, RigidBody2D& second, const Vector2f& firstAnchor, const Vector2f& secondAnchor, float restLength, float stiffness, float damping);
~DampedSpringConstraint2D() = default;
float GetDamping() const;
Vector2f GetFirstAnchor() const;
@ -69,13 +83,20 @@ namespace Nz
void SetRestLength(float newLength);
void SetSecondAnchor(const Vector2f& firstAnchor);
void SetStiffness(float newStiffness);
template<typename... Args> static DampedSpringConstraint2DRef New(Args&&... args);
};
class NAZARA_PHYSICS2D_API DampedRotarySpring2D : public Constraint2D
class DampedRotarySpringConstraint2D;
using DampedRotarySpringConstraint2DConstRef = ObjectRef<const DampedRotarySpringConstraint2D>;
using DampedRotarySpringConstraint2DRef = ObjectRef<DampedRotarySpringConstraint2D>;
class NAZARA_PHYSICS2D_API DampedRotarySpringConstraint2D : public Constraint2D
{
public:
DampedRotarySpring2D(PhysWorld2D& world, RigidBody2D& first, RigidBody2D& second, float restAngle, float stiffness, float damping);
~DampedRotarySpring2D() = default;
DampedRotarySpringConstraint2D(RigidBody2D& first, RigidBody2D& second, float restAngle, float stiffness, float damping);
~DampedRotarySpringConstraint2D() = default;
float GetDamping() const;
float GetRestAngle() const;
@ -84,36 +105,57 @@ namespace Nz
void SetDamping(float newDamping);
void SetRestAngle(float newAngle);
void SetStiffness(float newStiffness);
template<typename... Args> static DampedRotarySpringConstraint2DRef New(Args&&... args);
};
class GearConstraint2D;
using GearConstraint2DConstRef = ObjectRef<const GearConstraint2D>;
using GearConstraint2DRef = ObjectRef<GearConstraint2D>;
class NAZARA_PHYSICS2D_API GearJoint2D : public Constraint2D
class NAZARA_PHYSICS2D_API GearConstraint2D : public Constraint2D
{
public:
GearJoint2D(PhysWorld2D& world, RigidBody2D& first, RigidBody2D& second, float phase, float ratio);
~GearJoint2D() = default;
GearConstraint2D(RigidBody2D& first, RigidBody2D& second, float phase, float ratio);
~GearConstraint2D() = default;
float GetPhase() const;
float GetRatio() const;
void SetPhase(float phase);
void SetRatio(float ratio);
template<typename... Args> static GearConstraint2DRef New(Args&&... args);
};
class MotorConstraint2D;
using MotorConstraint2DConstRef = ObjectRef<const MotorConstraint2D>;
using MotorConstraint2DRef = ObjectRef<MotorConstraint2D>;
class NAZARA_PHYSICS2D_API MotorJoint2D : public Constraint2D
class NAZARA_PHYSICS2D_API MotorConstraint2D : public Constraint2D
{
public:
MotorJoint2D(PhysWorld2D& world, RigidBody2D& first, RigidBody2D& second, float rate);
~MotorJoint2D() = default;
MotorConstraint2D(RigidBody2D& first, RigidBody2D& second, float rate);
~MotorConstraint2D() = default;
float GetRate() const;
void SetRate(float rate);
template<typename... Args> static MotorConstraint2DRef New(Args&&... args);
};
class NAZARA_PHYSICS2D_API PinJoint2D : public Constraint2D
class PinConstraint2D;
using PinConstraint2DConstRef = ObjectRef<const PinConstraint2D>;
using PinConstraint2DRef = ObjectRef<PinConstraint2D>;
class NAZARA_PHYSICS2D_API PinConstraint2D : public Constraint2D
{
public:
PinJoint2D(PhysWorld2D& world, RigidBody2D& first, const Vector2f& firstAnchor, RigidBody2D& second, const Vector2f& secondAnchor);
~PinJoint2D() = default;
PinConstraint2D(RigidBody2D& first, RigidBody2D& second, const Vector2f& firstAnchor, const Vector2f& secondAnchor);
~PinConstraint2D() = default;
float GetDistance() const;
Vector2f GetFirstAnchor() const;
@ -122,27 +164,41 @@ namespace Nz
void SetDistance(float newDistance);
void SetFirstAnchor(const Vector2f& firstAnchor);
void SetSecondAnchor(const Vector2f& firstAnchor);
template<typename... Args> static PinConstraint2DRef New(Args&&... args);
};
class PivotConstraint2D;
using PivotConstraint2DConstRef = ObjectRef<const PivotConstraint2D>;
using PivotConstraint2DRef = ObjectRef<PivotConstraint2D>;
class NAZARA_PHYSICS2D_API PivotJoint2D : public Constraint2D
class NAZARA_PHYSICS2D_API PivotConstraint2D : public Constraint2D
{
public:
PivotJoint2D(PhysWorld2D& world, RigidBody2D& first, RigidBody2D& second, const Vector2f& anchor);
PivotJoint2D(PhysWorld2D& world, RigidBody2D& first, const Vector2f& firstAnchor, RigidBody2D& second, const Vector2f& secondAnchor);
~PivotJoint2D() = default;
PivotConstraint2D(RigidBody2D& first, RigidBody2D& second, const Vector2f& anchor);
PivotConstraint2D(RigidBody2D& first, RigidBody2D& second, const Vector2f& firstAnchor, const Vector2f& secondAnchor);
~PivotConstraint2D() = default;
Vector2f GetFirstAnchor() const;
Vector2f GetSecondAnchor() const;
void SetFirstAnchor(const Vector2f& firstAnchor);
void SetSecondAnchor(const Vector2f& firstAnchor);
template<typename... Args> static PivotConstraint2DRef New(Args&&... args);
};
class RatchetConstraint2D;
using RatchetConstraint2DConstRef = ObjectRef<const RatchetConstraint2D>;
using RatchetConstraint2DRef = ObjectRef<RatchetConstraint2D>;
class NAZARA_PHYSICS2D_API RatchetJoint2D : public Constraint2D
class NAZARA_PHYSICS2D_API RatchetConstraint2D : public Constraint2D
{
public:
RatchetJoint2D(PhysWorld2D& world, RigidBody2D& first, RigidBody2D& second, float phase, float ratchet);
~RatchetJoint2D() = default;
RatchetConstraint2D(RigidBody2D& first, RigidBody2D& second, float phase, float ratchet);
~RatchetConstraint2D() = default;
float GetAngle() const;
float GetPhase() const;
@ -151,26 +207,40 @@ namespace Nz
void SetAngle(float angle);
void SetPhase(float phase);
void SetRatchet(float ratchet);
template<typename... Args> static RatchetConstraint2DRef New(Args&&... args);
};
class NAZARA_PHYSICS2D_API RotaryLimitJoint2D : public Constraint2D
class RotaryLimitConstraint2D;
using RotaryLimitConstraint2DConstRef = ObjectRef<const RotaryLimitConstraint2D>;
using RotaryLimitConstraint2DRef = ObjectRef<RotaryLimitConstraint2D>;
class NAZARA_PHYSICS2D_API RotaryLimitConstraint2D : public Constraint2D
{
public:
RotaryLimitJoint2D(PhysWorld2D& world, RigidBody2D& first, RigidBody2D& second, float minAngle, float maxAngle);
~RotaryLimitJoint2D() = default;
RotaryLimitConstraint2D(RigidBody2D& first, RigidBody2D& second, float minAngle, float maxAngle);
~RotaryLimitConstraint2D() = default;
float GetMaxAngle() const;
float GetMinAngle() const;
void SetMaxAngle(float maxAngle);
void SetMinAngle(float minAngle);
template<typename... Args> static RotaryLimitConstraint2DRef New(Args&&... args);
};
class NAZARA_PHYSICS2D_API SlideJoint2D : public Constraint2D
class SlideConstraint2D;
using SlideConstraint2DConstRef = ObjectRef<const SlideConstraint2D>;
using SlideConstraint2DRef = ObjectRef<SlideConstraint2D>;
class NAZARA_PHYSICS2D_API SlideConstraint2D : public Constraint2D
{
public:
SlideJoint2D(PhysWorld2D& world, RigidBody2D& first, const Vector2f& firstAnchor, RigidBody2D& second, const Vector2f& secondAnchor, float min, float max);
~SlideJoint2D() = default;
SlideConstraint2D(RigidBody2D& first, RigidBody2D& second, const Vector2f& firstAnchor, const Vector2f& secondAnchor, float min, float max);
~SlideConstraint2D() = default;
Vector2f GetFirstAnchor() const;
float GetMaxDistance() const;
@ -181,6 +251,8 @@ namespace Nz
void SetMaxDistance(float newMaxDistance);
void SetMinDistance(float newMinDistance);
void SetSecondAnchor(const Vector2f& firstAnchor);
template<typename... Args> static SlideConstraint2DRef New(Args&&... args);
};
}

View File

@ -8,6 +8,86 @@
namespace Nz
{
template<typename... Args>
DampedSpringConstraint2DRef DampedSpringConstraint2D::New(Args&&... args)
{
std::unique_ptr<DampedSpringConstraint2D> object(new DampedSpringConstraint2D(std::forward<Args>(args)...));
object->SetPersistent(false);
return object.release();
}
template<typename... Args>
DampedRotarySpringConstraint2DRef DampedRotarySpringConstraint2D::New(Args&&... args)
{
std::unique_ptr<DampedRotarySpringConstraint2D> object(new DampedRotarySpringConstraint2D(std::forward<Args>(args)...));
object->SetPersistent(false);
return object.release();
}
template<typename... Args>
GearConstraint2DRef GearConstraint2D::New(Args&&... args)
{
std::unique_ptr<GearConstraint2D> object(new GearConstraint2D(std::forward<Args>(args)...));
object->SetPersistent(false);
return object.release();
}
template<typename... Args>
MotorConstraint2DRef MotorConstraint2D::New(Args&&... args)
{
std::unique_ptr<MotorConstraint2D> object(new MotorConstraint2D(std::forward<Args>(args)...));
object->SetPersistent(false);
return object.release();
}
template<typename... Args>
PinConstraint2DRef PinConstraint2D::New(Args&&... args)
{
std::unique_ptr<PinConstraint2D> object(new PinConstraint2D(std::forward<Args>(args)...));
object->SetPersistent(false);
return object.release();
}
template<typename... Args>
PivotConstraint2DRef PivotConstraint2D::New(Args&&... args)
{
std::unique_ptr<PivotConstraint2D> object(new PivotConstraint2D(std::forward<Args>(args)...));
object->SetPersistent(false);
return object.release();
}
template<typename... Args>
RatchetConstraint2DRef RatchetConstraint2D::New(Args&&... args)
{
std::unique_ptr<RatchetConstraint2D> object(new RatchetConstraint2D(std::forward<Args>(args)...));
object->SetPersistent(false);
return object.release();
}
template<typename... Args>
RotaryLimitConstraint2DRef RotaryLimitConstraint2D::New(Args&&... args)
{
std::unique_ptr<RotaryLimitConstraint2D> object(new RotaryLimitConstraint2D(std::forward<Args>(args)...));
object->SetPersistent(false);
return object.release();
}
template<typename... Args>
SlideConstraint2DRef SlideConstraint2D::New(Args&&... args)
{
std::unique_ptr<SlideConstraint2D> object(new SlideConstraint2D(std::forward<Args>(args)...));
object->SetPersistent(false);
return object.release();
}
}
#include <Nazara/Physics2D/DebugOff.hpp>

View File

@ -8,11 +8,11 @@
namespace Nz
{
Constraint2D::Constraint2D(PhysWorld2D& world, cpConstraint* constraint) :
Constraint2D::Constraint2D(Nz::PhysWorld2D* world, cpConstraint* constraint) :
m_constraint(constraint)
{
cpConstraintSetUserData(m_constraint, this);
cpSpaceAddConstraint(world.GetHandle(), m_constraint);
cpSpaceAddConstraint(world->GetHandle(), m_constraint);
}
Constraint2D::Constraint2D(Constraint2D&& rhs) :
@ -105,320 +105,319 @@ namespace Nz
}
DampedSpring2D::DampedSpring2D(PhysWorld2D& world, RigidBody2D& first, const Vector2f& firstAnchor, RigidBody2D& second, const Vector2f& secondAnchor, float restLength, float stiffness, float damping) :
Constraint2D(world, cpDampedSpringNew(first.GetHandle(), second.GetHandle(), cpv(firstAnchor.x, firstAnchor.y), cpv(secondAnchor.x, secondAnchor.y), restLength, stiffness, damping))
DampedSpringConstraint2D::DampedSpringConstraint2D(RigidBody2D& first, RigidBody2D& second, const Vector2f& firstAnchor, const Vector2f& secondAnchor, float restLength, float stiffness, float damping) :
Constraint2D(first.GetWorld(), cpDampedSpringNew(first.GetHandle(), second.GetHandle(), cpv(firstAnchor.x, firstAnchor.y), cpv(secondAnchor.x, secondAnchor.y), restLength, stiffness, damping))
{
}
float DampedSpring2D::GetDamping() const
float DampedSpringConstraint2D::GetDamping() const
{
return float(cpDampedSpringGetDamping(m_constraint));
}
Vector2f DampedSpring2D::GetFirstAnchor() const
Vector2f DampedSpringConstraint2D::GetFirstAnchor() const
{
cpVect anchor = cpDampedSpringGetAnchorA(m_constraint);
return Vector2f(static_cast<float>(anchor.x), static_cast<float>(anchor.y));
}
float DampedSpring2D::GetRestLength() const
float DampedSpringConstraint2D::GetRestLength() const
{
return float(cpDampedSpringGetRestLength(m_constraint));
}
Vector2f DampedSpring2D::GetSecondAnchor() const
Vector2f DampedSpringConstraint2D::GetSecondAnchor() const
{
cpVect anchor = cpDampedSpringGetAnchorB(m_constraint);
return Vector2f(static_cast<float>(anchor.x), static_cast<float>(anchor.y));
}
float DampedSpring2D::GetStiffness() const
float DampedSpringConstraint2D::GetStiffness() const
{
return float(cpDampedSpringGetStiffness(m_constraint));
}
void DampedSpring2D::SetDamping(float newDamping)
void DampedSpringConstraint2D::SetDamping(float newDamping)
{
cpDampedSpringSetDamping(m_constraint, newDamping);
}
void DampedSpring2D::SetFirstAnchor(const Vector2f& firstAnchor)
void DampedSpringConstraint2D::SetFirstAnchor(const Vector2f& firstAnchor)
{
cpDampedSpringSetAnchorA(m_constraint, cpv(firstAnchor.x, firstAnchor.y));
}
void DampedSpring2D::SetRestLength(float newLength)
void DampedSpringConstraint2D::SetRestLength(float newLength)
{
cpDampedSpringSetRestLength(m_constraint, newLength);
}
void DampedSpring2D::SetSecondAnchor(const Vector2f& firstAnchor)
void DampedSpringConstraint2D::SetSecondAnchor(const Vector2f& firstAnchor)
{
cpDampedSpringSetAnchorB(m_constraint, cpv(firstAnchor.x, firstAnchor.y));
}
void DampedSpring2D::SetStiffness(float newStiffness)
void DampedSpringConstraint2D::SetStiffness(float newStiffness)
{
cpDampedSpringSetStiffness(m_constraint, newStiffness);
}
DampedRotarySpring2D::DampedRotarySpring2D(PhysWorld2D& world, RigidBody2D& first, RigidBody2D& second, float restAngle, float stiffness, float damping) :
Constraint2D(world, cpDampedRotarySpringNew(first.GetHandle(), second.GetHandle(), restAngle, stiffness, damping))
DampedRotarySpringConstraint2D::DampedRotarySpringConstraint2D(RigidBody2D& first, RigidBody2D& second, float restAngle, float stiffness, float damping) :
Constraint2D(first.GetWorld(), cpDampedRotarySpringNew(first.GetHandle(), second.GetHandle(), restAngle, stiffness, damping))
{
}
float DampedRotarySpring2D::GetDamping() const
float DampedRotarySpringConstraint2D::GetDamping() const
{
return float(cpDampedRotarySpringGetDamping(m_constraint));
}
float DampedRotarySpring2D::GetRestAngle() const
float DampedRotarySpringConstraint2D::GetRestAngle() const
{
return float(cpDampedRotarySpringGetRestAngle(m_constraint));
}
float DampedRotarySpring2D::GetStiffness() const
float DampedRotarySpringConstraint2D::GetStiffness() const
{
return float(cpDampedRotarySpringGetStiffness(m_constraint));
}
void DampedRotarySpring2D::SetDamping(float newDamping)
void DampedRotarySpringConstraint2D::SetDamping(float newDamping)
{
cpDampedSpringSetDamping(m_constraint, newDamping);
}
void DampedRotarySpring2D::SetRestAngle(float newAngle)
void DampedRotarySpringConstraint2D::SetRestAngle(float newAngle)
{
cpDampedRotarySpringSetRestAngle(m_constraint, newAngle);
}
void DampedRotarySpring2D::SetStiffness(float newStiffness)
void DampedRotarySpringConstraint2D::SetStiffness(float newStiffness)
{
cpDampedRotarySpringSetStiffness(m_constraint, newStiffness);
}
GearJoint2D::GearJoint2D(PhysWorld2D& world, RigidBody2D& first, RigidBody2D& second, float phase, float ratio) :
Constraint2D(world, cpGearJointNew(first.GetHandle(), second.GetHandle(), phase, ratio))
GearConstraint2D::GearConstraint2D(RigidBody2D& first, RigidBody2D& second, float phase, float ratio) :
Constraint2D(first.GetWorld(), cpGearJointNew(first.GetHandle(), second.GetHandle(), phase, ratio))
{
}
float GearJoint2D::GetPhase() const
float GearConstraint2D::GetPhase() const
{
return float(cpGearJointGetPhase(m_constraint));
}
float GearJoint2D::GetRatio() const
float GearConstraint2D::GetRatio() const
{
return float(cpGearJointGetRatio(m_constraint));
}
void GearJoint2D::SetPhase(float phase)
void GearConstraint2D::SetPhase(float phase)
{
cpGearJointSetPhase(m_constraint, phase);
}
void GearJoint2D::SetRatio(float ratio)
void GearConstraint2D::SetRatio(float ratio)
{
cpGearJointSetRatio(m_constraint, ratio);
}
MotorJoint2D::MotorJoint2D(PhysWorld2D& world, RigidBody2D& first, RigidBody2D& second, float rate) :
Constraint2D(world, cpSimpleMotorNew(first.GetHandle(), second.GetHandle(), rate))
MotorConstraint2D::MotorConstraint2D(RigidBody2D& first, RigidBody2D& second, float rate) :
Constraint2D(first.GetWorld(), cpSimpleMotorNew(first.GetHandle(), second.GetHandle(), rate))
{
}
float MotorJoint2D::GetRate() const
float MotorConstraint2D::GetRate() const
{
return float(cpSimpleMotorGetRate(m_constraint));
}
void MotorJoint2D::SetRate(float rate)
void MotorConstraint2D::SetRate(float rate)
{
cpSimpleMotorSetRate(m_constraint, rate);
}
PinJoint2D::PinJoint2D(PhysWorld2D& world, RigidBody2D& first, const Vector2f& firstAnchor, RigidBody2D& second, const Vector2f& secondAnchor) :
Constraint2D(world, cpPinJointNew(first.GetHandle(), second.GetHandle(), cpv(firstAnchor.x, firstAnchor.y), cpv(secondAnchor.x, secondAnchor.y)))
PinConstraint2D::PinConstraint2D(RigidBody2D& first, RigidBody2D& second, const Vector2f& firstAnchor, const Vector2f& secondAnchor) :
Constraint2D(first.GetWorld(), cpPinJointNew(first.GetHandle(), second.GetHandle(), cpv(firstAnchor.x, firstAnchor.y), cpv(secondAnchor.x, secondAnchor.y)))
{
}
float PinJoint2D::GetDistance() const
float PinConstraint2D::GetDistance() const
{
return float(cpPinJointGetDist(m_constraint));
}
Vector2f PinJoint2D::GetFirstAnchor() const
Vector2f PinConstraint2D::GetFirstAnchor() const
{
cpVect anchor = cpPinJointGetAnchorA(m_constraint);
return Vector2f(static_cast<float>(anchor.x), static_cast<float>(anchor.y));
}
Vector2f PinJoint2D::GetSecondAnchor() const
Vector2f PinConstraint2D::GetSecondAnchor() const
{
cpVect anchor = cpPinJointGetAnchorB(m_constraint);
return Vector2f(static_cast<float>(anchor.x), static_cast<float>(anchor.y));
}
void PinJoint2D::SetDistance(float newDistance)
void PinConstraint2D::SetDistance(float newDistance)
{
cpPinJointSetDist(m_constraint, newDistance);
}
void PinJoint2D::SetFirstAnchor(const Vector2f& firstAnchor)
void PinConstraint2D::SetFirstAnchor(const Vector2f& firstAnchor)
{
cpPinJointSetAnchorA(m_constraint, cpv(firstAnchor.x, firstAnchor.y));
}
void PinJoint2D::SetSecondAnchor(const Vector2f& firstAnchor)
void PinConstraint2D::SetSecondAnchor(const Vector2f& firstAnchor)
{
cpPinJointSetAnchorB(m_constraint, cpv(firstAnchor.x, firstAnchor.y));
}
PivotJoint2D::PivotJoint2D(PhysWorld2D& world, RigidBody2D& first, RigidBody2D& second, const Vector2f& anchor) :
Constraint2D(world, cpPivotJointNew(first.GetHandle(), second.GetHandle(), cpv(anchor.x, anchor.y)))
PivotConstraint2D::PivotConstraint2D(RigidBody2D& first, RigidBody2D& second, const Vector2f& anchor) :
Constraint2D(first.GetWorld(), cpPivotJointNew(first.GetHandle(), second.GetHandle(), cpv(anchor.x, anchor.y)))
{
}
PivotJoint2D::PivotJoint2D(PhysWorld2D& world, RigidBody2D& first, const Vector2f& firstAnchor, RigidBody2D& second, const Vector2f& secondAnchor) :
Constraint2D(world, cpPivotJointNew2(first.GetHandle(), second.GetHandle(), cpv(firstAnchor.x, firstAnchor.y), cpv(secondAnchor.x, secondAnchor.y)))
PivotConstraint2D::PivotConstraint2D(RigidBody2D& first, RigidBody2D& second, const Vector2f& firstAnchor, const Vector2f& secondAnchor) :
Constraint2D(first.GetWorld(), cpPivotJointNew2(first.GetHandle(), second.GetHandle(), cpv(firstAnchor.x, firstAnchor.y), cpv(secondAnchor.x, secondAnchor.y)))
{
}
Vector2f PivotJoint2D::GetFirstAnchor() const
Vector2f PivotConstraint2D::GetFirstAnchor() const
{
cpVect anchor = cpPivotJointGetAnchorA(m_constraint);
return Vector2f(static_cast<float>(anchor.x), static_cast<float>(anchor.y));
}
Vector2f PivotJoint2D::GetSecondAnchor() const
Vector2f PivotConstraint2D::GetSecondAnchor() const
{
cpVect anchor = cpPivotJointGetAnchorB(m_constraint);
return Vector2f(static_cast<float>(anchor.x), static_cast<float>(anchor.y));
}
void PivotJoint2D::SetFirstAnchor(const Vector2f& firstAnchor)
void PivotConstraint2D::SetFirstAnchor(const Vector2f& firstAnchor)
{
cpPivotJointSetAnchorA(m_constraint, cpv(firstAnchor.x, firstAnchor.y));
}
void PivotJoint2D::SetSecondAnchor(const Vector2f& firstAnchor)
void PivotConstraint2D::SetSecondAnchor(const Vector2f& firstAnchor)
{
cpPivotJointSetAnchorB(m_constraint, cpv(firstAnchor.x, firstAnchor.y));
}
RatchetJoint2D::RatchetJoint2D(PhysWorld2D& world, RigidBody2D& first, RigidBody2D& second, float phase, float ratchet) :
Constraint2D(world, cpRatchetJointNew(first.GetHandle(), second.GetHandle(), phase, ratchet))
RatchetConstraint2D::RatchetConstraint2D(RigidBody2D& first, RigidBody2D& second, float phase, float ratchet) :
Constraint2D(first.GetWorld(), cpRatchetJointNew(first.GetHandle(), second.GetHandle(), phase, ratchet))
{
}
float RatchetJoint2D::GetAngle() const
float RatchetConstraint2D::GetAngle() const
{
return float(cpRatchetJointGetAngle(m_constraint));
}
float RatchetJoint2D::GetPhase() const
float RatchetConstraint2D::GetPhase() const
{
return float(cpRatchetJointGetPhase(m_constraint));
}
float RatchetJoint2D::GetRatchet() const
float RatchetConstraint2D::GetRatchet() const
{
return float(cpRatchetJointGetRatchet(m_constraint));
}
void RatchetJoint2D::SetAngle(float angle)
void RatchetConstraint2D::SetAngle(float angle)
{
cpRatchetJointSetAngle(m_constraint, angle);
}
void RatchetJoint2D::SetPhase(float phase)
void RatchetConstraint2D::SetPhase(float phase)
{
cpRatchetJointSetPhase(m_constraint, phase);
}
void RatchetJoint2D::SetRatchet(float ratchet)
void RatchetConstraint2D::SetRatchet(float ratchet)
{
cpRatchetJointSetRatchet(m_constraint, ratchet);
}
RotaryLimitJoint2D::RotaryLimitJoint2D(PhysWorld2D& world, RigidBody2D& first, RigidBody2D& second, float minAngle, float maxAngle) :
Constraint2D(world, cpRotaryLimitJointNew(first.GetHandle(), second.GetHandle(), minAngle, maxAngle))
RotaryLimitConstraint2D::RotaryLimitConstraint2D(RigidBody2D& first, RigidBody2D& second, float minAngle, float maxAngle) :
Constraint2D(first.GetWorld(), cpRotaryLimitJointNew(first.GetHandle(), second.GetHandle(), minAngle, maxAngle))
{
}
float RotaryLimitJoint2D::GetMaxAngle() const
float RotaryLimitConstraint2D::GetMaxAngle() const
{
return float(cpRotaryLimitJointGetMax(m_constraint));
}
float RotaryLimitJoint2D::GetMinAngle() const
float RotaryLimitConstraint2D::GetMinAngle() const
{
return float(cpRotaryLimitJointGetMax(m_constraint));
}
void RotaryLimitJoint2D::SetMaxAngle(float maxAngle)
void RotaryLimitConstraint2D::SetMaxAngle(float maxAngle)
{
cpRotaryLimitJointSetMax(m_constraint, maxAngle);
}
void RotaryLimitJoint2D::SetMinAngle(float minAngle)
void RotaryLimitConstraint2D::SetMinAngle(float minAngle)
{
cpRotaryLimitJointSetMin(m_constraint, minAngle);
}
SlideJoint2D::SlideJoint2D(PhysWorld2D& world, RigidBody2D& first, const Vector2f& firstAnchor, RigidBody2D& second, const Vector2f& secondAnchor, float min, float max) :
Constraint2D(world, cpSlideJointNew(first.GetHandle(), second.GetHandle(), cpv(firstAnchor.x, firstAnchor.y), cpv(secondAnchor.x, secondAnchor.y), min, max))
SlideConstraint2D::SlideConstraint2D(RigidBody2D& first, RigidBody2D& second, const Vector2f& firstAnchor, const Vector2f& secondAnchor, float min, float max) :
Constraint2D(first.GetWorld(), cpSlideJointNew(first.GetHandle(), second.GetHandle(), cpv(firstAnchor.x, firstAnchor.y), cpv(secondAnchor.x, secondAnchor.y), min, max))
{
}
Vector2f SlideJoint2D::GetFirstAnchor() const
Vector2f SlideConstraint2D::GetFirstAnchor() const
{
cpVect anchor = cpSlideJointGetAnchorA(m_constraint);
return Vector2f(static_cast<float>(anchor.x), static_cast<float>(anchor.y));
}
float SlideJoint2D::GetMaxDistance() const
float SlideConstraint2D::GetMaxDistance() const
{
return float(cpSlideJointGetMax(m_constraint));
}
float SlideJoint2D::GetMinDistance() const
float SlideConstraint2D::GetMinDistance() const
{
return float(cpSlideJointGetMin(m_constraint));
}
Vector2f SlideJoint2D::GetSecondAnchor() const
Vector2f SlideConstraint2D::GetSecondAnchor() const
{
cpVect anchor = cpSlideJointGetAnchorB(m_constraint);
return Vector2f(static_cast<float>(anchor.x), static_cast<float>(anchor.y));
}
void SlideJoint2D::SetFirstAnchor(const Vector2f& firstAnchor)
void SlideConstraint2D::SetFirstAnchor(const Vector2f& firstAnchor)
{
cpSlideJointSetAnchorA(m_constraint, cpv(firstAnchor.x, firstAnchor.y));
}
void SlideJoint2D::SetMaxDistance(float newMaxDistance)
void SlideConstraint2D::SetMaxDistance(float newMaxDistance)
{
cpSlideJointSetMax(m_constraint, newMaxDistance);
}
void SlideJoint2D::SetMinDistance(float newMinDistance)
void SlideConstraint2D::SetMinDistance(float newMinDistance)
{
cpSlideJointSetMin(m_constraint, newMinDistance);
}
void SlideJoint2D::SetSecondAnchor(const Vector2f& firstAnchor)
void SlideConstraint2D::SetSecondAnchor(const Vector2f& firstAnchor)
{
cpSlideJointSetAnchorB(m_constraint, cpv(firstAnchor.x, firstAnchor.y));
}
}