]> git.leopard-lacewing.eu Git - cgue_weave.git/commitdiff
renamed MetaModel -> IMetaMesh
authorPeter Schaefer <schaeferpm@gmail.com>
Wed, 22 Apr 2015 19:06:58 +0000 (21:06 +0200)
committerPeter Schaefer <schaeferpm@gmail.com>
Wed, 22 Apr 2015 19:06:58 +0000 (21:06 +0200)
renamed Model -> IMesh
created parentClass Model

15 files changed:
Weave/Game.cpp
Weave/Graphix/Graphix.cpp
Weave/Graphix/IMesh.cpp [new file with mode: 0644]
Weave/Graphix/IMesh.h [new file with mode: 0644]
Weave/Graphix/IMetaMesh.cpp [new file with mode: 0644]
Weave/Graphix/IMetaMesh.h [new file with mode: 0644]
Weave/Graphix/MetaModel.cpp [deleted file]
Weave/Graphix/MetaModel.h [deleted file]
Weave/Graphix/Model.cpp
Weave/Graphix/Model.h
Weave/Graphix/SceneObject.cpp
Weave/Graphix/SceneObject.h
Weave/Weave.vcxproj
Weave/Weave.vcxproj.filters
shader/skybox_FS.hlsl

index 2fab228ae12d652636fc1771c02db5f9198f690d..b7352fc58e6c5c13f681b00513e54d8dedb5d521 100644 (file)
@@ -18,6 +18,8 @@
 #include "Fps.h"
 #include "Events.h"
 
+#include "Graphix\Model.h"
+
 #include "Message.h"
 
 //#include "PlayerI.h"
