Nazara Engine  0.4
A fast, complete, cross-platform API designed for game development
CollisionComponent2D.hpp
1 // Copyright (C) 2017 Jérôme Leclercq
2 // This file is part of the "Nazara Development Kit"
3 // For conditions of distribution and use, see copyright notice in Prerequesites.hpp
4 
5 #pragma once
6 
7 #ifndef NDK_COMPONENTS_COLLISIONCOMPONENT2D_HPP
8 #define NDK_COMPONENTS_COLLISIONCOMPONENT2D_HPP
9 
10 #include <Nazara/Physics2D/Collider2D.hpp>
11 #include <Nazara/Physics2D/RigidBody2D.hpp>
12 #include <NDK/Component.hpp>
13 #include <memory>
14 
15 namespace Ndk
16 {
17  class NDK_API CollisionComponent2D : public Component<CollisionComponent2D>
18  {
19  friend class PhysicsSystem2D;
20 
21  public:
24  ~CollisionComponent2D() = default;
25 
26  Nz::Rectf GetAABB() const;
27  const Nz::Collider2DRef& GetGeom() const;
28 
29  void SetGeom(Nz::Collider2DRef geom);
30 
31  CollisionComponent2D& operator=(Nz::Collider2DRef geom);
32  CollisionComponent2D& operator=(CollisionComponent2D&& collision) = default;
33 
34  static ComponentIndex componentIndex;
35 
36  private:
37  void InitializeStaticBody();
38  Nz::RigidBody2D* GetStaticBody();
39 
40  void OnAttached() override;
41  void OnComponentAttached(BaseComponent& component) override;
42  void OnComponentDetached(BaseComponent& component) override;
43  void OnDetached() override;
44 
45  std::unique_ptr<Nz::RigidBody2D> m_staticBody;
46  Nz::Collider2DRef m_geom;
47  bool m_bodyUpdated;
48  };
49 }
50 
51 #include <NDK/Components/CollisionComponent2D.inl>
52 
53 #endif // NDK_COMPONENTS_COLLISIONCOMPONENT2D_HPP
TODO: For now is unable to display different color in the history, it needs a RichTextDrawer to do so...
Definition: Algorithm.hpp:12
NDK class that represents a two-dimensional collision geometry.
Definition: CollisionComponent2D.hpp:17
NDK class that represents a two-dimensional physics system.
Definition: PhysicsSystem2D.hpp:17
NDK class that represents the common base of all components.
Definition: BaseComponent.hpp:17