From c25f125dee7a0a83882ce3cfa12db8df3f42365b Mon Sep 17 00:00:00 2001 From: Edouard DUPIN Date: Sun, 21 May 2017 15:49:28 +0000 Subject: [PATCH] [DEV] collision and basic physics debug --- ege/CollisionShapeCreator.cpp | 180 ----------------------- ege/CollisionShapeCreator.hpp | 16 -- ege/Engine.cpp | 4 + ege/Engine.hpp | 11 +- ege/Environement.cpp | 64 ++------ ege/Environement.hpp | 9 +- ege/elements/Element.cpp | 42 +----- ege/elements/Element.hpp | 89 +---------- ege/elements/ElementBase.cpp | 3 + ege/elements/ElementBase.hpp | 7 + ege/elements/ElementPhysic.cpp | 42 +----- ege/elements/ElementPhysic.hpp | 7 + ege/particule/Engine.cpp | 4 +- ege/physics/Component.cpp | 237 ++++++++++++++++++++++++------ ege/physics/Component.hpp | 7 + ege/physics/Engine.cpp | 53 ++++++- ege/physics/Engine.hpp | 11 +- ege/physicsShape/PhysicsShape.cpp | 9 +- ege/physicsShape/PhysicsShape.hpp | 26 +++- ege/render/Component.cpp | 17 ++- ege/render/Component.hpp | 6 +- ege/render/Engine.cpp | 22 ++- ege/render/Engine.hpp | 10 +- ege/resource/Mesh.cpp | 56 ++++--- ege/resource/Mesh.hpp | 11 +- ege/resource/MeshCube.cpp | 8 +- ege/resource/MeshEmf.cpp | 10 +- ege/resource/MeshObj.cpp | 2 +- ege/resource/ParticuleMesh.cpp | 2 +- lutin_ege.py | 13 +- sample/Collision/appl/Windows.cpp | 21 ++- 31 files changed, 454 insertions(+), 545 deletions(-) diff --git a/ege/CollisionShapeCreator.cpp b/ege/CollisionShapeCreator.cpp index bde9442..e69de29 100644 --- a/ege/CollisionShapeCreator.cpp +++ b/ege/CollisionShapeCreator.cpp @@ -1,180 +0,0 @@ -/** @file - * @author Edouard DUPIN - * @copyright 2011, Edouard DUPIN, all right reserved - * @license MPL v2.0 (see license file) - */ - -#include -#include -#include -#include -#include -#include -#include -#include -#include - -// Documentetion of bullet library: -// http://bulletphysics.org/mediawiki-1.5.8/index.php/Collision_Shapes -/* -btCollisionShape* ege::collision::createShape(const ememory::SharedPtr& _mesh) { - if (_mesh == nullptr) { - EGE_ERROR("Create empty shape (no mesh)"); - return new btEmptyShape(); - } - const std::vector>& physiqueProperty = _mesh->getPhysicalProperties(); - if (physiqueProperty.size() == 0) { - EGE_ERROR("Create empty shape (no default shape)"); - return new btEmptyShape(); - } - int32_t count = 0; - for (size_t iii=0; iii1) { - EGE_ERROR("Create complexe shape"); - outputShape = new btCompoundShape(); - } else { - EGE_ERROR("Create simple shape"); - // TODO : Remove this line ==> it is bad but it correct a bug of a single shape that has no more display - outputShape = new btCompoundShape(); - } - for (size_t iii=0; iiigetType()) { - case ege::PhysicsShape::box : { - EGE_ERROR(" Box"); - const ege::PhysicsBox* tmpElement = physiqueProperty[iii]->toBox(); - if (tmpElement == nullptr) { - EGE_ERROR(" Box ==> can not cast in BOX"); - continue; - } - btCollisionShape* tmpShape = new btBoxShape(tmpElement->getSize()); - if (tmpShape != nullptr) { - if (outputShape == nullptr) { - return tmpShape; - } else { - vec4 qqq = tmpElement->getQuaternion(); - const btTransform localTransform(btQuaternion(qqq.x(),qqq.y(),qqq.z(),qqq.w()), tmpElement->getOrigin()); - outputShape->addChildShape(localTransform, tmpShape); - } - } else { - EGE_ERROR("Allocation shape error BOX"); - } - break; - } - case ege::PhysicsShape::cylinder : { - EGE_DEBUG(" Cylinder"); - const ege::PhysicsCylinder* tmpElement = physiqueProperty[iii]->toCylinder(); - if (tmpElement == nullptr) { - EGE_ERROR(" Cylinder ==> can not cast in Cylinder"); - continue; - } - btCollisionShape* tmpShape = new btCylinderShape(tmpElement->getSize()); - if (tmpShape != nullptr) { - if (outputShape == nullptr) { - return tmpShape; - } else { - vec4 qqq = tmpElement->getQuaternion(); - const btTransform localTransform(btQuaternion(qqq.x(),qqq.y(),qqq.z(),qqq.w()), tmpElement->getOrigin()); - outputShape->addChildShape(localTransform, tmpShape); - } - } - break; - } - case ege::PhysicsShape::capsule : { - EGE_DEBUG(" Capsule"); - const ege::PhysicsCapsule* tmpElement = physiqueProperty[iii]->toCapsule(); - if (tmpElement == nullptr) { - EGE_ERROR(" Capsule ==> can not cast in Capsule"); - continue; - } - btCollisionShape* tmpShape = new btCapsuleShape(tmpElement->getRadius(), tmpElement->getHeight()); - if (tmpShape != nullptr) { - if (outputShape == nullptr) { - return tmpShape; - } else { - vec4 qqq = tmpElement->getQuaternion(); - const btTransform localTransform(btQuaternion(qqq.x(),qqq.y(),qqq.z(),qqq.w()), tmpElement->getOrigin()); - outputShape->addChildShape(localTransform, tmpShape); - } - } - break; - } - case ege::PhysicsShape::cone : { - EGE_DEBUG(" Cone"); - const ege::PhysicsCone* tmpElement = physiqueProperty[iii]->toCone(); - if (tmpElement == nullptr) { - EGE_ERROR(" Cone ==> can not cast in Cone"); - continue; - } - btCollisionShape* tmpShape = new btConeShape(tmpElement->getRadius(), tmpElement->getHeight()); - if (tmpShape != nullptr) { - if (outputShape == nullptr) { - return tmpShape; - } else { - vec4 qqq = tmpElement->getQuaternion(); - const btTransform localTransform(btQuaternion(qqq.x(),qqq.y(),qqq.z(),qqq.w()), tmpElement->getOrigin()); - outputShape->addChildShape(localTransform, tmpShape); - } - } - break; - } - case ege::PhysicsShape::sphere : { - EGE_DEBUG(" Sphere"); - const ege::PhysicsSphere* tmpElement = physiqueProperty[iii]->toSphere(); - if (tmpElement == nullptr) { - EGE_ERROR(" Sphere ==> can not cast in Sphere"); - continue; - } - btCollisionShape* tmpShape = new btSphereShape(tmpElement->getRadius()); - if (tmpShape != nullptr) { - if (outputShape == nullptr) { - return tmpShape; - } else { - vec4 qqq = tmpElement->getQuaternion(); - const btTransform localTransform(btQuaternion(qqq.x(),qqq.y(),qqq.z(),qqq.w()), tmpElement->getOrigin()); - outputShape->addChildShape(localTransform, tmpShape); - } - } - break; - } - case ege::PhysicsShape::convexHull : { - EGE_DEBUG(" convexHull"); - const ege::PhysicsConvexHull* tmpElement = physiqueProperty[iii]->toConvexHull(); - if (tmpElement == nullptr) { - EGE_ERROR(" convexHull ==> can not cast in convexHull"); - continue; - } - btConvexHullShape* tmpShape = new btConvexHullShape(&(tmpElement->getPointList()[0].x()), tmpElement->getPointList().size()); - if (tmpShape != nullptr) { - if (outputShape == nullptr) { - return tmpShape; - } else { - vec4 qqq = tmpElement->getQuaternion(); - const btTransform localTransform(btQuaternion(qqq.x(),qqq.y(),qqq.z(),qqq.w()), tmpElement->getOrigin()); - outputShape->addChildShape(localTransform, tmpShape); - } - } - break; - } - default : - EGE_DEBUG(" ???"); - // TODO : UNKNOW type ... - break; - } - } - if (outputShape == nullptr) { - EGE_DEBUG("create empty shape ..."); - return new btEmptyShape(); - } - return outputShape; -} -*/ - diff --git a/ege/CollisionShapeCreator.hpp b/ege/CollisionShapeCreator.hpp index 832d6bd..e69de29 100644 --- a/ege/CollisionShapeCreator.hpp +++ b/ege/CollisionShapeCreator.hpp @@ -1,16 +0,0 @@ -/** @file - * @author Edouard DUPIN - * @copyright 2011, Edouard DUPIN, all right reserved - * @license MPL v2.0 (see license file) - */ -#pragma once - -#include -#include - -namespace ege { - namespace collision { - //btCollisionShape* createShape(const ememory::SharedPtr& _mesh); - } -} - diff --git a/ege/Engine.cpp b/ege/Engine.cpp index 3d70c4a..d6ea125 100644 --- a/ege/Engine.cpp +++ b/ege/Engine.cpp @@ -30,4 +30,8 @@ void ege::Engine::update(const echrono::Duration& _delta) { void ege::Engine::render(const echrono::Duration& _delta, const ememory::SharedPtr& _camera) { +} + +void ege::Engine::renderDebug(const echrono::Duration& _delta, const ememory::SharedPtr& _camera) { + } \ No newline at end of file diff --git a/ege/Engine.hpp b/ege/Engine.hpp index 6933275..6642448 100644 --- a/ege/Engine.hpp +++ b/ege/Engine.hpp @@ -11,11 +11,14 @@ #include #include #include +#include namespace ege { class Environement; class Camera; - class Engine : public ememory::EnableSharedFromThis { + class Engine : + public ememory::EnableSharedFromThis, + public eproperty::Interface { protected: ege::Environement* m_env; public: @@ -48,6 +51,12 @@ namespace ege { * @param[in] _camera Camera property to render the engine properties ... */ virtual void render(const echrono::Duration& _delta, const ememory::SharedPtr& _camera); + /** + * @brief Globalgame engine main cycle of draw + * @param[in] _delta time from the last render + * @param[in] _camera Camera property to render the engine properties ... + */ + virtual void renderDebug(const echrono::Duration& _delta, const ememory::SharedPtr& _camera); }; } diff --git a/ege/Environement.cpp b/ege/Environement.cpp index 20bceac..edba960 100644 --- a/ege/Environement.cpp +++ b/ege/Environement.cpp @@ -115,7 +115,7 @@ void ege::Environement::engineComponentAdd(const ememory::SharedPtr ege::Environement::getElementNearest(ememory::SharedPtr _sourceRequest, float& _distance) { if (_sourceRequest == nullptr) { return nullptr; @@ -210,6 +210,7 @@ void ege::Environement::getElementNearestFixed(const vec3& _sourcePosition, } } } +*/ static etk::Hash& getHachTableCreating() { static etk::Hash s_table; @@ -389,60 +390,6 @@ void ege::Environement::rmElement(ememory::SharedPtr _removeElemen } } -// TODO : DEPRECATED ==> special function of the renderer ... -void ege::Environement::getOrderedElementForDisplay(std::vector& _resultList, - const vec3& _position, - const vec3& _direction) { - // TODO : Set it back ... corrected... - // remove all unneeded elements (old display...) - _resultList.clear(); - // basic element result - ege::Environement::ResultNearestElement result; - result.dist = 99999999999.0f; - result.element = nullptr; - // for all element in the game we chek if it is needed to display it ... - for (size_t iii=0; iiigetPosition(); - vec3 angleView = (destPosition - _position); - angleView.safeNormalize(); - float dotResult=angleView.dot(_direction); - //EGE_DEBUG("Dot position : " << destPosition << " == > dot=" << dotResult); - /* - if (dotResult <= 0.85f) { - // they are not in the camera angle view ... == > no need to process display - continue; - } - */ - result.dist = (_position - destPosition).length(); - /* - if (result.dist>500.0f) { - // The element is realy too far ... == > no need to display - continue; - } - */ - // try to add the element at the best positions: - size_t jjj; - for (jjj=0; jjj<_resultList.size(); jjj++) { - if (_resultList[jjj].dist>result.dist) { - _resultList.insert(_resultList.begin()+jjj, result); - break; - } - } - // add element at the end : - if (jjj >= _resultList.size()) { - _resultList.push_back(result); - } - } -} - - void ege::Environement::generateInteraction(ege::ElementInteraction& _event) { // inform the element that an element has been removed == > this permit to keep pointer on elements ... for (size_t iii=0; iiigetType()); it->render(_delta, camera); } + for (auto &it: m_engine) { + if(it == nullptr) { + continue; + } + EGE_VERBOSE(" render: " << it->getType()); + it->renderDebug(_delta, camera); + } } void ege::Environement::onCallbackPeriodicCall(const ewol::event::Time& _event) { diff --git a/ege/Environement.hpp b/ege/Environement.hpp index 2d3740c..d452cfe 100644 --- a/ege/Environement.hpp +++ b/ege/Environement.hpp @@ -181,6 +181,7 @@ namespace ege { * @param[in] _distance Maximum distance search == > return the element distance * @return Pointer on the neares element OR nullptr */ + /* ememory::SharedPtr getElementNearest(ememory::SharedPtr _sourceRequest, float& _distance); void getElementNearest(const vec3& _sourcePosition, @@ -189,6 +190,7 @@ namespace ege { void getElementNearestFixed(const vec3& _sourcePosition, float _distanceMax, std::vector& _resultList); + */ /** * @brief add an element on the list availlable. * @param[in] _newElement Element to add. @@ -199,13 +201,6 @@ namespace ege { * @param[in] _removeElement Element to remove. */ void rmElement(ememory::SharedPtr _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. - * @param[in,out] _resultList List of the element ordered. - * @param[in] _position Camera position in the space. - * @param[in] _direction Camera direction of the view. - */ - void getOrderedElementForDisplay(std::vector& _resultList, const vec3& _position, const vec3& _direction); /** * @brief generate an event on all the sub element of the game == > usefull for explosion, or lazer fire ... * @param[in] _event event that might be apply ... diff --git a/ege/elements/Element.cpp b/ege/elements/Element.cpp index 48f67ec..5803237 100644 --- a/ege/elements/Element.cpp +++ b/ege/elements/Element.cpp @@ -8,7 +8,6 @@ #include #include #include -#include const std::string& ege::Element::getType() const { @@ -20,16 +19,14 @@ const std::string& ege::Element::getType() const { ege::Element::Element(const ememory::SharedPtr& _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); + //m_debugText.setFontSize(12); unique++; } @@ -183,27 +180,6 @@ bool ege::Element::unInit() { } -bool ege::Element::loadMesh(const std::string& _meshFileName) { - ememory::SharedPtr tmpMesh = ege::resource::Mesh::create(_meshFileName); - if(tmpMesh == nullptr) { - EGE_ERROR("can not load the resources : " << _meshFileName); - return false; - } - return setMesh(tmpMesh); -} - -bool ege::Element::setMesh(ememory::SharedPtr _mesh) { - if (m_mesh != nullptr) { - 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) { @@ -224,18 +200,12 @@ void ege::Element::setFireOn(int32_t _groupIdSource, int32_t _type, float _power } } -const vec3& ege::Element::getPosition() { - // this is to prevent error like segmentation fault ... - static vec3 emptyPosition(-1000000,-1000000,-1000000); - return emptyPosition; -}; - - const float lifeBorder = 0.1f; const float lifeHeight = 0.3f; const float lifeWidth = 2.0f; const float lifeYPos = 1.7f; +#if 0 void ege::Element::drawLife(ememory::SharedPtr _draw, ememory::SharedPtr _camera) { if (_draw == nullptr) { return; @@ -274,16 +244,20 @@ void ege::Element::drawLife(ememory::SharedPtr _draw->draw(localVertices, myColor, transformationMatrix, false, false); #endif } +#endif void ege::Element::drawDebug(ememory::SharedPtr _draw, ememory::SharedPtr _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(")")); /* + // TODO : Keep this it can be usefull to print something in direction of the camera ... 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())) @@ -291,10 +265,6 @@ void ege::Element::drawDebug(ememory::SharedPtr */ } -void ege::Element::drawNormalDebug(ememory::SharedPtr _draw, ememory::SharedPtr _camera) { - // nothing to do ... -} - diff --git a/ege/elements/Element.hpp b/ege/elements/Element.hpp index 051d943..5cbe27d 100644 --- a/ege/elements/Element.hpp +++ b/ege/elements/Element.hpp @@ -74,40 +74,6 @@ namespace ege { inline uint32_t getUID() const { return m_uID; }; - /* - * ********************************* - * Remove in progress .... [BEGIN] - * ********************************* - */ - protected: - ememory::SharedPtr m_mesh; //!< Mesh of the Element (can be nullptr) - public: - /** - * @brief Select a mesh with a specific name. - * @param[in] _meshFileName filename of the Mesh. - * @note Automaticly load the shape if it is specify in the mesh file - * @return true if no error occured - */ - virtual bool loadMesh(const std::string& _meshFileName); - /** - * @brief set the the Mesh properties. - * @param[in] _mesh The mesh pointer. (nullptr to force the mesh remove ...) - * @note : this remove the shape and the mesh properties. - * @return true if no error occured - */ - virtual bool setMesh(ememory::SharedPtr _mesh); - /** - * @brief get a pointer on the Mesh file. - * @return the mesh pointer. - */ - inline ememory::SharedPtr getMesh() { - return m_mesh; - }; - /* - * ********************************* - * Remove in progress .... [END] - * ********************************* - */ protected: float m_life; //!< Current life of the object float m_lifeMax; //!< Maximum possible life of the element @@ -160,28 +126,9 @@ namespace ege { inline void setGroup(int32_t _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) - * @param[in] the camera properties - * @ note by default nothing to do ... - */ - virtual void preCalculationDraw(const ege::Camera& _camera) { }; - /** - * @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 - */ - // TODO : Remove this ... - virtual void drawLife(ememory::SharedPtr _draw, ememory::SharedPtr _camera); - protected: // For debug only ... - ewol::compositing::Text m_debugText; + //ewol::compositing::Text m_debugText; // ==> this is reall y a bad idea==> it is inneficient ... public: /** * @brief Debug display of the current element @@ -189,45 +136,11 @@ namespace ege { * @param[in] _camera Current camera for display */ virtual void drawDebug(ememory::SharedPtr _draw, ememory::SharedPtr _camera); - /** - * @brief Debug display of the current element normal face - * @param[in,out] _draw Basic system to draw the debug shape and informations - * @param[in] _camera Current camera for display - */ - virtual void drawNormalDebug(ememory::SharedPtr _draw, ememory::SharedPtr _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 get the current position of the element - * @return the 3D position. - */ - virtual const vec3& getPosition(); - /** - * @brief set the current position of the element - * @param[in] _pos set the 3D position. - */ - virtual void setPosition(const vec3& _pos) {}; /** * @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. */ virtual void elementIsRemoved(ememory::SharedPtr _removedElement) { }; - protected: - bool m_fixe; //!< is a fixed element == > used for placement of every elements - public: - /** - * @brief get the element if it is fixed or not. if the element is fixed this is for tower, and all thing does not really move - * @return true : The element is fixed. - */ - inline bool isFixed() { - return m_fixe; - }; protected: float m_radius; //!< Radius of the element (all element have a radius, if == 0 ==> then ghost ... public: diff --git a/ege/elements/ElementBase.cpp b/ege/elements/ElementBase.cpp index c681c1a..53e4c2c 100644 --- a/ege/elements/ElementBase.cpp +++ b/ege/elements/ElementBase.cpp @@ -4,6 +4,9 @@ * @license MPL v2.0 (see license file) */ +******************************************* +** IS REMOVED +******************************************* #include #include diff --git a/ege/elements/ElementBase.hpp b/ege/elements/ElementBase.hpp index 42545bc..1223900 100644 --- a/ege/elements/ElementBase.hpp +++ b/ege/elements/ElementBase.hpp @@ -3,6 +3,13 @@ * @copyright 2011, Edouard DUPIN, all right reserved * @license MPL v2.0 (see license file) */ +******************************************* +** IS REMOVED +******************************************* + + + + #pragma once #include diff --git a/ege/elements/ElementPhysic.cpp b/ege/elements/ElementPhysic.cpp index b4d3afb..7b067bc 100644 --- a/ege/elements/ElementPhysic.cpp +++ b/ege/elements/ElementPhysic.cpp @@ -4,6 +4,13 @@ * @license MPL v2.0 (see license file) */ +******************************************* +** IS REMOVED +******************************************* + + + + #include #include #include @@ -318,41 +325,6 @@ void ege::ElementPhysic::drawShape(/*const btCollisionShape* _shape,*/ #endif } -void ege::ElementPhysic::drawDebug(ememory::SharedPtr _draw, ememory::SharedPtr _camera) { - ege::Element::drawDebug(_draw, _camera); - /* - btScalar mmm[16]; - if (m_body == nullptr) { - return; - } - btDefaultMotionState* myMotionState = (btDefaultMotionState*)m_body->getMotionState(); - myMotionState->m_graphicsWorldTrans.getOpenGLMatrix(mmm); - - mat4 transformationMatrix(mmm); - transformationMatrix.transpose(); - - // note : set the vertice here to prevent multiple allocations... - std::vector EwolVertices; - drawShape(m_shape, _draw, transformationMatrix, EwolVertices); - */ -} - -void ege::ElementPhysic::drawNormalDebug(ememory::SharedPtr _draw, ememory::SharedPtr _camera) { - /* - if( m_body != nullptr - && m_mesh != nullptr - && m_body->getMotionState() ) { - //EGE_INFO("element pos = " << getPosition()); - btScalar mmm[16]; - btDefaultMotionState* myMotionState = (btDefaultMotionState*)m_body->getMotionState(); - myMotionState->m_graphicsWorldTrans.getOpenGLMatrix(mmm); - - mat4 transformationMatrix(mmm); - transformationMatrix.transpose(); - m_mesh->drawNormal(transformationMatrix, _draw); - } - */ -} void ege::ElementPhysic::draw(int32_t _pass) { if (m_elementInPhysicsSystem == false) { diff --git a/ege/elements/ElementPhysic.hpp b/ege/elements/ElementPhysic.hpp index 4a381a2..81f2322 100644 --- a/ege/elements/ElementPhysic.hpp +++ b/ege/elements/ElementPhysic.hpp @@ -5,6 +5,13 @@ */ #pragma once +******************************************* +** IS REMOVED +******************************************* + + + + #include #include #include diff --git a/ege/particule/Engine.cpp b/ege/particule/Engine.cpp index 2d440a8..744cba1 100644 --- a/ege/particule/Engine.cpp +++ b/ege/particule/Engine.cpp @@ -7,7 +7,7 @@ #include #include #include -#include +#include ege::particule::Engine::Engine(ege::Environement* _env) : ege::Engine(_env) { @@ -88,7 +88,7 @@ void ege::particule::Engine::update(const echrono::Duration& _delta) { if (deltaTime>(1.0f/60.0f)) { deltaTime = (1.0f/60.0f); } - EGE_WARNING("Update the Particule engine ... " << deltaTime); + EGE_DEBUG("Update the Particule engine ... " << deltaTime); for (size_t iii=0; iii _env) { rp3d::Vector3 initPosition(0.0f, 0.0f, 0.0f); rp3d::Quaternion initOrientation = rp3d::Quaternion::identity(); rp3d::Transform transform(initPosition, initOrientation); + m_lastTransformEmit = etk::Transform3D(vec3(0,0,0), etk::Quaternion::identity()); m_rigidBody = m_engine->getDynamicWorld()->createRigidBody(transform); } @@ -40,6 +41,7 @@ ege::physics::Component::Component(ememory::SharedPtr _env, c rp3d::Transform transform(initPosition, initOrientation); // Create a rigid body in the world m_rigidBody = m_engine->getDynamicWorld()->createRigidBody(transform); + m_lastTransformEmit = _transform; } void ege::physics::Component::setType(enum ege::physics::Component::type _type) { @@ -79,7 +81,7 @@ void ege::physics::Component::generate() { } switch (it->getType()) { case ege::PhysicsShape::box : { - EGE_ERROR(" Box"); + EGE_DEBUG(" Box"); const ege::PhysicsBox* tmpElement = it->toBox(); if (tmpElement == nullptr) { EGE_ERROR(" Box ==> can not cast in BOX"); @@ -92,15 +94,15 @@ void ege::physics::Component::generate() { // Create the box shape rp3d::BoxShape* shape = new rp3d::BoxShape(halfExtents); m_listShape.push_back(shape); - rp3d::Vector3 position(tmpElement->getOrigin().x(), - tmpElement->getOrigin().y(), - tmpElement->getOrigin().z()); - rp3d::Quaternion orientation(tmpElement->getQuaternion().x(), - tmpElement->getQuaternion().y(), - tmpElement->getQuaternion().z(), - tmpElement->getQuaternion().w()); + rp3d::Vector3 position(it->getOrigin().x(), + it->getOrigin().y(), + it->getOrigin().z()); + rp3d::Quaternion orientation(it->getQuaternion().x(), + it->getQuaternion().y(), + it->getQuaternion().z(), + it->getQuaternion().w()); rp3d::Transform transform(position, orientation); - rp3d::ProxyShape* proxyShape = m_rigidBody->addCollisionShape(shape, transform, 4.0f /* mass */); + rp3d::ProxyShape* proxyShape = m_rigidBody->addCollisionShape(shape, transform, it->getMass()); m_listProxyShape.push_back(proxyShape); break; } @@ -113,15 +115,15 @@ void ege::physics::Component::generate() { } // Create the box shape rp3d::CylinderShape* shape = new rp3d::CylinderShape(tmpElement->getSize().x(), tmpElement->getSize().y()); - rp3d::Vector3 position(tmpElement->getOrigin().x(), - tmpElement->getOrigin().y(), - tmpElement->getOrigin().z()); - rp3d::Quaternion orientation(tmpElement->getQuaternion().x(), - tmpElement->getQuaternion().y(), - tmpElement->getQuaternion().z(), - tmpElement->getQuaternion().w()); + rp3d::Vector3 position(it->getOrigin().x(), + it->getOrigin().y(), + it->getOrigin().z()); + rp3d::Quaternion orientation(it->getQuaternion().x(), + it->getQuaternion().y(), + it->getQuaternion().z(), + it->getQuaternion().w()); rp3d::Transform transform(position, orientation); - rp3d::ProxyShape* proxyShape = m_rigidBody->addCollisionShape(shape, transform, 4.0f /* mass */); + rp3d::ProxyShape* proxyShape = m_rigidBody->addCollisionShape(shape, transform, it->getMass()); m_listProxyShape.push_back(proxyShape); break; } @@ -218,6 +220,46 @@ void ege::physics::Component::generate() { } +void ege::physics::Component::emitAll() { + // emit onbly of new ... + etk::Transform3D transform = getTransform(); + if (m_lastTransformEmit != transform) { + m_lastTransformEmit = transform; + signalPosition.emit(transform); + } +} + + +void ege::physics::Component::setTransform(const etk::Transform3D& _transform) { + if (m_rigidBody == nullptr) { + return; + } + rp3d::Vector3 position(_transform.getPosition().x(), + _transform.getPosition().y(), + _transform.getPosition().z()); + rp3d::Quaternion orientation(_transform.getOrientation().x(), + _transform.getOrientation().y(), + _transform.getOrientation().z(), + _transform.getOrientation().w()); + rp3d::Transform transform(position, orientation); + m_rigidBody->setTransform(transform); +} + +etk::Transform3D ege::physics::Component::getTransform() const { + if (m_rigidBody == nullptr) { + return etk::Transform3D::identity(); + } + rp3d::Transform transform = m_rigidBody->getTransform(); + vec3 position(transform.getPosition().x, + transform.getPosition().y, + transform.getPosition().z); + etk::Quaternion orientation(transform.getOrientation().x, + transform.getOrientation().y, + transform.getOrientation().z, + transform.getOrientation().w); + return etk::Transform3D(position, orientation); +} + vec3 ege::physics::Component::getLinearVelocity() const { if (m_rigidBody == nullptr) { return vec3(0,0,0); @@ -269,33 +311,138 @@ void ege::physics::Component::addShape(const ememory::SharedPtrsetTransform(transform); -} -etk::Transform3D ege::physics::Component::getTransform() const { - if (m_rigidBody == nullptr) { - return etk::Transform3D::identity(); +void ege::physics::Component::drawShape(ememory::SharedPtr _draw, ememory::SharedPtr _camera) { + etk::Transform3D transform = getTransform(); + float mmm[16]; + // Get the OpenGL matrix array of the transform + transform.getOpenGLMatrix(mmm); + mat4 transformationMatrix(mmm); + transformationMatrix.transpose(); + etk::Color tmpColor(1.0, 0.0, 0.0, 0.3); + for (auto &it: m_shape) { + if (it == nullptr) { + continue; + } + switch (it->getType()) { + case ege::PhysicsShape::box: { + EGE_DEBUG(" Box"); + const ege::PhysicsBox* tmpElement = it->toBox(); + if (tmpElement == nullptr) { + EGE_ERROR(" Box ==> can not cast in BOX"); + continue; + } + etk::Transform3D transformLocal(it->getOrigin(), it->getOrientation()); + transformLocal.getOpenGLMatrix(mmm); + mat4 transformationMatrixLocal(mmm); + transformationMatrixLocal.transpose(); + transformationMatrixLocal = transformationMatrix * transformationMatrixLocal; + _draw->drawSquare(tmpElement->getSize(), transformationMatrixLocal, tmpColor); + break; + } + case ege::PhysicsShape::cylinder : { + EGE_DEBUG(" Cylinder"); + const ege::PhysicsCylinder* tmpElement = it->toCylinder(); + if (tmpElement == nullptr) { + EGE_ERROR(" Cylinder ==> can not cast in Cylinder"); + continue; + } + etk::Transform3D transformLocal(it->getOrigin(), it->getOrientation()); + transformLocal.getOpenGLMatrix(mmm); + mat4 transformationMatrixLocal(mmm); + transformationMatrixLocal.transpose(); + transformationMatrixLocal = transformationMatrix * transformationMatrixLocal; + //_draw->drawSphere(radius, 10, 10, _transformationMatrix, tmpColor); + break; + } + case ege::PhysicsShape::capsule : { + EGE_DEBUG(" Capsule"); + const ege::PhysicsCapsule* tmpElement = it->toCapsule(); + if (tmpElement == nullptr) { + EGE_ERROR(" Capsule ==> can not cast in Capsule"); + continue; + } + /* + btCollisionShape* tmpShape = new btCapsuleShape(tmpElement->getRadius(), tmpElement->getHeight()); + if (tmpShape != nullptr) { + if (outputShape == nullptr) { + return tmpShape; + } else { + vec4 qqq = tmpElement->getQuaternion(); + const btTransform localTransform(btQuaternion(qqq.x(),qqq.y(),qqq.z(),qqq.w()), tmpElement->getOrigin()); + outputShape->addChildShape(localTransform, tmpShape); + } + } + */ + break; + } + case ege::PhysicsShape::cone : { + EGE_DEBUG(" Cone"); + const ege::PhysicsCone* tmpElement = it->toCone(); + if (tmpElement == nullptr) { + EGE_ERROR(" Cone ==> can not cast in Cone"); + continue; + } + /* + btCollisionShape* tmpShape = new btConeShape(tmpElement->getRadius(), tmpElement->getHeight()); + if (tmpShape != nullptr) { + if (outputShape == nullptr) { + return tmpShape; + } else { + vec4 qqq = tmpElement->getQuaternion(); + const btTransform localTransform(btQuaternion(qqq.x(),qqq.y(),qqq.z(),qqq.w()), tmpElement->getOrigin()); + outputShape->addChildShape(localTransform, tmpShape); + } + } + */ + break; + } + case ege::PhysicsShape::sphere : { + EGE_DEBUG(" Sphere"); + const ege::PhysicsSphere* tmpElement = it->toSphere(); + if (tmpElement == nullptr) { + EGE_ERROR(" Sphere ==> can not cast in Sphere"); + continue; + } + /* + btCollisionShape* tmpShape = new btSphereShape(tmpElement->getRadius()); + if (tmpShape != nullptr) { + if (outputShape == nullptr) { + return tmpShape; + } else { + vec4 qqq = tmpElement->getQuaternion(); + const btTransform localTransform(btQuaternion(qqq.x(),qqq.y(),qqq.z(),qqq.w()), tmpElement->getOrigin()); + outputShape->addChildShape(localTransform, tmpShape); + } + } + */ + break; + } + case ege::PhysicsShape::convexHull : { + EGE_DEBUG(" convexHull"); + const ege::PhysicsConvexHull* tmpElement = it->toConvexHull(); + if (tmpElement == nullptr) { + EGE_ERROR(" convexHull ==> can not cast in convexHull"); + continue; + } + /* + btConvexHullShape* tmpShape = new btConvexHullShape(&(tmpElement->getPointList()[0].x()), tmpElement->getPointList().size()); + if (tmpShape != nullptr) { + if (outputShape == nullptr) { + return tmpShape; + } else { + vec4 qqq = tmpElement->getQuaternion(); + const btTransform localTransform(btQuaternion(qqq.x(),qqq.y(),qqq.z(),qqq.w()), tmpElement->getOrigin()); + outputShape->addChildShape(localTransform, tmpShape); + } + } + */ + break; + } + default : + EGE_DEBUG(" ???"); + // TODO : UNKNOW type ... + break; + } } - rp3d::Transform transform = m_rigidBody->getTransform(); - vec3 position(transform.getPosition().x, - transform.getPosition().y, - transform.getPosition().z); - etk::Quaternion orientation(transform.getOrientation().x, - transform.getOrientation().y, - transform.getOrientation().z, - transform.getOrientation().w); - return etk::Transform3D(position, orientation); -} - +} \ No newline at end of file diff --git a/ege/physics/Component.hpp b/ege/physics/Component.hpp index 35213d8..220962f 100644 --- a/ege/physics/Component.hpp +++ b/ege/physics/Component.hpp @@ -12,6 +12,7 @@ #include #include #include +#include namespace ege { class Environement; @@ -20,6 +21,8 @@ namespace ege { class Component : public ege::Component { public: esignal::Signal signalPosition; + protected: + etk::Transform3D m_lastTransformEmit; protected: ememory::SharedPtr m_engine; rp3d::RigidBody* m_rigidBody; @@ -82,6 +85,10 @@ namespace ege { void setShape(const std::vector>& _prop); void addShape(const ememory::SharedPtr& _shape); void generate(); + void drawShape(ememory::SharedPtr _draw, ememory::SharedPtr _camera); + private: + void emitAll(); + friend class ege::physics::Engine; }; } } \ No newline at end of file diff --git a/ege/physics/Engine.cpp b/ege/physics/Engine.cpp index fa015b7..3c65aff 100644 --- a/ege/physics/Engine.cpp +++ b/ege/physics/Engine.cpp @@ -12,22 +12,36 @@ #include #include -#include - const std::string& ege::physics::Engine::getType() const { static std::string tmp("physics"); return tmp; } void ege::physics::Engine::componentRemove(const ememory::SharedPtr& _ref) { - + ememory::SharedPtr ref = ememory::dynamicPointerCast(_ref); + for (auto it=m_component.begin(); + it != m_component.end(); + ++it) { + if (*it == ref) { + it->reset(); + return; + } + } } void ege::physics::Engine::componentAdd(const ememory::SharedPtr& _ref) { - + ememory::SharedPtr ref = ememory::dynamicPointerCast(_ref); + for (auto it=m_component.begin(); + it != m_component.end(); + ++it) { + if (*it == nullptr) { + *it = ref; + return; + } + } + m_component.push_back(ref); } - // unique callback function : /* extern ContactProcessedCallback gContactProcessedCallback; @@ -54,8 +68,11 @@ static bool handleContactsProcess(btManifoldPoint& _point, btCollisionObject* _b ege::physics::Engine::Engine(ege::Environement* _env) : ege::Engine(_env), + propertyDebugAABB(this, "debug-AABB", false, "display the global AABB box of every shape"), + propertyDebugShape(this, "debug-shape", false, "display the physic shape"), m_dynamicsWorld(nullptr), m_accumulator(0.0f) { + m_debugDrawProperty = ewol::resource::Colored3DObject::create(); // Start engine with no gravity //rp3d::Vector3 gravity(0.0, -9.81, 0.0); // generic earth gravity rp3d::Vector3 gravity(0.0f, 0.0f, 0.0f); @@ -92,13 +109,34 @@ void ege::physics::Engine::update(const echrono::Duration& _delta) { while (m_accumulator >= timeStep) { if (m_dynamicsWorld != nullptr) { // Update the Dynamics world with a constant time step - EGE_WARNING("Update the Physic engine ... " << timeStep); + EGE_DEBUG("Update the Physic engine ... " << timeStep); m_dynamicsWorld->update(timeStep); } // Decrease the accumulated time m_accumulator -= timeStep; } + for (auto &it: m_component) { + // check nullptr pointer + if (it == nullptr) { + // no pointer null are set in the output list ... + continue; + } + it->emitAll(); + } } + + +void ege::physics::Engine::renderDebug(const echrono::Duration& _delta, const ememory::SharedPtr& _camera) { + if (propertyDebugShape.get() == true) { + for (auto &it : m_component) { + if (it == nullptr) { + continue; + } + it->drawShape(m_debugDrawProperty, _camera); + } + } +} + #if 0 std::vector ege::physics::Engine::getListOfCollision() { std::vector out; @@ -132,4 +170,5 @@ std::vector ege::physics::Engine::getList return out; } -#endif \ No newline at end of file +#endif + diff --git a/ege/physics/Engine.hpp b/ege/physics/Engine.hpp index 7bc89ba..c605240 100644 --- a/ege/physics/Engine.hpp +++ b/ege/physics/Engine.hpp @@ -23,11 +23,16 @@ namespace ege { #include #include #include +#include +#include namespace ege { namespace physics { class Engine : public ege::Engine { + public: + eproperty::Value propertyDebugAABB; + eproperty::Value propertyDebugShape; private: rp3d::DynamicsWorld* m_dynamicsWorld; float m_accumulator; // limit call of the step rendering @@ -74,12 +79,16 @@ namespace ege { rp3d::DynamicsWorld* getDynamicWorld() { return m_dynamicsWorld; } + protected: + std::vector> m_component; + //TODO : set it not in ewol ... + ememory::SharedPtr m_debugDrawProperty; public: const std::string& getType() const override; void componentRemove(const ememory::SharedPtr& _ref) override; void componentAdd(const ememory::SharedPtr& _ref) override; void update(const echrono::Duration& _delta) override; - //void render(const echrono::Duration& _delta, const ememory::SharedPtr& _camera) override; + void renderDebug(const echrono::Duration& _delta, const ememory::SharedPtr& _camera) override; }; } } diff --git a/ege/physicsShape/PhysicsShape.cpp b/ege/physicsShape/PhysicsShape.cpp index 9624872..af0e2ee 100644 --- a/ege/physicsShape/PhysicsShape.cpp +++ b/ege/physicsShape/PhysicsShape.cpp @@ -41,15 +41,20 @@ ememory::SharedPtr ege::PhysicsShape::create(const std::strin bool ege::PhysicsShape::parse(const char* _line) { if(strncmp(_line, "origin:", 7) == 0) { - sscanf(&_line[9], "%f %f %f", &m_origin.m_floats[0], &m_origin.m_floats[1], &m_origin.m_floats[2] ); + sscanf(&_line[7], "%f %f %f", &m_origin.m_floats[0], &m_origin.m_floats[1], &m_origin.m_floats[2] ); EGE_VERBOSE(" Origin=" << m_origin); return true; } if(strncmp(_line, "rotate:", 7) == 0) { - sscanf(&_line[9], "%f %f %f %f", &m_quaternion.m_floats[0], &m_quaternion.m_floats[1], &m_quaternion.m_floats[2], &m_quaternion.m_floats[3] ); + sscanf(&_line[7], "%f %f %f %f", &m_quaternion.m_floats[0], &m_quaternion.m_floats[1], &m_quaternion.m_floats[2], &m_quaternion.m_floats[3] ); EGE_VERBOSE(" rotate=" << m_quaternion); return true; } + if(strncmp(_line, "mass:", 5) == 0) { + sscanf(&_line[5], "%f", &m_mass ); + EGE_VERBOSE(" mass=" << m_mass); + return true; + } return false; } diff --git a/ege/physicsShape/PhysicsShape.hpp b/ege/physicsShape/PhysicsShape.hpp index d278001..620d53f 100644 --- a/ege/physicsShape/PhysicsShape.hpp +++ b/ege/physicsShape/PhysicsShape.hpp @@ -8,6 +8,7 @@ #include #include #include +#include #include @@ -35,34 +36,47 @@ namespace ege { public: PhysicsShape() : m_quaternion(1,0,0,0), - m_origin(0,0,0) { + m_origin(0,0,0), + m_mass(1) { // by default set mass at 1g - }; + } virtual ~PhysicsShape() { - }; + } public: virtual enum ege::PhysicsShape::type getType() const { return ege::PhysicsShape::unknow; - }; + } public: virtual bool parse(const char* _line); virtual void display() { - }; + } private: vec4 m_quaternion; public: const vec4& getQuaternion() const { return m_quaternion; - }; + } + etk::Quaternion getOrientation() const { + return etk::Quaternion(m_quaternion.x(), m_quaternion.y(), m_quaternion.z(), m_quaternion.w()); + } private: vec3 m_origin; public: const vec3& getOrigin() const { return m_origin; }; + private: + float m_mass; //!< element mass in "g" then 1000 for 1kg + public: + float getMass() const { + return m_mass; + } + void setMass(float _mass) { + m_mass = _mass; + } public: bool isBox() { return getType() == ege::PhysicsShape::box; diff --git a/ege/render/Component.cpp b/ege/render/Component.cpp index f03b428..bad79e1 100644 --- a/ege/render/Component.cpp +++ b/ege/render/Component.cpp @@ -76,13 +76,22 @@ void ege::render::Component::draw(int32_t _pass) { float mmm[16]; // Get the OpenGL matrix array of the transform m_transform.getOpenGLMatrix(mmm); - - //EGE_INFO(" mat = " << mat4(mmm)); mat4 transformationMatrix(mmm); - //mat4 transformationMatrix = mat4(mmm) * etk::matScale(vec3(20,20,20)); transformationMatrix.transpose(); // TODO: check this : transformationMatrix.transpose(); m_mesh->draw(transformationMatrix); } } -} \ No newline at end of file +} + +void ege::render::Component::drawNormalDebug(ememory::SharedPtr _draw) { + if(m_mesh != nullptr) { + float mmm[16]; + // Get the OpenGL matrix array of the transform + m_transform.getOpenGLMatrix(mmm); + mat4 transformationMatrix(mmm); + transformationMatrix.transpose(); + m_mesh->drawNormal(transformationMatrix, _draw); + } +} + diff --git a/ege/render/Component.hpp b/ege/render/Component.hpp index a5d7f79..9ae6f6c 100644 --- a/ege/render/Component.hpp +++ b/ege/render/Component.hpp @@ -64,7 +64,11 @@ namespace ege { * @param[in] pass Id of the current pass : [0..?] */ virtual void draw(int32_t _pass=0); - + /** + * @brief Debug display of the current element normal face + * @param[in,out] _draw Basic system to draw the debug shape and informations + */ + void drawNormalDebug(ememory::SharedPtr _draw); public: const std::string& getType() const override; void addFriendComponent(const ememory::SharedPtr& _component) override; diff --git a/ege/render/Engine.cpp b/ege/render/Engine.cpp index 5c6ca40..016f392 100644 --- a/ege/render/Engine.cpp +++ b/ege/render/Engine.cpp @@ -6,8 +6,9 @@ #include ege::render::Engine::Engine(ege::Environement* _env) : - ege::Engine(_env) { - + ege::Engine(_env), + propertyDebugNormal(this, "debug-normal", false, "display the normal debug information") { + m_debugDrawProperty = ewol::resource::Colored3DObject::create(); } const std::string& ege::render::Engine::getType() const { @@ -17,7 +18,7 @@ const std::string& ege::render::Engine::getType() const { void ege::render::Engine::componentRemove(const ememory::SharedPtr& _ref) { ememory::SharedPtr ref = ememory::dynamicPointerCast(_ref); - for (auto it=m_component.begin(); + for (auto it = m_component.begin(); it != m_component.end(); ++it) { if (*it == ref) { @@ -95,13 +96,14 @@ void ege::render::Engine::getOrderedElementForDisplay(std::vector& _camera) { + /* for (auto &it : m_component) { if (it == nullptr) { continue; } } - + */ //EGE_DEBUG("Draw (start)"); mat4 tmpMatrix; getOrderedElementForDisplay(m_displayElementOrdered, _camera->getEye(), _camera->getViewVector()); @@ -118,6 +120,13 @@ void ege::render::Engine::render(const echrono::Duration& _delta, const ememory: it.element->draw(pass); } } +} + +void ege::render::Engine::renderDebug(const echrono::Duration& _delta, const ememory::SharedPtr& _camera) { + //EGE_DEBUG("Draw (start)"); + mat4 tmpMatrix; + getOrderedElementForDisplay(m_displayElementOrdered, _camera->getEye(), _camera->getViewVector()); + EGE_VERBOSE("DRAW : " << m_displayElementOrdered.size() << "/" << m_component.size() << " elements"); #if 0 if (propertyDebugPhysic.get() == true) { // Draw debug ... (Object) @@ -134,13 +143,14 @@ void ege::render::Engine::render(const echrono::Duration& _delta, const ememory: } */ } + #endif if (propertyDebugNormal.get() == true) { // Draw debug ... (Object) for (int32_t iii=m_displayElementOrdered.size()-1; iii >= 0; iii--) { - m_displayElementOrdered[iii].element->drawNormalDebug(m_debugDrawProperty, camera); + m_displayElementOrdered[iii].element->drawNormalDebug(m_debugDrawProperty); } } - + #if 0 if (propertyDebugApplication.get() == true) { // Draw debug ... (User) signalDisplayDebug.emit(m_debugDrawProperty); diff --git a/ege/render/Engine.hpp b/ege/render/Engine.hpp index 4755bc2..e55cab3 100644 --- a/ege/render/Engine.hpp +++ b/ege/render/Engine.hpp @@ -12,6 +12,8 @@ #include #include #include +#include +#include namespace ege { @@ -20,6 +22,7 @@ namespace ege { public: Engine(ege::Environement* _env); ~Engine() {} + eproperty::Value propertyDebugNormal; protected: std::vector> m_component; class ResultNearestElement { @@ -28,14 +31,17 @@ namespace ege { float dist; }; std::vector m_displayElementOrdered; + //TODO : set it not in ewol ... + ememory::SharedPtr m_debugDrawProperty; public: const std::string& getType() const override; void componentRemove(const ememory::SharedPtr& _ref) override; void componentAdd(const ememory::SharedPtr& _ref) override; void render(const echrono::Duration& _delta, const ememory::SharedPtr& _camera) override; + void renderDebug(const echrono::Duration& _delta, const ememory::SharedPtr& _camera) override; void getOrderedElementForDisplay(std::vector& _resultList, - const vec3& _position, - const vec3& _direction); + const vec3& _position, + const vec3& _direction); }; } } diff --git a/ege/resource/Mesh.cpp b/ege/resource/Mesh.cpp index 2f2b1fd..ba573e9 100644 --- a/ege/resource/Mesh.cpp +++ b/ege/resource/Mesh.cpp @@ -14,7 +14,7 @@ #include ege::resource::Mesh::Mesh() : - m_normalMode(normalModeNone), + m_normalMode(ege::resource::Mesh::normalMode::none), m_checkNormal(false), m_GLPosition(-1), m_GLMatrix(-1), @@ -138,7 +138,7 @@ void ege::resource::Mesh::draw(mat4& _positionMatrix, m_GLprogram->sendAttributePointer(m_GLtexture, m_verticesVBO, MESH_VBO_TEXTURE); } // position : - if (m_normalMode != normalModeNone) { + if (m_normalMode != ege::resource::Mesh::normalMode::none) { m_GLprogram->sendAttributePointer(m_GLNormal, m_verticesVBO, MESH_VBO_VERTICES_NORMAL); #if DEBUG // TODO : ... @@ -184,7 +184,7 @@ void ege::resource::Mesh::draw(mat4& _positionMatrix, std::vector& tmppFaces = m_listFaces.getValue(kkk).m_faces; //std::vector& tmppIndex = m_listFaces.getValue(kkk).m_index; switch(m_normalMode) { - case normalModeFace: + case ege::resource::Mesh::normalMode::face: for(size_t iii=0; iii= 0.0f) { tmpIndexResult.push_back(iii*3); @@ -193,7 +193,7 @@ void ege::resource::Mesh::draw(mat4& _positionMatrix, } } break; - case normalModeVertex: + case ege::resource::Mesh::normalMode::vertex: for(size_t iii=0; iii= -0.2f) || ((mattttt * m_listVertexNormal[tmppFaces[iii].m_normal[1]]).dot(cameraNormal) >= -0.2f) @@ -278,17 +278,17 @@ void ege::resource::Mesh::drawNormal(mat4& _positionMatrix, FaceIndexing& tmpFaceList = m_listFaces.getValue(kkk); for (size_t iii=0; iii= m_listFacesNormal.size()) { + EGE_ERROR("not enougth normal in the buffer ... " << index << " >= " << m_listFacesNormal.size()); + return; + } + vec3 normal = m_listFacesNormal[index]; vertices.push_back(center); - vertices.push_back(center+normal*0.25f); + vertices.push_back(center+normal*0.5f); } break; - case normalModeNone: + case ege::resource::Mesh::normalMode::none: break; } } @@ -308,11 +313,15 @@ void ege::resource::Mesh::drawNormal(mat4& _positionMatrix, _draw->drawLine(vertices, tmpColor, _positionMatrix); } +void ege::resource::Mesh::setNormalMode(enum normalMode _mode) { + m_normalMode = _mode; +} + // normal calculation of the normal face is really easy : // TODO : Use it for multiple Material interface void ege::resource::Mesh::calculateNormaleFace(const std::string& _materialName) { m_listFacesNormal.clear(); - if (m_normalMode == ege::resource::Mesh::normalModeFace) { + if (m_normalMode == ege::resource::Mesh::normalMode::face) { EGE_VERBOSE("calculateNormaleFace(" << _materialName << ")"); gale::openGL::renderMode tmpRenderMode = m_materials[_materialName]->getRenderMode(); if ( tmpRenderMode == gale::openGL::renderMode::point @@ -320,25 +329,30 @@ void ege::resource::Mesh::calculateNormaleFace(const std::string& _materialName) || tmpRenderMode == gale::openGL::renderMode::lineStrip || tmpRenderMode == gale::openGL::renderMode::lineLoop) { EGE_ERROR("calculateNormaleFace(" << _materialName << ") : can not calculate normal on lines ..."); - m_normalMode = ege::resource::Mesh::normalModeNone; + m_normalMode = ege::resource::Mesh::normalMode::none; return; } for(auto &it : m_listFaces[_materialName].m_faces) { // for all case, We use only the 3 vertex for quad element, in theory 3D modeler export element in triangle if it is not a real plane. vec3 normal = (m_listVertex[it.m_vertex[0]]-m_listVertex[it.m_vertex[1]]).cross(m_listVertex[it.m_vertex[1]]-m_listVertex[it.m_vertex[2]]); + //EGE_INFO("normal: " << normal.normalized()); if (normal == vec3(0,0,0)) { EGE_ERROR("Null vertor for a face ... " << m_listVertex[it.m_vertex[0]] << " " << m_listVertex[it.m_vertex[1]] << " " << m_listVertex[it.m_vertex[2]]); m_listFacesNormal.push_back(vec3(1,0,0)); } else { m_listFacesNormal.push_back(normal.normalized()); } + int32_t normalID = m_listFacesNormal.size() - 1; + it.m_normal[0] = normalID; + it.m_normal[1] = normalID; + it.m_normal[2] = normalID; } } } void ege::resource::Mesh::calculateNormaleEdge(const std::string& _materialName) { m_listVertexNormal.clear(); - if (m_normalMode == ege::resource::Mesh::normalModeVertex) { + if (m_normalMode == ege::resource::Mesh::normalMode::vertex) { EGE_INFO("calculateNormaleEdge(" << _materialName << ")"); gale::openGL::renderMode tmpRenderMode = m_materials[_materialName]->getRenderMode(); if ( tmpRenderMode == gale::openGL::renderMode::point @@ -346,7 +360,7 @@ void ege::resource::Mesh::calculateNormaleEdge(const std::string& _materialName) || tmpRenderMode == gale::openGL::renderMode::lineStrip || tmpRenderMode == gale::openGL::renderMode::lineLoop) { EGE_ERROR("calculateNormaleEdge(" << _materialName << ") : can not calculate normal on lines ..."); - m_normalMode = ege::resource::Mesh::normalModeNone; + m_normalMode = ege::resource::Mesh::normalMode::none; return; } for(size_t iii=0 ; iii auto generate Face normal .... EGE_ERROR("Calculate normal face ... in case ????"); @@ -436,14 +450,14 @@ void ege::resource::Mesh::generateVBO() { // get Normal vec3 normal; switch(m_normalMode) { - case normalModeVertex: + case ege::resource::Mesh::normalMode::vertex: normal = m_listVertexNormal[tmpFaceList.m_faces[iii].m_normal[indice]]; break; - case normalModeFace: + case ege::resource::Mesh::normalMode::face: normal = m_listFacesNormal[tmpFaceList.m_faces[iii].m_normal[indice]]; break; default: - case normalModeNone: + case ege::resource::Mesh::normalMode::none: break; } // get Texture Position @@ -471,7 +485,7 @@ void ege::resource::Mesh::generateVBO() { #endif if (elementFind == false) { m_verticesVBO->pushOnBuffer(MESH_VBO_VERTICES, position); - if (m_normalMode != normalModeNone) { + if (m_normalMode != ege::resource::Mesh::normalMode::none) { m_verticesVBO->pushOnBuffer(MESH_VBO_VERTICES_NORMAL, normal); } m_verticesVBO->pushOnBuffer(MESH_VBO_TEXTURE, texturepos); @@ -493,14 +507,14 @@ void ege::resource::Mesh::generateVBO() { void ege::resource::Mesh::createViewBox(const std::string& _materialName,float _size) { - m_normalMode = normalModeNone; + m_normalMode = ege::resource::Mesh::normalMode::none; ege::viewBox::create(m_materials, m_listFaces, m_listVertex, m_listUV, _materialName, _size); calculateNormaleFace(_materialName); } void ege::resource::Mesh::createIcoSphere(const std::string& _materialName,float _size, int32_t _subdivision) { - m_normalMode = normalModeNone; + m_normalMode = ege::resource::Mesh::normalMode::none; ege::icoSphere::create(m_materials, m_listFaces, m_listVertex, m_listUV, _materialName, _size, _subdivision); calculateNormaleFace(_materialName); diff --git a/ege/resource/Mesh.hpp b/ege/resource/Mesh.hpp index ae48247..cbc6542 100644 --- a/ege/resource/Mesh.hpp +++ b/ege/resource/Mesh.hpp @@ -41,13 +41,16 @@ namespace ege { /** * @not_in_doc */ - enum normalMode { - normalModeNone, - normalModeFace, - normalModeVertex, + enum class normalMode { + none, + face, + vertex, }; protected: enum normalMode m_normalMode; // select the normal mode of display + public: + void setNormalMode(enum normalMode _mode); + protected: bool m_checkNormal; //!< when enable, this check the normal of the mesh before sending it at the 3d card protected: ememory::SharedPtr m_GLprogram; diff --git a/ege/resource/MeshCube.cpp b/ege/resource/MeshCube.cpp index 398610f..e11b5aa 100644 --- a/ege/resource/MeshCube.cpp +++ b/ege/resource/MeshCube.cpp @@ -23,11 +23,13 @@ ememory::SharedPtr ege::resource::Mesh::createCube(float _s out->addFaceIndexing(_materialName); out->addQuad(_materialName, vec3(-1,-1,-1)*_size, vec3(-1, 1,-1)*_size, vec3( 1, 1,-1)*_size, vec3( 1,-1,-1)*_size, _color); - out->addQuad(_materialName, vec3(-1,-1, 1)*_size, vec3(-1, 1, 1)*_size, vec3( 1, 1, 1)*_size, vec3( 1,-1, 1)*_size, _color); + out->addQuad(_materialName, vec3(-1, 1, 1)*_size, vec3(-1,-1, 1)*_size, vec3( 1,-1, 1)*_size, vec3( 1, 1, 1)*_size, _color); out->addQuad(_materialName, vec3(-1,-1,-1)*_size, vec3(-1,-1, 1)*_size, vec3(-1, 1, 1)*_size, vec3(-1, 1,-1)*_size, _color); - out->addQuad(_materialName, vec3( 1,-1,-1)*_size, vec3( 1,-1, 1)*_size, vec3( 1, 1, 1)*_size, vec3( 1, 1,-1)*_size, _color); - out->addQuad(_materialName, vec3(-1,-1,-1)*_size, vec3(-1,-1, 1)*_size, vec3( 1,-1, 1)*_size, vec3( 1,-1,-1)*_size, _color); + out->addQuad(_materialName, vec3( 1,-1, 1)*_size, vec3( 1,-1,-1)*_size, vec3( 1, 1,-1)*_size, vec3( 1, 1, 1)*_size, _color); + out->addQuad(_materialName, vec3(-1,-1, 1)*_size, vec3(-1,-1,-1)*_size, vec3( 1,-1,-1)*_size, vec3( 1,-1, 1)*_size, _color); out->addQuad(_materialName, vec3(-1, 1,-1)*_size, vec3(-1, 1, 1)*_size, vec3( 1, 1, 1)*_size, vec3( 1, 1,-1)*_size, _color); + out->setNormalMode(ege::resource::Mesh::normalMode::face); + out->calculateNormaleFace(_materialName); // generate the VBO out->generateVBO(); } else { diff --git a/ege/resource/MeshEmf.cpp b/ege/resource/MeshEmf.cpp index 6b8cd77..f892bbc 100644 --- a/ege/resource/MeshEmf.cpp +++ b/ege/resource/MeshEmf.cpp @@ -141,7 +141,7 @@ enum emfModuleMode { // TODO : rework with string line extractor bool ege::resource::Mesh::loadEMF(const std::string& _fileName) { m_checkNormal = true; - m_normalMode = normalModeNone; + m_normalMode = ege::resource::Mesh::normalMode::none; etk::FSNode fileName(_fileName); // get the fileSize ... int32_t size = fileName.fileSize(); @@ -294,7 +294,7 @@ bool ege::resource::Mesh::loadEMF(const std::string& _fileName) { break; } case EMFModuleMeshNormalVertex: { - m_normalMode = normalModeVertex; + m_normalMode = ege::resource::Mesh::normalMode::vertex; vec3 normal(0,0,0); // find the vertex Normal list. while (loadNextData(inputDataLine, 2048, fileName, true, true) != nullptr) { @@ -314,7 +314,7 @@ bool ege::resource::Mesh::loadEMF(const std::string& _fileName) { } case EMFModuleMeshNormalFace: { EGE_ERROR("Change mode in face mode ..."); - m_normalMode = normalModeFace; // TODO : check if it is the same mode of display the normal from the start of the file + m_normalMode = ege::resource::Mesh::normalMode::face; // TODO : check if it is the same mode of display the normal from the start of the file vec3 normal(0,0,0); // find the face Normal list. while (loadNextData(inputDataLine, 2048, fileName, true, true) != nullptr) { @@ -379,7 +379,7 @@ bool ege::resource::Mesh::loadEMF(const std::string& _fileName) { uvIndex[0] += offsetUV; uvIndex[1] += offsetUV; uvIndex[2] += offsetUV; - if (m_normalMode == normalModeFace) { + if (m_normalMode == ege::resource::Mesh::normalMode::face) { normalIndex[0] += offsetFaceNormal; normalIndex[1] += offsetFaceNormal; normalIndex[2] += offsetFaceNormal; @@ -396,7 +396,7 @@ bool ege::resource::Mesh::loadEMF(const std::string& _fileName) { vertexIndex[0] += offsetVertexId; vertexIndex[1] += offsetVertexId; vertexIndex[2] += offsetVertexId; - if (m_normalMode == normalModeFace) { + if (m_normalMode == ege::resource::Mesh::normalMode::face) { normalIndex[0] += offsetFaceNormal; normalIndex[1] += offsetFaceNormal; normalIndex[2] += offsetFaceNormal; diff --git a/ege/resource/MeshObj.cpp b/ege/resource/MeshObj.cpp index 14da550..23728d2 100644 --- a/ege/resource/MeshObj.cpp +++ b/ege/resource/MeshObj.cpp @@ -9,7 +9,7 @@ bool ege::resource::Mesh::loadOBJ(const std::string& _fileName) { - m_normalMode = normalModeNone; + m_normalMode = ege::resource::Mesh::normalMode::none; #if 0 etk::FSNode fileName(_fileName); // get the fileSize ... diff --git a/ege/resource/ParticuleMesh.cpp b/ege/resource/ParticuleMesh.cpp index 03f00ad..4836ff1 100644 --- a/ege/resource/ParticuleMesh.cpp +++ b/ege/resource/ParticuleMesh.cpp @@ -88,7 +88,7 @@ void ege::resource::ParticuleMesh::draw(mat4& _positionMatrix, std::vector tmpIndexResult; std::vector& tmppFaces = m_listFaces.getValue(kkk).m_faces; //std::vector& tmppIndex = m_listFaces.getValue(kkk).m_index; - if (normalModeFace == m_normalMode) { + if (m_normalMode == ege::resource::Mesh::normalMode::face) { for(size_t iii=0; iii= 0.0f) { tmpIndexResult.push_back(iii*3); diff --git a/lutin_ege.py b/lutin_ege.py index 67fe9fc..2e26deb 100644 --- a/lutin_ege.py +++ b/lutin_ege.py @@ -33,13 +33,12 @@ def configure(target, my_module): 'ege/camera/Camera.cpp', 'ege/camera/View.cpp', 'ege/camera/FPS.cpp', - 'ege/CollisionShapeCreator.cpp', 'ege/position/Component.cpp', 'ege/physics/Component.cpp', 'ege/physics/Engine.cpp', 'ege/elements/Element.cpp', - 'ege/elements/ElementBase.cpp', - 'ege/elements/ElementPhysic.cpp', + #'ege/elements/ElementBase.cpp', + #'ege/elements/ElementPhysic.cpp', 'ege/particule/Component.cpp', 'ege/particule/Engine.cpp', 'ege/particule/Simple.cpp', @@ -71,7 +70,7 @@ def configure(target, my_module): ]) my_module.copy_path('data/ParticuleMesh.*') my_module.copy_path('data/material3D.*') - my_module.add_depend(['ewol', 'ephysics', 'echrono']) + my_module.add_depend(['ewol', 'ephysics', 'eproperty', 'echrono']) my_module.add_flag('c++', [ '-Wno-write-strings', '-Wmissing-field-initializers', @@ -84,13 +83,12 @@ def configure(target, my_module): 'ege/camera/Camera.hpp', 'ege/camera/View.hpp', 'ege/camera/FPS.hpp', - 'ege/CollisionShapeCreator.hpp', 'ege/position/Component.hpp', 'ege/physics/Engine.hpp', 'ege/physics/Component.hpp', 'ege/elements/Element.hpp', - 'ege/elements/ElementBase.hpp', - 'ege/elements/ElementPhysic.hpp', + #'ege/elements/ElementBase.hpp', + #'ege/elements/ElementPhysic.hpp', 'ege/particule/Component.hpp', 'ege/particule/Engine.hpp', 'ege/particule/Simple.hpp', @@ -121,7 +119,6 @@ def configure(target, my_module): # TODO: Remove this ... my_module.add_flag('c++', "-Wno-unused-variable") my_module.add_flag('c++', "-Wno-overloaded-virtual") - my_module.add_path(".") return True diff --git a/sample/Collision/appl/Windows.cpp b/sample/Collision/appl/Windows.cpp index dfd3e01..2c5fd89 100644 --- a/sample/Collision/appl/Windows.cpp +++ b/sample/Collision/appl/Windows.cpp @@ -15,8 +15,7 @@ #include #include #include -#include -#include +#include #include #include #include @@ -76,6 +75,10 @@ void appl::Windows::init() { getObjectManager().periodicCall.connect(sharedFromThis(), &appl::Windows::onCallbackPeriodicCheckCollision); m_env = ege::Environement::create(); + // set the debug property on the engines + m_env->getEngine("render")->properties.set("debug-normal", "true"); + m_env->getEngine("physics")->properties.set("debug-AABB", "true"); + m_env->getEngine("physics")->properties.set("debug-shape", "true"); // Create basic Camera m_camera = ememory::makeShared(vec3(30,30,-100), vec3(0,0,0)); m_camera->setEye(vec3(100*std::sin(m_angleTetha),100*std::cos(m_angleTetha),40*std::cos(m_anglePsy))); @@ -93,7 +96,7 @@ void appl::Windows::init() { } ememory::SharedPtr myMesh; - // Create an external box: + // Create an external box: (no physics) myMesh = createViewBoxStar(); if (myMesh != nullptr) { ememory::SharedPtr element = ememory::makeShared(m_env); @@ -107,7 +110,7 @@ void appl::Windows::init() { // add it .. m_env->addElement(element); } - // create basic gird: + // create basic gird: (no physics) myMesh = ege::resource::Mesh::createGrid(10, vec3(0,0,0), 5); if (myMesh != nullptr) { ememory::SharedPtr element = ememory::makeShared(m_env); @@ -128,8 +131,6 @@ void appl::Windows::init() { // add all component: // 1st Position component: etk::Transform3D transform(vec3(0,0,2), etk::Quaternion::identity()); - //ememory::SharedPtr componentPosition = ememory::makeShared(transform); - //element->addComponent(componentPosition); // 2nd something to diplay: ememory::SharedPtr componentRender = ememory::makeShared(myMesh); element->addComponent(componentRender); @@ -137,6 +138,7 @@ void appl::Windows::init() { ememory::SharedPtr componentPhysics = ememory::makeShared(m_env, transform); ememory::SharedPtr physic = ememory::makeShared(); physic->setSize(vec3(3.2,3.2,3.2)); + physic->setMass(300000); componentPhysics->addShape(physic); componentPhysics->generate(); element->addComponent(componentPhysics); @@ -158,6 +160,7 @@ void appl::Windows::init() { ememory::SharedPtr componentPhysics = ememory::makeShared(m_env, transform); ememory::SharedPtr physic = ememory::makeShared(); physic->setSize(vec3(3.2,3.2,3.2)); + physic->setMass(50000); componentPhysics->addShape(physic); componentPhysics->generate(); element->addComponent(componentPhysics); @@ -166,7 +169,7 @@ void appl::Windows::init() { } m_env->propertyStatus.set(ege::gameStart); } - +/* namespace appl { class ElementHerit : public ege::ElementPhysic { public: @@ -179,6 +182,7 @@ namespace appl { } }; } +*/ bool appl::Windows::onEventInput(const ewol::event::Input& _event) { @@ -204,12 +208,13 @@ bool appl::Windows::onEventInput(const ewol::event::Input& _event) { ememory::SharedPtr componentPhysics = ememory::makeShared(m_env, transform); ememory::SharedPtr physic = ememory::makeShared(); physic->setSize(vec3(1.1,1.1,1.1)); + physic->setMass(1000); componentPhysics->setType(ege::physics::Component::type::bodyDynamic); componentPhysics->addShape(physic); componentPhysics->generate(); // set has dynamic object (can move) //APPL_CRITICAL("velocity : " << ray.getDirection()*100); - componentPhysics->setLinearVelocity(ray.getDirection()*1000); + componentPhysics->setLinearVelocity(ray.getDirection()*100); element->addComponent(componentPhysics); // add it .. m_env->addElement(element);