@@ -41,18 +43,17 @@ Game::Game() : playing(true)
 {
        srand((int)time(NULL));
        // Hauptfenster
-       Scene* tmp_Scene = new Scene(0, 0, Graphix::getWindowWidth(), Graphix::getWindowHeight(), 45, 0.1f, 15, vec3(0.0f, 0.0f, 0.f));
+       Scene* tmp_Scene = new Scene(0, 0, Graphix::getWindowWidth(), Graphix::getWindowHeight(), 45, 0.1f, 40, vec3(0.0f, 0.0f, 0.f));
        layer[0] = tmp_Scene;
 
-
        //SKYBOX! ---------------------------
                                //      tmp_Scene->addObject(new SceneObject(shaderSky, glm::mat4(1.0f), "SkyBox.dae", "skybox.jpg"));
                                //Message::info("Error from before?");
                                //Graphix::getGlError();
-                       //skybox = new Shader("skybox_VS.hlsl", "skybox_FS.hlsl");
+                       skybox = new Shader("skybox_VS.hlsl", "skybox_FS.hlsl");
                                //Message::info("Creating SkyBox Shader");
                                //Graphix::getGlError();
-                       //SkyBox = new SceneObject(skybox, mat4(1.f), "SkyBox.dae", "skybox_CUBE.jpg");
+                       SkyBox = new SceneObject(skybox, mat4(1.f), "SkyBox.dae", "skybox_CUBE.jpg");
                                //Message::info("Creating SkyBox SceneObject"); rotate((float)M_PI_2, vec3(1.f, 0.f, 0.f))
                                //Graphix::getGlError();
                                //Message::info("Done");
@@ -66,6 +67,10 @@ Game::Game() : playing(true)
        Shader* shader1 = new Shader("basicTexture_VS.hlsl", "lightingTexture_FS.hlsl");
 //     Shader* shaderSky = new Shader("skybox_VS.hlsl", "skybox_FS.hlsl");
 
+       // load LVL
+       tmp_Scene->addObject(new SceneObject(shader1, scale(3.f * vec3(1.f,.3f,1.f)), "level_test.dae", "model_duck.png"));
+
+
        //Player
        SceneObject* tmp_playerObject = new SceneObject(shader1, translate(vec3(1.f, 0.f, 1.f)), "Player.dae", "model_player_2D.png");
 
@@ -107,8 +112,6 @@ Game::Game() : playing(true)
        //tmp_Scene->addObject(new SceneObject(shader1, translate(vec3(-1.f, 2.f, -2.f)), "../models/box/box.dae", "../Textures/sky_withstars.png"));
        //tmp_Scene->addObject(new SceneObject(shader1, translate(vec3(1.f, 3.f, -2.f)), "../models/cow/cow.dae", "../models/cow/texture.jpg"));
 
-       // load LVL
-//     tmp_Scene->addObject(new SceneObject(shader1, glm::mat4(1.0f), "level_test.dae", "model_duck.png"));
 
        //import("level_test.dae", tmp_Scene, shader1);
 
index 90046a44fafe2747b31524a964de3ecd845dd907..0692d32d072b98580b5a51842a88d63dc3a43669 100644 (file)
@@ -63,7 +63,7 @@ void Graphix::init()
        //SDL_SetWindowGrab(sdl_window, SDL_TRUE);
        //SDL_ShowCursor(SDL_DISABLE);
        glEnable(GL_COLOR_MATERIAL);
-       glEnable(GL_TEXTURE_CUBE_MAP);
+       //glEnable(GL_TEXTURE_CUBE_MAP);
        glEnable(GL_LIGHTING);
        glEnable(GL_LIGHT0);
        glEnable(GL_CULL_FACE);
diff --git a/Weave/Graphix/IMesh.cpp b/Weave/Graphix/IMesh.cpp
new file mode 100644 (file)
index 0000000..6d35577
--- /dev/null
@@ -0,0 +1,271 @@
+#include "IMesh.h"
+
+#include <GL/glew.h>
+#include <assimp/Importer.hpp>
+#include <assimp/scene.h>
+#include <assimp/postprocess.h>
+
+#include "Shader.h"
+#include "Texture.h"
+#include "../Message.h"
+
+#include "Graphix.h"
+
+
+
+IMesh::IMesh(const string& _modelpath, uint _mindex) :
+numfaces(-1),
+numvertices(-1),
+vertexBuffer(-1),
+normalBuffer(-1),
+uvBuffer(-1),
+indexBuffer(-1) 
+{
+
+       float *vertex = nullptr, *normals = nullptr, *uvs = nullptr;
+       uint *index = nullptr;
+
+       aiMesh* mesh = import(_modelpath, _mindex);
+
+       import(mesh, numvertices, numfaces, vertex, uvs, normals, index);
+
+       genBuffer(vertexBuffer, numvertices * 3 * sizeof(float), (void*)vertex);
+       genBuffer(normalBuffer, numvertices * 3 * sizeof(float), (void*)normals);
+       genBuffer(uvBuffer, numvertices * 2 * sizeof(float), (void*)uvs);
+       genBuffer(indexBuffer, numfaces * 3 * sizeof(uint), (void*)index);
+
+       delete vertex, normals, uvs, index, mesh;
+
+}
+
+IMesh::IMesh(const aiMesh* _mesh) :
+numfaces(-1),
+numvertices(-1),
+vertexBuffer(-1),
+normalBuffer(-1),
+uvBuffer(-1),
+indexBuffer(-1)
+{
+
+       float *vertex = nullptr, *normals = nullptr, *uvs = nullptr;
+       uint *index = nullptr;
+
+       import(_mesh, numvertices, numfaces, vertex, uvs, normals, index);
+
+       genBuffer(vertexBuffer, numvertices * 3 * sizeof(float), (void*)vertex);
+       genBuffer(normalBuffer, numvertices * 3 * sizeof(float), (void*)normals);
+       genBuffer(uvBuffer, numvertices * 2 * sizeof(float), (void*)uvs);
+       genBuffer(indexBuffer, numfaces * 3 * sizeof(uint), (void*)index);
+
+       delete vertex, normals, uvs, index;
+
+}
+
+
+IMesh::~IMesh()
+{
+       glDeleteBuffers(1, &vertexBuffer);
+       glDeleteBuffers(1, &normalBuffer);
+       glDeleteBuffers(1, &uvBuffer);
+       glDeleteBuffers(1, &indexBuffer);
+
+}
+
+//void IMesh::useModel(Shader* _shader)
+//{
+//     uint vao=-1;
+//     auto i = shader_map.find(*_shader);
+//     if (i == shader_map.end())
+//             vao = bindShader(_shader);
+//     else
+//             vao = i->second;
+//
+//     glBindVertexArray(vao);
+//     _shader->useShader();
+//
+//}
+
+void IMesh::useModel(Shader* _shader) const
+{
+       _shader->useShader();
+       uint vao = -1;
+       auto i = shader_map.find(*_shader);
+       if (i == shader_map.end())
+               Message::error("The Shader wasn't bind to the IMesh.\n");
+       else
+               vao = i->second;
+
+       glBindVertexArray(vao);
+       
+
+}
+
+void IMesh::useTexture(Texture* _texture, Shader* _shader) const
+{
+       if (_texture != nullptr)
+       {
+               auto tmp = _shader->getUniformLocation("uColorTexture");
+               if (tmp < 0){
+                       return;
+               }
+               int unit = 0;
+               _texture->bind(unit);
+               glUniform1i(tmp, unit);
+       }
+}
+
+void IMesh::useModelMat(const mat4& _model, Shader* _shader) const
+{
+       int tmp = _shader->getUniformLocation("uModel");
+       if (tmp >= 0)
+               glUniformMatrix4fv(tmp, 1, GL_FALSE, value_ptr(_model));
+}
+
+void IMesh::drawModel(Shader* _shader, Texture* _texture, const mat4& _model) const
+{
+       //Message::info("Error from before?");
+       //Graphix::getGlError();
+       useModel(_shader);
+       //Message::info("IMesh loading Coordinates");
+       //Graphix::getGlError();
+       useTexture(_texture, _shader);
+       //Message::info("IMesh loading Texture");
+       //Graphix::getGlError();
+       useModelMat(_model, _shader);
+       //Message::info("IMesh loading MMatrix");
+       //Graphix::getGlError();
+       glDrawElements(GL_TRIANGLES, numfaces * 3, GL_UNSIGNED_INT, 0);
+       //Message::info("IMesh drawing Elements");
+       //Graphix::getGlError();
+       glBindVertexArray(0);
+       //system("pause");
+}
+
+void IMesh::bindShader(Shader* _shader)
+{
+       //Message::info("bindShader");
+       //Graphix::getGlError();
+       //Message::info("Do Stuff");
+       uint vao;
+       glGenVertexArrays(1, &vao);
+       glBindVertexArray(vao);
+
+       //Message::info("bindVAO");
+       //Graphix::getGlError();
+
+       bindBuffer(vertexBuffer, _shader->getAttribLocation("aPosition"));
+       //Message::info("aPosition");
+       //Graphix::getGlError();
+       bindBuffer(uvBuffer, _shader->getAttribLocation("aUV"), 2);
+       //Message::info("aUV");
+       //Graphix::getGlError();
+       bindBuffer(normalBuffer, _shader->getAttribLocation("aNormal"));
+       //Message::info("aNormal");
+       //Graphix::getGlError();
+
+       glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, indexBuffer);
+       //Message::info("bindIndexBuffer");
+       //Graphix::getGlError();
+
+       glBindVertexArray(0);
+
+       glBindBuffer(GL_ARRAY_BUFFER, 0);
+       glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);
+
+       shader_map[*_shader] = vao;
+
+       //Message::info("cleanUp");
+       //Graphix::getGlError();
+       //Message::info("Done");
+
+}
+
+void IMesh::genBuffer(uint &buffer, uint size, void* value)
+{
+       glGenBuffers(1, &buffer);
+       glBindBuffer(GL_ARRAY_BUFFER, buffer);
+       glBufferData(GL_ARRAY_BUFFER, size, value, GL_STATIC_DRAW);
+       glBindBuffer(GL_ARRAY_BUFFER, 0);
+}
+
+void IMesh::bindBuffer(const uint &buffer, const uint index, const uint dim)
+{
+       //Falls index nicht gefunden werden konnte
+       if (index == (uint)-1)
+       {
+               Message::info("IMesh: BindBuffer wird ausgelassen da index fehlerhaft ist.");
+               return;
+       }
+               
+       glBindBuffer(GL_ARRAY_BUFFER, buffer);
+       glEnableVertexAttribArray(index);
+       glVertexAttribPointer(index, dim, GL_FLOAT, GL_FALSE, 0, 0);
+       glBindBuffer(GL_ARRAY_BUFFER, 0);
+}
+
+
+aiMesh* IMesh::import(const string& _modelpath, uint _mindex) const
+{
+       Assimp::Importer importer;
+
+       const aiScene* scene = importer.ReadFile("../models/" + _modelpath, aiProcess_GenUVCoords | aiProcess_Triangulate | aiProcess_JoinIdenticalVertices | aiProcess_SortByPType);           //aiProcess_PreTransformVertices
+       if (!scene)
+       {
+               Message::error("The file " + _modelpath + " couldn't be read.\n" + importer.GetErrorString());
+               return nullptr;
+       }
+
+       if (!scene->HasMeshes() || scene->mNumMeshes <= _mindex)
+       {
+               Message::error("The file " + _modelpath + " doesn't contain any nodes.");
+               return nullptr;
+       }
+
+       return scene->mMeshes[_mindex];
+}
+
+bool IMesh::import(const aiMesh* mesh, uint& numvertices, uint& numfaces, float*& vertex, float*& uvs, float*& normals, uint*& index) const
+{
+
+       numvertices = mesh->mNumVertices;
+       numfaces = mesh->mNumFaces;
+       vertex = new float[numvertices * 3];
+       uvs = new float[numvertices * 2];
+       index = new uint[numfaces * 3];
+       normals = new float[numvertices * 3];
+       //aiFace* faces = mesh->mFaces;
+
+
+       //load vertices from Mesh
+       for (uint i = 0; i < numvertices; i++)
+       {
+               vertex[3 * i] = mesh->mVertices[i].x;
+               vertex[3 * i + 1] = mesh->mVertices[i].y;
+               vertex[3 * i + 2] = mesh->mVertices[i].z;
+       }
+
+       //load UVs from Mesh
+       for (uint i = 0; i < numvertices; i++)
+       {
+               uvs[2 * i] = mesh->mTextureCoords[0][i].x;//[i]->x;
+               uvs[2 * i + 1] = mesh->mTextureCoords[0][i].y;//[i]->y;
+       }
+
+       //load indices from Mesh
+       for (uint i = 0; i < numfaces; i++)
+       {
+               index[3 * i] = mesh->mFaces[i].mIndices[0];
+               index[3 * i + 1] = mesh->mFaces[i].mIndices[1];
+               index[3 * i + 2] = mesh->mFaces[i].mIndices[2];
+       }
+
+       //load normals from Mesh
+       for (uint i = 0; i < numvertices; i++)
+       {
+               normals[3 * i] = mesh->mNormals[i].x;
+               normals[3 * i + 1] = mesh->mNormals[i].y;
+               normals[3 * i + 2] = mesh->mNormals[i].z;
+       }
+
+       return true;
+}
diff --git a/Weave/Graphix/IMesh.h b/Weave/Graphix/IMesh.h
new file mode 100644 (file)
index 0000000..5ae07e2
--- /dev/null
@@ -0,0 +1,44 @@
+#pragma once
+
+#include <string>
+#include "GLM.h"
+
+#include "Model.h"
+
+using std::string;
+
+class Shader;
+class Texture;
+struct aiMesh;
+
+class IMesh : Model
+{
+public:
+       IMesh(const string& modelpath, uint index=0);
+       IMesh(const aiMesh* mesh);
+
+       virtual ~IMesh();
+
+       void drawModel(Shader* shader, Texture* texture, const mat4& modelMat) const;
+
+       void bindShader(Shader* shader);
+
+protected:
+       uint numvertices, numfaces;
+       uint vertexBuffer, normalBuffer, uvBuffer, indexBuffer;
+
+       // Mesh Speichern?
+       aiMesh* import(const string& modelpath, uint mindex = 0) const;
+       bool import(const aiMesh* mesh, uint& numvertices, uint& numfaces, float*& vertex, float*& uvs, float*& normals, uint*& index) const;
+
+       void genBuffer(uint &buffer, uint size, void* value);
+       void bindBuffer(const uint &buffer, const uint index,const uint dim = 3);
+
+       void useModel(Shader* shader) const;
+       void useTexture(Texture* texture, Shader* shader) const;
+       void useModelMat(const mat4& model, Shader* shader) const;
+
+       
+
+};
+
diff --git a/Weave/Graphix/IMetaMesh.cpp b/Weave/Graphix/IMetaMesh.cpp
new file mode 100644 (file)
index 0000000..251e384
--- /dev/null
@@ -0,0 +1,65 @@
+#include "IMetaMesh.h"
+
+#include <assimp/Importer.hpp>
+#include <assimp/scene.h>
+#include <assimp/postprocess.h>
+
+#include "IMesh.h"
+#include "Shader.h"
+#include "../Message.h"
+
+
+IMetaMesh::IMetaMesh(const string& _modelpath)
+{
+       Assimp::Importer importer;
+
+       const aiScene* scene = importer.ReadFile("../models/" + _modelpath, aiProcess_GenUVCoords | aiProcess_Triangulate | aiProcess_JoinIdenticalVertices | aiProcess_SortByPType | aiProcess_PreTransformVertices);
+       if (!scene)
+       {
+               Message::error("The file " + _modelpath + " couldn't be read.\n" + importer.GetErrorString());
+               return;
+       }
+
+       if (scene->HasMeshes())// && scene->mNumMeshes > mindex)
+       {
+               IMesh* tmp_model=nullptr;
+               for (unsigned int i = 0; i < scene->mNumMeshes; i++)
+               {
+                       models.push_back(new IMesh(scene->mMeshes[i]));
+               }       
+               
+       }
+       else
+       {
+               Message::error("The file " + _modelpath + " doesn't contain any nodes.");
+               return;
+       }
+
+
+}
+
+IMetaMesh::~IMetaMesh()
+{
+       for (auto i = models.begin(); i != models.end(); ++i)
+       {
+               delete (*i);
+       }
+}
+
+void IMetaMesh::bindShader(Shader* _shader)
+{
+       for (auto i = models.begin(); i != models.end(); ++i)
+       {
+               (*i)->bindShader(_shader);
+       }
+}
+
+void IMetaMesh::drawModel(Shader* _shader, Texture* _texture, const mat4& _modelMat) const
+{
+       for (auto i = models.begin(); i != models.end(); ++i)
+       {
+               (*i)->drawModel(_shader,_texture,_modelMat);
+       }
+}
+
+
diff --git a/Weave/Graphix/IMetaMesh.h b/Weave/Graphix/IMetaMesh.h
new file mode 100644 (file)
index 0000000..6c0b7d2
--- /dev/null
@@ -0,0 +1,28 @@
+#pragma once
+
+#include "Model.h"
+
+#include <string>
+#include <list>
+#include "GLM.h"
+
+using std::string;
+
+class IMesh;
+class Shader;
+class Texture;
+
+class IMetaMesh : Model
+{
+public:
+       IMetaMesh(const string& modelpath);
+       ~IMetaMesh();
+
+       void bindShader(Shader* shader);
+
+       void drawModel(Shader* shader, Texture* texture, const mat4& modelMat) const;
+
+protected:
+       std::list<IMesh*> models;
+};
+
diff --git a/Weave/Graphix/MetaModel.cpp b/Weave/Graphix/MetaModel.cpp
deleted file mode 100644 (file)
index 6c26124..0000000
+++ /dev/null
@@ -1,65 +0,0 @@
-#include "MetaModel.h"
-
-#include <assimp/Importer.hpp>
-#include <assimp/scene.h>
-#include <assimp/postprocess.h>
-
-#include "Model.h"
-#include "Shader.h"
-#include "../Message.h"
-
-
-MetaModel::MetaModel(const string& modelpath)
-{
-       Assimp::Importer importer;
-
-       const aiScene* scene = importer.ReadFile("../models/" + modelpath, aiProcess_GenUVCoords | aiProcess_Triangulate | aiProcess_JoinIdenticalVertices | aiProcess_SortByPType | aiProcess_PreTransformVertices);
-       if (!scene)
-       {
-               Message::error("The file " + modelpath + " couldn't be read.\n" + importer.GetErrorString());
-               return;
-       }
-
-       if (scene->HasMeshes())// && scene->mNumMeshes > mindex)
-       {
-               Model* tmp_model=nullptr;
-               for (unsigned int i = 0; i < scene->mNumMeshes; i++)
-               {
-                       models.push_back(new Model(scene->mMeshes[i]));
-               }       
-               
-       }
-       else
-       {
-               Message::error("The file " + modelpath + " doesn't contain any nodes.");
-               return;
-       }
-
-
-}
-
-MetaModel::~MetaModel()
-{
-       for (auto i = models.begin(); i != models.end(); ++i)
-       {
-               delete (*i);
-       }
-}
-
-void MetaModel::bindShader(Shader* _shader)
-{
-       for (auto i = models.begin(); i != models.end(); ++i)
-       {
-               (*i)->bindShader(_shader);
-       }
-}
-
-void MetaModel::drawModel(Shader* _shader, Texture* _texture, const mat4& _model) const
-{
-       for (auto i = models.begin(); i != models.end(); ++i)
-       {
-               (*i)->drawModel(_shader,_texture,_model);
-       }
-}
-
-
diff --git a/Weave/Graphix/MetaModel.h b/Weave/Graphix/MetaModel.h
deleted file mode 100644 (file)
index f4c63c1..0000000
+++ /dev/null
@@ -1,29 +0,0 @@
-#pragma once
-
-#include <string>
-#include <list>
-#include "GLM.h"
-
-using std::string;
-using std::list;
-
-class Model;
-class Shader;
-class Texture;
-
-typedef list<Model*> ModelList;
-
-class MetaModel
-{
-public:
-       MetaModel(const string& modelpath);
-       ~MetaModel();
-
-       void bindShader(Shader* shader);
-
-       void drawModel(Shader* shader, Texture* texture, const mat4& model) const;
-
-private:
-       ModelList models;
-};
-
index c810e5979623c8a2a5d4f7fc7512aef833305939..f797d4721c4abe08e3bbd2566e14bb1ce62d58c2 100644 (file)
@@ -1,84 +1,10 @@
 #include "Model.h"
 
 #include <GL/glew.h>
