Radium Engine  1.5.0
Component.hpp
1 #pragma once
2 
3 #include <Core/Utils/Index.hpp>
4 #include <Eigen/Core>
5 #include <Eigen/Geometry>
6 #include <Engine/RaEngine.hpp>
7 
8 #include <vector>
9 
10 #include <Core/Types.hpp>
11 
12 namespace Ra {
13 
14 namespace Engine {
15 
16 namespace Rendering {
17 class RenderObject;
18 class RenderObjectManager;
19 } // namespace Rendering
20 
21 namespace Scene {
22 class System;
23 class Entity;
24 
30 class RA_ENGINE_API Component
31 {
32  public:
34  Component( const std::string& name, Entity* entity );
35 
37  virtual ~Component();
38 
44  virtual void initialize() = 0;
50  virtual void setEntity( Entity* entity ) { m_entity = entity; }
51 
53  virtual Entity* getEntity() const { return m_entity; }
54 
56  virtual const std::string& getName() const { return m_name; }
57 
59  virtual void setSystem( System* system ) { m_system = system; }
60 
62  virtual System* getSystem() const { return m_system; }
63 
65  Core::Utils::Index addRenderObject( Rendering::RenderObject* renderObject );
66 
68  void removeRenderObject( const Core::Utils::Index& roIdx );
69 
70  // Editable transform interface.
71  // This allow to edit the data in the component with a render object
72  // as a key. An invalid RO index can be passed, meaning no specific RO is
73  // queried.
74 
76  virtual bool canEdit( const Core::Utils::Index& /*roIdx*/ ) const { return false; }
77 
79  virtual Core::Transform getTransform( const Core::Utils::Index& /*roIdx*/ ) const {
80  return Core::Transform::Identity();
81  }
82 
84  virtual void setTransform( const Core::Utils::Index& /*roIdx*/,
85  const Core::Transform& /*transform*/ ) {}
86 
87  void notifyRenderObjectExpired( const Core::Utils::Index& idx );
88 
89  // return the aabb of the union of visible RenderObjects aabb
90  virtual Core::Aabb computeAabb();
91 
92  void invalidateAabb();
93 
94  const std::vector<Core::Utils::Index>& getRenderObjects() { return m_renderObjects; }
95 
96  protected:
98  static Rendering::RenderObjectManager* getRoMgr();
99 
100  public:
101  std::vector<Core::Utils::Index> m_renderObjects;
102 
103  protected:
104  std::string m_name {};
105  Entity* m_entity { nullptr };
106  System* m_system { nullptr };
107 
108  private:
109  bool m_isAabbValid { false };
110  Core::Aabb m_aabb;
111 };
112 
113 } // namespace Scene
114 } // namespace Engine
115 } // namespace Ra
A component is an element that can be updated by a system. It is also linked to some other components...
Definition: Component.hpp:31
virtual void setTransform(const Core::Utils::Index &, const Core::Transform &)
Set the new transform associated with the RO index key.
Definition: Component.hpp:84
virtual Core::Transform getTransform(const Core::Utils::Index &) const
Get the transform associated with the given RO index key.
Definition: Component.hpp:79
virtual void initialize()=0
Pure virtual method to be overridden by any component. When this method is called you are guaranteed ...
virtual System * getSystem() const
Returns the system to which the component belongs.
Definition: Component.hpp:62
virtual bool canEdit(const Core::Utils::Index &) const
Returns true if a transform can be edited with the render object index given as a key.
Definition: Component.hpp:76
virtual const std::string & getName() const
Return the component's name.
Definition: Component.hpp:56
virtual void setEntity(Entity *entity)
Set entity the component is part of. This method is called by the entity.
Definition: Component.hpp:50
virtual Entity * getEntity() const
Return the entity the component belongs to.
Definition: Component.hpp:53
virtual void setSystem(System *system)
Set the system to which the component belongs.
Definition: Component.hpp:59
An entity is an scene element. It ties together components with a transform.
Definition: Entity.hpp:23
Definition: Cage.cpp:3