]> git.leopard-lacewing.eu Git - cgue_weave.git/commitdiff
added Model SkyBox
authorPeter Schaefer <schaeferpm@gmail.com>
Wed, 22 Apr 2015 21:16:50 +0000 (23:16 +0200)
committerPeter Schaefer <schaeferpm@gmail.com>
Wed, 22 Apr 2015 21:16:50 +0000 (23:16 +0200)
bend SceneObject to accept Models inside Constructor
fixed Black Zones in Shader (+1 /2)
new MODEL SkyBox works (without Textures)

18 files changed:
Weave/Game.cpp
Weave/Game.h
Weave/Graphix/IMesh.cpp
Weave/Graphix/IMesh.h
Weave/Graphix/IMetaMesh.cpp
Weave/Graphix/IMetaMesh.h
Weave/Graphix/Model.cpp
Weave/Graphix/Model.h
Weave/Graphix/Scene.h
Weave/Graphix/SceneObject.cpp
Weave/Graphix/SceneObject.h
Weave/Graphix/Shader.cpp
Weave/Graphix/Shader.h
Weave/Graphix/SkyBox.cpp [new file with mode: 0644]
Weave/Graphix/SkyBox.h [new file with mode: 0644]
Weave/Weave.vcxproj
Weave/Weave.vcxproj.filters
shader/skybox_FS.hlsl

index b7352fc58e6c5c13f681b00513e54d8dedb5d521..657ceba7c0be32b852dce7b2818fac37133d9a63 100644 (file)
@@ -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
index ba641f0153df34445e182689fff4cb49e6ab15f5..9c8d778a37ecbfe2701946b8cc91d9d653e5e01f 100644 (file)
@@ -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;
 
 };
 
index 6d35577cc3e0a26bcaca441541182bf966fef7d3..3bd5fb95b2b98405a528a5e9b149e45f97d3795e 100644 (file)
 
 
 
-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
index 5ae07e2991fc558f72f37d5df42dc98302fb8ea9..c090379471ef903a003c8887f371b1ebbf737b90 100644 (file)
@@ -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;
 
        
 
index 251e3847fdff4f9ec146e4686ed35cf522a6f487..811c5ab2a7f6178626d9a8882c1bdc32cce37a80 100644 (file)
@@ -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()
index 6c0b7d2f913cc767cea5600ae73a64afe42bd66f..c88e4eb0622a10d5d2b5562535d0fa86eda20e05 100644 (file)
@@ -12,7 +12,7 @@ class IMesh;
 class Shader;
 class Texture;
 
-class IMetaMesh : Model
+class IMetaMesh : public Model
 {
 public:
        IMetaMesh(const string& modelpath);
index f797d4721c4abe08e3bbd2566e14bb1ce62d58c2..05b13b59f49f84aac3bed7fd9b7779da4be476d2 100644 (file)
@@ -1,9 +1,20 @@
 #include "Model.h"
 
 #include <GL/glew.h>
+#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));
+}
index 4772e5919cbbb55b7611b95ebb1303b94b794ffc..8d8292700137f32cb0f108f1db03115d33f9a9ad 100644 (file)
@@ -24,11 +24,20 @@ public:
        virtual void drawBBox() const;
 
 protected:
+       uint numvertices, numfaces;
+       uint vertexBuffer, indexBuffer, normalBuffer, uvBuffer;
 
        std::unordered_map<uint, uint> 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;
 
index 0d623c6c33b1a4784e0a3e6d23f78e374456570f..20a0c5ea31624ec46732058b929b8a52c9d9a8c8 100644 (file)
@@ -40,6 +40,7 @@ protected:
        
        SceneObject* lookat;
 
+
        bool newObjects;
        SceneList* SceneObjects;
        set<Shader*>* ShaderSet;
index 800ee0e38fcab30bb5e62ca71c3cecf3df1ce2f9..e74437e15f6f7798f66805dbeb20128f0b8d099d 100644 (file)
@@ -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);
 //}
 //
 
index f029bde52d1597bf20db143bdd67718db6ef53e3..e5e635a7b42a8046565ca3322132a7bd6866ecb2 100644 (file)
@@ -3,8 +3,6 @@
 #include "GLM.h"
 
 #include "Drawable.h"
-#include "IMesh.h"
-#include "IMetaMesh.h"
 
 #include <string>
 
@@ -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;
+
 };
 
index 6caf78902c93771b3a7545d88bf152e79c1f67e2..d8a57238b4726ecf1d703efa42a36664ba46dc4c 100644 (file)
@@ -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)
index 3c580302c0adcf1a945316b414d540177322f5ef..027281aff7d851eeaa49122be3495b3e18816c29 100644 (file)
@@ -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 (file)
index 0000000..8e85a03
--- /dev/null
@@ -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 (file)
index 0000000..d6f6963
--- /dev/null
@@ -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;
+
+};
+
index c418fecad570a5543e8ec89003313036014f64a2..d21a26d5fe1b2cf5b0bafc69fb7091e3449766da 100644 (file)
     <ClCompile Include="Graphix\Scene.cpp" />
     <ClCompile Include="Graphix\SceneObject.cpp" />
     <ClCompile Include="Graphix\Shader.cpp" />
+    <ClCompile Include="Graphix\SkyBox.cpp" />
     <ClCompile Include="Graphix\Texture.cpp" />
     <ClCompile Include="Graphix\ViewPort.cpp" />
     <ClCompile Include="main.cpp" />
     <ClInclude Include="Graphix\Scene.h" />
     <ClInclude Include="Graphix\SceneObject.h" />
     <ClInclude Include="Graphix\Shader.h" />
+    <ClInclude Include="Graphix\SkyBox.h" />
     <ClInclude Include="Graphix\Texture.h" />
     <ClInclude Include="Graphix\ViewPort.h" />
     <ClInclude Include="Message.h" />
index cc08f6838af1959c8154b163034dd639c8354bc2..4820f10a8ed1566b4400b1b3823139ad03eaa158 100644 (file)
@@ -63,6 +63,9 @@
     <ClCompile Include="Graphix\IMetaMesh.cpp">
       <Filter>Source Files</Filter>
     </ClCompile>
+    <ClCompile Include="Graphix\SkyBox.cpp">
+      <Filter>Source Files</Filter>
+    </ClCompile>
   </ItemGroup>
   <ItemGroup>
     <ClInclude Include="Fps.h">
     <ClInclude Include="Graphix\IMetaMesh.h">
       <Filter>Header Files</Filter>
     </ClInclude>
+    <ClInclude Include="Graphix\SkyBox.h">
+      <Filter>Header Files</Filter>
+    </ClInclude>
   </ItemGroup>
 </Project>
\ No newline at end of file
index 4b4310372812bef1a5f0af7e32f8d11eec581573..18675d3d27383dca8cd524380e8f11efc83a66ad 100644 (file)
@@ -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);
 }