diff --git a/sources/Android.mk b/sources/Android.mk index d8f50d5b..ebd05166 100644 --- a/sources/Android.mk +++ b/sources/Android.mk @@ -55,6 +55,7 @@ $(LOCAL_PATH)/$(FILE_ABSTRACTION_DEST): $(FILE_ABSTRACTION) $(Q)sed -i "s|__PROJECT_VENDOR__|$(PROJECT_COMPAGNY_NAME2)|" $@ $(Q)sed -i "s|__PROJECT_NAME__|$(PROJECT_NAME2)|" $@ $(Q)sed -i "s|__PROJECT_PACKAGE__|$(PROJECT_NAME2)|" $@ + $(FILE_ABSTRACTION_DEST): $(LOCAL_PATH)/$(FILE_ABSTRACTION_DEST) diff --git a/sources/ewol/renderer/resources/Mesh.cpp b/sources/ewol/renderer/resources/Mesh.cpp index f35be53c..61fbe59b 100644 --- a/sources/ewol/renderer/resources/Mesh.cpp +++ b/sources/ewol/renderer/resources/Mesh.cpp @@ -163,6 +163,60 @@ void ewol::Mesh::Draw(mat4& positionMatrix) // TODO : UNDERSTAND why ... it is needed glBindBuffer(GL_ARRAY_BUFFER,0); } +void ewol::Mesh::Draw2(mat4& positionMatrix) +{ + #ifndef USE_INDEXED_MESH + if (m_numberOfElments<=0) { + return; + } + #else + if (m_listIndexFaces.Size()<=0) { + return; + } + #endif + if (NULL == m_texture0) { + EWOL_WARNING("Texture does not exist ..."); + return; + } + if (m_GLprogram==NULL) { + EWOL_ERROR("No shader ..."); + return; + } + ewol::openGL::Enable(ewol::openGL::FLAG_DEPTH_TEST); + //EWOL_DEBUG(" Display " << m_coord.Size() << " elements" ); + m_GLprogram->Use(); + // set Matrix : translation/positionMatrix + mat4 projMatrix = ewol::openGL::GetMatrix(); + mat4 tmpMatrix = projMatrix; + m_GLprogram->UniformMatrix4fv(m_GLMatrix, 1, tmpMatrix.m_mat); + m_GLprogram->UniformMatrix4fv(m_GLMatrixPosition, 1, positionMatrix.m_mat); + // TextureID + m_GLprogram->SetTexture0(m_GLtexID0, m_texture0->GetId()); + // position : + m_GLprogram->SendAttributePointer(m_GLPosition, 3/*x,y,z*/, m_verticesVBO, MESH_VBO_VERTICES); + // Texture : + m_GLprogram->SendAttributePointer(m_GLtexture, 2/*u,v*/, m_verticesVBO, MESH_VBO_TEXTURE); + // position : + m_GLprogram->SendAttributePointer(m_GLNormal, 3/*x,y,z*/, m_verticesVBO, MESH_VBO_VERTICES_NORMAL); + // position : + #ifndef USE_INDEXED_MESH + m_GLprogram->SendAttributePointer(m_GLNormalFace, 3/*x,y,z*/, m_verticesVBO, MESH_VBO_FACE_NORMAL); + #endif + // draw materials : + m_material.Draw(m_GLprogram); + m_light.Draw(m_GLprogram); + + #ifndef USE_INDEXED_MESH + // Request the draw od the elements : + ewol::openGL::DrawArrays(GL_TRIANGLES, 0, m_numberOfElments); + #else + ewol::openGL::DrawElements(GL_TRIANGLES, m_listIndexFaces); + #endif + m_GLprogram->UnUse(); + ewol::openGL::Disable(ewol::openGL::FLAG_DEPTH_TEST); + // TODO : UNDERSTAND why ... it is needed + glBindBuffer(GL_ARRAY_BUFFER,0); +} // normal calculation of the normal face is really easy : void ewol::Mesh::CalculateNormaleFace(void) diff --git a/sources/ewol/renderer/resources/Mesh.h b/sources/ewol/renderer/resources/Mesh.h index 2d61a3c2..485ab8f1 100644 --- a/sources/ewol/renderer/resources/Mesh.h +++ b/sources/ewol/renderer/resources/Mesh.h @@ -174,6 +174,7 @@ namespace ewol virtual ~Mesh(void); virtual const char* GetType(void) { return "ewol::Mesh"; }; virtual void Draw(mat4& positionMatrix); + virtual void Draw2(mat4& positionMatrix); void GenerateVBO(void); public: // some addition basic funtion that permit to create or overwrite some caracterstics : diff --git a/sources/ewol/widget/Mesh.cpp b/sources/ewol/widget/Mesh.cpp new file mode 100644 index 00000000..8865f18c --- /dev/null +++ b/sources/ewol/widget/Mesh.cpp @@ -0,0 +1,159 @@ +/** + * @author Edouard DUPIN + * + * @copyright 2011, Edouard DUPIN, all right reserved + * + * @license BSD v3 (see license file) + */ + +#include +#include +#include + + +extern const char * const ewolEventMeshPressed = "ewol-mesh-Pressed"; + +#undef __class__ +#define __class__ "Mesh" + + + +widget::Mesh::Mesh(const etk::UString& filename) : + m_meshName(filename), + m_object(NULL), + m_position(0,0,0), + m_angle(0,0,0), + m_angleSpeed(0,0,0), + m_cameraDistance(10.0), + m_lastTime(-1) +{ + AddEventId(ewolEventMeshPressed); + m_meshName = filename; + // Limit event at 1: + SetMouseLimit(1); + if (filename!="") { + if (false==ewol::resource::Keep(m_meshName, m_object)) { + EWOL_ERROR("Can not load the resource : \"" << m_meshName << "\""); + } + } +} + + +widget::Mesh::~Mesh(void) +{ + if (NULL != m_object) { + ewol::resource::Release(m_object); + m_object = NULL; + } +} +void widget::Mesh::OnDraw(ewol::DrawProperty& displayProp) +{ + mat4 transformationMatrix = etk::matTranslate(vec3(0,0,-m_cameraDistance)) + * etk::matTranslate(m_position) + * etk::matRotate(vec3(1,0,0),m_angle.x()) + * etk::matRotate(vec3(0,1,0),m_angle.y()) + * etk::matRotate(vec3(0,0,1),m_angle.z()); + if (NULL != m_object) { + m_object->Draw2(transformationMatrix); + } +} + +void widget::Mesh::GenDraw(ewol::DrawProperty displayProp) +{ + 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(), + m_origin.y(), + m_size.x(), + m_size.y()); + float ratio = m_size.x() / m_size.y(); + //EWOL_INFO("ratio : " << ratio); + mat4 tmpProjection = etk::matPerspective(M_PI/3.0, ratio, 0.5, 100); + //mat4 tmpMat = tmpProjection * m_camera.GetMatrix(); + // set internal matrix system : + //ewol::openGL::SetMatrix(tmpMat); + ewol::openGL::SetMatrix(tmpProjection); + + // Call the widget drawing methode + displayProp.m_origin = m_origin; + displayProp.m_size = m_size; + // Call the widget drawing methode + OnDraw(displayProp); + ewol::openGL::Pop(); +} + +void widget::Mesh::OnRegenerateDisplay(void) +{ + if (true == NeedRedraw()) { + + } +} + +void widget::Mesh::PeriodicCall(int64_t localTime) +{ + if (m_lastTime==-1) { + m_lastTime = localTime; + return; + } + + float deltaTime = (float)(localTime - m_lastTime)/1000000.0f;; + m_angle += m_angleSpeed*deltaTime; + MarkToRedraw(); + m_lastTime = localTime; +} + +bool widget::Mesh::OnEventInput(ewol::keyEvent::type_te type, int32_t IdInput, ewol::keyEvent::status_te typeEvent, vec2 pos) +{ + //EWOL_DEBUG("Event on BT ..."); + if (1 == IdInput) { + if( ewol::keyEvent::statusSingle == typeEvent) { + GenerateEventId(ewolEventMeshPressed); + return true; + } + } + return false; +} + +void widget::Mesh::SetFile(const etk::UString& filename) +{ + if (filename!="") { + if (NULL != m_object) { + ewol::resource::Release(m_object); + m_object = NULL; + } + if (false==ewol::resource::Keep(m_meshName, m_object)) { + EWOL_ERROR("Can not load the resource : \"" << m_meshName << "\""); + } + } + MarkToRedraw(); +} + +void widget::Mesh::SetPosition(const vec3& pos) +{ + m_position = pos; + MarkToRedraw(); +} + +void widget::Mesh::SetAngle(const vec3& angle) +{ + m_angle = angle; + MarkToRedraw(); +} + +void widget::Mesh::SetAngleSpeed(const vec3& speed) +{ + if (speed!=vec3(0,0,0)) { + PeriodicCallSet(true); + } else { + PeriodicCallSet(false); + } + m_lastTime = -1; + m_angleSpeed = speed; + MarkToRedraw(); +} + +void widget::Mesh::SetDistance(float distance) +{ + m_cameraDistance = distance; + MarkToRedraw(); +} diff --git a/sources/ewol/widget/Mesh.h b/sources/ewol/widget/Mesh.h new file mode 100644 index 00000000..7ae0aee6 --- /dev/null +++ b/sources/ewol/widget/Mesh.h @@ -0,0 +1,72 @@ +/** + * @author Edouard DUPIN + * + * @copyright 2011, Edouard DUPIN, all right reserved + * + * @license BSD v3 (see license file) + */ + +#ifndef __EWOL_WIDGET_MESH_H__ +#define __EWOL_WIDGET_MESH_H__ + +#include +#include +#include + +extern const char * const ewolEventMeshPressed; + + +namespace widget { + class Mesh :public ewol::Widget + { + private: + // mesh name : + etk::UString m_meshName; + ewol::MeshObj* m_object; + // mesh display properties: + vec3 m_position; + vec3 m_angle; + vec3 m_angleSpeed; + float m_cameraDistance; + int64_t m_lastTime; + public: + Mesh(const etk::UString& filename); // automatic considering in the appl Data older + virtual ~Mesh(void); + public: // Derived function + virtual const char * const GetObjectType(void) { return "widget::Mesh"; }; + virtual void OnRegenerateDisplay(void); + virtual void GenDraw(ewol::DrawProperty displayProp); + virtual void OnDraw(ewol::DrawProperty& displayProp); + virtual bool OnEventInput(ewol::keyEvent::type_te type, int32_t IdInput, ewol::keyEvent::status_te typeEvent, vec2 pos); + virtual void PeriodicCall(int64_t localTime); + public: + /** + * @brief Set a mesh name file + * @param[in] filename Name of the new mesh + */ + void SetFile(const etk::UString& filename); + /** + * @brief Set the mesh position + * @param[in] pos The new position of the mesh + */ + void SetPosition(const vec3& pos); + /** + * @brief Set the mesh angle of view + * @param[in] angle view angle of the mesh + */ + void SetAngle(const vec3& angle); + /** + * @brief Set the mesh angle speed + * @param[in] spped radian speed of the mesh + */ + void SetAngleSpeed(const vec3& speed); + /** + * @brief Set the camera distance of the mesh + * @param[in] dist Diatance of the mesh + */ + void SetDistance(float distance); + }; +}; + + +#endif diff --git a/sources/file.mk b/sources/file.mk index 75d4f8c2..d2673f62 100644 --- a/sources/file.mk +++ b/sources/file.mk @@ -71,6 +71,7 @@ FILE_LIST+= ewol/widget/Widget.cpp \ ewol/widget/ListFileSystem.cpp \ ewol/widget/Layer.cpp \ ewol/widget/Menu.cpp \ + ewol/widget/Mesh.cpp \ ewol/widget/PopUp.cpp \ ewol/widget/ProgressBar.cpp \ ewol/widget/Sizer.cpp \