Files
NazaraEngine/SDK/include/NDK/Components/PhysicsComponent2D.hpp
Faymoon 7c5b0df96c Make all component inherits of HandledObject (#185)
* Update

* Add: [Get/Set]AngularDaming for standardization

* Fix: Name error

* Add: [Get/Set][AngularDamping/MomentOfInertia] in PhysicsComponent2D

* Forgot in last commit

* Add: param coordSys in [PhysicsComponent2D/RigidBody2D]::SetMassCenter

* Add: Some forgotten inline

* Fix little error

* Fix: Indentation before case

* Move and Change GetCenterOfGravity

* Rename m_world into m_physWorld

* Rename GetWorld int GetPhysWorld

* Update: PhysicsSystem2D became an interface of PhysWorld2D

* Update Collison/PhysicsComponent because GetWorld was renamed

* Update tests

* Update: Make the interface usable with Entity instead of PhysicsComponent

* Update: Make GetPhysWorld private

* Update PhysicsSystem2D.hpp

* Update: indent

* Remove: useless blank line

* update order(?)

* Update PhysicsSystem2D.hpp

* Add calls to GetPhysWorld to attempt a nullptr value

* update include

* little fix

* add some missing inline

* Fix

* Make all component inherits of HandledObject

* fix: compilation error

* Add Handle alias for all Components

* forgot in last commit
2018-09-08 10:28:25 +02:00

80 lines
2.9 KiB
C++

// Copyright (C) 2017 Jérôme Leclercq
// This file is part of the "Nazara Development Kit"
// For conditions of distribution and use, see copyright notice in Prerequisites.hpp
#pragma once
#ifndef NDK_COMPONENTS_PHYSICSCOMPONENT2D_HPP
#define NDK_COMPONENTS_PHYSICSCOMPONENT2D_HPP
#include <Nazara/Physics2D/RigidBody2D.hpp>
#include <NDK/Component.hpp>
#include <memory>
namespace Ndk
{
class PhysicsComponent2D;
using PhysicsComponent2DHandle = Nz::ObjectHandle<PhysicsComponent2D>;
class NDK_API PhysicsComponent2D : public Component<PhysicsComponent2D>
{
friend class CollisionComponent2D;
friend class PhysicsSystem2D;
friend class ConstraintComponent2D;
public:
PhysicsComponent2D() = default;
PhysicsComponent2D(const PhysicsComponent2D& physics);
~PhysicsComponent2D() = default;
inline void AddForce(const Nz::Vector2f& force, Nz::CoordSys coordSys = Nz::CoordSys_Global);
inline void AddForce(const Nz::Vector2f& force, const Nz::Vector2f& point, Nz::CoordSys coordSys = Nz::CoordSys_Global);
inline void AddImpulse(const Nz::Vector2f& impulse, Nz::CoordSys coordSys = Nz::CoordSys_Global);
inline void AddImpulse(const Nz::Vector2f& impulse, const Nz::Vector2f& point, Nz::CoordSys coordSys = Nz::CoordSys_Global);
inline void AddTorque(float torque);
inline bool ClosestPointQuery(const Nz::Vector2f& position, Nz::Vector2f* closestPoint, float* closestDistance) const;
inline Nz::Rectf GetAABB() const;
inline float GetAngularDamping() const;
inline float GetAngularVelocity() const;
NAZARA_DEPRECATED("Name error, please use GetMassCenter")
inline Nz::Vector2f GetCenterOfGravity(Nz::CoordSys coordSys = Nz::CoordSys_Local) const;
inline float GetMass() const;
inline Nz::Vector2f GetMassCenter(Nz::CoordSys coordSys = Nz::CoordSys_Local) const;
inline float GetMomentOfInertia() const;
inline Nz::Vector2f GetPosition() const;
inline float GetRotation() const;
inline Nz::Vector2f GetVelocity() const;
inline bool IsSleeping() const;
inline void SetAngularDamping(float angularDamping);
inline void SetAngularVelocity(float angularVelocity);
inline void SetMass(float mass);
inline void SetMassCenter(const Nz::Vector2f& center, Nz::CoordSys coordSys = Nz::CoordSys_Local);
inline void SetMomentOfInertia(float moment);
inline void SetPosition(const Nz::Vector2f& position);
inline void SetRotation(float rotation);
inline void SetVelocity(const Nz::Vector2f& velocity);
static ComponentIndex componentIndex;
private:
Nz::RigidBody2D* GetRigidBody();
void OnAttached() override;
void OnComponentAttached(BaseComponent& component) override;
void OnComponentDetached(BaseComponent& component) override;
void OnDetached() override;
void OnEntityDestruction() override;
std::unique_ptr<Nz::RigidBody2D> m_object;
};
}
#include <NDK/Components/PhysicsComponent2D.inl>
#endif // NDK_COMPONENTS_PHYSICSCOMPONENT2D_HPP