From 05b6e4f9eded305a9a1f3105d1b230fc47c50042 Mon Sep 17 00:00:00 2001 From: Anakin Date: Mon, 12 Sep 2016 16:49:05 +0200 Subject: [PATCH] started msh read in --- MshViewer/Header/Camera.h | 44 ----------- MshViewer/Header/Object.h | 35 +-------- MshViewer/Source/Camera.cpp | 87 --------------------- MshViewer/Source/Object.cpp | 151 +++++++++--------------------------- MshViewer/main.cpp | 15 ++++ Release/Msh/cube.msh | Bin 0 -> 1144 bytes 6 files changed, 55 insertions(+), 277 deletions(-) delete mode 100644 MshViewer/Header/Camera.h delete mode 100644 MshViewer/Source/Camera.cpp create mode 100644 Release/Msh/cube.msh diff --git a/MshViewer/Header/Camera.h b/MshViewer/Header/Camera.h deleted file mode 100644 index 0509152..0000000 --- a/MshViewer/Header/Camera.h +++ /dev/null @@ -1,44 +0,0 @@ -#pragma once -#include -#include -#include - -class Camera -{ -public: - Camera(int width, int height); - ~Camera(); - -private: - float fFOV; - float fMinView; - float fMaxView; - - int iWidth; - int iHeight; - - double dTranslationX; - double dTranslationY; - double dTranslationZ; - - - glm::mat4 m4x4Projection; - glm::mat4 m4x4View; - -private: - void updateMatrices(); - -public: - glm::mat4 getMatrix(); - - void setFOV(float fov); - void setMinView(float distance); - void setMaxView(float distance); - void setSize(int width, int height); - - void add2x(double value); - void add2y(double value); - void add2z(double value); - - -}; \ No newline at end of file diff --git a/MshViewer/Header/Object.h b/MshViewer/Header/Object.h index 0c87730..f1cdb0e 100644 --- a/MshViewer/Header/Object.h +++ b/MshViewer/Header/Object.h @@ -1,9 +1,7 @@ #pragma once -#include -#include -#include #include + class Object { public: @@ -11,37 +9,8 @@ public: ~Object(); private: - GLuint gluiVertexArrayID; - GLuint gluiVertexBufferID; - GLuint gluiUVBufferID; - - GLuint gluiShaderPrgmID; - GLuint gluiTextureID; - - std::vector vfVertices; - std::vector vfUV; - - float fRotationX; - float fRotationY; - float fRotationZ; - - glm::mat4 m4x4Model; - -private: - void processTexture(); - void calcMatrix(); - void loadMesh2OGL(); - + public: - glm::mat4 getMatrix(); - GLuint getShader() const; - GLuint getTextureID() const; - GLuint getVertexBufferID() const; - GLuint getUVBufferID() const; - int getVertexNumber() const; - void add2x(float value); - void add2y(float value); - void add2z(float value); }; diff --git a/MshViewer/Source/Camera.cpp b/MshViewer/Source/Camera.cpp deleted file mode 100644 index 821a314..0000000 --- a/MshViewer/Source/Camera.cpp +++ /dev/null @@ -1,87 +0,0 @@ -#include "..\header\Camera.h" -#include - - -///////////////////////////////////////////////////////////////////////// -// constructor/destructor - -Camera::Camera(int width, int height): - fFOV(45), - fMinView(0.1f), - fMaxView(100.0f), - iWidth(width), - iHeight(height), - dTranslationX(0), - dTranslationY(0), - dTranslationZ(5) -{ -} - - -Camera::~Camera() -{ -} - - -///////////////////////////////////////////////////////////////////////// -// private functions - -void Camera::updateMatrices() -{ - m4x4Projection = glm::perspective(fFOV, float(iWidth) / float(iHeight), fMinView, fMaxView); - m4x4View = glm::lookAt( - glm::vec3(dTranslationX, dTranslationY, dTranslationZ), - glm::vec3(dTranslationX, dTranslationY, dTranslationZ - 1), - glm::vec3(0, 1, 0) - ); -} - - -///////////////////////////////////////////////////////////////////////// -// public getter - -glm::mat4 Camera::getMatrix() -{ - updateMatrices(); - return m4x4Projection * m4x4View; -} - - -///////////////////////////////////////////////////////////////////////// -// public setter - -void Camera::setFOV(float fov) -{ - fFOV = fov; -} - -void Camera::setMinView(float distance) -{ - fMinView = distance; -} - -void Camera::setMaxView(float distance) -{ - fMaxView = distance; -} - -void Camera::setSize(int width, int height) -{ - iWidth = width; - iHeight = height; -} - -void Camera::add2x(double value) -{ - dTranslationX += value; -} - -void Camera::add2y(double value) -{ - dTranslationY += value; -} - -void Camera::add2z(double value) -{ - dTranslationZ += value; -} diff --git a/MshViewer/Source/Object.cpp b/MshViewer/Source/Object.cpp index 6549cc4..bfc5cf8 100644 --- a/MshViewer/Source/Object.cpp +++ b/MshViewer/Source/Object.cpp @@ -1,145 +1,70 @@ -#include -#include -#include #include "Object.h" -#include "shader.hpp" -#include "import.h" -#include "Texture.h" +#include +#include -#define VERTEX_SHADER "Shader/VertexTextureShader.mv2shdr" -#define FRAGMENT_SHADER "Shader/FragmentTextureShader.mv2shdr" -#define TEXTURE_NAME "Textures/dice.tga" ///////////////////////////////////////////////////////////////////////// // public constructor/destructor -Object::Object(const char* path) : - fRotationX(0), - fRotationY(0), - fRotationZ(0) +Object::Object(const char* path) { - m4x4Model = glm::mat4(1.0f); + // open file + std::fstream fsMesh(path, std::ios::in | std::ios::binary); - glGenVertexArrays(1, &gluiVertexArrayID); + if (!fsMesh.is_open()) + throw std::invalid_argument(std::string("file not found: ") += path); - glGenBuffers(1, &gluiVertexBufferID); - glGenBuffers(1, &gluiUVBufferID); + std::uint8_t ui8x4Header[5] = { 0 }; - gluiShaderPrgmID = LoadShaders(VERTEX_SHADER, FRAGMENT_SHADER); + fsMesh.seekg(4, std::ios_base::cur); + std::uint32_t ui32FileSize; + fsMesh.read(reinterpret_cast(&ui32FileSize), sizeof(ui32FileSize)); - vfVertices = loadData(); - vfUV = loadUV(); - - processTexture(); - loadMesh2OGL(); + fsMesh.seekg(4, std::ios_base::cur); + std::uint32_t ui32MshSize; + fsMesh.read(reinterpret_cast(&ui32MshSize), sizeof(ui32MshSize)); + + std::cout << "Hedr " << ui32FileSize << std::endl; + std::cout << "Msh " << ui32MshSize << std::endl; + + + do + { + + char tempChunkName[5] = { 0 }; + std::uint32_t tempChunkSize = 0; + fsMesh.read(reinterpret_cast(&tempChunkName[0]), sizeof(tempChunkName) - 1); + fsMesh.read(reinterpret_cast(&tempChunkSize), sizeof(tempChunkSize)); + + std::cout << tempChunkName << " " << tempChunkSize << std::endl; + + fsMesh.seekg(tempChunkSize, std::ios_base::cur); + + if (!std::strcmp(tempChunkName, "CL1L")) + break; + } while (!fsMesh.eof()); + + + fsMesh.close(); } Object::~Object() { - glDeleteBuffers(1, &gluiUVBufferID); - glDeleteBuffers(1, &gluiVertexBufferID); - glDeleteVertexArrays(1, &gluiVertexArrayID); - glDeleteProgram(gluiShaderPrgmID); + } ///////////////////////////////////////////////////////////////////////// // private functions -void Object::processTexture() -{ - glGenTextures(1, &gluiTextureID); - glBindTexture(GL_TEXTURE_2D, gluiTextureID); - - TextureTGA tempTex(TEXTURE_NAME); - glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, tempTex.getWidth(), tempTex.getHeight(), 0, GL_BGR, GL_UNSIGNED_BYTE, tempTex.getData().data()); - - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR); - glGenerateMipmap(GL_TEXTURE_2D); -} - -void Object::calcMatrix() -{ - m4x4Model = glm::rotate(m4x4Model, fRotationX, glm::vec3(1, 0, 0)); - m4x4Model = glm::rotate(m4x4Model, fRotationY, glm::vec3(0, 1, 0)); - m4x4Model = glm::rotate(m4x4Model, fRotationZ, glm::vec3(0, 0, 1)); -} - -void Object::loadMesh2OGL() -{ - // load object to OGL - glBindBuffer(GL_ARRAY_BUFFER, gluiVertexBufferID); - glBufferData( - GL_ARRAY_BUFFER, - sizeof(vfVertices) * vfVertices.size(), - vfVertices.data(), - GL_STATIC_DRAW - ); - - // load UV to OGL - glBindBuffer(GL_ARRAY_BUFFER, gluiUVBufferID); - glBufferData( - GL_ARRAY_BUFFER, - sizeof(vfUV) * vfUV.size(), - vfUV.data(), - GL_STATIC_DRAW - ); -} ///////////////////////////////////////////////////////////////////////// // public getter -glm::mat4 Object::getMatrix() -{ - calcMatrix(); - return m4x4Model; -} - -GLuint Object::getShader() const -{ - return gluiShaderPrgmID; -} - -GLuint Object::getTextureID() const -{ - return gluiTextureID; -} - -GLuint Object::getVertexBufferID() const -{ - return gluiVertexBufferID; -} - -GLuint Object::getUVBufferID() const -{ - return gluiUVBufferID; -} - -int Object::getVertexNumber() const -{ - return 12*3; -} ///////////////////////////////////////////////////////////////////////// // public functions -void Object::add2x(float value) -{ - fRotationX += value; -} - -void Object::add2y(float value) -{ - fRotationY += value; -} - -void Object::add2z(float value) -{ - fRotationZ += value; -} diff --git a/MshViewer/main.cpp b/MshViewer/main.cpp index 4a90bc0..c2a1eca 100644 --- a/MshViewer/main.cpp +++ b/MshViewer/main.cpp @@ -3,9 +3,24 @@ #endif // DEBUG #include "OpenGLController.h" +#include "Object.h" +#include +#include int main(int argc, char** argv) { + try { + Object obj("..\\Release\\Msh\\cube.msh"); + } + catch (std::invalid_argument e) + { + std::cout << e.what() << std::endl; + } + + system("pause"); + + + return 0; OpenGLController *scene = OpenGLController::getInstance(); scene->loadMsh("test.msh"); diff --git a/Release/Msh/cube.msh b/Release/Msh/cube.msh new file mode 100644 index 0000000000000000000000000000000000000000..644f86e258dc5cb3cd8e4483cef0b88aedd6111c GIT binary patch literal 1144 zcmbVL%TB^j5FH*WDk>_z_AXqwP;o63TOLVoA#E4vMo_yjF=`AZEax}yH~awn1b43d z2S34?!jQojiQeS&oS8Xy=JuwoIkx|h1~5VGs7)Nyy~;HJc$RVU#KBc`7hRk?q0@V~ zf9ytFtN5155+?{81AJQLa-+2$YyH5YjsUPEcz^jQ87p*e$-sR`+ihZ=nTCvS(^2qy9u1Cc}vFkQkVJ7M&KUMA$Q_w z_)6!{D2-xft+hwA)HxO{taGe2#KWvLdn6VuF|&r$HH+3ht+_6cJjbGib&hom&o}Dc zV6<=`ihNV_v^sYZkFd`Ds?|R-{(g}9{gmfMw8k}5TIauM3je$Z2SMmJUD~-DZ%<+h z(m0EAkii99ge)%O3gmDN*CCIaxCIGJ;x^2XCk^xD$-okMvam{?9Bhy$52x-Sw}da0 Cpuz9} literal 0 HcmV?d00001