-#include <assimp/Importer.hpp>
-#include <assimp/scene.h>
-#include <assimp/postprocess.h>
 
-#include "Shader.h"
-#include "Texture.h"
-#include "../Message.h"
 
-#include "Graphix.h"
-
-typedef unsigned int uint;
-
-
-Model::Model(const string& _modelpath, unsigned int _mindex) :
-numfaces(-1),
-numvertices(-1),
-vertexBuffer(-1),
-normalBuffer(-1),
-uvBuffer(-1),
-indexBuffer(-1) 
-{
-
-       float *vertex = nullptr, *normals = nullptr, *uvs = nullptr;
-       uint *index = nullptr;
-       import(_modelpath, numvertices, numfaces, vertex, uvs, normals, index, _mindex);
-
-       genBuffer(vertexBuffer, numvertices * 3 * sizeof(float), (void*)vertex);
-       genBuffer(normalBuffer, numvertices * 3 * sizeof(float), (void*)normals);
-       genBuffer(uvBuffer, numvertices * 2 * sizeof(float), (void*)uvs);
-       genBuffer(indexBuffer, numfaces * 3 * sizeof(uint), (void*)index);
-
-       delete vertex, normals, uvs, index;
-
-}
-
-Model::Model(const aiMesh* _mesh) :
-numfaces(-1),
-numvertices(-1),
-vertexBuffer(-1),
-normalBuffer(-1),
-uvBuffer(-1),
-indexBuffer(-1)
-{
-
-       float *vertex = nullptr, *normals = nullptr, *uvs = nullptr;
-       uint *index = nullptr;
-
-       import(_mesh, numvertices, numfaces, vertex, uvs, normals, index);
-
-       genBuffer(vertexBuffer, numvertices * 3 * sizeof(float), (void*)vertex);
-       genBuffer(normalBuffer, numvertices * 3 * sizeof(float), (void*)normals);
-       genBuffer(uvBuffer, numvertices * 2 * sizeof(float), (void*)uvs);
-       genBuffer(indexBuffer, numfaces * 3 * sizeof(uint), (void*)index);
-
-       delete vertex, normals, uvs, index;
-
-}
-
-
-Model::Model(uint numvertices, uint numfaces, float *vertex, float *uvs, float *normals, uint *index) :
-vertexBuffer(-1),
-normalBuffer(-1),
-uvBuffer(-1),
-indexBuffer(-1)
+Model::Model()
 {
-
-       //float *vertex = nullptr, *normals = nullptr, *uvs = nullptr;
-       //uint *index = nullptr;
-
-       //import(_modelpath, numvertices, numfaces, vertex, uvs, normals, index);
-
-       genBuffer(vertexBuffer, numvertices * 3 * sizeof(float), (void*)vertex);
-       genBuffer(normalBuffer, numvertices * 3 * sizeof(float), (void*)normals);
-       genBuffer(uvBuffer, numvertices * 2 * sizeof(float), (void*)uvs);
-       genBuffer(indexBuffer, numfaces * 3 * sizeof(uint), (void*)index);
-
-       //delete vertex, normals, uvs, index;
-
 }
 
 
