[DEV] add engine and separate element property

This commit is contained in:
Edouard DUPIN 2014-11-10 21:32:42 +01:00
parent ca3ead0c8c
commit bdf3a56e6b
16 changed files with 713 additions and 391 deletions

View File

@ -8,7 +8,7 @@
#include <ege/debug.h> #include <ege/debug.h>
#include <ege/Environement.h> #include <ege/Environement.h>
#include <ege/ElementGame.h> #include <ege/elements/Element.h>
#include <ewol/object/Manager.h> #include <ewol/object/Manager.h>
#include <ewol/openGL/openGL.h> #include <ewol/openGL/openGL.h>
@ -30,31 +30,31 @@
#define __class__ "Environement" #define __class__ "Environement"
std::shared_ptr<ege::ElementGame> ege::Environement::getElementNearest(std::shared_ptr<ege::ElementGame> _sourceRequest, float& _distance) { std::shared_ptr<ege::Element> ege::Environement::getElementNearest(std::shared_ptr<ege::Element> _sourceRequest, float& _distance) {
if (_sourceRequest == nullptr) { if (_sourceRequest == nullptr) {
return nullptr; return nullptr;
} }
vec3 sourcePosition = _sourceRequest->getPosition(); vec3 sourcePosition = _sourceRequest->getPosition();
std::shared_ptr<ege::ElementGame> result = nullptr; std::shared_ptr<ege::Element> result = nullptr;
for (size_t iii=0; iii<m_listElementGame.size() ; iii++) { for (size_t iii=0; iii<m_listElement.size() ; iii++) {
// chack nullptr pointer // chack nullptr pointer
if (m_listElementGame[iii] == nullptr) { if (m_listElement[iii] == nullptr) {
continue; continue;
} }
if (m_listElementGame[iii]->getGroup() <= 0) { if (m_listElement[iii]->getGroup() <= 0) {
continue; continue;
} }
// check if they are in the same group: // check if they are in the same group:
if (m_listElementGame[iii]->getGroup() == _sourceRequest->getGroup()) { if (m_listElement[iii]->getGroup() == _sourceRequest->getGroup()) {
continue; continue;
} }
// check distance ... // check distance ...
vec3 destPosition = m_listElementGame[iii]->getPosition(); vec3 destPosition = m_listElement[iii]->getPosition();
float distance = btDistance(sourcePosition, destPosition); float distance = btDistance(sourcePosition, destPosition);
//EGE_DEBUG("Distance : " << _distance << " >? " << distance << " id=" << iii); //EGE_DEBUG("Distance : " << _distance << " >? " << distance << " id=" << iii);
if (_distance>distance) { if (_distance>distance) {
_distance = distance; _distance = distance;
result = m_listElementGame[iii]; result = m_listElement[iii];
} }
} }
return result; return result;
@ -68,9 +68,9 @@ void ege::Environement::getElementNearest(const vec3& _sourcePosition,
ege::Environement::ResultNearestElement result; ege::Environement::ResultNearestElement result;
result.dist = 99999999999.0f; result.dist = 99999999999.0f;
result.element = nullptr; result.element = nullptr;
for (size_t iii=0; iii<m_listElementGame.size() ; iii++) { for (size_t iii=0; iii<m_listElement.size() ; iii++) {
// chack nullptr pointer // chack nullptr pointer
result.element = m_listElementGame[iii]; result.element = m_listElement[iii];
if (nullptr == result.element) { if (nullptr == result.element) {
continue; continue;
} }
@ -94,9 +94,9 @@ void ege::Environement::getElementNearestFixed(const vec3& _sourcePosition,
ege::Environement::ResultNearestElement result; ege::Environement::ResultNearestElement result;
result.dist = 99999999999.0f; result.dist = 99999999999.0f;
result.element = nullptr; result.element = nullptr;
for (size_t iii=0; iii<m_listElementGame.size() ; iii++) { for (size_t iii=0; iii<m_listElement.size() ; iii++) {
// chack nullptr pointer // chack nullptr pointer
result.element = m_listElementGame[iii]; result.element = m_listElement[iii];
if (result.element == nullptr) { if (result.element == nullptr) {
continue; continue;
} }
@ -140,7 +140,7 @@ void ege::Environement::addCreator(const std::string& _type, ege::createElement_
EGE_DEBUG("Add creator: " << _type << " (done)"); EGE_DEBUG("Add creator: " << _type << " (done)");
} }
std::shared_ptr<ege::ElementGame> ege::Environement::createElement(const std::string& _type, bool _autoAddElement, enum ege::property _property, void* _value) { std::shared_ptr<ege::Element> ege::Environement::createElement(const std::string& _type, bool _autoAddElement, enum ege::property _property, void* _value) {
if (false == getHachTableCreating().exist(_type)) { if (false == getHachTableCreating().exist(_type)) {
EGE_ERROR("Request creating of an type that is not known '" << _type << "'"); EGE_ERROR("Request creating of an type that is not known '" << _type << "'");
return nullptr; return nullptr;
@ -150,7 +150,7 @@ std::shared_ptr<ege::ElementGame> ege::Environement::createElement(const std::st
EGE_ERROR("nullptr pointer creator == > internal error... '" << _type << "'"); EGE_ERROR("nullptr pointer creator == > internal error... '" << _type << "'");
return nullptr; return nullptr;
} }
std::shared_ptr<ege::ElementGame> tmpElement = creatorPointer(std::dynamic_pointer_cast<ege::Environement>(shared_from_this())); std::shared_ptr<ege::Element> tmpElement = creatorPointer(std::dynamic_pointer_cast<ege::Environement>(shared_from_this()));
if (tmpElement == nullptr) { if (tmpElement == nullptr) {
EGE_ERROR("allocation error '" << _type << "'"); EGE_ERROR("allocation error '" << _type << "'");
return nullptr; return nullptr;
@ -160,57 +160,57 @@ std::shared_ptr<ege::ElementGame> ege::Environement::createElement(const std::st
return nullptr; return nullptr;
} }
if (_autoAddElement == true) { if (_autoAddElement == true) {
addElementGame(tmpElement); addElement(tmpElement);
} }
return tmpElement; return tmpElement;
} }
std::shared_ptr<ege::ElementGame> ege::Environement::createElement(const std::string& _type, std::string& _description, bool _autoAddElement) { std::shared_ptr<ege::Element> ege::Environement::createElement(const std::string& _type, std::string& _description, bool _autoAddElement) {
return createElement(_type, _autoAddElement, ege::typeString, static_cast<void*>(&_description)); return createElement(_type, _autoAddElement, ege::typeString, static_cast<void*>(&_description));
} }
std::shared_ptr<ege::ElementGame> ege::Environement::createElement(const std::string& _type, ejson::Value* _value, bool _autoAddElement) { std::shared_ptr<ege::Element> ege::Environement::createElement(const std::string& _type, ejson::Value* _value, bool _autoAddElement) {
return createElement(_type, _autoAddElement, ege::typeJson, static_cast<void*>(_value)); return createElement(_type, _autoAddElement, ege::typeJson, static_cast<void*>(_value));
} }
std::shared_ptr<ege::ElementGame> ege::Environement::createElement(const std::string& _type, exml::Node* _node, bool _autoAddElement) { std::shared_ptr<ege::Element> ege::Environement::createElement(const std::string& _type, exml::Node* _node, bool _autoAddElement) {
return createElement(_type, _autoAddElement, ege::typeXml, static_cast<void*>(_node)); return createElement(_type, _autoAddElement, ege::typeXml, static_cast<void*>(_node));
} }
void ege::Environement::addElementGame(std::shared_ptr<ege::ElementGame> _newElement) { void ege::Environement::addElement(std::shared_ptr<ege::Element> _newElement) {
// prevent memory allocation and un allocation ... // prevent memory allocation and un allocation ...
if (_newElement == nullptr) { if (_newElement == nullptr) {
return; return;
} }
for (size_t iii=0; iii<m_listElementGame.size() ; iii++) { for (size_t iii=0; iii<m_listElement.size() ; iii++) {
if (m_listElementGame[iii] == nullptr) { if (m_listElement[iii] == nullptr) {
m_listElementGame[iii] = _newElement; m_listElement[iii] = _newElement;
m_listElementGame[iii]->dynamicEnable(); m_listElement[iii]->dynamicEnable();
return; return;
} }
} }
m_listElementGame.push_back(_newElement); m_listElement.push_back(_newElement);
_newElement->dynamicEnable(); _newElement->dynamicEnable();
} }
void ege::Environement::rmElementGame(std::shared_ptr<ege::ElementGame> _removeElement) { void ege::Environement::rmElement(std::shared_ptr<ege::Element> _removeElement) {
if (_removeElement == nullptr) { if (_removeElement == nullptr) {
return; return;
} }
// inform the element that an element has been removed == > this permit to keep pointer on elements ... // inform the element that an element has been removed == > this permit to keep pointer on elements ...
for (size_t iii=0; iii<m_listElementGame.size() ; iii++) { for (size_t iii=0; iii<m_listElement.size() ; iii++) {
if (m_listElementGame[iii] != nullptr) { if (m_listElement[iii] != nullptr) {
m_listElementGame[iii]->elementIsRemoved(_removeElement); m_listElement[iii]->elementIsRemoved(_removeElement);
} }
} }
// ream remove on the element : // ream remove on the element :
for (size_t iii=0; iii<m_listElementGame.size() ; iii++) { for (size_t iii=0; iii<m_listElement.size() ; iii++) {
if (_removeElement == m_listElementGame[iii]) { if (_removeElement == m_listElement[iii]) {
m_listElementGame[iii]->onDestroy(); m_listElement[iii]->onDestroy();
m_listElementGame[iii]->dynamicDisable(); m_listElement[iii]->dynamicDisable();
m_listElementGame[iii]->unInit(); m_listElement[iii]->unInit();
m_listElementGame[iii].reset(); m_listElement[iii].reset();
} }
} }
} }
@ -219,6 +219,7 @@ void ege::Environement::rmElementGame(std::shared_ptr<ege::ElementGame> _removeE
void ege::Environement::getOrderedElementForDisplay(std::vector<ege::Environement::ResultNearestElement>& _resultList, void ege::Environement::getOrderedElementForDisplay(std::vector<ege::Environement::ResultNearestElement>& _resultList,
const vec3& _position, const vec3& _position,
const vec3& _direction) { const vec3& _direction) {
// TODO : Set it back ... corrected...
// remove all unneeded elements (old display...) // remove all unneeded elements (old display...)
_resultList.clear(); _resultList.clear();
// basic element result // basic element result
@ -226,27 +227,31 @@ void ege::Environement::getOrderedElementForDisplay(std::vector<ege::Environemen
result.dist = 99999999999.0f; result.dist = 99999999999.0f;
result.element = nullptr; result.element = nullptr;
// for all element in the game we chek if it is needed to display it ... // for all element in the game we chek if it is needed to display it ...
for (size_t iii=0; iii<m_listElementGame.size() ; iii++) { for (size_t iii=0; iii<m_listElement.size() ; iii++) {
// chack nullptr pointer // chack nullptr pointer
if (nullptr == m_listElementGame[iii]) { if (nullptr == m_listElement[iii]) {
// no pointer null are set in the output list ... // no pointer null are set in the output list ...
continue; continue;
} }
result.element = m_listElementGame[iii]; result.element = m_listElement[iii];
// check distance ... // check distance ...
vec3 destPosition = result.element->getPosition(); vec3 destPosition = result.element->getPosition();
vec3 angleView = (destPosition - _position).normalized(); vec3 angleView = (destPosition - _position).normalized();
float dotResult=angleView.dot(_direction); float dotResult=angleView.dot(_direction);
//EGE_DEBUG("Dot position : " << destPosition << " == > dot=" << dotResult); //EGE_DEBUG("Dot position : " << destPosition << " == > dot=" << dotResult);
/*
if (dotResult <= 0.85f) { if (dotResult <= 0.85f) {
// they are not in the camera angle view ... == > no need to process display // they are not in the camera angle view ... == > no need to process display
continue; continue;
} }
*/
result.dist = btDistance(_position, destPosition); result.dist = btDistance(_position, destPosition);
/*
if (result.dist>500.0f) { if (result.dist>500.0f) {
// The element is realy too far ... == > no need to display // The element is realy too far ... == > no need to display
continue; continue;
} }
*/
// try to add the element at the best positions: // try to add the element at the best positions:
size_t jjj; size_t jjj;
for (jjj=0; jjj<_resultList.size(); jjj++) { for (jjj=0; jjj<_resultList.size(); jjj++) {
@ -265,27 +270,26 @@ void ege::Environement::getOrderedElementForDisplay(std::vector<ege::Environemen
void ege::Environement::generateInteraction(ege::ElementInteraction& _event) { void ege::Environement::generateInteraction(ege::ElementInteraction& _event) {
// inform the element that an element has been removed == > this permit to keep pointer on elements ... // inform the element that an element has been removed == > this permit to keep pointer on elements ...
for (size_t iii=0; iii<m_listElementGame.size() ; iii++) { for (size_t iii=0; iii<m_listElement.size() ; iii++) {
if (nullptr == m_listElementGame[iii]) { if (nullptr == m_listElement[iii]) {
continue; continue;
} }
_event.applyEvent(*m_listElementGame[iii]); _event.applyEvent(*m_listElement[iii]);
/* /*
vec3 destPosition = m_listElementGame[iii]->getPosition(); vec3 destPosition = m_listElement[iii]->getPosition();
float dist = btDistance(sourcePosition, destPosition); float dist = btDistance(sourcePosition, destPosition);
if (dist == 0 || dist>decreasePower) { if (dist == 0 || dist>decreasePower) {
continue; continue;
} }
float inpact = (decreasePower-dist)/decreasePower * power; float inpact = (decreasePower-dist)/decreasePower * power;
g_listElementGame[iii]->setFireOn(groupIdSource, type, -inpact, sourcePosition); g_listElement[iii]->setFireOn(groupIdSource, type, -inpact, sourcePosition);
*/ */
} }
} }
ege::Environement::Environement() : ege::Environement::Environement() :
signalPlayTimeChange(*this, "time-change"), signalPlayTimeChange(*this, "time-change"),
m_dynamicsWorld(), m_listElement(),
m_listElementGame(),
m_status(*this, "status", gameStart, "Satus of the activity of the Environement"), m_status(*this, "status", gameStart, "Satus of the activity of the Environement"),
m_ratio(*this, "ratio", 1.0f, "game speed ratio"), m_ratio(*this, "ratio", 1.0f, "game speed ratio"),
m_particuleEngine(*this) { m_particuleEngine(*this) {
@ -301,7 +305,7 @@ void ege::Environement::init() {
} }
void ege::Environement::clear() { void ege::Environement::clear() {
m_listElementGame.clear(); m_listElement.clear();
} }
@ -330,18 +334,18 @@ void ege::Environement::periodicCall(const ewol::event::Time& _event) {
} }
//EGE_DEBUG("stepSimulation (start)"); //EGE_DEBUG("stepSimulation (start)");
///step the simulation ///step the simulation
if (m_dynamicsWorld != nullptr) { if (m_physicEngine.getDynamicWorld() != nullptr) {
m_dynamicsWorld->stepSimulation(curentDelta); m_physicEngine.getDynamicWorld()->stepSimulation(curentDelta);
//optional but useful: debug drawing //optional but useful: debug drawing
m_dynamicsWorld->debugDrawWorld(); m_physicEngine.getDynamicWorld()->debugDrawWorld();
} }
m_particuleEngine.update(curentDelta); m_particuleEngine.update(curentDelta);
// remove all element that requested it ... // remove all element that requested it ...
{ {
int32_t numberEnnemyKilled=0; int32_t numberEnnemyKilled=0;
int32_t victoryPoint=0; int32_t victoryPoint=0;
auto it(m_listElementGame.begin()); auto it(m_listElement.begin());
while (it != m_listElementGame.end()) { while (it != m_listElement.end()) {
if(*it != nullptr) { if(*it != nullptr) {
if ((*it)->needToRemove() == true) { if ((*it)->needToRemove() == true) {
if ((*it)->getGroup() > 1) { if ((*it)->getGroup() > 1) {
@ -349,7 +353,10 @@ void ege::Environement::periodicCall(const ewol::event::Time& _event) {
victoryPoint++; victoryPoint++;
} }
EGE_DEBUG("[" << (*it)->getUID() << "] element Removing ... " << (*it)->getType()); EGE_DEBUG("[" << (*it)->getUID() << "] element Removing ... " << (*it)->getType());
rmElementGame((*it)); rmElement((*it));
it = m_listElement.begin();
} else {
++it;
} }
} }
} }

View File

@ -29,6 +29,7 @@ class btDynamicsWorld;
#include <ewol/event/Time.h> #include <ewol/event/Time.h>
#include <ewol/parameter/Value.h> #include <ewol/parameter/Value.h>
#include <ege/resource/Mesh.h> #include <ege/resource/Mesh.h>
#include <ege/physics/Engine.h>
namespace ege { namespace ege {
enum property { enum property {
@ -39,9 +40,9 @@ namespace ege {
typeUser1, //!< user type 1 typeUser1, //!< user type 1
typeUser2 //!< User type 2 typeUser2 //!< User type 2
}; };
class ElementGame; class Element;
class Environement; class Environement;
typedef std::shared_ptr<ege::ElementGame> (*createElement_tf)(const std::shared_ptr<ege::Environement>& _env); typedef std::shared_ptr<ege::Element> (*createElement_tf)(const std::shared_ptr<ege::Environement>& _env);
enum gameStatus { enum gameStatus {
gameStart, gameStart,
@ -84,7 +85,7 @@ namespace ege {
m_positionSource(_pos) m_positionSource(_pos)
{ }; { };
public: public:
virtual void applyEvent(ege::ElementGame& _element) { }; virtual void applyEvent(ege::Element& _element) { };
}; };
class Environement : public ewol::Object { class Environement : public ewol::Object {
@ -92,8 +93,9 @@ namespace ege {
// extern event // extern event
ewol::Signal<float> signalPlayTimeChange; ewol::Signal<float> signalPlayTimeChange;
private: private:
std::shared_ptr<btDynamicsWorld> m_dynamicsWorld; //!< curent system world description //std::shared_ptr<btDynamicsWorld> m_dynamicsWorld; //!< curent system world description
std::vector<std::shared_ptr<ege::ElementGame>> m_listElementGame; //!< List of all element added in the Game ege::physics::Engine m_physicEngine; //!< EGE physic engine interface.
std::vector<std::shared_ptr<ege::Element>> m_listElement; //!< List of all element added in the Game
protected: protected:
Environement(); Environement();
void init(); void init();
@ -168,16 +170,17 @@ namespace ege {
* @return nullptr if an error occured OR the pointer on the element and it is already added on the system. * @return nullptr if an error occured OR the pointer on the element and it is already added on the system.
* @note Pointer is return in case of setting properties on it... * @note Pointer is return in case of setting properties on it...
*/ */
std::shared_ptr<ege::ElementGame> createElement(const std::string& _type, bool _autoAddElement=true, enum ege::property _property=ege::typeNone, void* _value=nullptr); std::shared_ptr<ege::Element> createElement(const std::string& _type, bool _autoAddElement=true, enum ege::property _property=ege::typeNone, void* _value=nullptr);
std::shared_ptr<ege::ElementGame> createElement(const std::string& _type, std::string& _description, bool _autoAddElement=true); std::shared_ptr<ege::Element> createElement(const std::string& _type, std::string& _description, bool _autoAddElement=true);
std::shared_ptr<ege::ElementGame> createElement(const std::string& _type, ejson::Value* _value, bool _autoAddElement=true); std::shared_ptr<ege::Element> createElement(const std::string& _type, ejson::Value* _value, bool _autoAddElement=true);
std::shared_ptr<ege::ElementGame> createElement(const std::string& _type, exml::Node* _node, bool _autoAddElement=true); std::shared_ptr<ege::Element> createElement(const std::string& _type, exml::Node* _node, bool _autoAddElement=true);
public: public:
class ResultNearestElement { class ResultNearestElement {
public: public:
std::shared_ptr<ege::ElementGame> element; std::shared_ptr<ege::Element> element;
float dist; float dist;
}; };
#if 0
/** /**
* @brief set the curent world * @brief set the curent world
* @param[in] _newWorld Pointer on the current world * @param[in] _newWorld Pointer on the current world
@ -192,12 +195,16 @@ namespace ege {
std::shared_ptr<btDynamicsWorld> getDynamicWorld() { std::shared_ptr<btDynamicsWorld> getDynamicWorld() {
return m_dynamicsWorld; return m_dynamicsWorld;
}; };
#endif
ege::physics::Engine& getPhysicEngine() {
return m_physicEngine;
}
/** /**
* @breif get a reference on the curent list of element games * @breif get a reference on the curent list of element games
* @return all element list * @return all element list
*/ */
std::vector<std::shared_ptr<ege::ElementGame>>& getElementGame() { std::vector<std::shared_ptr<ege::Element>>& getElement() {
return m_listElementGame; return m_listElement;
}; };
/** /**
* @brief get the nearest Element * @brief get the nearest Element
@ -205,7 +212,7 @@ namespace ege {
* @param[in] _distance Maximum distance search == > return the element distance * @param[in] _distance Maximum distance search == > return the element distance
* @return Pointer on the neares element OR nullptr * @return Pointer on the neares element OR nullptr
*/ */
std::shared_ptr<ege::ElementGame> getElementNearest(std::shared_ptr<ege::ElementGame> _sourceRequest, float& _distance); std::shared_ptr<ege::Element> getElementNearest(std::shared_ptr<ege::Element> _sourceRequest, float& _distance);
void getElementNearest(const vec3& _sourcePosition, void getElementNearest(const vec3& _sourcePosition,
float _distanceMax, float _distanceMax,
@ -217,12 +224,12 @@ namespace ege {
* @brief add an element on the list availlable. * @brief add an element on the list availlable.
* @param[in] _newElement Element to add. * @param[in] _newElement Element to add.
*/ */
void addElementGame(std::shared_ptr<ege::ElementGame> _newElement); void addElement(std::shared_ptr<ege::Element> _newElement);
/** /**
* @brief remove an element on the list availlable. * @brief remove an element on the list availlable.
* @param[in] _removeElement Element to remove. * @param[in] _removeElement Element to remove.
*/ */
void rmElementGame(std::shared_ptr<ege::ElementGame> _removeElement); void rmElement(std::shared_ptr<ege::Element> _removeElement);
/** /**
* @brief get the element order from the nearest to the farest, and remove all element that are not in the camera angle and axes. * @brief get the element order from the nearest to the farest, and remove all element that are not in the camera angle and axes.
* @param[in,out] _resultList List of the element ordered. * @param[in,out] _resultList List of the element ordered.

View File

@ -32,7 +32,7 @@ void ege::camera::View::update() {
m_matrix.translate(vec3(0,0,-distance)); m_matrix.translate(vec3(0,0,-distance));
m_matrix.rotate(vec3(1,0,0), -M_PI*0.5f + psy); m_matrix.rotate(vec3(1,0,0), -M_PI*0.5f + psy);
m_matrix.rotate(vec3(0,0,1), tetha); m_matrix.rotate(vec3(0,0,1), tetha);
m_matrix.translate(m_target); m_matrix.translate(-m_target);
EGE_DEBUG("Camera properties : distance=" << distance ); EGE_DEBUG("Camera properties : distance=" << distance );
EGE_DEBUG(" psy=" << psy); EGE_DEBUG(" psy=" << psy);

209
ege/elements/Element.cpp Normal file
View File

@ -0,0 +1,209 @@
/**
* @author Edouard DUPIN
*
* @copyright 2011, Edouard DUPIN, all right reserved
*
* @license BSD v3 (see license file)
*/
#include <etk/types.h>
#include <ege/debug.h>
#include <ege/elements/Element.h>
#include <ege/Environement.h>
#include <BulletDynamics/Dynamics/btRigidBody.h>
#include <LinearMath/btDefaultMotionState.h>
#include <BulletDynamics/Dynamics/btDynamicsWorld.h>
#include <BulletCollision/CollisionShapes/btCollisionShape.h>
#include <LinearMath/btIDebugDraw.h>
#include <btBulletCollisionCommon.h>
#include <BulletCollision/CollisionShapes/btConvexPolyhedron.h>
#include <BulletCollision/CollisionShapes/btShapeHull.h>
#include <LinearMath/btTransformUtil.h>
#include <LinearMath/btIDebugDraw.h>
#include <btBulletDynamicsCommon.h>
#include <BulletCollision/CollisionDispatch/btCollisionObject.h>
#include <ege/CollisionShapeCreator.h>
#undef __class__
#define __class__ "Element"
const std::string& ege::Element::getType() const {
static const std::string nameType("----");
return nameType;
}
ege::Element::Element(const std::shared_ptr<ege::Environement>& _env) :
m_env(_env),
m_uID(0),
m_mesh(),
m_life(100),
m_lifeMax(100),
m_group(0),
m_fixe(true),
m_radius(0) {
static uint32_t unique=0;
m_uID = unique;
EGE_DEBUG("Create element : uId=" << m_uID);
m_debugText.setFontSize(12);
unique++;
}
ege::Element::~Element() {
EGE_DEBUG("Destroy element : uId=" << m_uID);
}
bool ege::Element::loadMesh(const std::string& _meshFileName) {
std::shared_ptr<ege::resource::Mesh> tmpMesh = ege::resource::Mesh::create(_meshFileName);
if(nullptr == tmpMesh) {
EGE_ERROR("can not load the resources : " << _meshFileName);
return false;
}
return setMesh(tmpMesh);
}
bool ege::Element::setMesh(const std::shared_ptr<ege::resource::Mesh>& _mesh) {
if (nullptr!=m_mesh) {
m_mesh.reset();
}
m_mesh = _mesh;
// auto load the shape :
if (m_mesh == nullptr) {
return true;
}
return true;
}
float ege::Element::getLifeRatio() {
if (0 >= m_life) {
return 0;
}
return m_life/m_lifeMax;
}
void ege::Element::setFireOn(int32_t _groupIdSource, int32_t _type, float _power, const vec3& _center) {
float previousLife = m_life;
m_life += _power;
m_life = std::avg(0.0f, m_life, m_lifeMax);
if (m_life <= 0) {
EGE_DEBUG("[" << getUID() << "] element is killed ..." << getType());
}
if (m_life!=previousLife) {
onLifeChange();
}
}
const vec3& ege::Element::getPosition() {
// this is to prevent error like segmentation fault ...
static vec3 emptyPosition(-1000000,-1000000,-1000000);
return emptyPosition;
};
static void drawSphere(const std::shared_ptr<ewol::resource::Colored3DObject>& _draw,
btScalar _radius,
int _lats,
int _longs,
mat4& _transformationMatrix,
etk::Color<float>& _tmpColor) {
int i, j;
std::vector<vec3> EwolVertices;
for(i = 0; i <= _lats; i++) {
btScalar lat0 = SIMD_PI * (-btScalar(0.5) + (btScalar) (i - 1) / _lats);
btScalar z0 = _radius*sin(lat0);
btScalar zr0 = _radius*cos(lat0);
btScalar lat1 = SIMD_PI * (-btScalar(0.5) + (btScalar) i / _lats);
btScalar z1 = _radius*sin(lat1);
btScalar zr1 = _radius*cos(lat1);
//glBegin(GL_QUAD_STRIP);
for(j = 0; j < _longs; j++) {
btScalar lng = 2 * SIMD_PI * (btScalar) (j - 1) / _longs;
btScalar x = cos(lng);
btScalar y = sin(lng);
vec3 v1 = vec3(x * zr1, y * zr1, z1);
vec3 v4 = vec3(x * zr0, y * zr0, z0);
lng = 2 * SIMD_PI * (btScalar) (j) / _longs;
x = cos(lng);
y = sin(lng);
vec3 v2 = vec3(x * zr1, y * zr1, z1);
vec3 v3 = vec3(x * zr0, y * zr0, z0);
EwolVertices.push_back(v1);
EwolVertices.push_back(v2);
EwolVertices.push_back(v3);
EwolVertices.push_back(v1);
EwolVertices.push_back(v3);
EwolVertices.push_back(v4);
}
}
_draw->draw(EwolVertices, _tmpColor, _transformationMatrix);
}
const float lifeBorder = 0.1f;
const float lifeHeight = 0.3f;
const float lifeWidth = 2.0f;
const float lifeYPos = 1.7f;
void ege::Element::drawLife(const std::shared_ptr<ewol::resource::Colored3DObject>& _draw, const ege::Camera& _camera) {
if (nullptr == _draw) {
return;
}
float ratio = getLifeRatio();
if (ratio == 1.0f) {
return;
}
#if 0
mat4 transformationMatrix = etk::matTranslate(getPosition())
* etk::matRotate(vec3(0,0,1),_camera.getAngleZ())
* etk::matRotate(vec3(1,0,0),(M_PI/2.0f-_camera.getAngleTeta()));
std::vector<vec3> localVertices;
localVertices.push_back(vec3(-lifeWidth/2.0-lifeBorder,lifeYPos -lifeBorder,0));
localVertices.push_back(vec3(-lifeWidth/2.0-lifeBorder,lifeYPos+lifeHeight+lifeBorder,0));
localVertices.push_back(vec3( lifeWidth/2.0+lifeBorder,lifeYPos+lifeHeight+lifeBorder,0));
localVertices.push_back(vec3(-lifeWidth/2.0-lifeBorder,lifeYPos -lifeBorder,0));
localVertices.push_back(vec3( lifeWidth/2.0+lifeBorder,lifeYPos+lifeHeight+lifeBorder,0));
localVertices.push_back(vec3( lifeWidth/2.0+lifeBorder,lifeYPos -lifeBorder,0));
etk::Color<float> myColor(0x0000FF99);
_draw->draw(localVertices, myColor, transformationMatrix, false, false);
localVertices.clear();
/** Bounding box == > model shape **/
localVertices.push_back(vec3(-lifeWidth/2.0 ,lifeYPos,0));
localVertices.push_back(vec3(-lifeWidth/2.0 ,lifeYPos + lifeHeight,0));
localVertices.push_back(vec3(-lifeWidth/2.0+lifeWidth*ratio,lifeYPos + lifeHeight,0));
localVertices.push_back(vec3(-lifeWidth/2.0 ,lifeYPos,0));
localVertices.push_back(vec3(-lifeWidth/2.0+lifeWidth*ratio,lifeYPos + lifeHeight,0));
localVertices.push_back(vec3(-lifeWidth/2.0+lifeWidth*ratio,lifeYPos,0));
myColor =0x00FF00FF;
if (ratio < 0.2f) {
myColor = 0xFF0000FF;
} else if (ratio < 0.4f) {
myColor = 0xDA7B00FF;
}
_draw->draw(localVertices, myColor, transformationMatrix, false, false);
#endif
}
void ege::Element::drawDebug(const std::shared_ptr<ewol::resource::Colored3DObject>& _draw, const ege::Camera& _camera) {
m_debugText.clear();
m_debugText.setColor(etk::Color<>(0x00, 0xFF, 0x00, 0xFF));
m_debugText.setPos(vec3(-20,32,0));
m_debugText.print(getType());
m_debugText.setPos(vec3(-20,20,0));
m_debugText.print("life=("+etk::to_string(getLifeRatio()));
//m_debugText.print(std::string("Axe=(")+std::string(m_tmpAxe.x())+std::string(",")+etk::UString(m_tmpAxe.y())+etk::UString(",")+etk::UString(m_tmpAxe.z())+etk::UString(")"));
/*
m_debugText.draw( etk::matTranslate(getPosition())
* etk::matRotate(vec3(0,0,1),_camera.getAngleZ())
* etk::matRotate(vec3(1,0,0),(M_PI/2.0f-_camera.getAngleTeta()))
* etk::matScale(vec3(0.05,0.05,0.05)));
*/
}

View File

@ -6,8 +6,8 @@
* @license BSD v3 (see license file) * @license BSD v3 (see license file)
*/ */
#ifndef __EGE_ELEMENT_GAME_H__ #ifndef __EGE_ELEMENT_H__
#define __EGE_ELEMENT_GAME_H__ #define __EGE_ELEMENT_H__
#include <etk/types.h> #include <etk/types.h>
#include <etk/math/Vector3D.h> #include <etk/math/Vector3D.h>
@ -29,24 +29,20 @@
#define ELEMENT_SCALE (1.0f/8.0f) #define ELEMENT_SCALE (1.0f/8.0f)
namespace ege { namespace ege {
class ElementGame { class Element {
private:
static void FunctionFreeShape(void* _pointer);
protected: protected:
std::shared_ptr<ege::Environement> m_env; std::shared_ptr<ege::Environement> m_env;
protected:
btRigidBody* m_body; //!< all the element have a body == > otherwise it will be not manage with this system...
public: public:
/** /**
* @brief Constructor (when constructer is called just add element that did not change. * @brief Constructor (when constructer is called just add element that did not change.
* The objest will be stored in a pool of element and keep a second time if needed == > redure memory allocation, * The objest will be stored in a pool of element and keep a second time if needed == > redure memory allocation,
* when needed, the system will call the init and un-init function... * when needed, the system will call the init and un-init function...
*/ */
ElementGame(const std::shared_ptr<ege::Environement>& _env); Element(const std::shared_ptr<ege::Environement>& _env);
/** /**
* @brief Destructor * @brief Destructor
*/ */
virtual ~ElementGame(); virtual ~Element();
/** /**
* @brief get the element Type description string. * @brief get the element Type description string.
* @return A reference on the descriptive string. * @return A reference on the descriptive string.
@ -76,7 +72,6 @@ namespace ege {
}; };
protected: protected:
std::shared_ptr<ege::resource::Mesh> m_mesh; //!< Mesh of the Element (can be nullptr) std::shared_ptr<ege::resource::Mesh> m_mesh; //!< Mesh of the Element (can be nullptr)
btCollisionShape* m_shape; //!< shape of the element (set a copy here to have the debug display of it)
public: public:
/** /**
* @brief Select a mesh with a specific name. * @brief Select a mesh with a specific name.
@ -84,21 +79,14 @@ namespace ege {
* @note Automaticly load the shape if it is specify in the mesh file * @note Automaticly load the shape if it is specify in the mesh file
* @return true if no error occured * @return true if no error occured
*/ */
bool loadMesh(const std::string& _meshFileName); virtual bool loadMesh(const std::string& _meshFileName);
/** /**
* @brief set the the Mesh properties. * @brief set the the Mesh properties.
* @param[in] _mesh The mesh pointer. (nullptr to force the mesh remove ...) * @param[in] _mesh The mesh pointer. (nullptr to force the mesh remove ...)
* @note : this remove the shape and the mesh properties. * @note : this remove the shape and the mesh properties.
* @return true if no error occured * @return true if no error occured
*/ */
bool setMesh(const std::shared_ptr<ege::resource::Mesh>& _mesh); virtual bool setMesh(const std::shared_ptr<ege::resource::Mesh>& _mesh);
/**
* @brief set the shape properties.
* @param[in] _shape The shape pointer.
* @note : this remove the shape properties.
* @return true if no error occured
*/
bool setShape(btCollisionShape* _shape);
/** /**
* @brief get a pointer on the Mesh file. * @brief get a pointer on the Mesh file.
* @return the mesh pointer. * @return the mesh pointer.
@ -106,18 +94,6 @@ namespace ege {
inline const std::shared_ptr<ege::resource::Mesh>& getMesh() { inline const std::shared_ptr<ege::resource::Mesh>& getMesh() {
return m_mesh; return m_mesh;
}; };
/**
* @brief get a pointer on the bullet collision shape.
* @return the collision pointer.
*/
inline btCollisionShape* getShape() {
return m_shape;
};
private:
/**
* @brief remove the curent selected shape.
*/
void removeShape();
protected: protected:
float m_life; //!< Current life of the object float m_life; //!< Current life of the object
float m_lifeMax; //!< Maximum possible life of the element float m_lifeMax; //!< Maximum possible life of the element
@ -150,7 +126,7 @@ namespace ege {
*/ */
virtual void setFireOn(int32_t _groupIdSource, int32_t _type, float _power, const vec3& _center=vec3(0,0,0)); virtual void setFireOn(int32_t _groupIdSource, int32_t _type, float _power, const vec3& _center=vec3(0,0,0));
/** /**
* @brief Call chan the element life change * @brief Call when the element life change.
*/ */
virtual void onLifeChange() { }; virtual void onLifeChange() { };
protected: protected:
@ -170,7 +146,7 @@ namespace ege {
inline void setGroup(int32_t _newGroup) { inline void setGroup(int32_t _newGroup) {
m_group=_newGroup; m_group=_newGroup;
}; };
public:
/** /**
* @brief Can be call tu opdate the list of the element displayed on the scren (example : no display of the hiden triangle) * @brief Can be call tu opdate the list of the element displayed on the scren (example : no display of the hiden triangle)
* @param[in] the camera properties * @param[in] the camera properties
@ -181,11 +157,12 @@ namespace ege {
* @brief draw the curent element (can have multiple display) * @brief draw the curent element (can have multiple display)
* @param[in] pass Id of the current pass : [0..?] * @param[in] pass Id of the current pass : [0..?]
*/ */
virtual void draw(int32_t _pass=0); virtual void draw(int32_t _pass=0) = 0;
/** /**
* @brief draw the current life of the element * @brief draw the current life of the element
*/ */
// TODO : Remove this ...
virtual void drawLife(const std::shared_ptr<ewol::resource::Colored3DObject>& _draw, const ege::Camera& _camera); virtual void drawLife(const std::shared_ptr<ewol::resource::Colored3DObject>& _draw, const ege::Camera& _camera);
protected: protected:
@ -205,36 +182,21 @@ namespace ege {
virtual vec3 getPositionTheoric() { virtual vec3 getPositionTheoric() {
return getPosition(); return getPosition();
}; };
/**
* @brief set the current Theoric position of the element
* @param[in] set the 3D position.
*/
virtual void setPositionTheoric(const vec3& _pos) { };
/** /**
* @brief get the current position of the element * @brief get the current position of the element
* @return the 3D position. * @return the 3D position.
*/ */
const vec3& getPosition(); virtual const vec3& getPosition();
/** /**
* @brief set the current position of the element * @brief set the current position of the element
* @param[in] _pos set the 3D position. * @param[in] _pos set the 3D position.
*/ */
void setPosition(const vec3& _pos); virtual void setPosition(const vec3& _pos) {};
/**
* @brief get the current speed of the element
* @return the 3D speed.
*/
const vec3& getSpeed();
/**
* @brief get the current mass of the element
* @return the mass in kG.
*/
const float getInvMass();
/** /**
* @brief Event arrive when an element has been remove from the system == > this permit to keep pointer of ennemy, and not search them every cycle ... * @brief Event arrive when an element has been remove from the system == > this permit to keep pointer of ennemy, and not search them every cycle ...
* @param[in] _removedElement Pointer on the element removed. * @param[in] _removedElement Pointer on the element removed.
*/ */
virtual void elementIsRemoved(std::shared_ptr<ege::ElementGame> _removedElement) { }; virtual void elementIsRemoved(std::shared_ptr<ege::Element> _removedElement) { };
protected: protected:
bool m_fixe; //!< is a fixed element == > used for placement of every elements bool m_fixe; //!< is a fixed element == > used for placement of every elements
public: public:
@ -252,66 +214,21 @@ namespace ege {
* @brief get the current space needed by the element in the workspace * @brief get the current space needed by the element in the workspace
* @return The dimention needed. * @return The dimention needed.
*/ */
inline float getRadius() inline float getRadius() {
{
return m_radius; return m_radius;
}; };
protected: /**
bool m_elementInPhysicsSystem; * @brief, call when the element is removed (call only one time)
public: */
virtual void onDestroy() {};
/** /**
* @brief set the elment in the physique engine * @brief set the elment in the physique engine
*/ */
void dynamicEnable(); virtual void dynamicEnable() {};
/** /**
* @brief remove this element from the physique engine * @brief remove this element from the physique engine
*/ */
void dynamicDisable(); virtual void dynamicDisable() {};
private:
class localIA : public btActionInterface {
private:
ege::ElementGame& m_element;
public:
/**
* @brief Constructor
*/
localIA(ElementGame& _element) :
m_element(_element) {
};
/**
* @brief Destructor
*/
virtual ~localIA() {
};
public: // herited function
void debugDraw(btIDebugDraw* _debugDrawer) {
};
void updateAction(btCollisionWorld* _collisionWorld, btScalar _step) {
m_element.iaAction(_step);
};
};
localIA* m_IA;
public:
/**
* @brief enable periodic call Of this object for processing Artificial Intelligence
*/
void iaEnable();
/**
* @brief disable periodic call Of this object for processing Artificial Intelligence
*/
void iaDisable();
/**
* @brief periodic call for intelligence artificial.
* @param[in] step : step of time in s
*/
virtual void iaAction(float _step) { };
/**
* @brief, call when the element is removed (call only one time
*/
virtual void onDestroy() {};
}; };
}; };

View File

@ -0,0 +1,44 @@
/**
* @author Edouard DUPIN
*
* @copyright 2011, Edouard DUPIN, all right reserved
*
* @license BSD v3 (see license file)
*/
#include <ege/elements/ElementBase.h>
#include <ege/debug.h>
ege::ElementBase::ElementBase(const std::shared_ptr<ege::Environement>& _env) :
ege::Element(_env),
m_position(0,0,0) {
}
ege::ElementBase::~ElementBase() {
EGE_WARNING("Remove ... ");
}
const std::string& ege::ElementBase::getType() const {
return ege::Element::getType();
}
void ege::ElementBase::draw(int32_t _pass) {
mat4 transformationMatrix(0);
transformationMatrix.identity();
transformationMatrix.translate(m_position);
//transformationMatrix.transpose();
m_mesh->draw(transformationMatrix);
EGE_VERBOSE("draw ... " << transformationMatrix);
}
const vec3& ege::ElementBase::getPosition() {
return m_position;
}
void ege::ElementBase::setPosition(const vec3& _pos) {
m_position = _pos;
}

View File

@ -0,0 +1,44 @@
/**
* @author Edouard DUPIN
*
* @copyright 2011, Edouard DUPIN, all right reserved
*
* @license BSD v3 (see license file)
*/
#ifndef __EGE_ELEMENT_BASE_H__
#define __EGE_ELEMENT_BASE_H__
#include <ege/elements/Element.h>
namespace ege {
class ElementBase : public ege::Element {
public:
/**
* @brief Constructor (when constructer is called just add element that did not change.
* The objest will be stored in a pool of element and keep a second time if needed == > redure memory allocation,
* when needed, the system will call the init and un-init function...
*/
ElementBase(const std::shared_ptr<ege::Environement>& _env);
/**
* @brief Destructor
*/
virtual ~ElementBase();
/**
* @brief get the element Type description string.
* @return A reference on the descriptive string.
*/
virtual const std::string& getType() const;
virtual void draw(int32_t _pass=0);
private:
vec3 m_position;
public:
virtual const vec3& getPosition();
virtual void setPosition(const vec3& _pos);
};
};
#endif

View File

@ -8,7 +8,7 @@
#include <etk/types.h> #include <etk/types.h>
#include <ege/debug.h> #include <ege/debug.h>
#include <ege/ElementGame.h> #include <ege/elements/ElementPhysic.h>
#include <ege/Environement.h> #include <ege/Environement.h>
#include <BulletDynamics/Dynamics/btRigidBody.h> #include <BulletDynamics/Dynamics/btRigidBody.h>
#include <LinearMath/btDefaultMotionState.h> #include <LinearMath/btDefaultMotionState.h>
@ -26,35 +26,24 @@
#include <ege/CollisionShapeCreator.h> #include <ege/CollisionShapeCreator.h>
#undef __class__ #undef __class__
#define __class__ "ElementGame" #define __class__ "ElementPhysic"
const std::string& ege::ElementGame::getType() const { const std::string& ege::ElementPhysic::getType() const {
static const std::string nameType("----"); static const std::string nameType("----");
return nameType; return nameType;
} }
ege::ElementGame::ElementGame(const std::shared_ptr<ege::Environement>& _env) : ege::ElementPhysic::ElementPhysic(const std::shared_ptr<ege::Environement>& _env) :
m_env(_env), ege::Element(_env),
m_body(nullptr), m_body(nullptr),
m_uID(0),
m_mesh(),
m_shape(nullptr), m_shape(nullptr),
m_life(100),
m_lifeMax(100),
m_group(0),
m_fixe(true),
m_radius(0),
m_elementInPhysicsSystem(false), m_elementInPhysicsSystem(false),
m_IA(nullptr) { m_IA(nullptr) {
static uint32_t unique=0;
m_uID = unique;
EGE_DEBUG("Create element : uId=" << m_uID);
m_debugText.setFontSize(12);
unique++;
} }
ege::ElementGame::~ElementGame() { ege::ElementPhysic::~ElementPhysic() {
// in every case remove IA // in every case remove IA
iaDisable(); iaDisable();
// same ... // same ...
@ -62,10 +51,35 @@ ege::ElementGame::~ElementGame() {
removeShape(); removeShape();
delete m_body; delete m_body;
m_body = nullptr; m_body = nullptr;
EGE_DEBUG("Destroy element : uId=" << m_uID);
} }
void ege::ElementGame::removeShape() { bool ege::ElementPhysic::setMesh(const std::shared_ptr<ege::resource::Mesh>& _mesh) {
if (nullptr!=m_mesh) {
removeShape();
}
ege::Element::setMesh(_mesh);
// auto load the shape :
if (m_mesh == nullptr) {
return true;
}
if (m_mesh->getShape() != nullptr) {
m_shape = static_cast<btCollisionShape*>(m_mesh->getShape());
return true;
}
m_mesh->setShape(ege::collision::createShape(m_mesh));
m_mesh->setFreeShapeFunction(&FunctionFreeShape);
m_shape = static_cast<btCollisionShape*>(m_mesh->getShape());
return true;
}
bool ege::ElementPhysic::setShape(btCollisionShape* _shape) {
removeShape();
m_shape = _shape;
return true;
}
void ege::ElementPhysic::removeShape() {
// no shape // no shape
if (nullptr == m_shape) { if (nullptr == m_shape) {
return; return;
@ -85,68 +99,14 @@ void ege::ElementGame::removeShape() {
// otherwise : the shape is auto remove by the resources when no more needed ... // otherwise : the shape is auto remove by the resources when no more needed ...
} }
void ege::ElementGame::FunctionFreeShape(void* _pointer) { void ege::ElementPhysic::FunctionFreeShape(void* _pointer) {
if (nullptr == _pointer) { if (nullptr == _pointer) {
return; return;
} }
delete(static_cast<btCollisionShape*>(_pointer)); delete(static_cast<btCollisionShape*>(_pointer));
} }
bool ege::ElementGame::loadMesh(const std::string& _meshFileName) { void ege::ElementPhysic::setPosition(const vec3& _pos) {
std::shared_ptr<ege::resource::Mesh> tmpMesh = ege::resource::Mesh::create(_meshFileName);
if(nullptr == tmpMesh) {
EGE_ERROR("can not load the resources : " << _meshFileName);
return false;
}
return setMesh(tmpMesh);
}
bool ege::ElementGame::setMesh(const std::shared_ptr<ege::resource::Mesh>& _mesh) {
if (nullptr!=m_mesh) {
removeShape();
m_mesh.reset();
}
m_mesh = _mesh;
// auto load the shape :
if (m_mesh == nullptr) {
return true;
}
if (m_mesh->getShape() != nullptr) {
m_shape = static_cast<btCollisionShape*>(m_mesh->getShape());
return true;
}
m_mesh->setShape(ege::collision::createShape(m_mesh));
m_mesh->setFreeShapeFunction(&FunctionFreeShape);
m_shape = static_cast<btCollisionShape*>(m_mesh->getShape());
return true;
}
bool ege::ElementGame::setShape(btCollisionShape* _shape) {
removeShape();
m_shape = _shape;
return true;
}
float ege::ElementGame::getLifeRatio() {
if (0 >= m_life) {
return 0;
}
return m_life/m_lifeMax;
}
void ege::ElementGame::setFireOn(int32_t _groupIdSource, int32_t _type, float _power, const vec3& _center) {
float previousLife = m_life;
m_life += _power;
m_life = std::avg(0.0f, m_life, m_lifeMax);
if (m_life <= 0) {
EGE_DEBUG("[" << getUID() << "] element is killed ..." << getType());
}
if (m_life!=previousLife) {
onLifeChange();
}
}
void ege::ElementGame::setPosition(const vec3& _pos) {
if (nullptr!=m_body) { if (nullptr!=m_body) {
btTransform transformation = m_body->getCenterOfMassTransform(); btTransform transformation = m_body->getCenterOfMassTransform();
transformation.setOrigin(_pos); transformation.setOrigin(_pos);
@ -154,17 +114,14 @@ void ege::ElementGame::setPosition(const vec3& _pos) {
} }
} }
const vec3& ege::ElementGame::getPosition() { const vec3& ege::ElementPhysic::getPosition() {
// this is to prevent error like segmentation fault ...
static vec3 emptyPosition(-1000000,-1000000,-1000000);
if (nullptr!=m_body) { if (nullptr!=m_body) {
return m_body->getCenterOfMassPosition(); return m_body->getCenterOfMassPosition();
} }
return emptyPosition; return ege::Element::getPosition();
}; };
const vec3& ege::ElementGame::getSpeed() { const vec3& ege::ElementPhysic::getSpeed() {
// this is to prevent error like segmentation fault ...
static vec3 emptySpeed(0,0,0); static vec3 emptySpeed(0,0,0);
if (nullptr!=m_body) { if (nullptr!=m_body) {
return m_body->getLinearVelocity(); return m_body->getLinearVelocity();
@ -172,100 +129,13 @@ const vec3& ege::ElementGame::getSpeed() {
return emptySpeed; return emptySpeed;
}; };
const float ege::ElementGame::getInvMass() { const float ege::ElementPhysic::getInvMass() {
if (nullptr!=m_body) { if (nullptr!=m_body) {
return m_body->getInvMass(); return m_body->getInvMass();
} }
return 0.0000000001f; return 0.0000000001f;
}; };
static void drawSphere(const std::shared_ptr<ewol::resource::Colored3DObject>& _draw,
btScalar _radius,
int _lats,
int _longs,
mat4& _transformationMatrix,
etk::Color<float>& _tmpColor) {
int i, j;
std::vector<vec3> EwolVertices;
for(i = 0; i <= _lats; i++) {
btScalar lat0 = SIMD_PI * (-btScalar(0.5) + (btScalar) (i - 1) / _lats);
btScalar z0 = _radius*sin(lat0);
btScalar zr0 = _radius*cos(lat0);
btScalar lat1 = SIMD_PI * (-btScalar(0.5) + (btScalar) i / _lats);
btScalar z1 = _radius*sin(lat1);
btScalar zr1 = _radius*cos(lat1);
//glBegin(GL_QUAD_STRIP);
for(j = 0; j < _longs; j++) {
btScalar lng = 2 * SIMD_PI * (btScalar) (j - 1) / _longs;
btScalar x = cos(lng);
btScalar y = sin(lng);
vec3 v1 = vec3(x * zr1, y * zr1, z1);
vec3 v4 = vec3(x * zr0, y * zr0, z0);
lng = 2 * SIMD_PI * (btScalar) (j) / _longs;
x = cos(lng);
y = sin(lng);
vec3 v2 = vec3(x * zr1, y * zr1, z1);
vec3 v3 = vec3(x * zr0, y * zr0, z0);
EwolVertices.push_back(v1);
EwolVertices.push_back(v2);
EwolVertices.push_back(v3);
EwolVertices.push_back(v1);
EwolVertices.push_back(v3);
EwolVertices.push_back(v4);
}
}
_draw->draw(EwolVertices, _tmpColor, _transformationMatrix);
}
const float lifeBorder = 0.1f;
const float lifeHeight = 0.3f;
const float lifeWidth = 2.0f;
const float lifeYPos = 1.7f;
void ege::ElementGame::drawLife(const std::shared_ptr<ewol::resource::Colored3DObject>& _draw, const ege::Camera& _camera) {
if (nullptr == _draw) {
return;
}
float ratio = getLifeRatio();
if (ratio == 1.0f) {
return;
}
#if 0
mat4 transformationMatrix = etk::matTranslate(getPosition())
* etk::matRotate(vec3(0,0,1),_camera.getAngleZ())
* etk::matRotate(vec3(1,0,0),(M_PI/2.0f-_camera.getAngleTeta()));
std::vector<vec3> localVertices;
localVertices.push_back(vec3(-lifeWidth/2.0-lifeBorder,lifeYPos -lifeBorder,0));
localVertices.push_back(vec3(-lifeWidth/2.0-lifeBorder,lifeYPos+lifeHeight+lifeBorder,0));
localVertices.push_back(vec3( lifeWidth/2.0+lifeBorder,lifeYPos+lifeHeight+lifeBorder,0));
localVertices.push_back(vec3(-lifeWidth/2.0-lifeBorder,lifeYPos -lifeBorder,0));
localVertices.push_back(vec3( lifeWidth/2.0+lifeBorder,lifeYPos+lifeHeight+lifeBorder,0));
localVertices.push_back(vec3( lifeWidth/2.0+lifeBorder,lifeYPos -lifeBorder,0));
etk::Color<float> myColor(0x0000FF99);
_draw->draw(localVertices, myColor, transformationMatrix, false, false);
localVertices.clear();
/** Bounding box == > model shape **/
localVertices.push_back(vec3(-lifeWidth/2.0 ,lifeYPos,0));
localVertices.push_back(vec3(-lifeWidth/2.0 ,lifeYPos + lifeHeight,0));
localVertices.push_back(vec3(-lifeWidth/2.0+lifeWidth*ratio,lifeYPos + lifeHeight,0));
localVertices.push_back(vec3(-lifeWidth/2.0 ,lifeYPos,0));
localVertices.push_back(vec3(-lifeWidth/2.0+lifeWidth*ratio,lifeYPos + lifeHeight,0));
localVertices.push_back(vec3(-lifeWidth/2.0+lifeWidth*ratio,lifeYPos,0));
myColor =0x00FF00FF;
if (ratio < 0.2f) {
myColor = 0xFF0000FF;
} else if (ratio < 0.4f) {
myColor = 0xDA7B00FF;
}
_draw->draw(localVertices, myColor, transformationMatrix, false, false);
#endif
}
static void drawShape(const btCollisionShape* _shape, static void drawShape(const btCollisionShape* _shape,
const std::shared_ptr<ewol::resource::Colored3DObject>& _draw, const std::shared_ptr<ewol::resource::Colored3DObject>& _draw,
mat4 _transformationMatrix, mat4 _transformationMatrix,
@ -284,7 +154,7 @@ static void drawShape(const btCollisionShape* _shape,
//EGE_DEBUG(" draw (01): SPHERE_SHAPE_PROXYTYPE"); //EGE_DEBUG(" draw (01): SPHERE_SHAPE_PROXYTYPE");
const btSphereShape* sphereShape = static_cast<const btSphereShape*>(_shape); const btSphereShape* sphereShape = static_cast<const btSphereShape*>(_shape);
float radius = sphereShape->getMargin();//radius doesn't include the margin, so draw with margin float radius = sphereShape->getMargin();//radius doesn't include the margin, so draw with margin
drawSphere(_draw, radius, 10, 10, _transformationMatrix, tmpColor); // TODO : drawSphere(_draw, radius, 10, 10, _transformationMatrix, tmpColor);
break; break;
} }
case BOX_SHAPE_PROXYTYPE: { case BOX_SHAPE_PROXYTYPE: {
@ -434,14 +304,8 @@ static void drawShape(const btCollisionShape* _shape,
} }
} }
void ege::ElementGame::drawDebug(const std::shared_ptr<ewol::resource::Colored3DObject>& _draw, const ege::Camera& _camera) { void ege::ElementPhysic::drawDebug(const std::shared_ptr<ewol::resource::Colored3DObject>& _draw, const ege::Camera& _camera) {
m_debugText.clear(); ege::Element::drawDebug(_draw, _camera);
m_debugText.setColor(etk::Color<>(0x00, 0xFF, 0x00, 0xFF));
m_debugText.setPos(vec3(-20,32,0));
m_debugText.print(getType());
m_debugText.setPos(vec3(-20,20,0));
m_debugText.print("life=("+etk::to_string(getLifeRatio()));
//m_debugText.print(std::string("Axe=(")+std::string(m_tmpAxe.x())+std::string(",")+etk::UString(m_tmpAxe.y())+etk::UString(",")+etk::UString(m_tmpAxe.z())+etk::UString(")"));
btScalar mmm[16]; btScalar mmm[16];
btDefaultMotionState* myMotionState = (btDefaultMotionState*)m_body->getMotionState(); btDefaultMotionState* myMotionState = (btDefaultMotionState*)m_body->getMotionState();
myMotionState->m_graphicsWorldTrans.getOpenGLMatrix(mmm); myMotionState->m_graphicsWorldTrans.getOpenGLMatrix(mmm);
@ -452,15 +316,9 @@ void ege::ElementGame::drawDebug(const std::shared_ptr<ewol::resource::Colored3D
// note : set the vertice here to prevent multiple allocations... // note : set the vertice here to prevent multiple allocations...
std::vector<vec3> EwolVertices; std::vector<vec3> EwolVertices;
drawShape(m_shape, _draw, transformationMatrix, EwolVertices); drawShape(m_shape, _draw, transformationMatrix, EwolVertices);
/*
m_debugText.draw( etk::matTranslate(getPosition())
* etk::matRotate(vec3(0,0,1),_camera.getAngleZ())
* etk::matRotate(vec3(1,0,0),(M_PI/2.0f-_camera.getAngleTeta()))
* etk::matScale(vec3(0.05,0.05,0.05)));
*/
} }
void ege::ElementGame::draw(int32_t _pass) { void ege::ElementPhysic::draw(int32_t _pass) {
if (false == m_elementInPhysicsSystem) { if (false == m_elementInPhysicsSystem) {
return; return;
} }
@ -479,35 +337,35 @@ void ege::ElementGame::draw(int32_t _pass) {
} }
} }
void ege::ElementGame::dynamicEnable() { void ege::ElementPhysic::dynamicEnable() {
if (true == m_elementInPhysicsSystem) { if (true == m_elementInPhysicsSystem) {
return; return;
} }
if(nullptr!=m_body) { if(nullptr!=m_body) {
m_env->getDynamicWorld()->addRigidBody(m_body); m_env->getPhysicEngine().getDynamicWorld()->addRigidBody(m_body);
} }
if(nullptr!=m_IA) { if(nullptr!=m_IA) {
m_env->getDynamicWorld()->addAction(m_IA); m_env->getPhysicEngine().getDynamicWorld()->addAction(m_IA);
} }
m_elementInPhysicsSystem = true; m_elementInPhysicsSystem = true;
} }
void ege::ElementGame::dynamicDisable() { void ege::ElementPhysic::dynamicDisable() {
if (false == m_elementInPhysicsSystem) { if (false == m_elementInPhysicsSystem) {
return; return;
} }
if(nullptr!=m_IA) { if(nullptr!=m_IA) {
m_env->getDynamicWorld()->removeAction(m_IA); m_env->getPhysicEngine().getDynamicWorld()->removeAction(m_IA);
} }
if(nullptr!=m_body) { if(nullptr!=m_body) {
// Unlink element from the engine // Unlink element from the engine
m_env->getDynamicWorld()->removeRigidBody(m_body); m_env->getPhysicEngine().getDynamicWorld()->removeRigidBody(m_body);
m_env->getDynamicWorld()->removeCollisionObject(m_body); m_env->getPhysicEngine().getDynamicWorld()->removeCollisionObject(m_body);
} }
m_elementInPhysicsSystem = false; m_elementInPhysicsSystem = false;
} }
void ege::ElementGame::iaEnable() { void ege::ElementPhysic::iaEnable() {
if (nullptr != m_IA) { if (nullptr != m_IA) {
// IA already started ... // IA already started ...
return; return;
@ -518,17 +376,17 @@ void ege::ElementGame::iaEnable() {
return; return;
} }
if (true == m_elementInPhysicsSystem) { if (true == m_elementInPhysicsSystem) {
m_env->getDynamicWorld()->addAction(m_IA); m_env->getPhysicEngine().getDynamicWorld()->addAction(m_IA);
} }
} }
void ege::ElementGame::iaDisable() { void ege::ElementPhysic::iaDisable() {
if (nullptr == m_IA) { if (nullptr == m_IA) {
// IA already stopped ... // IA already stopped ...
return; return;
} }
if (true == m_elementInPhysicsSystem) { if (true == m_elementInPhysicsSystem) {
m_env->getDynamicWorld()->removeAction(m_IA); m_env->getPhysicEngine().getDynamicWorld()->removeAction(m_IA);
} }
// remove IA : // remove IA :
delete(m_IA); delete(m_IA);

View File

@ -0,0 +1,170 @@
/**
* @author Edouard DUPIN
*
* @copyright 2011, Edouard DUPIN, all right reserved
*
* @license BSD v3 (see license file)
*/
#ifndef __EGE_ELEMENT_PHYSIC_H__
#define __EGE_ELEMENT_PHYSIC_H__
#include <etk/types.h>
#include <etk/math/Vector3D.h>
#include <etk/math/Matrix4.h>
#include <vector>
#include <ewol/debug.h>
#include <ewol/widget/Widget.h>
#include <ewol/openGL/openGL.h>
#include <ewol/resource/Colored3DObject.h>
#include <ege/resource/Mesh.h>
#include <ege/camera/Camera.h>
#include <ewol/compositing/Text.h>
#include <ege/Environement.h>
#include <ege/elements/Element.h>
#define INDEX_RIGHT_AXIS (0)
#define INDEX_FORWARD_AXIS (1)
#define INDEX_UP_AXIS (2)
#define ELEMENT_SCALE (1.0f/8.0f)
namespace ege {
class ElementPhysic : public ege::Element {
private:
static void FunctionFreeShape(void* _pointer);
protected:
btRigidBody* m_body; //!< all the element have a body == > otherwise it will be not manage with this system...
public:
/**
* @brief Constructor (when constructer is called just add element that did not change.
* The objest will be stored in a pool of element and keep a second time if needed == > redure memory allocation,
* when needed, the system will call the init and un-init function...
*/
ElementPhysic(const std::shared_ptr<ege::Environement>& _env);
/**
* @brief Destructor
*/
virtual ~ElementPhysic();
/**
* @brief get the element Type description string.
* @return A reference on the descriptive string.
*/
virtual const std::string& getType() const;
protected:
btCollisionShape* m_shape; //!< shape of the element (set a copy here to have the debug display of it)
public:
/**
* @brief set the shape properties.
* @param[in] _shape The shape pointer.
* @note : this remove the shape properties.
* @return true if no error occured
*/
bool setShape(btCollisionShape* _shape);
/**
* @brief get a pointer on the bullet collision shape.
* @return the collision pointer.
*/
inline btCollisionShape* getShape() {
return m_shape;
};
private:
/**
* @brief remove the curent selected shape.
*/
void removeShape();
public:
virtual bool setMesh(const std::shared_ptr<ege::resource::Mesh>& _mesh);
/**
* @brief draw the curent element (can have multiple display)
* @param[in] pass Id of the current pass : [0..?]
*/
virtual void draw(int32_t _pass=0);
/**
* @brief draw the current life of the element
*/
// virtual void drawLife(const std::shared_ptr<ewol::resource::Colored3DObject>& _draw, const ege::Camera& _camera);
/**
* @brief get the theoric position. Sometimes, the element has move due to an explosion or something else, then its real position in not the one that woult it be at the end ...
* @return the theoric position
*/
virtual vec3 getPositionTheoric() {
return getPosition();
};
/**
* @brief set the current Theoric position of the element
* @param[in] set the 3D position.
*/
virtual void setPositionTheoric(const vec3& _pos) { };
/**
* @brief get the current speed of the element
* @return the 3D speed.
*/
const vec3& getSpeed();
/**
* @brief get the current mass of the element
* @return the mass in kG.
*/
const float getInvMass();
protected:
bool m_elementInPhysicsSystem;
public:
virtual void dynamicEnable();
virtual void dynamicDisable();
private:
class localIA : public btActionInterface {
private:
ege::ElementPhysic& m_element;
public:
/**
* @brief Constructor
*/
localIA(ElementPhysic& _element) :
m_element(_element) {
};
/**
* @brief Destructor
*/
virtual ~localIA() {
};
public: // herited function
void debugDraw(btIDebugDraw* _debugDrawer) {
};
void updateAction(btCollisionWorld* _collisionWorld, btScalar _step) {
m_element.iaAction(_step);
};
};
localIA* m_IA;
public:
/**
* @brief enable periodic call Of this object for processing Artificial Intelligence
*/
void iaEnable();
/**
* @brief disable periodic call Of this object for processing Artificial Intelligence
*/
void iaDisable();
/**
* @brief periodic call for intelligence artificial.
* @param[in] step : step of time in s
*/
virtual void iaAction(float _step) { };
/**
* @brief, call when the element is removed (call only one time
*/
virtual void onDestroy() {};
virtual const vec3& getPosition();
virtual void setPosition(const vec3& _pos);
virtual void drawDebug(const std::shared_ptr<ewol::resource::Colored3DObject>& _draw, const ege::Camera& _camera);
};
};
#endif

View File

@ -9,6 +9,21 @@
#include <ege/physics/Engine.h> #include <ege/physics/Engine.h>
#include <ewol/openGL/openGL.h>
#include <etk/math/Matrix4.h>
#include <BulletDynamics/Dynamics/btRigidBody.h>
#include <LinearMath/btDefaultMotionState.h>
#include <BulletDynamics/Dynamics/btDynamicsWorld.h>
#include <BulletCollision/CollisionShapes/btCollisionShape.h>
#include <LinearMath/btIDebugDraw.h>
#include <btBulletCollisionCommon.h>
#include <BulletCollision/CollisionShapes/btConvexPolyhedron.h>
#include <BulletCollision/CollisionShapes/btShapeHull.h>
#include <LinearMath/btTransformUtil.h>
#include <LinearMath/btIDebugDraw.h>
#include <btBulletDynamicsCommon.h>
#include <BulletCollision/CollisionDispatch/btCollisionObject.h>
ege::physics::Engine::Engine() { ege::physics::Engine::Engine() {
setBulletConfig(); setBulletConfig();
@ -24,43 +39,43 @@ ege::physics::Engine::~Engine() {
*/ */
} }
void ege::physics::Engine::setBulletConfig(std::make_shared(btDefaultCollisionConfiguration> _collisionConfiguration, void ege::physics::Engine::setBulletConfig(std::shared_ptr<btDefaultCollisionConfiguration> _collisionConfiguration,
std::make_shared(btCollisionDispatcher> _dispatcher, std::shared_ptr<btCollisionDispatcher> _dispatcher,
std::make_shared(btBroadphaseInterface> _broadphase, std::shared_ptr<btBroadphaseInterface> _broadphase,
std::make_shared(btConstraintSolver> _solver, std::shared_ptr<btConstraintSolver> _solver,
std::make_shared(btDynamicsWorld> _dynamicsWorld) { std::shared_ptr<btDynamicsWorld> _dynamicsWorld) {
if (_collisionConfiguration != nullptr) { if (_collisionConfiguration != nullptr) {
m_collisionConfiguration = _collisionConfiguration; m_collisionConfiguration = _collisionConfiguration;
} else { } else {
m_collisionConfiguration = std::make_shared(btDefaultCollisionConfiguration()); m_collisionConfiguration = std::make_shared<btDefaultCollisionConfiguration>();
} }
///use the default collision dispatcher. ///use the default collision dispatcher.
if (_dispatcher != nullptr) { if (_dispatcher != nullptr) {
m_dispatcher = _dispatcher; m_dispatcher = _dispatcher;
} else { } else {
m_dispatcher = std::make_shared(btCollisionDispatcher(m_collisionConfiguration)); m_dispatcher = std::make_shared<btCollisionDispatcher>(m_collisionConfiguration.get());
} }
if (_broadphase != nullptr) { if (_broadphase != nullptr) {
m_broadphase = _broadphase; m_broadphase = _broadphase;
} else { } else {
m_broadphase = std::make_shared(btDbvtBroadphase()); m_broadphase = std::make_shared<btDbvtBroadphase>();
} }
///the default constraint solver. ///the default constraint solver.
if (_solver != nullptr) { if (_solver != nullptr) {
m_solver = _solver; m_solver = _solver;
} else { } else {
m_solver = std::make_shared(btSequentialImpulseConstraintSolver()); m_solver = std::make_shared<btSequentialImpulseConstraintSolver>();
} }
if (_dynamicsWorld != nullptr) { if (_dynamicsWorld != nullptr) {
m_dynamicsWorld = _dynamicsWorld; m_dynamicsWorld = _dynamicsWorld;
} else { } else {
m_dynamicsWorld = std::make_shared(btDiscreteDynamicsWorld(m_dispatcher,m_broadphase,m_solver,m_collisionConfiguration)); m_dynamicsWorld = std::make_shared<btDiscreteDynamicsWorld>(m_dispatcher.get(),m_broadphase.get(),m_solver.get(),m_collisionConfiguration.get());
// By default we set no gravity // By default we set no gravity
m_dynamicsWorld->setGravity(btVector3(0,0,0)); m_dynamicsWorld->setGravity(btVector3(0,0,0));
} }
m_env.setDynamicWorld(m_dynamicsWorld); //m_env.setDynamicWorld(m_dynamicsWorld);
} }

View File

@ -14,11 +14,10 @@
#include <etk/math/Matrix4.h> #include <etk/math/Matrix4.h>
#include <vector> #include <vector>
#include <ewol/debug.h> #include <ewol/debug.h>
#include <ege/Camera.h> #include <ege/camera/Camera.h>
#include <ewol/widget/Widget.h> #include <ewol/widget/Widget.h>
#include <ewol/openGL/openGL.h> #include <ewol/openGL/openGL.h>
#include <ewol/resource/Manager.h> #include <ewol/resource/Manager.h>
#include <ege/ElementGame.h>
#include <ewol/Dimension.h> #include <ewol/Dimension.h>
class btBroadphaseInterface; class btBroadphaseInterface;
@ -32,13 +31,14 @@ class btDynamicsWorld;
#include <LinearMath/btScalar.h> #include <LinearMath/btScalar.h>
class btVector3; class btVector3;
//#include <ege/elements/Element.h>
namespace ege { namespace ege {
namespace physics { namespace physics {
class Engine { class Engine {
private: private:
///this is the most important class ///this is the most important class
std::shared_ptr<btDefaultCollisionConfiguration< m_collisionConfiguration; std::shared_ptr<btDefaultCollisionConfiguration> m_collisionConfiguration;
std::shared_ptr<btCollisionDispatcher> m_dispatcher; std::shared_ptr<btCollisionDispatcher> m_dispatcher;
std::shared_ptr<btBroadphaseInterface> m_broadphase; std::shared_ptr<btBroadphaseInterface> m_broadphase;
std::shared_ptr<btConstraintSolver> m_solver; std::shared_ptr<btConstraintSolver> m_solver;
@ -51,6 +51,20 @@ namespace ege {
std::shared_ptr<btBroadphaseInterface> _broadphase=nullptr, std::shared_ptr<btBroadphaseInterface> _broadphase=nullptr,
std::shared_ptr<btConstraintSolver> _solver=nullptr, std::shared_ptr<btConstraintSolver> _solver=nullptr,
std::shared_ptr<btDynamicsWorld> _dynamicsWorld=nullptr); std::shared_ptr<btDynamicsWorld> _dynamicsWorld=nullptr);
/**
* @brief set the curent world
* @param[in] _newWorld Pointer on the current world
*/
void setDynamicWorld(const std::shared_ptr<btDynamicsWorld>& _newWorld) {
m_dynamicsWorld=_newWorld;
};
/**
* @brief get the curent world
* @return pointer on the current world
*/
std::shared_ptr<btDynamicsWorld> getDynamicWorld() {
return m_dynamicsWorld;
};
}; };
}; };
}; };

View File

@ -258,19 +258,44 @@ void ege::resource::Mesh::generateVBO() {
// when no normal detected == > auto generate Face normal .... // when no normal detected == > auto generate Face normal ....
calculateNormaleFace(m_listFaces.getKeys()[0]); calculateNormaleFace(m_listFaces.getKeys()[0]);
} }
// generate element in 2 pass : // generate element in 2 pass :
// - create new index dependeng a vertex is a unique componenet of position, texture, normal // - create new index dependeng a vertex is a unique componenet of position, texture, normal
// - the index list generation (can be dynamic ... (TODO later) // - the index list generation (can be dynamic ... (TODO later)
for (int32_t kkk=0; kkk<m_listFaces.size(); kkk++) { for (int32_t kkk=0; kkk<m_listFaces.size(); kkk++) {
// clean faces indexes : // clean faces indexes :
m_listFaces.getValue(kkk).m_index.clear(); m_listFaces.getValue(kkk).m_index.clear();
int32_t nbIndicInFace = 3;
switch (m_materials[m_listFaces.getKey(kkk)]->getRenderMode()) {
case ewol::openGL::renderTriangle:
case ewol::openGL::renderTriangleStrip:
case ewol::openGL::renderTriangleFan:
nbIndicInFace = 3;
break;
case ewol::openGL::renderLine:
case ewol::openGL::renderLineStrip:
case ewol::openGL::renderLineLoop:
nbIndicInFace = 2;
break;
case ewol::openGL::renderPoint:
nbIndicInFace = 1;
break;
case ewol::openGL::renderQuad:
case ewol::openGL::renderQuadStrip:
nbIndicInFace = 4;
break;
case ewol::openGL::renderPolygon:
nbIndicInFace = 3;
break;
}
#ifdef TRY_MINIMAL_VBO #ifdef TRY_MINIMAL_VBO
int64_t tmpppppp=0; int64_t tmpppppp=0;
#endif #endif
FaceIndexing& tmpFaceList = m_listFaces.getValue(kkk); FaceIndexing& tmpFaceList = m_listFaces.getValue(kkk);
for (size_t iii=0; iii<tmpFaceList.m_faces.size() ; iii++) { for (size_t iii=0; iii<tmpFaceList.m_faces.size() ; iii++) {
int32_t vertexVBOId[3]; int32_t vertexVBOId[3];
for(size_t indice=0 ; indice<3; indice++) { for(size_t indice=0 ; indice<nbIndicInFace; indice++) {
// ghet position // ghet position
vec3 position = m_listVertex[tmpFaceList.m_faces[iii].m_vertex[indice]]; vec3 position = m_listVertex[tmpFaceList.m_faces[iii].m_vertex[indice]];
// get Color // get Color
@ -1077,7 +1102,7 @@ void ege::resource::Mesh::addTriangle(const std::string& _layerName,
} }
ewol::openGL::renderMode tmpRenderMode = m_materials[_layerName]->getRenderMode(); ewol::openGL::renderMode tmpRenderMode = m_materials[_layerName]->getRenderMode();
if ( tmpRenderMode != ewol::openGL::renderTriangle if ( tmpRenderMode != ewol::openGL::renderTriangle
&& tmpRenderMode != ewol::openGL::renderLineStrip && tmpRenderMode != ewol::openGL::renderTriangleStrip
&& tmpRenderMode != ewol::openGL::renderTriangleFan) { && tmpRenderMode != ewol::openGL::renderTriangleFan) {
EGE_ERROR("try to add Line in a mesh material section that not support Line"); EGE_ERROR("try to add Line in a mesh material section that not support Line");
return; return;

View File

@ -83,11 +83,11 @@ void ege::widget::Scene::onDraw() {
std::shared_ptr<ege::Camera> camera = m_env->getCamera(m_cameraName); std::shared_ptr<ege::Camera> camera = m_env->getCamera(m_cameraName);
//EGE_DEBUG("Draw (start)"); //EGE_DEBUG("Draw (start)");
mat4 tmpMatrix; mat4 tmpMatrix;
std::shared_ptr<btDynamicsWorld> world = m_env->getDynamicWorld(); std::shared_ptr<btDynamicsWorld> world = m_env->getPhysicEngine().getDynamicWorld();
if (world != nullptr) { if (world != nullptr) {
m_env->getOrderedElementForDisplay(m_displayElementOrdered, camera->getEye(), camera->getViewVector()); m_env->getOrderedElementForDisplay(m_displayElementOrdered, camera->getEye(), camera->getViewVector());
//EGE_DEBUG("DRAW : " << m_displayElementOrdered.size() << " elements"); EGE_DEBUG("DRAW : " << m_displayElementOrdered.size() << "/" << m_env->getElement().size() << " elements");
// TODO : remove this == > no more needed ==> checked in the generate the list of the element ordered // TODO : remove this == > no more needed ==> checked in the generate the list of the element ordered
for (size_t iii=0; iii<m_displayElementOrdered.size(); iii++) { for (size_t iii=0; iii<m_displayElementOrdered.size(); iii++) {
@ -104,6 +104,8 @@ void ege::widget::Scene::onDraw() {
m_displayElementOrdered[iii].element->draw(pass); m_displayElementOrdered[iii].element->draw(pass);
} }
} }
} else {
EGE_WARNING("No Dynamic world ...");
} }
if (camera != nullptr) { if (camera != nullptr) {
m_env->getParticuleEngine().draw(*camera); m_env->getParticuleEngine().draw(*camera);

View File

@ -18,7 +18,7 @@
#include <ewol/widget/Widget.h> #include <ewol/widget/Widget.h>
#include <ewol/openGL/openGL.h> #include <ewol/openGL/openGL.h>
#include <ewol/resource/Manager.h> #include <ewol/resource/Manager.h>
#include <ege/ElementGame.h> #include <ege/elements/Element.h>
#include <ewol/Dimension.h> #include <ewol/Dimension.h>
class btBroadphaseInterface; class btBroadphaseInterface;

View File

@ -19,7 +19,10 @@ def create(target):
'ege/camera/View.cpp', 'ege/camera/View.cpp',
'ege/camera/FPS.cpp', 'ege/camera/FPS.cpp',
'ege/CollisionShapeCreator.cpp', 'ege/CollisionShapeCreator.cpp',
'ege/ElementGame.cpp', 'ege/physics/Engine.cpp',
'ege/elements/Element.cpp',
'ege/elements/ElementBase.cpp',
'ege/elements/ElementPhysic.cpp',
'ege/Particule.cpp', 'ege/Particule.cpp',
'ege/ParticuleEngine.cpp', 'ege/ParticuleEngine.cpp',
'ege/ParticuleSimple.cpp', 'ege/ParticuleSimple.cpp',

View File

@ -14,6 +14,8 @@
#include <ege/widget/Scene.h> #include <ege/widget/Scene.h>
#include <ege/camera/View.h> #include <ege/camera/View.h>
#include <etk/tool.h> #include <etk/tool.h>
#include <ege/elements/ElementBase.h>
#include <ege/elements/ElementPhysic.h>
#undef __class__ #undef __class__
#define __class__ "Windows" #define __class__ "Windows"
@ -137,7 +139,12 @@ void appl::Windows::init() {
myMesh->addMaterial("basics", material); myMesh->addMaterial("basics", material);
myMesh->createIcoSphere("basics", 16, 3); myMesh->createIcoSphere("basics", 16, 3);
myMesh->generateVBO(); myMesh->generateVBO();
m_env->addStaticMeshToDraw(myMesh); std::shared_ptr<ege::ElementBase> element = std::make_shared<ege::ElementBase>(m_env);
//std::shared_ptr<ege::ElementPhysic> element = std::make_shared<ege::ElementPhysic>(m_env);
element->setPosition(vec3(50,0,0));
element->setMesh(myMesh);
m_env->addElement(element);
//m_env->addStaticMeshToDraw(myMesh);
} }
} }
} }
@ -146,7 +153,7 @@ void appl::Windows::init() {
void appl::Windows::onCallbackPeriodicUpdateCamera(const ewol::event::Time& _event) { void appl::Windows::onCallbackPeriodicUpdateCamera(const ewol::event::Time& _event) {
static float offset = 0; static float offset = 0;
offset += 0.01; offset += 0.01;
m_camera->setEye(vec3(100*std::sin(offset),100*std::cos(offset),40)); m_camera->setEye(vec3(100*std::sin(offset),100*std::cos(offset),40)+vec3(50,0,0));
} }