From 90145f722ca92e67cb589d707a12e808775b5306 Mon Sep 17 00:00:00 2001 From: Peter Schaefer Date: Wed, 22 Apr 2015 23:16:50 +0200 Subject: [PATCH] added Model SkyBox bend SceneObject to accept Models inside Constructor fixed Black Zones in Shader (+1 /2) new MODEL SkyBox works (without Textures) --- Weave/Game.cpp | 20 ++-- Weave/Game.h | 8 +- Weave/Graphix/IMesh.cpp | 167 ++++------------------------------ Weave/Graphix/IMesh.h | 15 +-- Weave/Graphix/IMetaMesh.cpp | 2 - Weave/Graphix/IMetaMesh.h | 2 +- Weave/Graphix/Model.cpp | 130 +++++++++++++++++++++++++- Weave/Graphix/Model.h | 9 ++ Weave/Graphix/Scene.h | 1 + Weave/Graphix/SceneObject.cpp | 81 +++++++++++------ Weave/Graphix/SceneObject.h | 13 ++- Weave/Graphix/Shader.cpp | 4 +- Weave/Graphix/Shader.h | 16 ++-- Weave/Graphix/SkyBox.cpp | 39 ++++++++ Weave/Graphix/SkyBox.h | 17 ++++ Weave/Weave.vcxproj | 2 + Weave/Weave.vcxproj.filters | 6 ++ shader/skybox_FS.hlsl | 2 +- 18 files changed, 311 insertions(+), 223 deletions(-) create mode 100644 Weave/Graphix/SkyBox.cpp create mode 100644 Weave/Graphix/SkyBox.h diff --git a/Weave/Game.cpp b/Weave/Game.cpp index b7352fc..657ceba 100644 --- a/Weave/Game.cpp +++ b/Weave/Game.cpp @@ -18,6 +18,8 @@ #include "Fps.h" #include "Events.h" +#include "Graphix\SkyBox.h" + #include "Graphix\Model.h" #include "Message.h" @@ -47,20 +49,10 @@ Game::Game() : playing(true) 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"); - //Message::info("Creating SkyBox Shader"); - //Graphix::getGlError(); - 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"); - - //tmp_Scene->addObject(new SceneObject(shader1, rotate((float)M_PI_2,vec3(1.f,0.f,0.f)), "SkyBox.dae", "skybox.jpg")); - - //tmp_Scene->addObject(SkyBox); + shader_skybox = new Shader("skybox_VS.hlsl", "skybox_FS.hlsl"); + //texture_skybox = new Texture("skybox_CUBE.jpg"); + + tmp_Scene->addObject(new SceneObject(shader_skybox, scale(3.f * vec3(1.f, .3f, 1.f)), new SkyBox(), "skybox_CUBE.jpg")); //SKYBOX! ---------------------------- //Allg Shader diff --git a/Weave/Game.h b/Weave/Game.h index ba641f0..9c8d778 100644 --- a/Weave/Game.h +++ b/Weave/Game.h @@ -10,6 +10,9 @@ using std::map; +#include "Graphix\Shader.h" +#include "Graphix\Texture.h" +#include "Graphix\Model.h" class Game { @@ -37,8 +40,9 @@ private: void draw() const; //bool import(const string &path, Scene *scene, Shader* shader); - Shader* skybox; - SceneObject* SkyBox; + Shader* shader_skybox; + Texture* texture_skybox; + Model* model_skybox; }; diff --git a/Weave/Graphix/IMesh.cpp b/Weave/Graphix/IMesh.cpp index 6d35577..3bd5fb9 100644 --- a/Weave/Graphix/IMesh.cpp +++ b/Weave/Graphix/IMesh.cpp @@ -13,38 +13,24 @@ -IMesh::IMesh(const string& _modelpath, uint _mindex) : -numfaces(-1), -numvertices(-1), -vertexBuffer(-1), -normalBuffer(-1), -uvBuffer(-1), -indexBuffer(-1) +IMesh::IMesh(const string& _modelpath, uint _mindex) { float *vertex = nullptr, *normals = nullptr, *uvs = nullptr; uint *index = nullptr; - aiMesh* mesh = import(_modelpath, _mindex); - - import(mesh, numvertices, numfaces, vertex, uvs, normals, index); + 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, mesh; + delete vertex, normals, uvs, index; } -IMesh::IMesh(const aiMesh* _mesh) : -numfaces(-1), -numvertices(-1), -vertexBuffer(-1), -normalBuffer(-1), -uvBuffer(-1), -indexBuffer(-1) +IMesh::IMesh(const aiMesh* _mesh) { float *vertex = nullptr, *normals = nullptr, *uvs = nullptr; @@ -65,146 +51,25 @@ indexBuffer(-1) IMesh::~IMesh() { glDeleteBuffers(1, &vertexBuffer); + glDeleteBuffers(1, &indexBuffer); glDeleteBuffers(1, &normalBuffer); glDeleteBuffers(1, &uvBuffer); - glDeleteBuffers(1, &indexBuffer); - } -//void IMesh::useModel(Shader* _shader) + + +//void IMesh::drawModel(Shader* _shader, Texture* _texture, const mat4& _modelMat) const //{ -// 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); -} +//void IMesh::bindShader(Shader* _shader) +//{ +// +//} -aiMesh* IMesh::import(const string& _modelpath, uint _mindex) const +bool IMesh::import(const string& _modelpath, uint& numvertices, uint& numfaces, float*& vertex, float*& uvs, float*& normals, uint*& index, uint _mindex) const { Assimp::Importer importer; @@ -212,16 +77,16 @@ aiMesh* IMesh::import(const string& _modelpath, uint _mindex) const if (!scene) { Message::error("The file " + _modelpath + " couldn't be read.\n" + importer.GetErrorString()); - return nullptr; + return false; } if (!scene->HasMeshes() || scene->mNumMeshes <= _mindex) { Message::error("The file " + _modelpath + " doesn't contain any nodes."); - return nullptr; + return false; } - return scene->mMeshes[_mindex]; + return import(scene->mMeshes[_mindex], numvertices, numfaces, vertex, uvs, normals, index); } bool IMesh::import(const aiMesh* mesh, uint& numvertices, uint& numfaces, float*& vertex, float*& uvs, float*& normals, uint*& index) const diff --git a/Weave/Graphix/IMesh.h b/Weave/Graphix/IMesh.h index 5ae07e2..c090379 100644 --- a/Weave/Graphix/IMesh.h +++ b/Weave/Graphix/IMesh.h @@ -11,7 +11,7 @@ class Shader; class Texture; struct aiMesh; -class IMesh : Model +class IMesh : public Model { public: IMesh(const string& modelpath, uint index=0); @@ -19,24 +19,17 @@ public: virtual ~IMesh(); - void drawModel(Shader* shader, Texture* texture, const mat4& modelMat) const; + //void drawModel(Shader* shader, Texture* texture, const mat4& modelMat) const; - void bindShader(Shader* shader); + //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 string& modelpath, uint& numvertices, uint& numfaces, float*& vertex, float*& uvs, float*& normals, uint*& index , 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 index 251e384..811c5ab 100644 --- a/Weave/Graphix/IMetaMesh.cpp +++ b/Weave/Graphix/IMetaMesh.cpp @@ -22,7 +22,6 @@ IMetaMesh::IMetaMesh(const string& _modelpath) 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])); @@ -35,7 +34,6 @@ IMetaMesh::IMetaMesh(const string& _modelpath) return; } - } IMetaMesh::~IMetaMesh() diff --git a/Weave/Graphix/IMetaMesh.h b/Weave/Graphix/IMetaMesh.h index 6c0b7d2..c88e4eb 100644 --- a/Weave/Graphix/IMetaMesh.h +++ b/Weave/Graphix/IMetaMesh.h @@ -12,7 +12,7 @@ class IMesh; class Shader; class Texture; -class IMetaMesh : Model +class IMetaMesh : public Model { public: IMetaMesh(const string& modelpath); diff --git a/Weave/Graphix/Model.cpp b/Weave/Graphix/Model.cpp index f797d47..05b13b5 100644 --- a/Weave/Graphix/Model.cpp +++ b/Weave/Graphix/Model.cpp @@ -1,9 +1,20 @@ #include "Model.h" #include +#include "../Message.h" +#include "Shader.h" +#include "Texture.h" -Model::Model() +#include "Graphix.h" + +Model::Model() : + numfaces(0), + numvertices(0), + vertexBuffer(-1), + normalBuffer(-1), + uvBuffer(-1), + indexBuffer(-1) { } @@ -17,10 +28,69 @@ Model::~Model() void Model::bindShader(Shader* _shader) { + //Message::info("bindShader"); + //Graphix::getGlError(); + //Message::info("Do Stuff"); + + if (indexBuffer == (uint)-1) + { + Message::error("Model: IndexBuffer wurde nicht geladen."); + return; + } + + uint vao; + glGenVertexArrays(1, &vao); + glBindVertexArray(vao); + + //Message::info("bindVAO"); + //Graphix::getGlError(); + if (vertexBuffer != (uint)-1) + bindBuffer(vertexBuffer, _shader->getAttribLocation("aPosition")); + //Message::info("aPosition"); + //Graphix::getGlError(); + if (uvBuffer != (uint)-1) + bindBuffer(uvBuffer, _shader->getAttribLocation("aUV"), 2); + //Message::info("aUV"); + //Graphix::getGlError(); + if (normalBuffer != (uint)-1) + 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 Model::drawModel(Shader* _shader, Texture* _texture, const mat4& _modelMat) 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(_modelMat, _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 Model::drawBBox() const @@ -32,3 +102,61 @@ void Model::updateBB(const vec3& _min, const vec3& _max) BBsize = _max - _min; BBposition = (_min + _max) / 2.f; } + +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); +} + +void Model::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 Model.\n"); + else + vao = i->second; + + glBindVertexArray(vao); + +} + +void Model::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 Model::useModelMat(const mat4& _model, Shader* _shader) const +{ + int tmp = _shader->getUniformLocation("uModel"); + if (tmp >= 0) + glUniformMatrix4fv(tmp, 1, GL_FALSE, value_ptr(_model)); +} diff --git a/Weave/Graphix/Model.h b/Weave/Graphix/Model.h index 4772e59..8d82927 100644 --- a/Weave/Graphix/Model.h +++ b/Weave/Graphix/Model.h @@ -24,11 +24,20 @@ public: virtual void drawBBox() const; protected: + uint numvertices, numfaces; + uint vertexBuffer, indexBuffer, normalBuffer, uvBuffer; std::unordered_map shader_map; void updateBB(const vec3& min, const vec3& max); + void genBuffer(uint &buffer, uint size, void* value); + void bindBuffer(const uint &buffer, const uint index, const uint dim = 3); + + virtual void useModel(Shader* shader) const; + virtual void useTexture(Texture* texture, Shader* shader) const; + virtual void useModelMat(const mat4& model, Shader* shader) const; + private: vec3 BBsize, BBposition; diff --git a/Weave/Graphix/Scene.h b/Weave/Graphix/Scene.h index 0d623c6..20a0c5e 100644 --- a/Weave/Graphix/Scene.h +++ b/Weave/Graphix/Scene.h @@ -40,6 +40,7 @@ protected: SceneObject* lookat; + bool newObjects; SceneList* SceneObjects; set* ShaderSet; diff --git a/Weave/Graphix/SceneObject.cpp b/Weave/Graphix/SceneObject.cpp index 800ee0e..e74437e 100644 --- a/Weave/Graphix/SceneObject.cpp +++ b/Weave/Graphix/SceneObject.cpp @@ -12,6 +12,9 @@ #include "Scene.h" #include "Texture.h" +#include "IMesh.h" +#include "IMetaMesh.h" + #include "Graphix.h" using std::string; @@ -19,9 +22,9 @@ using std::string; using std::cout; using std::endl; -SceneObject::SceneObject(Shader* _shader, mat4& _model, string _modelpath, string texturepath, unsigned int _model_index) : -IMetaMesh(_modelpath), -model(_model), +SceneObject::SceneObject(Shader* _shader, mat4& _modelMat, string _modelpath, string texturepath, unsigned int _model_index) : +model(new IMetaMesh(_modelpath)), +modelMat(_modelMat), shader(_shader), mainScene(NULL), collision_ignore(false), @@ -29,31 +32,57 @@ texture(nullptr) { //Message::info("Error from befor?"); //Graphix::getGlError(); - new IMetaMesh(_modelpath); - //Message::info("Creating Model"); +// new IMetaMesh(_modelpath); + //Message::info("Creating modelMat"); //Graphix::getGlError(); - //modelID = _shader->getUniformLocation("model"); + //modelID = _shader->getUniformLocation("modelMat"); if (texturepath!="") texture = new Texture(texturepath); //Message::info("Creating SkyBox Shader"); //Graphix::getGlError(); - bindShader(shader); + model->bindShader(shader); + //Message::info("Binding Shader"); + //Graphix::getGlError(); + //Message::info("Done"); + +} + +SceneObject::SceneObject(Shader* _shader, mat4& _modelMat, Model* _model, string texturepath) : +model(_model), +modelMat(_modelMat), +shader(_shader), +mainScene(NULL), +collision_ignore(false), +texture(nullptr) +{ + //Message::info("Error from befor?"); + //Graphix::getGlError(); + // new IMetaMesh(_modelpath); + //Message::info("Creating modelMat"); + //Graphix::getGlError(); + //modelID = _shader->getUniformLocation("modelMat"); + if (texturepath != "") + texture = new Texture(texturepath); + //Message::info("Creating SkyBox Shader"); + //Graphix::getGlError(); + + model->bindShader(shader); //Message::info("Binding Shader"); //Graphix::getGlError(); //Message::info("Done"); } -//SceneObject::SceneObject(Shader* _shader, mat4& _model, IMesh* model_obj, string texturepath) : +//SceneObject::SceneObject(Shader* _shader, mat4& _modelMat, IMesh* model_obj, string texturepath) : //IMesh(*model_obj), -//model(_model), +//modelMat(_modelMat), //shader(_shader), //mainScene(NULL), //collision_ignore(false), //texture(nullptr) //{ -// modelID = _shader->getUniformLocation("model"); +// modelID = _shader->getUniformLocation("modelMat"); // if (texturepath != "") // texture = new Texture(texturepath); // @@ -71,8 +100,8 @@ void SceneObject::update(float deltaT) - //model = scale(model, vec3(matter)); - //model = (deltaT * spin) * model; //TODO drehen scheint nicht zu funktionieren + //modelMat = scale(modelMat, vec3(matter)); + //modelMat = (deltaT * spin) * modelMat; //TODO drehen scheint nicht zu funktionieren } @@ -82,13 +111,13 @@ void SceneObject::draw() const // useTexture(texture, shader); -// useMMatrix(model,shader); +// useMMatrix(modelMat,shader); // glUniform1i(shader->getUniformLocation ("inv"), 1); // drawModel(); - drawModel(shader, texture, model); + model->drawModel(shader, texture, modelMat); } void SceneObject::collisions(SceneObject* _other) @@ -99,36 +128,36 @@ void SceneObject::collisions(SceneObject* _other) } vec3 SceneObject::getPosition() const{ - return vec3(model[3]); + return vec3(modelMat[3]); } -void SceneObject::setModel(mat4& _model){ - model = _model; +void SceneObject::setModel(mat4& _modelMat){ + modelMat = _modelMat; } void SceneObject::turn(float angle, vec3& axis){ //vec3 pos = getPosition(); - //model = rotate(degree, axis)*model; - //model = model*translate(pos - getPosition()); - model = model * rotate(angle, axis); + //modelMat = rotate(degree, axis)*modelMat; + //modelMat = modelMat*translate(pos - getPosition()); + modelMat = modelMat * rotate(angle, axis); } void SceneObject::turnTo(vec3& direction, float speed){ vec3 pos = getPosition(); float perc = 1; - model = translate(-pos) * model; - float rot_angle = orientedAngle(normalize((vec3)(model * vec4(0.f, 0.f, 1.f, 1.f))), direction, vec3(0.f, 1.f, 0.f)); + modelMat = translate(-pos) * modelMat; + float rot_angle = orientedAngle(normalize((vec3)(modelMat * vec4(0.f, 0.f, 1.f, 1.f))), direction, vec3(0.f, 1.f, 0.f)); if (abs(rot_angle) / M_PI > speed) perc = speed / abs(rot_angle) * M_PI; - model = rotate(rot_angle *perc , vec3(0.f, 1.f, 0.f)) * model; - model = translate(pos) * model; + modelMat = rotate(rot_angle *perc , vec3(0.f, 1.f, 0.f)) * modelMat; + modelMat = translate(pos) * modelMat; } void SceneObject::move(vec3& dist){ - model = translate(dist) * model; + modelMat = translate(dist) * modelMat; } @@ -147,7 +176,7 @@ void SceneObject::setCollision(bool _col) //SceneObject* SceneObject::copy() //{ -// return new SceneObject(shader, model, modelpath, *texture); +// return new SceneObject(shader, modelMat, modelpath, *texture); //} // diff --git a/Weave/Graphix/SceneObject.h b/Weave/Graphix/SceneObject.h index f029bde..e5e635a 100644 --- a/Weave/Graphix/SceneObject.h +++ b/Weave/Graphix/SceneObject.h @@ -3,8 +3,6 @@ #include "GLM.h" #include "Drawable.h" -#include "IMesh.h" -#include "IMetaMesh.h" #include @@ -13,17 +11,20 @@ using std::string; class Scene; class Texture; class Shader; +class Model; //class string; class SceneObject : - public Drawable, - public IMetaMesh + public Drawable { public: //SceneObject(Shader* _shader, mat4& model); SceneObject(Shader* _shader, mat4& model, string modelpath, string texturepath, unsigned int model_index=0); + + SceneObject(Shader* _shader, mat4& modelMat, Model* model, string texturepath); + //SceneObject(Shader* _shader, mat4& model, IMesh* model_obj, string texturepath); virtual ~SceneObject(); @@ -58,7 +59,7 @@ protected: void setMatter(float); - mat4 model; + mat4 modelMat; //__declspec(deprecated) //unsigned int modelID; @@ -70,5 +71,7 @@ protected: Texture* texture; + Model* model; + }; diff --git a/Weave/Graphix/Shader.cpp b/Weave/Graphix/Shader.cpp index 6caf789..d8a5723 100644 --- a/Weave/Graphix/Shader.cpp +++ b/Weave/Graphix/Shader.cpp @@ -30,7 +30,7 @@ void Shader::useShader() const glUseProgram(handle); } -GLuint Shader::getAttribLocation(const string& name) const +int Shader::getAttribLocation(const string& name) const { int ind = glGetAttribLocation(handle, name.c_str()); if (ind < 0) @@ -39,7 +39,7 @@ GLuint Shader::getAttribLocation(const string& name) const return ind; } -GLuint Shader::getUniformLocation(const string& name) const +int Shader::getUniformLocation(const string& name) const { int ind = glGetUniformLocation(handle, name.c_str()); if (ind < 0) diff --git a/Weave/Graphix/Shader.h b/Weave/Graphix/Shader.h index 3c58030..027281a 100644 --- a/Weave/Graphix/Shader.h +++ b/Weave/Graphix/Shader.h @@ -5,6 +5,8 @@ using std::string; +typedef unsigned int uint; + class Shader { public: @@ -13,16 +15,16 @@ public: void useShader() const; - unsigned int getAttribLocation(const string& name) const; - unsigned int getUniformLocation(const string& name) const; - unsigned int getHandle() const; - operator unsigned int() const; + int getAttribLocation(const string& name) const; + int getUniformLocation(const string& name) const; + uint getHandle() const; + operator uint() const; private: - unsigned int handle; + uint handle; - unsigned int loadShader(string& _shaderPath); - unsigned int loadProgram(unsigned int _shader1, unsigned int _shader2); + uint loadShader(string& _shaderPath); + uint loadProgram(uint _shader1, uint _shader2); diff --git a/Weave/Graphix/SkyBox.cpp b/Weave/Graphix/SkyBox.cpp new file mode 100644 index 0000000..8e85a03 --- /dev/null +++ b/Weave/Graphix/SkyBox.cpp @@ -0,0 +1,39 @@ +#include "SkyBox.h" + +#include "GL/glew.h" +#include "Graphix.h" + + +SkyBox::SkyBox() +{ + numvertices = 4; + numfaces = 2; + + float vertex[] { -1.f, - 1.f, 0.f, 1.f, - 1.f, 0.f, - 1.f, 1.f, 0.f, 1.f, 1.f, 0.f }; + uint index[] { 1,3,2,0,1,2}; + + //import("skybox.dae", numvertices, numfaces, vertex, uvs, normals, index, 0); + + genBuffer(vertexBuffer, numvertices * 3 * sizeof(float), (void*)vertex); + genBuffer(indexBuffer, numfaces * 3 * sizeof(uint), (void*)index); + +// delete vertex, index; +} + + +SkyBox::~SkyBox() +{ +} + +void SkyBox::drawModel(Shader* _shader, Texture* _texture, const mat4& _modelMat) const +{ + glDisable(GL_DEPTH_TEST); + Model::drawModel(_shader, _texture, _modelMat); + glEnable(GL_DEPTH_TEST); +} + +void SkyBox::useModelMat(const mat4& model, Shader* shader) const +{ + +} + diff --git a/Weave/Graphix/SkyBox.h b/Weave/Graphix/SkyBox.h new file mode 100644 index 0000000..d6f6963 --- /dev/null +++ b/Weave/Graphix/SkyBox.h @@ -0,0 +1,17 @@ +#pragma once + +#include "Model.h" + +class SkyBox : + public Model +{ +public: + SkyBox(); + ~SkyBox(); + + void drawModel(Shader* shader, Texture* texture, const mat4& modelMat) const; + + void useModelMat(const mat4& model, Shader* shader) const; + +}; + diff --git a/Weave/Weave.vcxproj b/Weave/Weave.vcxproj index c418fec..d21a26d 100644 --- a/Weave/Weave.vcxproj +++ b/Weave/Weave.vcxproj @@ -103,6 +103,7 @@ + @@ -122,6 +123,7 @@ + diff --git a/Weave/Weave.vcxproj.filters b/Weave/Weave.vcxproj.filters index cc08f68..4820f10 100644 --- a/Weave/Weave.vcxproj.filters +++ b/Weave/Weave.vcxproj.filters @@ -63,6 +63,9 @@ Source Files + + Source Files + @@ -113,5 +116,8 @@ Header Files + + Header Files + \ No newline at end of file diff --git a/shader/skybox_FS.hlsl b/shader/skybox_FS.hlsl index 4b43103..18675d3 100644 --- a/shader/skybox_FS.hlsl +++ b/shader/skybox_FS.hlsl @@ -7,5 +7,5 @@ out vec4 FragmentColor; void main(){ //FragmentColor = texture(uColorTexture, eyeDirection); - FragmentColor = vec4(eyeDirection, 0.5); + FragmentColor = vec4((eyeDirection+vec3(2.f))/4, 0.5); } -- 2.47.3