@@ -87,220 +13,22 @@ Model::~Model()
        for (auto i = shader_map.begin(); i != shader_map.end(); ++i){
                glDeleteVertexArrays(1, &(i->second));
        }
-       glDeleteBuffers(1, &vertexBuffer);
-       glDeleteBuffers(1, &normalBuffer);
-       glDeleteBuffers(1, &uvBuffer);
-       glDeleteBuffers(1, &indexBuffer);
-
-
 }
 
-//void Model::useModel(Shader* _shader)
-//{
-//     uint vao=-1;
-//     auto i = shader_map.find(*_shader);
-//     if (i == shader_map.end())
-//             vao = bindShader(_shader);
-//     else
-//             vao = i->second;
-//
-//     glBindVertexArray(vao);
-//     _shader->useShader();
-//
-//}
-
-void Model::useModel(Shader* _shader) const
+void Model::bindShader(Shader* _shader)
 {
-       _shader->useShader();
-       uint vao = -1;
-       auto i = shader_map.find(*_shader);
-       if (i == shader_map.end())
-               Message::error("The Shader wasn't bind to the Model.\n");
-       else
-               vao = i->second;
-
-       glBindVertexArray(vao);
-       
-
 }
 
-void Model::useTexture(Texture* _texture, Shader* _shader) const
+void Model::drawModel(Shader* _shader, Texture* _texture, const mat4& _modelMat) const
 {
-       if (_texture != nullptr)
-       {
-               auto tmp = _shader->getUniformLocation("uColorTexture");
-               if (tmp < 0){
-                       return;
-               }
-               int unit = 0;
-               _texture->bind(unit);
-               glUniform1i(tmp, unit);
-       }
 }
 
