diff --git a/ege/camera/Camera.cpp b/ege/camera/Camera.cpp index 4a168d7..265c00a 100644 --- a/ege/camera/Camera.cpp +++ b/ege/camera/Camera.cpp @@ -10,9 +10,59 @@ #include #include +#include + #undef __class__ #define __class__ "Camera" -ege::Camera::Camera() { +ege::Camera::Camera() : + m_aspectRatio(0.5), + m_angleView(M_PI/3.0), + m_zFar(4000.0f), + m_zNear(1.0f) { m_matrix.identity(); + updateProjectionMatrix(); } + +void ege::Camera::setAspectRatio(float _ratio) { + if (m_aspectRatio == _ratio) { + return; + } + m_aspectRatio = _ratio; + updateProjectionMatrix(); +} + +void ege::Camera::setXAngleView(float _angleRad) { + if (m_angleView == _angleRad) { + return; + } + m_angleView = _angleRad; + updateProjectionMatrix(); +} + +void ege::Camera::setZFar(float _distance) { + if (m_zFar == _distance) { + return; + } + m_zFar = _distance; + updateProjectionMatrix(); +} + +void ege::Camera::setZNear(float _distance) { + if (m_zNear == _distance) { + return; + } + m_zNear = _distance; + updateProjectionMatrix(); +} + + +void ege::Camera::updateProjectionMatrix() { + m_matrixProjection = etk::matPerspective(m_angleView, m_aspectRatio, m_zNear, m_zFar); +} + +void ege::Camera::configureOpenGL() { + ewol::openGL::setCameraMatrix(getMatrixCamera()); + ewol::openGL::setMatrix(getMatrixProjection()); +} + diff --git a/ege/camera/Camera.h b/ege/camera/Camera.h index 3693ef3..8cba304 100644 --- a/ege/camera/Camera.h +++ b/ege/camera/Camera.h @@ -17,8 +17,6 @@ namespace ege { class Camera { - protected: - mat4 m_matrix; //!< transformation matrix. public: /** * @brief Constructor. @@ -28,25 +26,123 @@ namespace ege { * @brief Destructor. */ virtual ~Camera() {}; - /** - * @brief get the transformation matix for the camera. - * @return the current transformation matrix - */ - const mat4& getMatrix() const { - return m_matrix; - }; + public: /** * @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) {}; - + public: + /** + * @brief Configure projection matrix and camera matrix + */ + virtual void configureOpenGL(); + protected: + mat4 m_matrix; //!< transformation matrix. + public: + /** + * @brief get the transformation matix for the camera. + * @return the current transformation matrix + */ + const mat4& getMatrixCamera() const { + return m_matrix; + }; + protected: + mat4 m_matrixProjection; //!< projection matrix. + /** + * @bref Update the current projection matrix. + */ + virtual void updateProjectionMatrix(); + public: + /** + * @brief get the transformation matix for the camera. + * @return the current transformation matrix + */ + const mat4& getMatrixProjection() const { + return m_matrixProjection; + }; + public: virtual vec3 getViewVector() const { return vec3(0,0,-1); } virtual vec3 getEye() const { return vec3(0,0,0); } + protected: + float m_aspectRatio; //!< depending to the display the aspect ratio is simply calculated x/y + public: + /** + * @brief Set the aspectRatio of the camera: + * @param[in] _ratio New aspect ratio. + */ + virtual void setAspectRatio(float _ratio); + /** + * @brief Set the screen size to display OpenGl interface + * @param[in] _screenSize New screen size. + */ + virtual void setSceenSize(const vec2& _screenSize) { + setAspectRatio(_screenSize.x()/_screenSize.y()); + } + /** + * @brief get the current aspect Ratio. + * @return The current aspect ratio. + */ + float getAspectRatio() const { + return m_aspectRatio; + } + protected: + float m_angleView; //!< X angle view of the camera + public: + /** + * @brief Set the the X angle view of the camera: + * @param[in] _angleRad New angle view in X of the camera. + */ + virtual void setXAngleView(float _angleRad); + /** + * @brief Set the the Y angle view of the camera: + * @param[in] _angleRad New angle view in Y of the camera. + * @note Pay attention that the AspectRatio parameter is set before + */ + virtual void setYAngleView(float _angleRad) { + setXAngleView(_angleRad * m_aspectRatio); + } + /** + * @brief get the current X angle view. + * @return the current X angle view. + */ + float getXAngleView() const { + return m_angleView; + } + protected: + float m_zFar; //!< Z camera far view + public: + /** + * @brief Set the Z far distane of the camera: + * @param[in] _distance New end distance view. + */ + virtual void setZFar(float _distance); + /** + * @brief Get the Z far distane of the camera: + * @return the current end distance view. + */ + float getZFar() { + return m_zFar; + } + protected: + float m_zNear; //!< Z camera near view + public: + /** + * @brief Set the Z near distane of the camera: + * @param[in] _distance New start distance view. + */ + virtual void setZNear(float _distance); + /** + * @brief Get the Z Near distane of the camera: + * @return the current start distance view. + */ + float getZNear() { + return m_zNear; + } }; }; diff --git a/ege/resource/Mesh.cpp b/ege/resource/Mesh.cpp index 14ec1f0..12af74b 100644 --- a/ege/resource/Mesh.cpp +++ b/ege/resource/Mesh.cpp @@ -349,7 +349,7 @@ void ege::resource::Mesh::generateVBO() { vertexVBOId[indice] = m_verticesVBO->bufferSize(MESH_VBO_VERTICES)-1; } } - for(size_t indice=0 ; indice<3; indice++) { + for(size_t indice=0 ; indice& _color) { +void ege::resource::Mesh::addPoint(const std::string& _layerName, const vec3& _pos, 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) << " ..."); @@ -1064,7 +1064,14 @@ void ege::resource::Mesh::addPoint(const std::string& _layerName, const vec3& _p EGE_ERROR("try to add Point in a mesh material section that not support Point"); return; } - EGE_TODO("addPoint ..."); + // try to find position: + int32_t pos = findPositionInList(_pos); + // try to find UV mapping: + int32_t color = findColorInList(_color); + Face tmpFace; + tmpFace.setVertex(pos); + tmpFace.setColor(color, color, color); + m_listFaces[_layerName].m_faces.push_back(tmpFace); } void ege::resource::Mesh::addLine(const std::string& _layerName, const vec3& _pos1, const vec3& _pos2, const etk::Color& _color) { diff --git a/ege/resource/Mesh.h b/ege/resource/Mesh.h index aed4f86..d096bc2 100644 --- a/ege/resource/Mesh.h +++ b/ege/resource/Mesh.h @@ -143,8 +143,10 @@ namespace ege { */ void addFaceIndexing(const std::string& _layerName); public: + + void addPoint(const std::string& _layerName, const vec3& _pos, const etk::Color& _color); + 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 diff --git a/ege/widget/Scene.cpp b/ege/widget/Scene.cpp index ab5c35d..57e1b3b 100644 --- a/ege/widget/Scene.cpp +++ b/ege/widget/Scene.cpp @@ -131,9 +131,6 @@ void ege::widget::Scene::periodicCall(const ewol::event::Time& _event) { markToRedraw(); } -#define GAME_Z_NEAR (1) -#define GAME_Z_FAR (4000) - //#define SCENE_BRUT_PERFO_TEST void ege::widget::Scene::systemDraw(const ewol::DrawProperty& _displayProp) { @@ -146,29 +143,17 @@ void ege::widget::Scene::systemDraw(const ewol::DrawProperty& _displayProp) { m_origin.y(), m_size.x(), m_size.y()); - #ifdef SCENE_BRUT_PERFO_TEST - float tmp___localTime0 = (float)(ewol::getTime() - tmp___startTime0) / 1000.0f; - EWOL_DEBUG(" SCENE000 : " << tmp___localTime0 << "ms "); - #endif + // configure render with the camera... std::shared_ptr camera = m_env->getCamera(m_cameraName); if (camera != nullptr) { - ewol::openGL::setCameraMatrix(camera->getMatrix()); + camera->configureOpenGL(); } - // TODO : set this in the camera ... - float ratio = m_size.x() / m_size.y(); - //EWOL_INFO("ratio : " << ratio); - float angleView = (M_PI/3.0); - mat4 tmpProjection = etk::matPerspective(angleView, ratio, GAME_Z_NEAR, GAME_Z_FAR); - ewol::openGL::setMatrix(tmpProjection); - #ifdef SCENE_BRUT_PERFO_TEST - int64_t tmp___startTime3 = ewol::getTime(); - #endif onDraw(); - #ifdef SCENE_BRUT_PERFO_TEST - float tmp___localTime3 = (float)(ewol::getTime() - tmp___startTime3) / 1000.0f; - EWOL_DEBUG(" SCENE333 : " << tmp___localTime3 << "ms "); - #endif ewol::openGL::pop(); + #ifdef SCENE_BRUT_PERFO_TEST + float tmp___localTime1 = (float)(ewol::getTime() - tmp___startTime0) / 1000.0f; + EWOL_DEBUG(" SCENE render : " << tmp___localTime1 << "ms "); + #endif } void ege::widget::Scene::onParameterChangeValue(const ewol::parameter::Ref& _paramPointer) { @@ -181,4 +166,25 @@ void ege::widget::Scene::onParameterChangeValue(const ewol::parameter::Ref& _par } +void ege::widget::Scene::setCamera(const std::string& _cameraName) { + if (m_cameraName == _cameraName) { + return; + } + m_cameraName = _cameraName; + // Update camera aspect ratio: + std::shared_ptr camera = m_env->getCamera(m_cameraName); + if (camera != nullptr) { + camera->setSceenSize(m_size); + } +} + +void ege::widget::Scene::calculateSize(const vec2& _available) { + ewol::Widget::calculateSize(_available); + // Update camera aspect ratio: + std::shared_ptr camera = m_env->getCamera(m_cameraName); + if (camera != nullptr) { + camera->setSceenSize(m_size); + } +} + diff --git a/ege/widget/Scene.h b/ege/widget/Scene.h index 219bd92..12da304 100644 --- a/ege/widget/Scene.h +++ b/ege/widget/Scene.h @@ -52,10 +52,19 @@ namespace ege { */ virtual ~Scene(); protected: - std::string m_cameraName; + std::string m_cameraName; //!< current camera name public: - void setCamera(const std::string& _cameraName) { - m_cameraName = _cameraName; + /** + * @brief Select a Camera for the display. + * @param[in] _cameraName New name of the camera. + */ + void setCamera(const std::string& _cameraName); + /** + * @brief Get the current camera name to display the environnement. + * @return the current camera name. + */ + const std::string& getCamera() const { + return m_cameraName; } protected: // Note : This is only for temporary elements : on the display @@ -67,6 +76,7 @@ namespace ege { virtual void systemDraw(const ewol::DrawProperty& _displayProp); virtual void onRegenerateDisplay(); virtual void periodicCall(const ewol::event::Time& _event); + virtual void calculateSize(const vec2& _available); }; }; }; diff --git a/sample/MeshCreator/appl/Windows.cpp b/sample/MeshCreator/appl/Windows.cpp index 5e8b0be..c018bb8 100644 --- a/sample/MeshCreator/appl/Windows.cpp +++ b/sample/MeshCreator/appl/Windows.cpp @@ -36,31 +36,21 @@ static std::shared_ptr createGrid(int32_t _lineCount) { material->setSpecularFactor(vec4(0,0,0,1)); material->setShininess(1); material->setRenderMode(ewol::openGL::renderLine); + //material->setRenderMode(ewol::openGL::renderPoint); out->addMaterial("basics", material); out->addFaceIndexing("basics"); - /* - out->addQuad("basics", - vec3(-10,0,0), vec3(10,0,0), vec3(10,10,-lineSize), vec3(-10,10,-lineSize), - etk::color::white, etk::color::red, etk::color::green, etk::color::blue); - */ // 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); + //out->addPoint("basics", vec3(-_lineCount,iii,0), etk::color::white); + //out->addPoint("basics", 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); + //out->addPoint("basics", vec3(iii,-_lineCount,0), etk::color::white); + //out->addPoint("basics", vec3(iii,_lineCount,0), etk::color::white); } // generate the VBO @@ -153,7 +143,9 @@ void appl::Windows::init() { void appl::Windows::onCallbackPeriodicUpdateCamera(const ewol::event::Time& _event) { static float offset = 0; offset += 0.01; - m_camera->setEye(vec3(100*std::sin(offset),100*std::cos(offset),40)+vec3(50,0,0)); + static float offset2 = 0; + offset2 += 0.003; + m_camera->setEye(vec3(100*std::sin(offset),100*std::cos(offset),40*std::cos(offset2))+vec3(50,0,0)); }