started msh read in

This commit is contained in:
Anakin 2016-09-12 16:49:05 +02:00
parent 663bb62098
commit 05b6e4f9ed
6 changed files with 55 additions and 277 deletions

View File

@ -1,44 +0,0 @@
#pragma once
#include <gl\glew.h>
#include <gl\glfw3.h>
#include <glm\glm.hpp>
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);
};

View File

@ -1,9 +1,7 @@
#pragma once #pragma once
#include <gl\glew.h>
#include <gl\glfw3.h>
#include <glm\glm.hpp>
#include <vector> #include <vector>
class Object class Object
{ {
public: public:
@ -11,37 +9,8 @@ public:
~Object(); ~Object();
private: private:
GLuint gluiVertexArrayID;
GLuint gluiVertexBufferID;
GLuint gluiUVBufferID;
GLuint gluiShaderPrgmID;
GLuint gluiTextureID;
std::vector<GLfloat> vfVertices;
std::vector<GLfloat> vfUV;
float fRotationX;
float fRotationY;
float fRotationZ;
glm::mat4 m4x4Model;
private:
void processTexture();
void calcMatrix();
void loadMesh2OGL();
public: 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);
}; };

View File

@ -1,87 +0,0 @@
#include "..\header\Camera.h"
#include <glm\gtc\matrix_transform.hpp>
/////////////////////////////////////////////////////////////////////////
// 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;
}

View File

@ -1,145 +1,70 @@
#include <gl\glew.h>
#include <gl\glfw3.h>
#include <glm\gtc\matrix_transform.hpp>
#include "Object.h" #include "Object.h"
#include "shader.hpp" #include <fstream>
#include "import.h" #include <iostream>
#include "Texture.h"
#define VERTEX_SHADER "Shader/VertexTextureShader.mv2shdr"
#define FRAGMENT_SHADER "Shader/FragmentTextureShader.mv2shdr"
#define TEXTURE_NAME "Textures/dice.tga"
///////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////
// public constructor/destructor // public constructor/destructor
Object::Object(const char* path) : Object::Object(const char* path)
fRotationX(0),
fRotationY(0),
fRotationZ(0)
{ {
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); std::uint8_t ui8x4Header[5] = { 0 };
glGenBuffers(1, &gluiUVBufferID);
gluiShaderPrgmID = LoadShaders(VERTEX_SHADER, FRAGMENT_SHADER); fsMesh.seekg(4, std::ios_base::cur);
std::uint32_t ui32FileSize;
fsMesh.read(reinterpret_cast<char*>(&ui32FileSize), sizeof(ui32FileSize));
vfVertices = loadData(); fsMesh.seekg(4, std::ios_base::cur);
vfUV = loadUV(); std::uint32_t ui32MshSize;
fsMesh.read(reinterpret_cast<char*>(&ui32MshSize), sizeof(ui32MshSize));
processTexture();
loadMesh2OGL(); 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<char*>(&tempChunkName[0]), sizeof(tempChunkName) - 1);
fsMesh.read(reinterpret_cast<char*>(&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() Object::~Object()
{ {
glDeleteBuffers(1, &gluiUVBufferID);
glDeleteBuffers(1, &gluiVertexBufferID);
glDeleteVertexArrays(1, &gluiVertexArrayID);
glDeleteProgram(gluiShaderPrgmID);
} }
///////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////
// private functions // 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 // 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 // public functions
void Object::add2x(float value)
{
fRotationX += value;
}
void Object::add2y(float value)
{
fRotationY += value;
}
void Object::add2z(float value)
{
fRotationZ += value;
}

View File

@ -3,9 +3,24 @@
#endif // DEBUG #endif // DEBUG
#include "OpenGLController.h" #include "OpenGLController.h"
#include "Object.h"
#include <iostream>
#include <Windows.h>
int main(int argc, char** argv) 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(); OpenGLController *scene = OpenGLController::getInstance();
scene->loadMsh("test.msh"); scene->loadMsh("test.msh");

BIN
Release/Msh/cube.msh Normal file

Binary file not shown.