Nazara Engine  0.4
A fast, complete, cross-platform API designed for game development
PhysicsComponent3D.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_PHYSICSCOMPONENT3D_HPP
8 #define NDK_COMPONENTS_PHYSICSCOMPONENT3D_HPP
9 
10 #include <Nazara/Physics3D/RigidBody3D.hpp>
11 #include <NDK/Component.hpp>
12 #include <memory>
13 
14 namespace Ndk
15 {
16  class NDK_API PhysicsComponent3D : public Component<PhysicsComponent3D>
17  {
18  friend class CollisionComponent3D;
19  friend class PhysicsSystem3D;
20 
21  public:
22  PhysicsComponent3D() = default;
23  PhysicsComponent3D(const PhysicsComponent3D& physics);
24  ~PhysicsComponent3D() = default;
25 
26  void AddForce(const Nz::Vector3f& force, Nz::CoordSys coordSys = Nz::CoordSys_Global);
27  void AddForce(const Nz::Vector3f& force, const Nz::Vector3f& point, Nz::CoordSys coordSys = Nz::CoordSys_Global);
28  void AddTorque(const Nz::Vector3f& torque, Nz::CoordSys coordSys = Nz::CoordSys_Global);
29 
30  void EnableAutoSleep(bool autoSleep);
31 
32  Nz::Boxf GetAABB() const;
33  Nz::Vector3f GetAngularVelocity() const;
34  float GetGravityFactor() const;
35  float GetMass() const;
36  Nz::Vector3f GetMassCenter(Nz::CoordSys coordSys = Nz::CoordSys_Local) const;
37  const Nz::Matrix4f& GetMatrix() const;
38  Nz::Vector3f GetPosition() const;
39  Nz::Quaternionf GetRotation() const;
40  Nz::Vector3f GetVelocity() const;
41 
42  bool IsAutoSleepEnabled() const;
43  bool IsMoveable() const;
44  bool IsSleeping() const;
45 
46  void SetAngularVelocity(const Nz::Vector3f& angularVelocity);
47  void SetGravityFactor(float gravityFactor);
48  void SetMass(float mass);
49  void SetMassCenter(const Nz::Vector3f& center);
50  void SetPosition(const Nz::Vector3f& position);
51  void SetRotation(const Nz::Quaternionf& rotation);
52  void SetVelocity(const Nz::Vector3f& velocity);
53 
54  static ComponentIndex componentIndex;
55 
56  private:
57  Nz::RigidBody3D& GetRigidBody();
58 
59  void OnAttached() override;
60  void OnComponentAttached(BaseComponent& component) override;
61  void OnComponentDetached(BaseComponent& component) override;
62  void OnDetached() override;
63  void OnEntityDestruction() override;
64 
65  std::unique_ptr<Nz::RigidBody3D> m_object;
66  };
67 }
68 
69 #include <NDK/Components/PhysicsComponent3D.inl>
70 
71 #endif // NDK_COMPONENTS_PHYSICSCOMPONENT3D_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 the component for collision (meant for static objects)
Definition: CollisionComponent3D.hpp:17
NDK class that represents the component for physics (meant for dynamic objects)
Definition: PhysicsComponent3D.hpp:16
NDK class that represents the common base of all components.
Definition: BaseComponent.hpp:17