-void Model::useMMatrix(const mat4& _model, Shader* _shader) const
+void Model::drawBBox() const
 {
-       int tmp = _shader->getUniformLocation("uModel");
-       if (tmp >= 0)
-               glUniformMatrix4fv(tmp, 1, GL_FALSE, value_ptr(_model));
 }
 
-void Model::drawModel(Shader* _shader, Texture* _texture, const mat4& _model) const
+void Model::updateBB(const vec3& _min, const vec3& _max)
 {
-       //Message::info("Error from before?");
-       //Graphix::getGlError();
-       useModel(_shader);
-       //Message::info("Model loading Coordinates");
-       //Graphix::getGlError();
-       useTexture(_texture, _shader);
-       //Message::info("Model loading Texture");
-       //Graphix::getGlError();
-       useMMatrix(_model, _shader);
-       //Message::info("Model loading MMatrix");
-       //Graphix::getGlError();
-       glDrawElements(GL_TRIANGLES, numfaces * 3, GL_UNSIGNED_INT, 0);
-       //Message::info("Model drawing Elements");
-       //Graphix::getGlError();
-       glBindVertexArray(0);
-       //system("pause");
-}
-
-void Model::drawModel() const
-{
-       glDrawElements(GL_TRIANGLES, numfaces * 3, GL_UNSIGNED_INT, 0);
-       glBindVertexArray(0);
-}
-
-unsigned int Model::bindShader(Shader* _shader)
-{
-       //Message::info("bindShader");
-       //Graphix::getGlError();
-       //Message::info("Do Stuff");
-       uint vao;
-       glGenVertexArrays(1, &vao);
-       glBindVertexArray(vao);
-
-       //Message::info("bindVAO");
-       //Graphix::getGlError();
-
-       bindBuffer(vertexBuffer, _shader->getAttribLocation("aPosition"));
-       //Message::info("aPosition");
-       //Graphix::getGlError();
-       bindBuffer(uvBuffer, _shader->getAttribLocation("aUV"), 2);
-       //Message::info("aUV");
-       //Graphix::getGlError();
-       bindBuffer(normalBuffer, _shader->getAttribLocation("aNormal"));
-       //Message::info("aNormal");
-       //Graphix::getGlError();
-
-       glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, indexBuffer);
-       //Message::info("bindIndexBuffer");
-       //Graphix::getGlError();
-
-       glBindVertexArray(0);
-
-       glBindBuffer(GL_ARRAY_BUFFER, 0);
-       glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);
-
-       shader_map[*_shader] = vao;
-
-       //Message::info("cleanUp");
-       //Graphix::getGlError();
-       //Message::info("Done");
-
-       return vao;
-}
-
-void Model::genBuffer(uint &buffer, uint size, void* value)
-{
-       glGenBuffers(1, &buffer);
-       glBindBuffer(GL_ARRAY_BUFFER, buffer);
-       glBufferData(GL_ARRAY_BUFFER, size, value, GL_STATIC_DRAW);
-       glBindBuffer(GL_ARRAY_BUFFER, 0);
-}
-
-void Model::bindBuffer(const uint &buffer, const uint index, const uint dim)
-{
-       //Falls index nicht gefunden werden konnte
-       if (index == (uint)-1)
-       {
-               Message::info("Model: BindBuffer wird ausgelassen da index fehlerhaft ist.");
-               return;
-       }
-               
-       glBindBuffer(GL_ARRAY_BUFFER, buffer);
-       glEnableVertexAttribArray(index);
-       glVertexAttribPointer(index, dim, GL_FLOAT, GL_FALSE, 0, 0);
-       glBindBuffer(GL_ARRAY_BUFFER, 0);
-}
-
-
-bool Model::import(const string& path, uint& numvertices, uint& numfaces, float*& vertex, float*& uvs, float*& normals, uint*& index, uint mindex)
-{
-       Assimp::Importer importer;
-
-       const aiScene* scene = importer.ReadFile("../models/" + path, aiProcess_GenUVCoords | aiProcess_Triangulate | aiProcess_JoinIdenticalVertices | aiProcess_SortByPType);         //aiProcess_PreTransformVertices
-       if (!scene)
-       {
-               Message::error("The file " + path + " couldn't be read.\n" + importer.GetErrorString());
-               return false;
-       }
-
-       if (scene->HasMeshes() && scene->mNumMeshes > mindex)
-       {
-               import(scene->mMeshes[mindex], numvertices, numfaces, vertex, uvs, normals, index);
-       }
-       else
-       {
-               Message::error("The file " + path + " doesn't contain any nodes.");
-               return false;
-       }
-
-       return true;
-}
-
-bool Model::import(const aiMesh* mesh, uint& numvertices, uint& numfaces, float*& vertex, float*& uvs, float*& normals, uint*& index)
-{
-
-       numvertices = mesh->mNumVertices;
-       numfaces = mesh->mNumFaces;
-       vertex = new float[numvertices * 3];
-       uvs = new float[numvertices * 2];
-       index = new uint[numfaces * 3];
-       normals = new float[numvertices * 3];
-       //aiFace* faces = mesh->mFaces;
-
-
-       //load vertices from Mesh
-       for (uint i = 0; i < numvertices; i++)
-       {
-               vertex[3 * i] = mesh->mVertices[i].x;
-               vertex[3 * i + 1] = mesh->mVertices[i].y;
-               vertex[3 * i + 2] = mesh->mVertices[i].z;
-       }
-
-       //load UVs from Mesh
-       for (uint i = 0; i < numvertices; i++)
-       {
-               uvs[2 * i] = mesh->mTextureCoords[0][i].x;//[i]->x;
-               uvs[2 * i + 1] = mesh->mTextureCoords[0][i].y;//[i]->y;
-       }
-
-       //load indices from Mesh
-       for (uint i = 0; i < numfaces; i++)
-       {
-               index[3 * i] = mesh->mFaces[i].mIndices[0];
-               index[3 * i + 1] = mesh->mFaces[i].mIndices[1];
-               index[3 * i + 2] = mesh->mFaces[i].mIndices[2];
-       }
-
-       //load normals from Mesh
-       for (uint i = 0; i < numvertices; i++)
-       {
-               normals[3 * i] = mesh->mNormals[i].x;
-               normals[3 * i + 1] = mesh->mNormals[i].y;
-               normals[3 * i + 2] = mesh->mNormals[i].z;
-       }
-
-       return true;
+       BBsize = _max - _min;
+       BBposition = (_min + _max) / 2.f;
 }
