From e0f0c1d65b779382b3a3fd793fb074e377c9a5bc Mon Sep 17 00:00:00 2001 From: Edouard DUPIN Date: Fri, 21 Nov 2014 21:01:26 +0100 Subject: [PATCH] [DEBUG] new step --- ege/CollisionShapeCreator.cpp | 14 +++++++++ ege/Material.cpp | 49 ++++++++++++++++++++++++++------ ege/Material.h | 3 +- ege/elements/ElementPhysic.cpp | 34 ++++++++++++++++------ ege/elements/ElementPhysic.h | 2 -- ege/physicsShape/PhysicsSphere.h | 3 ++ ege/resource/Mesh.cpp | 23 ++++++++++++--- ege/resource/MeshCube.cpp | 3 ++ ege/widget/Scene.cpp | 1 + sample/RayTest/appl/Windows.cpp | 48 ++++++++++++++++++++----------- 10 files changed, 140 insertions(+), 40 deletions(-) diff --git a/ege/CollisionShapeCreator.cpp b/ege/CollisionShapeCreator.cpp index 55ecf79..c2f0f19 100644 --- a/ege/CollisionShapeCreator.cpp +++ b/ege/CollisionShapeCreator.cpp @@ -7,6 +7,7 @@ * */ +#include #include #include @@ -29,10 +30,12 @@ btCollisionShape* ege::collision::createShape(const std::shared_ptr& _mesh) { if (nullptr == _mesh) { + EGE_DEBUG("Create empty shape (no mesh)"); return new btEmptyShape();; } const std::vector>& physiqueProperty = _mesh->getPhysicalProperties(); if (physiqueProperty.size() == 0) { + EGE_DEBUG("Create empty shape (no default shape)"); return new btEmptyShape();; } int32_t count = 0; @@ -44,7 +47,10 @@ btCollisionShape* ege::collision::createShape(const std::shared_ptr1) { + EGE_DEBUG("Create complexe shape"); outputShape = new btCompoundShape(); + } else { + EGE_DEBUG("Create simple shape"); } for (size_t iii=0; iiigetType()) { case ege::PhysicsShape::box : { + EGE_DEBUG(" Box"); const ege::PhysicsBox* tmpElement = physiqueProperty[iii]->toBox(); if (nullptr == tmpElement) { // ERROR ... @@ -70,6 +77,7 @@ btCollisionShape* ege::collision::createShape(const std::shared_ptrtoCylinder(); if (nullptr == tmpElement) { // ERROR ... @@ -88,6 +96,7 @@ btCollisionShape* ege::collision::createShape(const std::shared_ptrtoCapsule(); if (nullptr == tmpElement) { // ERROR ... @@ -106,6 +115,7 @@ btCollisionShape* ege::collision::createShape(const std::shared_ptrtoCone(); if (nullptr == tmpElement) { // ERROR ... @@ -124,6 +134,7 @@ btCollisionShape* ege::collision::createShape(const std::shared_ptrtoSphere(); if (nullptr == tmpElement) { // ERROR ... @@ -142,6 +153,7 @@ btCollisionShape* ege::collision::createShape(const std::shared_ptrtoConvexHull(); if (nullptr == tmpElement) { // ERROR ... @@ -160,11 +172,13 @@ btCollisionShape* ege::collision::createShape(const std::shared_ptr& _prog, _prog->uniform1f(_glID.m_GL_shininess, m_shininess); if (nullptr != m_texture0) { _prog->setTexture0(_glID.m_GL_texture0, m_texture0->getId()); + #if DEBUG + if (_prog->checkIdValidity(_glID.m_GL_texture0) == false) { + EGE_ERROR("try to set texture on a unexistant shader interface (wrong ID)"); + } + #endif + } else { + #if DEBUG + if (_prog->checkIdValidity(_glID.m_GL_texture0) == true) { + EGE_ERROR("Missing texture to send on the shader ..."); + } + #endif } } void ege::Material::setTexture0(const std::string& _filename) { ivec2 tmpSize(256, 256); - // prevent overloard error : - std::shared_ptr tmpCopy = m_texture0; - m_texture0 = ewol::resource::TextureFile::create(_filename, tmpSize); - if (m_texture0 == nullptr) { - EGE_ERROR("Can not load specific texture : " << _filename); - // retreave previous texture: - m_texture0 = tmpCopy; - return; + if (_filename != "") { + // prevent overloard error : + std::shared_ptr tmpCopy = m_texture0; + m_texture0 = ewol::resource::TextureFile::create(_filename, tmpSize); + if (m_texture0 == nullptr) { + EGE_ERROR("Can not load specific texture : " << _filename); + // retreave previous texture: + m_texture0 = tmpCopy; + if (m_texture0 != nullptr) { + return; + } + } + } else { + m_texture0.reset(); + } +} + +void ege::Material::setTexture0Magic(const ivec2& _size) { + // create a simple custum texture : + m_texture0 = ewol::resource::Texture::create(); + if (m_texture0 != nullptr) { + setImageSize(_size); + egami::Image& img = m_texture0->get(); + for (int32_t xxx=0; xxx<_size.x(); ++xxx) { + for (int32_t yyy=0; yyy<_size.y(); ++yyy) { + img.set(ivec2(xxx,yyy), etk::Color<>(1,0,0,1)); + } + } + } else { + EGE_ERROR("Can not create empty stupid texture ..."); } } diff --git a/ege/Material.h b/ege/Material.h index 7cdbf51..4eb2189 100644 --- a/ege/Material.h +++ b/ege/Material.h @@ -40,7 +40,7 @@ namespace ege { vec4 m_specularFactor; float m_shininess; enum ewol::openGL::renderMode m_renderMode; // Select Render mode (triangle/Line/point ...) - std::shared_ptr m_texture0; + std::shared_ptr m_texture0; public: std::vector m_listIndexFaces; public: @@ -65,6 +65,7 @@ namespace ege { return m_renderMode; } void setTexture0(const std::string& _filename); + void setTexture0Magic(const ivec2& _size); void setImageSize(const ivec2& _newSize) { if (m_texture0 == nullptr){ diff --git a/ege/elements/ElementPhysic.cpp b/ege/elements/ElementPhysic.cpp index 08376a4..91af970 100644 --- a/ege/elements/ElementPhysic.cpp +++ b/ege/elements/ElementPhysic.cpp @@ -34,7 +34,7 @@ const std::string& ege::ElementPhysic::getType() const { } -ege::ElementPhysic::ElementPhysic(const std::shared_ptr& _env, bool _autoRigidBody) : +ege::ElementPhysic::ElementPhysic(const std::shared_ptr& _env, bool _autoRigidBody) ://, float _mass) : ege::Element(_env), m_body(nullptr), m_shape(nullptr), @@ -59,27 +59,25 @@ ege::ElementPhysic::~ElementPhysic() { void ege::ElementPhysic::createRigidBody(float _mass) { - /// Create Dynamic Objects btTransform startTransform; startTransform.setIdentity(); vec3 localInertia(0,0,0); //rigidbody is dynamic if and only if mass is non zero, otherwise static - /* - if (mass != 0.0f && getShape()!=nullptr) { - getShape()->calculateLocalInertia(mass, localInertia); + if (_mass != 0.0f && getShape()!=nullptr) { + getShape()->calculateLocalInertia(_mass, localInertia); } - */ //using motionstate is recommended, it provides interpolation capabilities, and only synchronizes 'active' objects - m_motionState = new btDefaultMotionState(startTransform); - btRigidBody::btRigidBodyConstructionInfo rbInfo(_mass,m_motionState,getShape(),localInertia); + btDefaultMotionState* motionState = new btDefaultMotionState(startTransform); + btRigidBody::btRigidBodyConstructionInfo rbInfo(_mass, motionState, getShape(), localInertia); m_body = new btRigidBody(rbInfo); //m_body->applyTorqueImpulse(btVector3(0,0,0.2)); - //m_body->setAngularVelocity(vec3(etk::tool::frand(-1,1),etk::tool::frand(-1,1),etk::tool::frand(-1,1))); + m_body->setAngularVelocity(vec3(0,0,0)); } bool ege::ElementPhysic::setMesh(const std::shared_ptr& _mesh) { + EGE_WARNING("Set Mesh"); if (nullptr!=m_mesh) { removeShape(); } @@ -89,19 +87,30 @@ bool ege::ElementPhysic::setMesh(const std::shared_ptr& _me return true; } if (m_mesh->getShape() != nullptr) { + EGE_WARNING("create shape whith mesh internal shape ..."); m_shape = static_cast(m_mesh->getShape()); return true; } + EGE_WARNING("create the mesh shape with the mesh"); m_mesh->setShape(ege::collision::createShape(m_mesh)); + EGE_WARNING("set remove function shape"); m_mesh->setFreeShapeFunction(&FunctionFreeShape); m_shape = static_cast(m_mesh->getShape()); + vec3 localInertia(0,0,0); + m_shape->calculateLocalInertia(50000000, localInertia); // TODO : BETTER /// return true; } bool ege::ElementPhysic::setShape(btCollisionShape* _shape) { + EGE_WARNING("Set Shape"); removeShape(); m_shape = _shape; + if (_shape == nullptr) { + EGE_WARNING("Remove shape ..."); + } else { + EGE_INFO("set shape ..."); + } return true; } @@ -115,11 +124,13 @@ void ege::ElementPhysic::removeShape() { // no mesh == > standalone shape delete(m_shape); m_shape=nullptr; + EGE_WARNING("Remove shape .2."); return; } if (m_shape != m_mesh->getShape()) { delete(m_shape); m_shape=nullptr; + EGE_WARNING("Remove shape .3."); return; } // otherwise : the shape is auto remove by the resources when no more needed ... @@ -360,6 +371,7 @@ void ege::ElementPhysic::draw(int32_t _pass) { mat4 transformationMatrix(mmm); transformationMatrix.transpose(); + EGE_INFO("element pos = " << getPosition() << " mat=" << transformationMatrix); m_mesh->draw(transformationMatrix); } } @@ -370,9 +382,11 @@ void ege::ElementPhysic::dynamicEnable() { return; } if(m_body != nullptr) { + EGE_ERROR("dynamicEnable : RigidBody"); m_env->getPhysicEngine().getDynamicWorld()->addRigidBody(m_body); } if(m_IA != nullptr) { + EGE_ERROR("dynamicEnable : IA"); m_env->getPhysicEngine().getDynamicWorld()->addAction(m_IA); } m_elementInPhysicsSystem = true; @@ -383,9 +397,11 @@ void ege::ElementPhysic::dynamicDisable() { return; } if(m_IA != nullptr) { + EGE_ERROR("dynamicDisable : IA"); m_env->getPhysicEngine().getDynamicWorld()->removeAction(m_IA); } if(m_body != nullptr) { + EGE_ERROR("dynamicDisable : RigidBody"); // Unlink element from the engine m_env->getPhysicEngine().getDynamicWorld()->removeRigidBody(m_body); m_env->getPhysicEngine().getDynamicWorld()->removeCollisionObject(m_body); diff --git a/ege/elements/ElementPhysic.h b/ege/elements/ElementPhysic.h index 1cc9721..3f7d7fd 100644 --- a/ege/elements/ElementPhysic.h +++ b/ege/elements/ElementPhysic.h @@ -37,8 +37,6 @@ namespace ege { static void FunctionFreeShape(void* _pointer); protected: btRigidBody* m_body; //!< all the element have a body == > otherwise it will be not manage with this system... - private: - btDefaultMotionState* m_motionState; public: void createRigidBody(float _mass=400000000.0f); public: diff --git a/ege/physicsShape/PhysicsSphere.h b/ege/physicsShape/PhysicsSphere.h index 72ab639..d0a64d9 100644 --- a/ege/physicsShape/PhysicsSphere.h +++ b/ege/physicsShape/PhysicsSphere.h @@ -32,6 +32,9 @@ namespace ege { float getRadius() const { return m_radius; }; + void setRadius(float _radius) { + m_radius = _radius; + }; private: virtual const ege::PhysicsSphere* toSphere() const { return this; diff --git a/ege/resource/Mesh.cpp b/ege/resource/Mesh.cpp index 41bd747..59d7a71 100644 --- a/ege/resource/Mesh.cpp +++ b/ege/resource/Mesh.cpp @@ -102,7 +102,7 @@ void ege::resource::Mesh::clean() { } -//#define DISPLAY_NB_VERTEX_DISPLAYED +#define DISPLAY_NB_VERTEX_DISPLAYED void ege::resource::Mesh::draw(mat4& _positionMatrix, bool _enableDepthTest, @@ -128,14 +128,20 @@ void ege::resource::Mesh::draw(mat4& _positionMatrix, mat4 tmpMatrix = projMatrix * camMatrix; m_GLprogram->uniformMatrix(m_GLMatrix, tmpMatrix); m_GLprogram->uniformMatrix(m_GLMatrixPosition, _positionMatrix); + EGE_DEBUG(" m_GLMatrix=" << m_GLMatrix << " ==> " << tmpMatrix); + EGE_DEBUG(" m_GLMatrixPosition=" << m_GLMatrixPosition << " ==> " << _positionMatrix); // position : m_GLprogram->sendAttributePointer(m_GLPosition, m_verticesVBO, MESH_VBO_VERTICES); + EGE_DEBUG(" m_GLPosition=" << m_GLPosition << " ==> " << ""); // Texture : m_GLprogram->sendAttributePointer(m_GLtexture, m_verticesVBO, MESH_VBO_TEXTURE); + EGE_DEBUG(" m_GLtexture=" << m_GLtexture << " ==> " << ""); // position : m_GLprogram->sendAttributePointer(m_GLNormal, m_verticesVBO, MESH_VBO_VERTICES_NORMAL); + EGE_DEBUG(" m_GLNormal=" << m_GLNormal << " ==> " << ""); // position : m_GLprogram->sendAttributePointer(m_GLColor, m_verticesVBO, MESH_VBO_COLOR); + EGE_DEBUG(" m_GLColor=" << m_GLColor << " ==> " << ""); // draw lights : m_light.draw(m_GLprogram); #ifdef DISPLAY_NB_VERTEX_DISPLAYED @@ -193,9 +199,18 @@ void ege::resource::Mesh::draw(mat4& _positionMatrix, } } #ifdef DISPLAY_NB_VERTEX_DISPLAYED - EGE_DEBUG(((float)nbElementDraw/(float)nbElementDrawTheoric*100.0f) << "% Request draw : " << m_listFaces.size() << ":" << nbElementDraw << "/" << nbElementDrawTheoric << " elements [" << m_name << "]"); + if (m_listFaces.size() == 0) { + EGE_ERROR(" !!!! No Face to display elements [" << m_name << "]"); + } else { + if (nbElementDrawTheoric != 0) { + EGE_DEBUG(((float)nbElementDraw/(float)nbElementDrawTheoric*100.0f) << "% Request draw : " << m_listFaces.size() << ":" << nbElementDraw << "/" << nbElementDrawTheoric << " elements [" << m_name << "]"); + } else { + EGE_DEBUG("0% Request draw : " << m_listFaces.size() << ":" << nbElementDraw << "/" << nbElementDrawTheoric << " elements [" << m_name << "]"); + } + } #endif m_GLprogram->unUse(); + if (_enableDepthTest == true){ if (false == _enableDepthUpdate) { glDepthMask(GL_TRUE); @@ -203,7 +218,7 @@ void ege::resource::Mesh::draw(mat4& _positionMatrix, ewol::openGL::disable(ewol::openGL::FLAG_DEPTH_TEST); } // TODO : UNDERSTAND why ... it is needed - glBindBuffer(GL_ARRAY_BUFFER,0); + //glBindBuffer(GL_ARRAY_BUFFER,0); } // normal calculation of the normal face is really easy : @@ -267,7 +282,7 @@ void ege::resource::Mesh::generateVBO() { // when no normal detected == > auto generate Face normal .... calculateNormaleFace(m_listFaces.getKeys()[0]); } - + EGE_WARNING("Generate VBO for nb faces : " << m_listFaces.size()); // generate element in 2 pass : // - create new index dependeng a vertex is a unique componenet of position, texture, normal diff --git a/ege/resource/MeshCube.cpp b/ege/resource/MeshCube.cpp index 7ceb828..ae9f78e 100644 --- a/ege/resource/MeshCube.cpp +++ b/ege/resource/MeshCube.cpp @@ -10,6 +10,7 @@ #include std::shared_ptr ege::resource::Mesh::createCube(float _size, const std::string& _materialName, const etk::Color& _color) { + EGE_ERROR(" create a cube _size=" << _size << " _materialName=" << _materialName << " _color=" << _color); std::shared_ptr out = ege::resource::Mesh::create("---", "DATA:color3.prog"); if (out != nullptr) { std::shared_ptr material = std::make_shared(); @@ -31,6 +32,8 @@ std::shared_ptr ege::resource::Mesh::createCube(float _size out->addQuad(_materialName, vec3(-1, 1,-1)*_size, vec3(-1, 1, 1)*_size, vec3( 1, 1, 1)*_size, vec3( 1, 1,-1)*_size, _color); // generate the VBO out->generateVBO(); + } else { + EGE_ERROR("can not create the basic mesh interface"); } return out; } \ No newline at end of file diff --git a/ege/widget/Scene.cpp b/ege/widget/Scene.cpp index 349a53d..0339d3f 100644 --- a/ege/widget/Scene.cpp +++ b/ege/widget/Scene.cpp @@ -147,6 +147,7 @@ void ege::widget::Scene::systemDraw(const ewol::DrawProperty& _displayProp) { #ifdef SCENE_BRUT_PERFO_TEST int64_t tmp___startTime0 = ewol::getTime(); #endif + glBindBuffer(GL_ARRAY_BUFFER,0); ewol::openGL::push(); // here we invert the reference of the standard openGl view because the reference in the common display is Top left and not buttom left glViewport( m_origin.x(), diff --git a/sample/RayTest/appl/Windows.cpp b/sample/RayTest/appl/Windows.cpp index ec1fa60..a2b927f 100644 --- a/sample/RayTest/appl/Windows.cpp +++ b/sample/RayTest/appl/Windows.cpp @@ -17,6 +17,7 @@ #include #include #include +#include #undef __class__ #define __class__ "Windows" @@ -26,7 +27,7 @@ appl::Windows::Windows() { } static std::shared_ptr createViewBoxStar() { - std::shared_ptr out = ege::resource::Mesh::create("---", "DATA:texturedNoMaterial.prog"); + std::shared_ptr out = ege::resource::Mesh::create("viewBoxStar", "DATA:texturedNoMaterial.prog"); if (out != nullptr) { std::shared_ptr material = std::make_shared(); // set the element material properties : @@ -34,13 +35,14 @@ static std::shared_ptr createViewBoxStar() { material->setDiffuseFactor(vec4(0,0,0,1)); material->setSpecularFactor(vec4(0,0,0,1)); material->setShininess(1); - material->setTexture0(""); //" - out->addMaterial("basics", material); // 1024 == > 1<<9 // 2048 == > 1<<10 // 4096 == > 1<<11 int32_t size = 1<<11; - material->setImageSize(ivec2(size,size)); + //material->setTexture0(""); //" + material->setTexture0Magic(ivec2(size,size)); + out->addMaterial("basics", material); + //material->setImageSize(ivec2(size,size)); egami::Image* myImage = material->get(); if (nullptr == myImage) { return out; @@ -96,24 +98,38 @@ void appl::Windows::init() { if (myMesh != nullptr) { //std::shared_ptr element = std::make_shared(m_env); std::shared_ptr element = std::make_shared(m_env); - element->setMesh(myMesh); - element->setPosition(vec3(20,10,10)); // add physic interface: + /* std::shared_ptr physic = std::make_shared(); physic->setSize(vec3(3.2,3.2,3.2)); + */ + std::shared_ptr physic = std::make_shared(); + physic->setRadius(4.2f); myMesh->addPhysicElement(physic); - m_env->addElement(element); - - - //element = std::make_shared(m_env); - element = std::make_shared(m_env); element->setMesh(myMesh); - element->setPosition(vec3(20,-10,10)); + element->createRigidBody(4000000); + element->setPosition(vec3(20,10,10)); + + m_env->addElement(element); + } + myMesh = ege::resource::Mesh::createCube(3); + if (myMesh != nullptr) { + //element = std::make_shared(m_env); + std::shared_ptr element = std::make_shared(m_env); // add physic interface: - physic = std::make_shared(); - physic->setSize(vec3(3.2,3.2,3.2)); + std::shared_ptr physic = std::make_shared(); + physic->setRadius(3.3f); + myMesh->addPhysicElement(physic); + + + element->setMesh(myMesh); + element->createRigidBody(4000000); + element->setPosition(vec3(20,-10,10)); + + element->iaEnable(); + m_env->addElement(element); } @@ -124,8 +140,8 @@ void appl::Windows::onCallbackPeriodicUpdateCamera(const ewol::event::Time& _eve static float offset = 0; offset += 0.01; static float offset2 = 0; - offset2 += 0.003; - //m_camera->setEye(vec3(100*std::sin(offset),100*std::cos(offset),40*std::cos(offset2))); + //offset2 += 0.003; + m_camera->setEye(vec3(100*std::sin(offset),100*std::cos(offset),40*std::cos(offset2))); }