Element.hpp
Go to the documentation of this file.
1 
6 #pragma once
7 
8 #include <etk/types.hpp>
9 #include <etk/math/Vector3D.hpp>
10 #include <etk/math/Matrix4.hpp>
11 #include <vector>
12 #include <ewol/debug.hpp>
13 #include <ewol/widget/Widget.hpp>
14 #include <gale/renderer/openGL/openGL.hpp>
15 #include <ewol/resource/Colored3DObject.hpp>
16 #include <ege/resource/Mesh.hpp>
17 #include <ege/camera/Camera.hpp>
18 #include <ewol/compositing/Text.hpp>
19 #include <ege/Environement.hpp>
20 
21 #define INDEX_RIGHT_AXIS (0)
22 #define INDEX_FORWARD_AXIS (1)
23 #define INDEX_UP_AXIS (2)
24 
25 #define ELEMENT_SCALE (1.0f/8.0f)
26 
27 namespace ege {
28  class Element : public ememory::EnableSharedFromThis<Element> {
29  protected:
31  public:
41  virtual ~Element();
46  virtual const std::string& getType() const;
53  virtual bool init();
54  virtual bool initString(const std::string& _description);
55  virtual bool initXML(const exml::Node& _node);
56  virtual bool initJSON(const ejson::Value& _value);
57  virtual bool initVoid(void* _value);
58  virtual bool unInit();
59  private:
60  uint32_t m_uID;
61  public:
66  inline uint32_t getUID() const {
67  return m_uID;
68  };
69  protected:
71  public:
78  virtual bool loadMesh(const std::string& _meshFileName);
91  return m_mesh;
92  };
93  protected:
94  float m_life;
95  float m_lifeMax;
96  public:
101  float getLifeRatio();
106  bool isDead() {
107  return (0 >= m_life)?true:false;
108  };
113  virtual bool needToRemove() {
114  return isDead();
115  }
123  virtual void setFireOn(int32_t _groupIdSource, int32_t _type, float _power, const vec3& _center=vec3(0,0,0));
127  virtual void onLifeChange() { };
128  protected:
129  int32_t m_group;
130  public:
135  inline int32_t getGroup() const {
136  return m_group;
137  };
142  inline void setGroup(int32_t _newGroup) {
143  m_group=_newGroup;
144  };
145  public:
151  virtual void preCalculationDraw(const ege::Camera& _camera) { };
156  virtual void draw(int32_t _pass=0) = 0;
157 
161  // TODO : Remove this ...
163 
164  protected:
165  // For debug only ...
166  ewol::compositing::Text m_debugText;
167  public:
173 
179  return getPosition();
180  };
185  virtual const vec3& getPosition();
190  virtual void setPosition(const vec3& _pos) {};
195  virtual void elementIsRemoved(ememory::SharedPtr<ege::Element> _removedElement) { };
196  protected:
197  bool m_fixe;
198  public:
203  inline bool isFixed() {
204  return m_fixe;
205  };
206  protected:
207  float m_radius;
208  public:
213  inline float getRadius() {
214  return m_radius;
215  };
219  virtual void onDestroy() {};
223  virtual void dynamicEnable() {};
227  virtual void dynamicDisable() {};
228  };
229 }
230 
231 
void setGroup(int32_t _newGroup)
set the group of the curent element
Definition: Element.hpp:142
float m_lifeMax
Maximum possible life of the element.
Definition: Element.hpp:95
float m_life
Current life of the object.
Definition: Element.hpp:92
int32_t getGroup() const
get the Group of the element.
Definition: Element.hpp:135
bool isDead()
Check if the element is dead.
Definition: Element.hpp:106
virtual void dynamicDisable()
remove this element from the physique engine
Definition: Element.hpp:227
virtual bool init()
init the element with the defined properties
virtual void drawDebug(ememory::SharedPtr< ewol::resource::Colored3DObject > _draw, ememory::SharedPtr< ege::Camera > _camera)
Debug display of the current element.
Definition: AudioElement.hpp:8
virtual void draw(int32_t _pass=0)=0
draw the curent element (can have multiple display)
virtual void elementIsRemoved(ememory::SharedPtr< ege::Element > _removedElement)
Event arrive when an element has been remove from the system == > this permit to keep pointer of enne...
Definition: Element.hpp:195
bool isFixed()
get the element if it is fixed or not. if the element is fixed this is for tower, and all thing does ...
Definition: Element.hpp:203
Element(const ememory::SharedPtr< ege::Environement > &_env)
Constructor (when constructer is called just add element that did not change. The objest will be stor...
Definition: Camera.hpp:18
virtual void dynamicEnable()
set the elment in the physique engine
Definition: Element.hpp:223
virtual void onLifeChange()
Call when the element life change.
Definition: Element.hpp:127
float getRadius()
get the current space needed by the element in the workspace
Definition: Element.hpp:213
int32_t m_group
Every element has a generic group.
Definition: Element.hpp:127
virtual bool loadMesh(const std::string &_meshFileName)
Select a mesh with a specific name.
uint32_t getUID() const
get the curent Element Unique ID in the all Game.
Definition: Element.hpp:66
virtual void drawLife(ememory::SharedPtr< ewol::resource::Colored3DObject > _draw, ememory::SharedPtr< ege::Camera > _camera)
draw the current life of the element
virtual bool needToRemove()
Request if the element might be removed from the system.
Definition: Element.hpp:113
float getLifeRatio()
get the curent life ratio [0..1]
virtual void onDestroy()
, call when the element is removed (call only one time)
Definition: Element.hpp:219
virtual void setPosition(const vec3 &_pos)
set the current position of the element
Definition: Element.hpp:190
virtual ~Element()
Destructor.
virtual const vec3 & getPosition()
get the current position of the element
virtual void setFireOn(int32_t _groupIdSource, int32_t _type, float _power, const vec3 &_center=vec3(0, 0, 0))
apply a fire on the element at a current power and a specific power.
bool m_fixe
is a fixed element == > used for placement of every elements
Definition: Element.hpp:195
float m_radius
Radius of the element (all element have a radius, if == 0 ==> then ghost ...
Definition: Element.hpp:205
virtual const std::string & getType() const
get the element Type description string.
ememory::SharedPtr< ege::resource::Mesh > m_mesh
Mesh of the Element (can be nullptr)
Definition: Element.hpp:68
ememory::SharedPtr< ege::resource::Mesh > getMesh()
get a pointer on the Mesh file.
Definition: Element.hpp:90
virtual void preCalculationDraw(const ege::Camera &_camera)
Can be call tu opdate the list of the element displayed on the scren (example : no display of the hid...
Definition: Element.hpp:151
virtual vec3 getPositionTheoric()
get the theoric position. Sometimes, the element has move due to an explosion or something else...
Definition: Element.hpp:178
virtual bool setMesh(ememory::SharedPtr< ege::resource::Mesh > _mesh)
set the the Mesh properties.
Definition: Element.hpp:28