ElementPhysic.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 #include <ege/elements/Element.hpp>
21 
22 #include <LinearMath/btDefaultMotionState.h>
23 
24 #define INDEX_RIGHT_AXIS (0)
25 #define INDEX_FORWARD_AXIS (1)
26 #define INDEX_UP_AXIS (2)
27 
28 #define ELEMENT_SCALE (1.0f/8.0f)
29 
30 namespace ege {
31  class ElementPhysic : public ege::Element {
32  private:
33  static void FunctionFreeShape(void* _pointer);
34  protected:
35  btRigidBody* m_body;
36  public:
37  void createRigidBody(float _mass=400000000.0f);
38  public:
46  ElementPhysic(const ememory::SharedPtr<ege::Environement>& _env, bool _autoRigidBody=true);
50  virtual ~ElementPhysic();
55  virtual const std::string& getType() const;
56  protected:
57  btCollisionShape* m_shape;
58  public:
65  bool setShape(btCollisionShape* _shape);
70  inline btCollisionShape* getShape() {
71  return m_shape;
72  };
73  private:
77  void removeShape();
78  public:
84  virtual void draw(int32_t _pass=0);
85 
89  // virtual void drawLife(const ememory::SharedPtr<ewol::resource::Colored3DObject>& _draw, const ememory::SharedPtr<ege::Camera>& _camera);
90  // TODO : Remove this ...
91  protected:
93  public:
99  return m_theoricPosition;
100  };
105  virtual void setPositionTheoric(const vec3& _pos) { m_theoricPosition = _pos; };
106 
111  const vec3& getSpeed();
112 
117  const float getInvMass();
118 
119  virtual void setMass(float _value);
120  virtual void setLinearVelocity(const vec3& _value);
121  virtual void setTorqueImpulse(const vec3& _value);
122  virtual void setAngularVelocity(const vec3& _value);
123 
124  btQuaternion getOrientation() const;
125 
126  protected:
127  bool m_elementInPhysicsSystem;
128  public:
129  virtual void dynamicEnable();
130  virtual void dynamicDisable();
131  private:
132  class localIA : public btActionInterface {
133  private:
134  ege::ElementPhysic& m_element;
135  public:
139  localIA(ElementPhysic& _element) :
140  m_element(_element) {
141 
142  };
146  virtual ~localIA() {
147 
148  };
149  public: // herited function
150  void debugDraw(btIDebugDraw* _debugDrawer) {
151 
152  };
153  void updateAction(btCollisionWorld* _collisionWorld, btScalar _step) {
154  m_element.iaAction(_step);
155  };
156  };
157  localIA* m_IA;
158  public:
162  void iaEnable();
166  void iaDisable();
171  virtual void iaAction(float _step) { };
175  virtual void onDestroy() {};
176  virtual const vec3& getPosition();
177  virtual void setPosition(const vec3& _pos);
179  protected:
180  void drawShape(const btCollisionShape* _shape,
182  mat4 _transformationMatrix,
183  std::vector<vec3> _tmpVertices);
184  protected:
186  public:
193  }
198  void setCollisionDetectionStatus(bool _status=true);
205  virtual void onCollisionDetected(const ememory::SharedPtr<ege::Element>& _obj, const vec3& _point, const vec3& _normal) {};
206  };
207 }
208 
209 
bool m_detectCollisionEnable
physic collision detect enable.
Definition: ElementPhysic.hpp:185
virtual void draw(int32_t _pass=0)
draw the curent element (can have multiple display)
virtual vec3 getPositionTheoric()
get the theoric position. Sometimes, the element has move due to an explosion or something else...
Definition: ElementPhysic.hpp:98
virtual void drawDebug(ememory::SharedPtr< ewol::resource::Colored3DObject > _draw, ememory::SharedPtr< ege::Camera > _camera)
Debug display of the current element.
const vec3 & getSpeed()
get the current speed of the element
btCollisionShape * getShape()
get a pointer on the bullet collision shape.
Definition: ElementPhysic.hpp:70
bool getCollisionDetectionStatus()
get collision status of the object.
Definition: ElementPhysic.hpp:191
ElementPhysic(const ememory::SharedPtr< ege::Environement > &_env, bool _autoRigidBody=true)
Constructor (when constructer is called just add element that did not change. The object will be stor...
Definition: AudioElement.hpp:8
virtual ~ElementPhysic()
Destructor.
bool setShape(btCollisionShape *_shape)
set the shape properties.
float btScalar
btCollisionShape * m_shape
shape of the element (set a copy here to have the debug display of it)
Definition: ElementPhysic.hpp:57
const float getInvMass()
get the current mass of the element
virtual void onCollisionDetected(const ememory::SharedPtr< ege::Element > &_obj, const vec3 &_point, const vec3 &_normal)
when a collision is detected with an other object (just after calculate data update ...
Definition: ElementPhysic.hpp:205
void iaEnable()
enable periodic call Of this object for processing Artificial Intelligence
void iaDisable()
disable periodic call Of this object for processing Artificial Intelligence
vec3 m_theoricPosition
draw the current life of the element
Definition: ElementPhysic.hpp:92
virtual void onDestroy()
, call when the element is removed (call only one time
Definition: ElementPhysic.hpp:175
virtual void dynamicEnable()
set the elment in the physique engine
void setCollisionDetectionStatus(bool _status=true)
Change enable status of the object.
virtual bool setMesh(ememory::SharedPtr< ege::resource::Mesh > _mesh)
set the the Mesh properties.
virtual const vec3 & getPosition()
get the current position of the element
virtual void setPositionTheoric(const vec3 &_pos)
set the current Theoric position of the element
Definition: ElementPhysic.hpp:105
Definition: ElementPhysic.hpp:31
virtual void setPosition(const vec3 &_pos)
set the current position of the element
virtual void dynamicDisable()
remove this element from the physique engine
btRigidBody * m_body
all the element have a body == > otherwise it will be not manage with this system...
Definition: ElementPhysic.hpp:35
Definition: Element.hpp:28
virtual const std::string & getType() const
get the element Type description string.
virtual void iaAction(float _step)
periodic call for intelligence artificial.
Definition: ElementPhysic.hpp:171