// Copyright (C) 2020 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_COLLISIONCOMPONENT2D_HPP #define NDK_COMPONENTS_COLLISIONCOMPONENT2D_HPP #include #include #include #include namespace Ndk { class CollisionComponent2D; using CollisionComponent2DHandle = Nz::ObjectHandle; class NDK_API CollisionComponent2D : public Component { friend class ConstraintComponent2D; friend class PhysicsComponent2D; friend class PhysicsSystem2D; public: CollisionComponent2D(std::shared_ptr geom = std::shared_ptr()); CollisionComponent2D(const CollisionComponent2D& collision); ~CollisionComponent2D() = default; Nz::Rectf GetAABB() const; const std::shared_ptr& GetGeom() const; const Nz::Vector2f& GetGeomOffset() const; void Recenter(const Nz::Vector2f& origin); void SetGeom(std::shared_ptr geom, bool recomputeMoment = true, bool recomputeMassCenter = true); void SetGeomOffset(const Nz::Vector2f& geomOffset); CollisionComponent2D& operator=(std::shared_ptr geom); CollisionComponent2D& operator=(CollisionComponent2D&& collision) = delete; static ComponentIndex componentIndex; private: void InitializeStaticBody(); Nz::RigidBody2D* GetRigidBody(); const Nz::RigidBody2D* GetRigidBody() const; Nz::RigidBody2D* GetStaticBody(); const Nz::RigidBody2D* GetStaticBody() const; void OnAttached() override; void OnComponentAttached(BaseComponent& component) override; void OnComponentDetached(BaseComponent& component) override; void OnDetached() override; std::unique_ptr m_staticBody; std::shared_ptr m_geom; bool m_bodyUpdated; }; } #include #endif // NDK_COMPONENTS_COLLISIONCOMPONENT2D_HPP