Nazara Engine  0.4
A fast, complete, cross-platform API designed for game development
PhysicsComponent2D.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_PHYSICSCOMPONENT2D_HPP
8 #define NDK_COMPONENTS_PHYSICSCOMPONENT2D_HPP
9 
10 #include <Nazara/Physics2D/RigidBody2D.hpp>
11 #include <NDK/Component.hpp>
12 #include <memory>
13 
14 namespace Ndk
15 {
16  class NDK_API PhysicsComponent2D : public Component<PhysicsComponent2D>
17  {
18  friend class CollisionComponent2D;
19  friend class PhysicsSystem2D;
20 
21  public:
22  PhysicsComponent2D() = default;
23  PhysicsComponent2D(const PhysicsComponent2D& physics);
24  ~PhysicsComponent2D() = default;
25 
26  void AddForce(const Nz::Vector2f& force, Nz::CoordSys coordSys = Nz::CoordSys_Global);
27  void AddForce(const Nz::Vector2f& force, const Nz::Vector2f& point, Nz::CoordSys coordSys = Nz::CoordSys_Global);
28  void AddTorque(float torque);
29 
30  Nz::Rectf GetAABB() const;
31  float GetAngularVelocity() const;
32  Nz::Vector2f GetCenterOfGravity(Nz::CoordSys coordSys = Nz::CoordSys_Local) const;
33  float GetMass() const;
34  Nz::Vector2f GetPosition() const;
35  float GetRotation() const;
36  Nz::Vector2f GetVelocity() const;
37 
38  bool IsSleeping() const;
39 
40  void SetAngularVelocity(float angularVelocity);
41  void SetMass(float mass);
42  void SetMassCenter(const Nz::Vector2f& center);
43  void SetPosition(const Nz::Vector2f& position);
44  void SetRotation(float rotation);
45  void SetVelocity(const Nz::Vector2f& velocity);
46 
47  static ComponentIndex componentIndex;
48 
49  private:
50  Nz::RigidBody2D& GetRigidBody();
51 
52  void OnAttached() override;
53  void OnComponentAttached(BaseComponent& component) override;
54  void OnComponentDetached(BaseComponent& component) override;
55  void OnDetached() override;
56  void OnEntityDestruction() override;
57 
58  std::unique_ptr<Nz::RigidBody2D> m_object;
59  };
60 }
61 
62 #include <NDK/Components/PhysicsComponent2D.inl>
63 
64 #endif // NDK_COMPONENTS_PHYSICSCOMPONENT2D_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 physics point, without any collision.
Definition: PhysicsComponent2D.hpp:16
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