From d6527d28ad2a8138cb2950a575ebe9775c2d8393 Mon Sep 17 00:00:00 2001 From: Edouard DUPIN Date: Fri, 7 Nov 2014 23:20:22 +0100 Subject: [PATCH] [DEV] rework Camera interface and mesh create lines --- ege/Camera.cpp | 142 ------------------------ ege/Camera.h | 145 ------------------------- ege/ElementGame.cpp | 5 +- ege/ElementGame.h | 2 +- ege/Environement.h | 2 +- ege/Material.cpp | 45 +++++++- ege/Material.h | 8 ++ ege/Particule.h | 2 +- ege/camera/Camera.cpp | 18 ++++ ege/camera/Camera.h | 54 ++++++++++ ege/camera/FPS.cpp | 0 ege/camera/FPS.h | 0 ege/camera/View.cpp | 46 ++++++++ ege/camera/View.h | 83 +++++++++++++++ ege/resource/Mesh.cpp | 160 +++++++++++++++++++++------- ege/resource/Mesh.h | 7 +- ege/resource/tools/Face.h | 26 ++++- ege/widget/Scene.cpp | 2 +- ege/widget/Scene.h | 2 +- lutin_ege.py | 4 +- sample/MeshCreator/appl/Windows.cpp | 38 ++++--- 21 files changed, 438 insertions(+), 353 deletions(-) delete mode 100644 ege/Camera.cpp delete mode 100644 ege/Camera.h create mode 100644 ege/camera/Camera.cpp create mode 100644 ege/camera/Camera.h create mode 100644 ege/camera/FPS.cpp create mode 100644 ege/camera/FPS.h create mode 100644 ege/camera/View.cpp create mode 100644 ege/camera/View.h diff --git a/ege/Camera.cpp b/ege/Camera.cpp deleted file mode 100644 index 19e5890..0000000 --- a/ege/Camera.cpp +++ /dev/null @@ -1,142 +0,0 @@ -/** - * @author Edouard DUPIN - * - * @copyright 2013, Edouard DUPIN, all right reserved - * - * @license BSD v3 (see license file) - */ - - -#include -#include - -#undef __class__ -#define __class__ "Camera" - -void ege::Camera::update() { - // Note the view axes of the basic camera is (0,0,-1) - // clean matrix : - m_matrix.identity(); - // move the world from the camera distance - m_matrix.translate(vec3(0,0,-m_distance)); - // teta represent the angle from the ground to the axes then 90-teta represent the angle to apply (inverted for the world) - m_matrix.rotate(vec3(1,0,0), -((M_PI/2.0f-m_angleTeta)*m_offsetFactor) ); - m_matrix.rotate(vec3(0,0,1), -m_angleZ ); - // move the camera to the end point of view - m_matrix.translate(-m_eye); - #if 1 - m_calculatedViewVector = vec3(0,0,-1); - m_calculatedViewVector = m_calculatedViewVector.rotate(vec3(1,0,0), -((M_PI/2.0f-m_angleTeta)*m_offsetFactor) ); - m_calculatedViewVector = m_calculatedViewVector.rotate(vec3(0,0,1), -m_angleZ ); - m_calculatedViewVector *= vec3(1,-1,1); - m_calculatedOrigin = m_eye - m_calculatedViewVector*m_distance; - #else - float onGround = cosf(m_angleTeta)*m_distance; - m_calculatedOrigin.setValue(sinf(m_angleZ)*onGround, - -cosf(m_angleZ)*onGround, - sinf(m_angleTeta)*m_distance); - m_calculatedViewVector= -m_calculatedOrigin.normalized(); - m_calculatedOrigin += m_eye; - #endif - - #if 0 - EGE_DEBUG("Camera properties : eye=" << m_eye ); - EGE_DEBUG(" Z=" << RAD_TO_DEG(m_angleZ) << ""); - EGE_DEBUG(" Teta=" << RAD_TO_DEG(m_angleTeta) << "" ); - EGE_DEBUG(" distance=" << m_distance); - EGE_DEBUG(" origin=" << m_calculatedOrigin ); - EGE_DEBUG(" m_calculatedViewVector=" << m_calculatedViewVector); - #endif -} - -vec3 ege::Camera::projectOnZGround(const vec2& _cameraDeltaAngle, float _zValue) { - vec3 viewVector(0,0,-1); - viewVector = viewVector.rotate(vec3(0,1,0), -_cameraDeltaAngle.x()); - viewVector = viewVector.rotate(vec3(1,0,0), -_cameraDeltaAngle.y()); - viewVector = viewVector.rotate(vec3(1,0,0), -((M_PI/2.0f-m_angleTeta)*m_offsetFactor) ); - viewVector = viewVector.rotate(vec3(0,0,1), -m_angleZ ); - viewVector *= vec3(1,-1,1); - // get intersection with the plane : z=0 - // equation : pointIntersect = viewVector * alpha + origin; - float alpha = (_zValue - m_calculatedOrigin.z()) / viewVector.z(); - return vec3(viewVector.x()*alpha + m_calculatedOrigin.x(), - viewVector.y()*alpha + m_calculatedOrigin.y(), - _zValue); -} - -ege::Camera::Camera(const vec3& _eye, float _angleZ, float _angleTeta, float _distance) : - m_offsetFactor(1.0f), - m_eye(_eye), - m_angleZ(_angleZ), - m_angleTeta(_angleTeta), - m_distance(_distance), - m_forceViewTop(false) { - setEye(_eye); - setAngleZ(_angleZ); - setDistance(_distance); - setAngleTeta(_angleTeta); - update(); -} - -void ege::Camera::setEye(const vec3& _eye) { - m_eye = _eye; - if (m_eye.x() < -1000) { - m_eye.setX(-1000); - } - if (m_eye.x() > 1000) { - m_eye.setX(1000); - } - if (m_eye.y() < -1000) { - m_eye.setY(-1000); - } - if (m_eye.y() > 1000) { - m_eye.setY(1000); - } - if (m_eye.z() < -10) { - m_eye.setZ(-10); - } - if (m_eye.z() > 10) { - m_eye.setZ(10); - } - update(); -} - -void ege::Camera::setAngleZ(float _angleZ) { - if (_angleZ == NAN) { - EGE_CRITICAL("try to set NAN value for the angle ..."); - } else if (_angleZ == INFINITY) { - EGE_CRITICAL("try to set INFINITY value for the angle ..."); - } else { - m_angleZ = _angleZ; - } - update(); -} - -void ege::Camera::setAngleTeta(float _angleTeta) { - m_angleTeta = std::avg((float)M_PI/10.0f, _angleTeta, (float)M_PI/2.0f); - update(); -} - -void ege::Camera::setDistance(float _distance) { - m_distance = std::avg(5.0f, _distance, 150.0f); - update(); -} - -const float localFactor = 2.0; - -void ege::Camera::periodicCall(float _step) { - //Note we need to view to the top in 500ms - if (true == m_forceViewTop) { - if (0.0f != m_offsetFactor) { - m_offsetFactor -= _step*localFactor; - m_offsetFactor = std::avg(0.0f,m_offsetFactor,1.0f); - update(); - } - } else { - if (1.0f != m_offsetFactor) { - m_offsetFactor += _step*localFactor; - m_offsetFactor = std::avg(0.0f,m_offsetFactor,1.0f); - update(); - } - } -} diff --git a/ege/Camera.h b/ege/Camera.h deleted file mode 100644 index 06b3197..0000000 --- a/ege/Camera.h +++ /dev/null @@ -1,145 +0,0 @@ -/** - * @author Edouard DUPIN - * - * @copyright 2013, Edouard DUPIN, all right reserved - * - * @license BSD v3 (see license file) - */ - -#ifndef __EGE_CAMERA_H__ -#define __EGE_CAMERA_H__ - - -#include -#include -#include -#include - -namespace ege { - class Camera { - protected: - mat4 m_matrix; //!< transformation matrix. - float m_offsetFactor; //!< this variable is used to move the camera to the top position of the system == > automaticly - /** - * @brief update the matrix property - */ - void update(); - public: - /** - * @brief Constructor. - * @param[in] _eye Position of the camera destination view. - * @param[in] _angleZ Z rotation angle. - * @param[in] _angleTeta Angle of the camera inclinason. - * @param[in] _distance distance to the eye point - */ - Camera(const vec3& _eye=vec3(0,0,0), float _angleZ=0, float _angleTeta=0, float _distance=10); - // TODO : Rework this API ... - protected: - vec3 m_eye; //!< position where the camera see - public: - /** - * @brief set the position of the camera. - * @param[in] pos Position of the camera. - */ - void setEye(const vec3& _eye); - /** - * @brief get the curent Camera Eye position. - * @return the current position. - */ - const vec3& getEye() const { - return m_eye; - }; - protected: - vec3 m_calculatedOrigin; - public: - /** - * @brief get the curent Camera origin position. - * @return the current position. - */ - const vec3& getOrigin() const { - return m_calculatedOrigin; - }; - protected: - vec3 m_calculatedViewVector; - public: - /** - * @brief Get the camera viewing vector. - * @return the current position. - */ - const vec3& getViewVector() const { - return m_calculatedViewVector; - }; - protected: - float m_angleZ; - public: - /** - * @brief set the angle on the camera - * @param[in] _angleZ Rotation angle in Z - */ - void setAngleZ(float _angleZ); - /** - * @brief get the curent Camera angles. - * @return the current angles Z. - */ - float getAngleZ() const { - return m_angleZ; - }; - protected: - float m_angleTeta; - public: - /** - * @brief set the angle on the camera - * @param[in] _angleTeta Rotation angle in Teta - */ - void setAngleTeta(float _angleTeta); - /** - * @brief get the curent Camera angles. - * @return the current angles Teta. - */ - float getAngleTeta() const { - return m_angleTeta; - }; - protected: - float m_distance; - public: - /** - * @brief set the angle on the camera - * @param[in] _distance Distance to the eye - */ - void setDistance(float _distance); - /** - * @brief get the curent Camera angles. - * @return the current distance to the eye. - */ - float getDistance() const { - return m_distance; - }; - /** - * @brief get the transformation matix for the camera. - * @return the current transformation matrix - */ - const mat4& getMatrix() const { - return m_matrix; - }; - protected: - bool m_forceViewTop; - public: - /** - * @brief change camera mode of view == > force to the top view - * @param[in] _newState The new state of this mode... - */ - void setForcingViewTop(bool _newState) { - m_forceViewTop = _newState; - }; - /** - * @brief It is really needed to call the camera periodicly for performing automatic movement - * @param[in] _step step time of moving - */ - void periodicCall(float _step); - vec3 projectOnZGround(const vec2& _cameraDeltaAngle, float _zValue=0.0f); - - }; -}; - -#endif - diff --git a/ege/ElementGame.cpp b/ege/ElementGame.cpp index 812cfcb..c8e3b50 100644 --- a/ege/ElementGame.cpp +++ b/ege/ElementGame.cpp @@ -235,6 +235,7 @@ void ege::ElementGame::drawLife(const std::shared_ptrdraw(localVertices, myColor, transformationMatrix, false, false); + #endif } static void drawShape(const btCollisionShape* _shape, @@ -450,11 +452,12 @@ void ege::ElementGame::drawDebug(const std::shared_ptr 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) { diff --git a/ege/ElementGame.h b/ege/ElementGame.h index 6572c76..7d90c69 100644 --- a/ege/ElementGame.h +++ b/ege/ElementGame.h @@ -18,7 +18,7 @@ #include #include #include -#include +#include #include #include diff --git a/ege/Environement.h b/ege/Environement.h index 65735f1..6ad6e7b 100644 --- a/ege/Environement.h +++ b/ege/Environement.h @@ -13,7 +13,7 @@ namespace ege { class Environement; class ElementInteraction; }; -#include +#include #include #include diff --git a/ege/Material.cpp b/ege/Material.cpp index 2daeb3f..06b79c5 100644 --- a/ege/Material.cpp +++ b/ege/Material.cpp @@ -19,7 +19,6 @@ ege::MaterialGlId::MaterialGlId() : // nothing to do else ... } - void ege::MaterialGlId::link(const std::shared_ptr& _prog, const std::string& _baseName) { if (nullptr == _prog) { return; @@ -36,9 +35,11 @@ ege::Material::Material() : m_diffuseFactor(0,0,0,1), m_specularFactor(0,0,0,1), m_shininess(1), + m_renderMode(ewol::openGL::renderTriangle), m_texture0(nullptr) { // nothing to do else ... } + ege::Material::~Material() { } @@ -66,5 +67,47 @@ void ege::Material::setTexture0(const std::string& _filename) { } } +int32_t ege::Material::getRenderModeOpenGl() { + return static_cast(m_renderMode); +} +void ege::Material::setRenderMode(enum ewol::openGL::renderMode _val) { + switch (_val) { + case ewol::openGL::renderPoint: + break; + case ewol::openGL::renderLine: + break; + case ewol::openGL::renderLineStrip: + EGE_INFO("Does not support " << _val << " auto convert it in 'LINE'"); + _val = ewol::openGL::renderLine; + break; + case ewol::openGL::renderLineLoop: + EGE_INFO("Does not support " << _val << " auto convert it in 'LINE'"); + _val = ewol::openGL::renderLine; + break; + case ewol::openGL::renderTriangle: + break; + case ewol::openGL::renderTriangleStrip: + EGE_INFO("Does not support " << _val << " auto convert it in 'TRIANGLE'"); + _val = ewol::openGL::renderTriangle; + break; + case ewol::openGL::renderTriangleFan: + EGE_INFO("Does not support " << _val << " auto convert it in 'TRIANGLE'"); + _val = ewol::openGL::renderTriangle; + break; + case ewol::openGL::renderQuad: + EGE_INFO("Does not support " << _val << " auto convert it in 'TRIANGLE'"); + _val = ewol::openGL::renderTriangle; + break; + case ewol::openGL::renderQuadStrip: + EGE_INFO("Does not support " << _val << " auto convert it in 'TRIANGLE'"); + _val = ewol::openGL::renderTriangle; + break; + case ewol::openGL::renderPolygon: + EGE_ERROR("Does not support " << _val << " try convert it in 'TRIANGLE'"); + _val = ewol::openGL::renderTriangle; + break; + } + m_renderMode = _val; +} diff --git a/ege/Material.h b/ege/Material.h index 05ae576..7cdbf51 100644 --- a/ege/Material.h +++ b/ege/Material.h @@ -30,6 +30,8 @@ namespace ege { MaterialGlId(); void link(const std::shared_ptr& _prog, const std::string& _baseName); }; + + class Material { private: // values @@ -37,6 +39,7 @@ namespace ege { vec4 m_diffuseFactor; vec4 m_specularFactor; float m_shininess; + enum ewol::openGL::renderMode m_renderMode; // Select Render mode (triangle/Line/point ...) std::shared_ptr m_texture0; public: std::vector m_listIndexFaces; @@ -56,6 +59,11 @@ namespace ege { void setShininess(float _val) { m_shininess = _val; } + void setRenderMode(enum ewol::openGL::renderMode _val); + int32_t getRenderModeOpenGl(); + enum ewol::openGL::renderMode getRenderMode() { + return m_renderMode; + } void setTexture0(const std::string& _filename); void setImageSize(const ivec2& _newSize) { diff --git a/ege/Particule.h b/ege/Particule.h index eda487d..b54794d 100644 --- a/ege/Particule.h +++ b/ege/Particule.h @@ -15,7 +15,7 @@ namespace ege { #include #include -#include +#include namespace ege { diff --git a/ege/camera/Camera.cpp b/ege/camera/Camera.cpp new file mode 100644 index 0000000..4a168d7 --- /dev/null +++ b/ege/camera/Camera.cpp @@ -0,0 +1,18 @@ +/** + * @author Edouard DUPIN + * + * @copyright 2013, Edouard DUPIN, all right reserved + * + * @license BSD v3 (see license file) + */ + + +#include +#include + +#undef __class__ +#define __class__ "Camera" + +ege::Camera::Camera() { + m_matrix.identity(); +} diff --git a/ege/camera/Camera.h b/ege/camera/Camera.h new file mode 100644 index 0000000..3693ef3 --- /dev/null +++ b/ege/camera/Camera.h @@ -0,0 +1,54 @@ +/** + * @author Edouard DUPIN + * + * @copyright 2013, Edouard DUPIN, all right reserved + * + * @license BSD v3 (see license file) + */ + +#ifndef __EGE_CAMERA_H__ +#define __EGE_CAMERA_H__ + + +#include +#include +#include +#include + +namespace ege { + class Camera { + protected: + mat4 m_matrix; //!< transformation matrix. + public: + /** + * @brief Constructor. + */ + Camera(); + /** + * @brief Destructor. + */ + virtual ~Camera() {}; + /** + * @brief get the transformation matix for the camera. + * @return the current transformation matrix + */ + const mat4& getMatrix() const { + return m_matrix; + }; + /** + * @brief It is really needed to call the camera periodicly for performing automatic movement + * @param[in] _step step time of moving + */ + virtual void periodicCall(float _step) {}; + + virtual vec3 getViewVector() const { + return vec3(0,0,-1); + } + virtual vec3 getEye() const { + return vec3(0,0,0); + } + }; +}; + +#endif + diff --git a/ege/camera/FPS.cpp b/ege/camera/FPS.cpp new file mode 100644 index 0000000..e69de29 diff --git a/ege/camera/FPS.h b/ege/camera/FPS.h new file mode 100644 index 0000000..e69de29 diff --git a/ege/camera/View.cpp b/ege/camera/View.cpp new file mode 100644 index 0000000..64dc2fa --- /dev/null +++ b/ege/camera/View.cpp @@ -0,0 +1,46 @@ +/** + * @author Edouard DUPIN + * + * @copyright 2013, Edouard DUPIN, all right reserved + * + * @license BSD v3 (see license file) + */ + + +#include +#include + +#undef __class__ +#define __class__ "camera::View" + +void ege::camera::View::update() { + m_matrix = etk::matLookAt(m_eye, m_target, m_up); + //m_matrix.translate(m_eye); +} + +ege::camera::View::View(const vec3& _eye, const vec3& _target, const vec3& _up) : + m_eye(_eye), + m_target(_target), + m_up(_up) { + update(); +} + +void ege::camera::View::setEye(const vec3& _eye) { + m_eye = _eye; + update(); +} + +void ege::camera::View::setTarget(const vec3& _target) { + m_target = _target; + update(); +} + +void ege::camera::View::setUp(const vec3& _up) { + m_up = _up; + update(); +} + +vec3 ege::camera::View::getViewVector() const { + return m_eye-m_target; +} + diff --git a/ege/camera/View.h b/ege/camera/View.h new file mode 100644 index 0000000..f54da5c --- /dev/null +++ b/ege/camera/View.h @@ -0,0 +1,83 @@ +/** + * @author Edouard DUPIN + * + * @copyright 2013, Edouard DUPIN, all right reserved + * + * @license BSD v3 (see license file) + */ + +#ifndef __EGE_CAMERA_VIEW_H__ +#define __EGE_CAMERA_VIEW_H__ + +#include + +namespace ege { + namespace camera { + class View : public Camera { + protected: + /** + * @brief update the matrix property + */ + void update(); + public: + /** + * @brief Constructor. + */ + View(const vec3& _eye=vec3(0,0,0), const vec3& _target=vec3(0,0,1), const vec3& _up=vec3(1,0,0)); + /** + * @brief Destructor. + */ + ~View() {} + protected: + vec3 m_eye; //!< position where the camera see + public: + /** + * @brief set the position of the camera. + * @param[in] pos Position of the camera. + */ + void setEye(const vec3& _eye); + /** + * @brief get the curent Camera Eye position. + * @return the current position. + */ + virtual vec3 getEye() const { + return m_eye; + }; + protected: + vec3 m_target; //!< origin of the camera + public: + /** + * @brief set a new Camera target position. + * @param[in] _target New camera target position. + */ + void setTarget(const vec3& _target); + /** + * @brief Get the curent Camera target position. + * @return The target position. + */ + const vec3& getTarget() const { + return m_target; + }; + protected: + vec3 m_up; //!< rotation angle of the camera (in rad) through the axis origin->eye + public: + /** + * @brief Set the up camera axis. + * @param[in] _up camera up axis. + */ + void setUp(const vec3& _up); + /** + * @brief Get the up camera axis. + * @return the up camera axis. + */ + const vec3& getUp() const { + return m_up; + }; + protected: + virtual vec3 getViewVector() const; + }; + }; +}; + +#endif + diff --git a/ege/resource/Mesh.cpp b/ege/resource/Mesh.cpp index 466fd05..05695d9 100644 --- a/ege/resource/Mesh.cpp +++ b/ege/resource/Mesh.cpp @@ -19,7 +19,8 @@ ege::resource::Mesh::Mesh() : m_normalMode(normalModeNone), - m_checkNormal(false) { + m_checkNormal(false), + m_functionFreeShape(nullptr) { addObjectType("ege::resource::Mesh"); } @@ -139,9 +140,7 @@ void ege::resource::Mesh::draw(mat4& _positionMatrix, } m_materials[m_listFaces.getKey(kkk)]->draw(m_GLprogram, m_GLMaterial); if (m_checkNormal == false) { - //ewol::openGL::drawElements(GL_TRIANGLES, m_listFaces.getValue(kkk).m_index); - //ewol::openGL::drawElements(GL_LINE_LOOP, m_listFaces.getValue(kkk).m_index); - ewol::openGL::drawElements(GL_LINES, m_listFaces.getValue(kkk).m_index); + ewol::openGL::drawElements(m_materials[m_listFaces.getKey(kkk)]->getRenderModeOpenGl(), m_listFaces.getValue(kkk).m_index); #ifdef DISPLAY_NB_VERTEX_DISPLAYED nbElementDraw += m_listFaces.getValue(kkk).m_index.size(); nbElementDrawTheoric += m_listFaces.getValue(kkk).m_index.size(); @@ -177,8 +176,7 @@ void ege::resource::Mesh::draw(mat4& _positionMatrix, } } } - ewol::openGL::drawElements(GL_TRIANGLES, tmpIndexResult); - //ewol::openGL::drawElements(GL_LINE_LOOP, tmpIndexResult); + ewol::openGL::drawElements(m_materials[m_listFaces.getKey(kkk)]->getRenderModeOpenGl(), tmpIndexResult); #ifdef DISPLAY_NB_VERTEX_DISPLAYED nbElementDraw += tmpIndexResult.size(); nbElementDrawTheoric += m_listFaces.getValue(kkk).m_index.size(); @@ -200,25 +198,36 @@ void ege::resource::Mesh::draw(mat4& _positionMatrix, } // normal calculation of the normal face is really easy : -void ege::resource::Mesh::calculateNormaleFace() { +// 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) { - std::vector& tmpFaceList = m_listFaces.getValue(0).m_faces; - for(size_t iii=0 ; iiigetRenderMode(); + if ( tmpRenderMode == ewol::openGL::renderPoint + || tmpRenderMode == ewol::openGL::renderLine + || tmpRenderMode == ewol::openGL::renderLineStrip + || tmpRenderMode == ewol::openGL::renderLineLoop) { + // can not calculate normal on lines ... + m_normalMode = ege::resource::Mesh::normalModeNone; + 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 = btCross(m_listVertex[tmpFaceList[iii].m_vertex[0]]-m_listVertex[tmpFaceList[iii].m_vertex[1]], - m_listVertex[tmpFaceList[iii].m_vertex[1]]-m_listVertex[tmpFaceList[iii].m_vertex[2]]); + vec3 normal = btCross(m_listVertex[it.m_vertex[0]]-m_listVertex[it.m_vertex[1]], + m_listVertex[it.m_vertex[1]]-m_listVertex[it.m_vertex[2]]); m_listFacesNormal.push_back(normal.normalized()); } m_normalMode = ege::resource::Mesh::normalModeFace; } } -void ege::resource::Mesh::calculateNormaleEdge() { +void ege::resource::Mesh::calculateNormaleEdge(const std::string& _materialName) { m_listVertexNormal.clear(); if (m_normalMode != ege::resource::Mesh::normalModeVertex) { + EGE_INFO("calculateNormaleEdge(" << _materialName << ")"); for(size_t iii=0 ; iii& tmpFaceList = m_listFaces.getValue(0).m_faces; + std::vector& tmpFaceList = m_listFaces[_materialName].m_faces; vec3 normal(0,0,0); // add the vertex from all the element in the list for face when the element in the face ... for(size_t jjj=0 ; jjj auto generate Face normal .... - calculateNormaleFace(); + calculateNormaleFace(m_listFaces.getKeys()[0]); } // generate element in 2 pass : // - create new index dependeng a vertex is a unique componenet of position, texture, normal @@ -273,10 +282,16 @@ void ege::resource::Mesh::generateVBO() { } // get µNormal vec3 normal; - if (m_normalMode == normalModeVertex) { - normal = m_listVertexNormal[tmpFaceList.m_faces[iii].m_normal[indice]]; - } else { - normal = m_listFacesNormal[tmpFaceList.m_faces[iii].m_normal[indice]]; + switch(m_normalMode) { + case normalModeVertex: + normal = m_listVertexNormal[tmpFaceList.m_faces[iii].m_normal[indice]]; + break; + case normalModeFace: + normal = m_listFacesNormal[tmpFaceList.m_faces[iii].m_normal[indice]]; + break; + default: + case normalModeNone: + break; } // get Texture Position vec2 texturepos; @@ -326,14 +341,14 @@ void ege::resource::Mesh::createViewBox(const std::string& _materialName,float _ m_normalMode = normalModeNone; ege::viewBox::create(m_materials, m_listFaces, m_listVertex, m_listUV, _materialName, _size); - calculateNormaleFace(); + calculateNormaleFace(_materialName); } void ege::resource::Mesh::createIcoSphere(const std::string& _materialName,float _size, int32_t _subdivision) { m_normalMode = normalModeNone; ege::icoSphere::create(m_materials, m_listFaces, m_listVertex, m_listUV, _materialName, _size, _subdivision); - calculateNormaleFace(); + calculateNormaleFace(_materialName); } bool ege::resource::Mesh::loadOBJ(const std::string& _fileName) { @@ -584,7 +599,7 @@ enum emfModuleMode { EMFModuleMaterialNamed, EMFModuleMaterial_END, }; - +// TODO : rework with string line extractor bool ege::resource::Mesh::loadEMF(const std::string& _fileName) { m_checkNormal = true; m_normalMode = normalModeNone; @@ -927,6 +942,11 @@ bool ege::resource::Mesh::loadEMF(const std::string& _fileName) { } else if(0 == strncmp(inputDataLine,"map_Kd ",7)) { material->setTexture0(fileName.getRelativeFolder() + &inputDataLine[7]); EGE_VERBOSE(" Texture " << &inputDataLine[7]); + } else if(0 == strncmp(inputDataLine,"renderMode ",11)) { + ewol::openGL::renderMode mode; + etk::from_string(mode, &inputDataLine[11]); + material->setRenderMode(mode); + EGE_VERBOSE(" Texture " << mode); } else { EGE_ERROR("unknow material property ... : '" << inputDataLine << "'"); } @@ -1007,23 +1027,70 @@ void ege::resource::Mesh::addFaceIndexing(const std::string& _layerName) { m_listFaces.add(_layerName, empty); } } + +void ege::resource::Mesh::addPoint(const std::string& _layerName, const vec3& _pos1, const vec3& _pos2, const etk::Color& _color) { + if ( m_listFaces.exist(_layerName) == false + || m_materials.exist(_layerName) == false) { + EGE_ERROR("Mesh layer : " << _layerName << " does not exist in list faces=" << m_listFaces.exist(_layerName) << " materials=" << m_listFaces.exist(_layerName) << " ..."); + return; + } + ewol::openGL::renderMode tmpRenderMode = m_materials[_layerName]->getRenderMode(); + if (tmpRenderMode != ewol::openGL::renderPoint) { + EGE_ERROR("try to add Point in a mesh material section that not support Point"); + return; + } + EGE_TODO("addPoint ..."); +} + +void ege::resource::Mesh::addLine(const std::string& _layerName, const vec3& _pos1, const vec3& _pos2, const etk::Color& _color) { + if ( m_listFaces.exist(_layerName) == false + || m_materials.exist(_layerName) == false) { + EGE_ERROR("Mesh layer : " << _layerName << " does not exist in list faces=" << m_listFaces.exist(_layerName) << " materials=" << m_listFaces.exist(_layerName) << " ..."); + return; + } + ewol::openGL::renderMode tmpRenderMode = m_materials[_layerName]->getRenderMode(); + if ( tmpRenderMode != ewol::openGL::renderLine + && tmpRenderMode != ewol::openGL::renderLineStrip + && tmpRenderMode != ewol::openGL::renderLineLoop) { + EGE_ERROR("try to add Line in a mesh material section that not support Line"); + return; + } + // try to find position: + int32_t pos1 = findPositionInList(_pos1); + int32_t pos2 = findPositionInList(_pos2); + // try to find UV mapping: + int32_t color = findColorInList(_color); + Face tmpFace; + tmpFace.setVertex(pos1, pos2); + tmpFace.setColor(color, color, color); + m_listFaces[_layerName].m_faces.push_back(tmpFace); +} + void ege::resource::Mesh::addTriangle(const std::string& _layerName, const vec3& _pos1, const vec3& _pos2, const vec3& _pos3, const vec2& _uv1, const vec2& _uv2, const vec2& _uv3, const etk::Color& _color1, const etk::Color& _color2, const etk::Color& _color3) { - if (m_listFaces.exist(_layerName) == false) { - EGE_ERROR("Mesh layer : " << _layerName << " does not exist in list faces ..."); + if ( m_listFaces.exist(_layerName) == false + || m_materials.exist(_layerName) == false) { + EGE_ERROR("Mesh layer : " << _layerName << " does not exist in list faces=" << m_listFaces.exist(_layerName) << " materials=" << m_listFaces.exist(_layerName) << " ..."); + return; + } + ewol::openGL::renderMode tmpRenderMode = m_materials[_layerName]->getRenderMode(); + if ( tmpRenderMode != ewol::openGL::renderTriangle + && tmpRenderMode != ewol::openGL::renderLineStrip + && tmpRenderMode != ewol::openGL::renderTriangleFan) { + EGE_ERROR("try to add Line in a mesh material section that not support Line"); return; } // try to find position: int32_t pos1 = findPositionInList(_pos1); int32_t pos2 = findPositionInList(_pos2); int32_t pos3 = findPositionInList(_pos3); - // try to find Color: + // try to find UV mapping: int32_t uv1 = findTextureInList(_uv1); int32_t uv2 = findTextureInList(_uv2); int32_t uv3 = findTextureInList(_uv3); - // try to find UV mapping: + // try to find Color: int32_t color1 = findColorInList(_color1); int32_t color2 = findColorInList(_color2); int32_t color3 = findColorInList(_color3); @@ -1036,21 +1103,34 @@ void ege::resource::Mesh::addTriangle(const std::string& _layerName, void ege::resource::Mesh::addTriangle(const std::string& _layerName, const vec3& _pos1, const vec3& _pos2, const vec3& _pos3, const etk::Color& _color1, const etk::Color& _color2, const etk::Color& _color3) { - if (m_listFaces.exist(_layerName) == false) { - EGE_ERROR("Mesh layer : " << _layerName << " does not exist in list faces ..."); + if ( m_listFaces.exist(_layerName) == false + || m_materials.exist(_layerName) == false) { + EGE_ERROR("Mesh layer : " << _layerName << " does not exist in list faces=" << m_listFaces.exist(_layerName) << " materials=" << m_listFaces.exist(_layerName) << " ..."); + return; + } + ewol::openGL::renderMode tmpRenderMode = m_materials[_layerName]->getRenderMode(); + if ( tmpRenderMode != ewol::openGL::renderQuad + || tmpRenderMode != ewol::openGL::renderQuadStrip) { + EGE_TODO("Create quad interface ..."); + } else if ( tmpRenderMode == ewol::openGL::renderTriangle + || tmpRenderMode == ewol::openGL::renderLineStrip + || tmpRenderMode == ewol::openGL::renderTriangleFan) { + + // try to find position: + int32_t pos1 = findPositionInList(_pos1); + int32_t pos2 = findPositionInList(_pos2); + int32_t pos3 = findPositionInList(_pos3); + // try to find Color: + int32_t color1 = findColorInList(_color1); + int32_t color2 = findColorInList(_color2); + int32_t color3 = findColorInList(_color3); + Face tmpFace(pos1, -1, + pos2, -1, + pos3, -1); + tmpFace.setColor(color1, color2, color3); + m_listFaces[_layerName].m_faces.push_back(tmpFace); + } else { + EGE_ERROR("try to add Quad in a mesh material section that not support Quad"); return; } - // try to find position: - int32_t pos1 = findPositionInList(_pos1); - int32_t pos2 = findPositionInList(_pos2); - int32_t pos3 = findPositionInList(_pos3); - // try to find UV mapping: - int32_t color1 = findColorInList(_color1); - int32_t color2 = findColorInList(_color2); - int32_t color3 = findColorInList(_color3); - Face tmpFace(pos1, -1, - pos2, -1, - pos3, -1); - tmpFace.setColor(color1, color2, color3); - m_listFaces[_layerName].m_faces.push_back(tmpFace); } diff --git a/ege/resource/Mesh.h b/ege/resource/Mesh.h index 5f74f22..aed4f86 100644 --- a/ege/resource/Mesh.h +++ b/ege/resource/Mesh.h @@ -88,8 +88,8 @@ namespace ege { } void generateVBO(); private: - void calculateNormaleFace(); - void calculateNormaleEdge(); + void calculateNormaleFace(const std::string& _materialName); + void calculateNormaleEdge(const std::string& _materialName); public : void createViewBox(const std::string& _materialName,float _size=1.0); void createIcoSphere(const std::string& _materialName,float _size=1.0, int32_t _subdivision=3); @@ -143,6 +143,9 @@ namespace ege { */ void addFaceIndexing(const std::string& _layerName); public: + void addLine(const std::string& _layerName, const vec3& _pos1, const vec3& _pos2, const etk::Color& _color); + void addPoint(const std::string& _layerName, const vec3& _pos1, const vec3& _pos2, const etk::Color& _color); + /** * @not-in-doc * @brief draw a colored triangle (usefull for debug and test) diff --git a/ege/resource/tools/Face.h b/ege/resource/tools/Face.h index 4058a4c..6a623a9 100644 --- a/ege/resource/tools/Face.h +++ b/ege/resource/tools/Face.h @@ -15,15 +15,28 @@ namespace ege { */ class Face { public: + int8_t m_nbElement; int32_t m_vertex[3]; int32_t m_uv[3]; int32_t m_normal[3]; int32_t m_color[3]; public: - Face() {}; + Face() { + m_nbElement = 1; + m_uv[0] = -1; + m_uv[1] = -1; + m_uv[2] = -1; + m_normal[0] = -1; + m_normal[1] = -1; + m_normal[2] = -1; + m_color[0] = -1; + m_color[1] = -1; + m_color[2] = -1; + }; Face(int32_t _v1, int32_t _t1, int32_t _v2, int32_t _t2, int32_t _v3, int32_t _t3) { + m_nbElement = 3; m_vertex[0] = _v1; m_vertex[1] = _v2; m_vertex[2] = _v3; @@ -40,6 +53,7 @@ namespace ege { Face(int32_t _v1, int32_t _t1, int32_t _n1, int32_t _v2, int32_t _t2, int32_t _n2, int32_t _v3, int32_t _t3, int32_t _n3) { + m_nbElement = 3; m_vertex[0] = _v1; m_vertex[1] = _v2; m_vertex[2] = _v3; @@ -53,7 +67,17 @@ namespace ege { m_color[1] = -1; m_color[2] = -1; }; + void setVertex(int32_t _v1) { + m_nbElement = 1; + m_vertex[0] = _v1; + } + void setVertex(int32_t _v1, int32_t _v2) { + m_nbElement = 2; + m_vertex[0] = _v1; + m_vertex[1] = _v2; + } void setVertex(int32_t _v1, int32_t _v2, int32_t _v3) { + m_nbElement = 3; m_vertex[0] = _v1; m_vertex[1] = _v2; m_vertex[2] = _v3; diff --git a/ege/widget/Scene.cpp b/ege/widget/Scene.cpp index be06f2e..d3afcd5 100644 --- a/ege/widget/Scene.cpp +++ b/ege/widget/Scene.cpp @@ -86,7 +86,7 @@ void ege::widget::Scene::onDraw() { std::shared_ptr world = m_env->getDynamicWorld(); if (world != nullptr) { - m_env->getOrderedElementForDisplay(m_displayElementOrdered, camera->getOrigin(), camera->getViewVector()); + m_env->getOrderedElementForDisplay(m_displayElementOrdered, camera->getEye(), camera->getViewVector()); //EGE_DEBUG("DRAW : " << m_displayElementOrdered.size() << " elements"); // TODO : remove this == > no more needed ==> checked in the generate the list of the element ordered diff --git a/ege/widget/Scene.h b/ege/widget/Scene.h index 10998fc..d68ec4f 100644 --- a/ege/widget/Scene.h +++ b/ege/widget/Scene.h @@ -14,7 +14,7 @@ #include #include #include -#include +#include #include #include #include diff --git a/lutin_ege.py b/lutin_ege.py index 168032a..6ac691a 100644 --- a/lutin_ege.py +++ b/lutin_ege.py @@ -15,7 +15,9 @@ def create(target): 'ege/debug.cpp', 'ege/AudioElement.cpp', 'ege/AudioEngine.cpp', - 'ege/Camera.cpp', + 'ege/camera/Camera.cpp', + 'ege/camera/View.cpp', + 'ege/camera/FPS.cpp', 'ege/CollisionShapeCreator.cpp', 'ege/ElementGame.cpp', 'ege/Particule.cpp', diff --git a/sample/MeshCreator/appl/Windows.cpp b/sample/MeshCreator/appl/Windows.cpp index dbdd0ce..1cdf6cf 100644 --- a/sample/MeshCreator/appl/Windows.cpp +++ b/sample/MeshCreator/appl/Windows.cpp @@ -11,6 +11,7 @@ #include #include #include +#include #include #undef __class__ @@ -31,6 +32,7 @@ static std::shared_ptr createGrid(int32_t _lineCount) { material->setDiffuseFactor(vec4(0,0,0,1)); material->setSpecularFactor(vec4(0,0,0,1)); material->setShininess(1); + material->setRenderMode(ewol::openGL::renderLine); out->addMaterial("basics", material); out->addFaceIndexing("basics"); @@ -41,15 +43,21 @@ static std::shared_ptr createGrid(int32_t _lineCount) { */ // create horizontal lines for (int32_t iii=-_lineCount; iii<=_lineCount; ++iii) { + /* out->addQuad("basics", vec3(-_lineCount,iii,0), vec3(_lineCount,iii,0), vec3(_lineCount,iii,lineSize), vec3(-_lineCount,iii,lineSize), etk::color::white); + */ + out->addLine("basics", vec3(-_lineCount,iii,0), vec3(_lineCount,iii,0), etk::color::white); } // create vertical lines for (int32_t iii=-_lineCount; iii<=_lineCount; ++iii) { + /* out->addQuad("basics", vec3(iii,-_lineCount,0), vec3(iii,_lineCount,0), vec3(iii,_lineCount,lineSize), vec3(iii,-_lineCount,lineSize), etk::color::white); + */ + out->addLine("basics", vec3(iii,-_lineCount,0), vec3(iii,_lineCount,0), etk::color::white); } // generate the VBO @@ -65,7 +73,7 @@ void appl::Windows::init() { m_env = ege::Environement::create(); // Create basic Camera - m_env->addCamera("basic", std::make_shared(vec3(0,0,0),0,0,10)); + m_env->addCamera("basic", std::make_shared(vec3(30,30,-100), vec3(0,0,0))); std::shared_ptr tmpWidget = ege::widget::Scene::create(m_env); if (tmpWidget == nullptr) { @@ -113,21 +121,21 @@ void appl::Windows::init() { if (myMesh != nullptr) { m_env->addStaticMeshToDraw(myMesh); } - /* - myMesh = ege::resource::Mesh::create("---"); - if (myMesh != nullptr) { - std::shared_ptr material = std::make_shared(); - material->setAmbientFactor(vec4(0.112f,0.112f,0.112f,1.0f)); - material->setDiffuseFactor(vec4(0.512f,0.512f,0.512f,1.0f)); - material->setSpecularFactor(vec4(0.5f,0.5f,0.5f,1.0f)); - material->setShininess(96.078431f); - material->setTexture0("DATA:texture_mars.png"); - myMesh->addMaterial("basics", material); - myMesh->createIcoSphere("basics", 16, 3); - myMesh->generateVBO(); - m_env->addStaticMeshToDraw(myMesh); + if (true) { + myMesh = ege::resource::Mesh::create("---"); + if (myMesh != nullptr) { + std::shared_ptr material = std::make_shared(); + material->setAmbientFactor(vec4(0.112f,0.112f,0.112f,1.0f)); + material->setDiffuseFactor(vec4(0.512f,0.512f,0.512f,1.0f)); + material->setSpecularFactor(vec4(0.5f,0.5f,0.5f,1.0f)); + material->setShininess(96.078431f); + material->setTexture0("DATA:texture_mars.png"); + myMesh->addMaterial("basics", material); + myMesh->createIcoSphere("basics", 16, 3); + myMesh->generateVBO(); + m_env->addStaticMeshToDraw(myMesh); + } } - */ }