index 778becb4f3d93be5c4562f25ddc27565d64e67e9..4772e5919cbbb55b7611b95ebb1303b94b794ffc 100644 (file)
@@ -1,54 +1,36 @@
 #pragma once
 
-#include <string>
-#include <unordered_map>
 #include "GLM.h"
-
-
-using std::string;
-using std::unordered_map;
-
-//VAO MAP
-typedef unordered_map<unsigned int, unsigned int> int2int_map;
+#include <unordered_map>
 
 class Shader;
 class Texture;
-struct aiMesh;
+
+typedef unsigned int uint;
 
 class Model
 {
 public:
-       __declspec(deprecated)
-       Model(const string& modelpath, unsigned int index=0);
-       Model(const aiMesh* mesh);
-       __declspec(deprecated)
-       Model(unsigned int numvertices, unsigned int numfaces, float *vertex, float *uvs, float *normals, unsigned int *index);
-
+       Model();
        virtual ~Model();
 
-//     void useModel(Shader* shader);
+       /* Binds Model to the Model*/
+       virtual void bindShader(Shader* shader);
 
-       void useModel(Shader* shader) const;
-       void useTexture(Texture* texture, Shader* shader) const;
-       void useMMatrix(const mat4& model,Shader* shader) const;
+       /* Draws Model */
+       virtual void drawModel(Shader* shader, Texture* texture, const mat4& modelMat) const;
 
-       __declspec(deprecated)
-       void drawModel() const;
-       void drawModel(Shader* _shader, Texture* texture, const mat4& model) const;
-       unsigned int bindShader(Shader* shader);
+       /* Draws a BoundingBox around the Model */
+       virtual void drawBBox() const;
 
-private:
-       unsigned int numvertices, numfaces;
-       unsigned int vertexBuffer, normalBuffer, uvBuffer, indexBuffer;
+protected:
 
-       int2int_map shader_map;
-       __declspec(deprecated)
-       bool import(const string& path, unsigned int& numvertices, unsigned int& numfaces, float*& vertex, float*& uvs, float*& normals, unsigned int*& index, unsigned int mindex = 0);
-       bool import(const aiMesh* mesh, unsigned int& numvertices, unsigned int& numfaces, float*& vertex, float*& uvs, float*& normals, unsigned int*& index);
+       std::unordered_map<uint, uint> shader_map;
 
-       void genBuffer(unsigned int &buffer, unsigned int size, void* value);
-       void bindBuffer(const unsigned int &buffer, const unsigned int index,const unsigned int dim = 3);
-       
+       void updateBB(const vec3& min, const vec3& max);
+
+private:
+       vec3 BBsize, BBposition;
 
 };
 
