From 9308b50a801d4464081322f8f0a8e0290e39f743 Mon Sep 17 00:00:00 2001 From: Peter Schaefer Date: Fri, 3 Apr 2015 19:47:19 +0200 Subject: [PATCH] Duck is drawn --- Weave/Game.cpp | 58 ++++++++-------- Weave/Graphix/Graphix.cpp | 2 +- Weave/Graphix/Model.cpp | 122 ++++++++++++++++------------------ Weave/Graphix/Scene.cpp | 2 +- Weave/Graphix/SceneObject.cpp | 7 +- Weave/Graphix/SceneObject.h | 2 + Weave/Graphix/Texture.cpp | 2 +- Weave/main.cpp | 2 +- 8 files changed, 99 insertions(+), 98 deletions(-) diff --git a/Weave/Game.cpp b/Weave/Game.cpp index 845e115..4199dd3 100644 --- a/Weave/Game.cpp +++ b/Weave/Game.cpp @@ -33,14 +33,14 @@ Game::Game() : playing(true) { srand((int)time(NULL)); // Hauptfenster - Scene* tmp_Scene = new Scene(0, 0, Graphix::getWindowWidth(), Graphix::getWindowHeight(), 60, 0.1f, 100, vec3(0.0f, 0.0f, -4.0f)); + Scene* tmp_Scene = new Scene(0, 0, Graphix::getWindowWidth(), Graphix::getWindowHeight(), 60, 0.1f, 100, vec3(0.0f, 0.0f, -3.0f)); layer[0] = tmp_Scene; //Allg Shader Shader* shader1 = new Shader("basicTexture_VS.hlsl", "lightingTexture_FS.hlsl"); //Player - SceneObject* tmp_playerObject = new SceneObject(shader1, glm::mat4(1.0f), "sphere/sphere.dae", "simple_trans.png"); + SceneObject* tmp_playerObject = new SceneObject(shader1, glm::mat4(1.0f), "duck.dae", "model_duck.png"); //tmp_playerObject->setIntelligenz(new PlayerI(tmp_playerObject)); tmp_Scene->addObject(tmp_playerObject); @@ -48,33 +48,33 @@ Game::Game() : playing(true) //player1 = Player(tmp_playerObject); // World - SceneObject* tmp_world = new SceneObject(shader1, scale(vec3(15.f)), "sphere/sphere.dae", "sky_withstars.png",1.f,1.f,1.f,vec3(0.f)); - tmp_world->setCollision(false); - - SceneObject::setTextureDanger("enemy.png"); - SceneObject::setTextureSave("enemy_save.png"); - - tmp_Scene->addObject(tmp_world); - - int size = 5; - int steps = 10; - - vec3 pos; - - SceneObject* tmp_enemy; - for (auto i = 0; i < 10;++i) - { - pos = vec3(((float)(rand() % (size*steps * 2)) / steps - size), ((float)(rand() % (size*steps * 2)) / steps - size), ((float)(rand() % (size*steps * 2)) / steps - size)); - if (VektorAbs(pos) < 2) - { - --i; - continue; - } - tmp_enemy = new SceneObject(shader1, translate(pos), "sphere/sphere.dae", "", (float)(rand() % 10 + 2) / 10.f); - tmp_enemy->setEnemy(true); - tmp_Scene->addObject(tmp_enemy); - //cout << ((float)(rand() % (size*steps * 2)) / steps - size) << ((float)(rand() % (size*steps * 2)) / steps - size) << ((float)(rand() % (size*steps * 2)) / steps - size) << endl; - } + //SceneObject* tmp_world = new SceneObject(shader1, scale(vec3(15.f)), "sphere/sphere.dae", "sky_withstars.png",1.f,1.f,1.f,vec3(0.f)); + //tmp_world->setCollision(false); + + //SceneObject::setTextureDanger("model_cow.jpg"); + //SceneObject::setTextureSave("model_cow.jpg"); + + //tmp_Scene->addObject(tmp_world); + + //int size = 5; + //int steps = 10; + + //vec3 pos; + + //SceneObject* tmp_enemy; + //for (auto i = 0; i < 10;++i) + //{ + // pos = vec3(((float)(rand() % (size*steps * 2)) / steps - size), ((float)(rand() % (size*steps * 2)) / steps - size), ((float)(rand() % (size*steps * 2)) / steps - size)); + // if (VektorAbs(pos) < 2) + // { + // --i; + // continue; + // } + // tmp_enemy = new SceneObject(shader1, translate(pos), "cow/cow.dae", "", (float)(rand() % 10 + 2) / 10.f); + // tmp_enemy->setEnemy(true); + // tmp_Scene->addObject(tmp_enemy); + // //cout << ((float)(rand() % (size*steps * 2)) / steps - size) << ((float)(rand() % (size*steps * 2)) / steps - size) << ((float)(rand() % (size*steps * 2)) / steps - size) << endl; + //} //ein Gegner //tmp_Scene->addObject(new SceneObject(shader1, translate(vec3(1.f, -2.f, 2.f)), "../models/sphere/sphere.dae", "../Textures/game_box.png")); //tmp_Scene->addObject(new SceneObject(shader1, translate(vec3(-1.f, 2.f, -2.f)), "../models/box/box.dae", "../Textures/sky_withstars.png")); diff --git a/Weave/Graphix/Graphix.cpp b/Weave/Graphix/Graphix.cpp index b62781a..1c3c149 100644 --- a/Weave/Graphix/Graphix.cpp +++ b/Weave/Graphix/Graphix.cpp @@ -86,7 +86,7 @@ void Graphix::freeMouse() void Graphix::clear() { - glClearColor(0, 0, 0.3f, 1); + glClearColor(0.9f, 0.9f, 1.0f, 1); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); } diff --git a/Weave/Graphix/Model.cpp b/Weave/Graphix/Model.cpp index d75258e..5e97749 100644 --- a/Weave/Graphix/Model.cpp +++ b/Weave/Graphix/Model.cpp @@ -115,10 +115,10 @@ void Model::genBuffer(uint &buffer, uint size, void* value) void Model::bindBuffer(const uint &buffer,const uint index,const uint dim) { - glBindBuffer(GL_ARRAY_BUFFER, buffer); - glEnableVertexAttribArray(index); - glVertexAttribPointer(index, dim, GL_FLOAT, GL_FALSE, 0, 0); - glBindBuffer(GL_ARRAY_BUFFER, 0); + glBindBuffer(GL_ARRAY_BUFFER, buffer); + glEnableVertexAttribArray(index); + glVertexAttribPointer(index, dim, GL_FLOAT, GL_FALSE, 0, 0); + glBindBuffer(GL_ARRAY_BUFFER, 0); } @@ -127,66 +127,60 @@ bool Model::import(const string& path,uint& numvertices, uint& numfaces, float*& { Assimp::Importer importer; - //const aiScene* scene = importer.ReadFile(path, aiProcess_GenUVCoords | aiProcess_Triangulate | aiProcess_JoinIdenticalVertices | aiProcess_SortByPType); - //if (!scene) - //{ - // Message::error("The file " + path + " couldn't be read.\n" + importer.GetErrorString()); - //} - - //if (scene->HasMeshes()) - //{ - // //aiMesh* mesh = scene->mMeshes[0]; - // 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 file - // 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 file - // 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 file - // 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]; - // } - - // //TODO SHOULD BE IVERTED - // //load normals from file - - - // 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; - // } - - //} - //else - //{ - // Message::error("The file " + path + " doesn't contain any nodes."); - //} + const aiScene* scene = importer.ReadFile("../models/" + path, aiProcess_GenUVCoords | aiProcess_Triangulate | aiProcess_JoinIdenticalVertices | aiProcess_SortByPType); + if (!scene) + { + Message::error("The file " + path + " couldn't be read.\n" + importer.GetErrorString()); + } + + if (scene->HasMeshes()) + { + aiMesh* mesh = scene->mMeshes[0]; + 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 file + 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 file + 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 file + 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 file + 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; + } + + } + else + { + Message::error("The file " + path + " doesn't contain any nodes."); + } return true; } diff --git a/Weave/Graphix/Scene.cpp b/Weave/Graphix/Scene.cpp index 98e0997..2ab84d1 100644 --- a/Weave/Graphix/Scene.cpp +++ b/Weave/Graphix/Scene.cpp @@ -197,7 +197,7 @@ void Scene::draw() const void Scene::addObject(SceneObject* _add) { SceneObjects->push_back(_add); -// ShaderSet->insert(_add->getShader()); + ShaderSet->insert(_add->getShader()); _add->setMainScene(this); } diff --git a/Weave/Graphix/SceneObject.cpp b/Weave/Graphix/SceneObject.cpp index 3835ffa..0a3e0f1 100644 --- a/Weave/Graphix/SceneObject.cpp +++ b/Weave/Graphix/SceneObject.cpp @@ -101,7 +101,7 @@ void SceneObject::draw() const } glUniformMatrix4fv(modelID, 1, GL_FALSE, value_ptr(model)); -// glUniform1i(shader->getUniformLocation ("inv"), invert ? -1 : 1); +// glUniform1i(shader->getUniformLocation ("inv"), 1); drawModel(); } @@ -237,6 +237,11 @@ void SceneObject::setEnemy(bool _isenemy) isenemy = _isenemy; } +Shader* SceneObject::getShader() +{ + return shader; +} + bool SceneObject::isEnemy() { return isenemy; diff --git a/Weave/Graphix/SceneObject.h b/Weave/Graphix/SceneObject.h index aea26ab..5cd58c1 100644 --- a/Weave/Graphix/SceneObject.h +++ b/Weave/Graphix/SceneObject.h @@ -54,6 +54,8 @@ public: void useTextureSave(); void useTextureDanger(); + Shader* getShader(); + void setEnemy(bool isenemy); bool isEnemy(); diff --git a/Weave/Graphix/Texture.cpp b/Weave/Graphix/Texture.cpp index 9b32961..3dd6953 100644 --- a/Weave/Graphix/Texture.cpp +++ b/Weave/Graphix/Texture.cpp @@ -21,7 +21,7 @@ Texture::Texture(const string& _path) : path(_path) glActiveTexture(GL_TEXTURE0); glBindTexture(GL_TEXTURE_2D, handle); - FREE_IMAGE_FORMAT format = FreeImage_GetFileType(path.c_str());//Automatocally detects the format + FREE_IMAGE_FORMAT format = FreeImage_GetFileType(("../textures/" + path).c_str());//Automatocally detects the format if (format == FIF_UNKNOWN) { cout << "Couldn't detect texture file format." << endl; diff --git a/Weave/main.cpp b/Weave/main.cpp index 76cd9e7..da01542 100644 --- a/Weave/main.cpp +++ b/Weave/main.cpp @@ -45,7 +45,7 @@ int main(int argc, char *argv[]) Game spiel1; -// spiel1.play(); + spiel1.play(); Graphix::cleanup(); -- 2.47.3