index f14cf3458860ee27bad33f020a2eaceae3fa2231..800ee0e38fcab30bb5e62ca71c3cecf3df1ce2f9 100644 (file)
@@ -20,7 +20,7 @@ using std::cout;
 using std::endl;
 
 SceneObject::SceneObject(Shader* _shader, mat4& _model, string _modelpath, string texturepath, unsigned int _model_index) :
-MetaModel(_modelpath),
+IMetaMesh(_modelpath),
 model(_model),
 shader(_shader),
 mainScene(NULL),
@@ -29,7 +29,7 @@ texture(nullptr)
 {
        //Message::info("Error from befor?");
        //Graphix::getGlError();
-       new MetaModel(_modelpath);
+       new IMetaMesh(_modelpath);
        //Message::info("Creating Model");
        //Graphix::getGlError();
        //modelID = _shader->getUniformLocation("model");
@@ -45,8 +45,8 @@ texture(nullptr)
 
 }
 
-//SceneObject::SceneObject(Shader* _shader, mat4& _model, Model* model_obj, string texturepath) :
-//Model(*model_obj),
+//SceneObject::SceneObject(Shader* _shader, mat4& _model, IMesh* model_obj, string texturepath) :
+//IMesh(*model_obj),
 //model(_model),
 //shader(_shader),
 //mainScene(NULL),
index 439c0dd96dcaeeaa289044340bc70b50b3533a43..f029bde52d1597bf20db143bdd67718db6ef53e3 100644 (file)
@@ -3,8 +3,8 @@
 #include "GLM.h"
 
 #include "Drawable.h"
-#include "Model.h"
-#include "MetaModel.h"
+#include "IMesh.h"
+#include "IMetaMesh.h"
 
 #include <string>
 
@@ -18,13 +18,13 @@ class Shader;
 
 class SceneObject :
        public Drawable,
-       public MetaModel
+       public IMetaMesh
 {
 public:
 
        //SceneObject(Shader* _shader, mat4& model);
        SceneObject(Shader* _shader, mat4& model, string modelpath, string texturepath, unsigned int model_index=0);
-       //SceneObject(Shader* _shader, mat4& model, Model* model_obj, string texturepath);
+       //SceneObject(Shader* _shader, mat4& model, IMesh* model_obj, string texturepath);
        virtual ~SceneObject();
 
        virtual void update(float);
index c8bc3f6319d8df877b7d1207051c5566391b44cb..c418fecad570a5543e8ec89003313036014f64a2 100644 (file)
     </Link>
   </ItemDefinitionGroup>
   <ItemGroup>
+    <ClCompile Include="Graphix\Model.cpp" />
     <ClCompile Include="Events.cpp" />
     <ClCompile Include="Fps.cpp" />
     <ClCompile Include="Game.cpp" />
     <ClCompile Include="Graphix\Drawable.cpp" />
     <ClCompile Include="Graphix\GLM.cpp" />
     <ClCompile Include="Graphix\Graphix.cpp" />
-    <ClCompile Include="Graphix\Model.cpp" />
+    <ClCompile Include="Graphix\IMesh.cpp" />
     <ClCompile Include="Graphix\Scene.cpp" />
     <ClCompile Include="Graphix\SceneObject.cpp" />
     <ClCompile Include="Graphix\Shader.cpp" />
     <ClCompile Include="Graphix\ViewPort.cpp" />
     <ClCompile Include="main.cpp" />
     <ClCompile Include="Message.cpp" />
-    <ClCompile Include="Graphix\MetaModel.cpp" />
+    <ClCompile Include="Graphix\IMetaMesh.cpp" />
   </ItemGroup>
   <ItemGroup>
     <ClInclude Include="Average.h" />
+    <ClInclude Include="Graphix\Model.h" />
     <ClInclude Include="Events.h" />
     <ClInclude Include="Fps.h" />
     <ClInclude Include="Game.h" />
     <ClInclude Include="Graphix\Drawable.h" />
     <ClInclude Include="Graphix\GLM.h" />
     <ClInclude Include="Graphix\Graphix.h" />
-    <ClInclude Include="Graphix\Model.h" />
+    <ClInclude Include="Graphix\IMesh.h" />
     <ClInclude Include="Graphix\Scene.h" />
     <ClInclude Include="Graphix\SceneObject.h" />
     <ClInclude Include="Graphix\Shader.h" />
     <ClInclude Include="Graphix\Texture.h" />
     <ClInclude Include="Graphix\ViewPort.h" />
     <ClInclude Include="Message.h" />
-    <ClInclude Include="Graphix\MetaModel.h" />
+    <ClInclude Include="Graphix\IMetaMesh.h" />
   </ItemGroup>
   <Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
   <ImportGroup Label="ExtensionTargets">
index 0aa0e2948f3413ecde77976ee33751bde7ca58bf..cc08f6838af1959c8154b163034dd639c8354bc2 100644 (file)
@@ -45,9 +45,6 @@
     <ClCompile Include="Graphix\ViewPort.cpp">
       <Filter>Source Files</Filter>
     </ClCompile>
-    <ClCompile Include="Graphix\Model.cpp">
-      <Filter>Source Files</Filter>
-    </ClCompile>
     <ClCompile Include="Game.cpp">
       <Filter>Source Files</Filter>
     </ClCompile>
     <ClCompile Include="Graphix\SceneObject.cpp">
       <Filter>Source Files</Filter>
     </ClCompile>
-    <ClCompile Include="Graphix\MetaModel.cpp">
+    <ClCompile Include="Graphix\IMesh.cpp">
+      <Filter>Source Files</Filter>
+    </ClCompile>
+    <ClCompile Include="Graphix\Model.cpp">
+      <Filter>Source Files</Filter>
+    </ClCompile>
+    <ClCompile Include="Graphix\IMetaMesh.cpp">
       <Filter>Source Files</Filter>
     </ClCompile>
   </ItemGroup>
@@ -92,9 +95,6 @@
     <ClInclude Include="Graphix\ViewPort.h">
       <Filter>Header Files</Filter>
     </ClInclude>
-    <ClInclude Include="Graphix\Model.h">
-      <Filter>Header Files</Filter>
-    </ClInclude>
     <ClInclude Include="Game.h">
       <Filter>Header Files</Filter>
     </ClInclude>
     <ClInclude Include="Graphix\SceneObject.h">
       <Filter>Header Files</Filter>
     </ClInclude>
-    <ClInclude Include="Graphix\MetaModel.h">
+    <ClInclude Include="Graphix\IMesh.h">
+      <Filter>Header Files</Filter>
+    </ClInclude>
+    <ClInclude Include="Graphix\Model.h">
+      <Filter>Header Files</Filter>
+    </ClInclude>
+    <ClInclude Include="Graphix\IMetaMesh.h">
       <Filter>Header Files</Filter>
     </ClInclude>
   </ItemGroup>
index 8198ee869bf04bee8c1818e230d8ca6b1b6778ca..4b4310372812bef1a5f0af7e32f8d11eec581573 100644 (file)
@@ -6,6 +6,6 @@ smooth in vec3 eyeDirection;
 out vec4 FragmentColor;
  
 void main(){
-       FragmentColor = texture(uColorTexture, eyeDirection);
-       //FragmentColor = vec4(eyeDirection, 0.5);
+       //FragmentColor = texture(uColorTexture, eyeDirection);
+       FragmentColor = vec4(eyeDirection, 0.5);
 }