class Fps
{
public:
- Fps(const float=0.6f);
+ Fps(const float=0.3f);
~Fps();
/* FrameZeit in Millisekunden */
#include "Message.h"
-#include "PlayerI.h"
+//#include "PlayerI.h"
#include <iostream>
#include <time.h>
using std::string;
-Game::Game()
+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));
layer[0] = tmp_Scene;
- //Minimap
- layer[1] = new Scene(tmp_Scene, Graphix::getWindowWidth() - 200, 0, 200, 100, 60, 0.1f, 100, vec3(0.0f, 0.0f, -8.0f));
-
//Allg Shader
- Shader* shader1 = new Shader("../shader/basicTexture_VS.hlsl", "../shader/lightingTexture_FS.hlsl");
+ Shader* shader1 = new Shader("basicTexture_VS.hlsl", "lightingTexture_FS.hlsl");
//Player
- SceneObject* tmp_playerObject = new SceneObject(shader1, glm::mat4(1.0f), "../models/sphere/sphere.dae", "../Textures/simple_trans.png");
+ SceneObject* tmp_playerObject = new SceneObject(shader1, glm::mat4(1.0f), "sphere/sphere.dae", "simple_trans.png");
- tmp_playerObject->setIntelligenz(new PlayerI(tmp_playerObject));
+ //tmp_playerObject->setIntelligenz(new PlayerI(tmp_playerObject));
tmp_Scene->addObject(tmp_playerObject);
tmp_Scene->setLookAt(tmp_playerObject);
//player1 = Player(tmp_playerObject);
// World
- SceneObject* tmp_world = new SceneObject(shader1, scale(vec3(15.f)), "../models/sphere/sphere.dae", "../Textures/sky_withstars.png",1.f,1.f,1.f,vec3(0.f),nullptr,true);
+ 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("../Textures/enemy.png");
- SceneObject::setTextureSave("../Textures/enemy_save.png");
+ SceneObject::setTextureDanger("enemy.png");
+ SceneObject::setTextureSave("enemy_save.png");
tmp_Scene->addObject(tmp_world);
--i;
continue;
}
- tmp_enemy = new SceneObject(shader1, translate(pos), "../models/sphere/sphere.dae", "", (float)(rand() % 10 + 2) / 10.f);
+ 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;
while (!Events::quit){
fps.step();
- //cout << "fps:" << fps.getAvFPS();
-
sleep_time += (int)(1000./ FRAMERATE_FIX - fps.getTicks());
if (sleep_time < 0)
sleep_time = 0;
- //cout << " stime:" << sleep_time << endl;
Sleep(sleep_time);
Events::processEvents();
void Game::update(float deltaT)
{
+ if (playing){
+ for (auto i = layer.begin(); i != layer.end(); ++i){
+ (*i).second->update(deltaT);
+ }
- for (auto i = layer.begin(); i != layer.end(); ++i){
- (*i).second->update(deltaT);
- }
+ // l_interface->update(deltaT);
+ }else
+ l_menu->update(deltaT);
}
void Game::draw() const
{
-
- for (auto i = layer.begin(); i != layer.end(); ++i){
- (*i).second->draw();
+ if (playing){
+ for (auto i = layer.begin(); i != layer.end(); ++i){
+ (*i).second->draw();
+ }
+ // l_interface->draw();
}
+ else
+ l_menu->draw();
}
private:
+ bool playing;
+
+ Drawable *l_interface, *l_menu;
+
map<int,Drawable*> layer;
//Player player1;
+++ /dev/null
-#include "Act.h"
-#include "Performer.h"
-
-#include <iostream>
-
-using std::cout;
-using std::endl;
-
-Act::Act(Performer* _performer, mat4 _model) : modelMatrix(_model), performer(_performer), boxPos(vec3(0))
-{
-
-}
-
-Act::~Act()
-{
- cout << "NICE!" << endl;
-}
-
-
-mat4 Act::getModelMatrix() const
-{
- return modelMatrix;
-}
-
-void Act::draw() const
-{
- performer->draw(modelMatrix, -1);
-}
-
-void Act::updateBoxPos(const mat4& _perspective)
-{
- boxPos = (vec3)(_perspective*modelMatrix)[4];
-}
-vec3 Act::getBoxPos() const
-{
- return boxPos;
-}
\ No newline at end of file
+++ /dev/null
-#pragma once
-
-#include "GLM.h"
-
-class Performer;
-
-class Act
-{
-public:
- Act(Performer*,mat4);
- ~Act();
-
- //setModelMatrix();
- //setTexture();
-
- mat4 getModelMatrix() const;
-
- void updateBoxPos(const mat4& _perspective);
- vec3 Act::getBoxPos() const;
-
- void draw() const;
-
-
-private:
- Performer* performer;
- mat4 modelMatrix;
-
- vec3 boxPos;
-
- //Texture
-};
-
#include "Model.h"
#include <GL/glew.h>
-#include <assimp/Importer.hpp>
-#include <assimp/scene.h>
-#include <assimp/postprocess.h>
+//#include <assimp/Importer.hpp>
+//#include <assimp/scene.h>
+//#include <assimp/postprocess.h>
#include "Shader.h"
#include "../Message.h"
typedef unsigned int uint;
-Model::Model(const string& _modelpath, Shader* _shader, bool invert) :
- shader(_shader),
- modelpath(_modelpath),
- vao(-1),
- numfaces(0),
- numvertices(-1)
+Model::Model(const string& _modelpath) :
+ numfaces(-1),
+ numvertices(-1),
+ vertexBuffer(-1),
+ normalBuffer(-1),
+ uvBuffer(-1),
+ indexBuffer(-1)
{
- //falls Model mit Shader schon geladen wurde
- auto i = vao_map.find(*shader);
- if (i != vao_map.end())
- {
- auto j = i->second.find(modelpath);
- if (j != i->second.end())
- {
- vao = vao_map[*shader][modelpath];
- numvertices = buffer_map[modelpath].numvertices;
- numfaces = buffer_map[modelpath].numfaces;
- return;
- }
- }
-
- {
-
- uint vertexBuffer = -1, normalBuffer = -1, uvBuffer = -1, indexBuffer = -1;
-
- //falls model aber noch nicht mit dem Shader geladen wurde
- auto i = buffer_map.find(modelpath);
- if (i != buffer_map.end())
- {
- vertexBuffer = i->second.vertexBuffer;
- normalBuffer = i->second.normalBuffer;
- uvBuffer = i->second.uvBuffer;
- indexBuffer = i->second.indexBuffer;
- numvertices = i->second.numvertices;
- numfaces = i->second.numfaces;
- }
- else
- {
-
float *vertex = nullptr, *normals = nullptr, *uvs = nullptr;
uint *index = nullptr;
- import(modelpath, numvertices,numfaces,vertex,uvs,normals,index,invert);
+ 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);
- buffer_map[modelpath].vertexBuffer = vertexBuffer;
- buffer_map[modelpath].normalBuffer = normalBuffer;
- buffer_map[modelpath].uvBuffer = uvBuffer;
- buffer_map[modelpath].indexBuffer = indexBuffer;
- buffer_map[modelpath].numfaces = numfaces;
- buffer_map[modelpath].numvertices = numvertices;
-
delete vertex, normals, uvs, index;
- }
-
- glGenVertexArrays(1, &vao);
- glBindVertexArray(vao);
-
- bindBuffer(vertexBuffer, "position");
- bindBuffer(uvBuffer, "uv", 2);
- bindBuffer(normalBuffer, "normal");
- glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, indexBuffer);
-
- glBindVertexArray(0);
-
- glBindBuffer(GL_ARRAY_BUFFER, 0);
- glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);
-
- vao_map[*shader][modelpath] = vao;
- }
}
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);
- glDeleteVertexArrays(1, &vao);
- */
+
+
}
-void Model::useModel() const
+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
+{
+ 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);
+ _shader->useShader();
- shader->useShader();
}
void Model::drawModel() const
{
glDrawElements(GL_TRIANGLES, numfaces * 3, GL_UNSIGNED_INT, 0);
-
glBindVertexArray(0);
}
+unsigned int Model::bindShader(Shader* _shader)
+{
+ uint vao;
+ glGenVertexArrays(1, &vao);
+ glBindVertexArray(vao);
+ bindBuffer(vertexBuffer, _shader->getAttribLocation("position"));
+ bindBuffer(uvBuffer, _shader->getAttribLocation("uv"), 2);
+ bindBuffer(normalBuffer, _shader->getAttribLocation("normal"));
+
+ glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, indexBuffer);
+
+ glBindVertexArray(0);
+
+ glBindBuffer(GL_ARRAY_BUFFER, 0);
+ glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);
+
+ shader_map[*_shader] = vao;
+
+ return vao;
+}
void Model::genBuffer(uint &buffer, uint size, void* value)
{
glBindBuffer(GL_ARRAY_BUFFER, 0);
}
-void Model::bindBuffer(uint &buffer, string name, uint dim)
+void Model::bindBuffer(const uint &buffer,const uint index,const uint dim)
{
- GLint Index = glGetAttribLocation(*shader, name.c_str());
- if (Index >= 0)
- {
glBindBuffer(GL_ARRAY_BUFFER, buffer);
- glEnableVertexAttribArray(Index);
- glVertexAttribPointer(Index, dim, GL_FLOAT, GL_FALSE, 0, 0);
+ glEnableVertexAttribArray(index);
+ glVertexAttribPointer(index, dim, GL_FLOAT, GL_FALSE, 0, 0);
glBindBuffer(GL_ARRAY_BUFFER, 0);
- }
- else{
- Message::info("GL_GetAttLoc: Kann '" + name + "' nicht finden.");
- }
}
-bool Model::import(const string& path,uint& numvertices, uint& numfaces, float*& vertex, float*& uvs, float*& normals, uint*& index, bool invert)
+bool Model::import(const string& path,uint& numvertices, uint& numfaces, float*& vertex, float*& uvs, float*& normals, uint*& index)
{
- 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;
- }
-
-
-
- //TODO SHOULD BE IVERTED
- //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
-
- if (invert)
- {
- 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{
- 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.");
- }
+ //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.");
+ //}
return true;
}
-
-Shader* Model::getShader() const
-{
- return shader;
-}
-
-int2str2int_map Model::vao_map;
-str2buffer_map Model::buffer_map;
\ No newline at end of file
using std::unordered_map;
//VAO MAP
-typedef unordered_map<string, unsigned int> str2int_map;
-typedef unordered_map<unsigned int, str2int_map> int2str2int_map;
-
-//BUFFER MAP
-typedef struct _myBuffer
-{
- unsigned int vertexBuffer = -1, normalBuffer = -1, uvBuffer = -1, indexBuffer = -1, numfaces=0, numvertices=0;
-} Buffer;
-typedef unordered_map<string, Buffer> str2buffer_map;
-
+typedef unordered_map<unsigned int, unsigned int> int2int_map;
class Shader;
-
class Model
{
public:
- Model(const string& modelpath,Shader* _shader,bool invert=false);
+ Model(const string& modelpath);
virtual ~Model();
- void useModel() const;
+ void useModel(Shader* shader);
+ void useModel(Shader* shader) const;
void drawModel() const;
+ unsigned int bindShader(Shader* shader);
- Shader* getShader() const;
-
-protected:
- unsigned int vao;
- Shader* shader;
- string modelpath;
+private:
unsigned int numvertices, numfaces;
+ unsigned int vertexBuffer, normalBuffer, uvBuffer, indexBuffer;
-private:
+ int2int_map shader_map;
- bool import(const string& path, unsigned int& numvertices, unsigned int& numfaces, float*& vertex, float*& uvs, float*& normals, unsigned int*& index, bool invert=false);
+ bool import(const string& path, unsigned int& numvertices, unsigned int& numfaces, float*& vertex, float*& uvs, float*& normals, unsigned int*& index);
void genBuffer(unsigned int &buffer, unsigned int size, void* value);
- void bindBuffer(unsigned int &buffer, string name, unsigned int dim = 3);
-
- static int2str2int_map vao_map;
- static str2buffer_map buffer_map;
+ void bindBuffer(const unsigned int &buffer, const unsigned int index,const unsigned int dim = 3);
+
};
+++ /dev/null
-#include "Performer.h"
-
-#include "GLM.h"
-#include <GL\glew.h>
-#include <fstream>
-
-#include <assimp/Importer.hpp>
-#include <assimp/scene.h>
-#include <assimp/postprocess.h>
-
-
-#include "../Message.h"
-
-using std::ifstream;
-using std::istreambuf_iterator;
-
-typedef unsigned int uint;
-
-
-Performer::Performer(const string& _shader1, const string& _shader2, const string& _modelpath)
-{
- //SHADER ----------------------------------------------------
- initShader(_shader1, _shader2);
-
- //MODEL ------------------------------------------------------
- initModel(_modelpath);
-}
-
-
-Performer::~Performer()
-{
-
- glDeleteBuffers(1, &vertexBuffer);
- glDeleteBuffers(1, &normalBuffer);
- glDeleteBuffers(1, &uvBuffer);
- glDeleteBuffers(1, &indexBuffer);
- glDeleteVertexArrays(1, &vao);
-
- glDeleteProgram(shader);
-}
-
-void Performer::initShader(const string& _shader1, const string& _shader2)
-{
- uint handleS1 = loadShader(_shader1);
- uint handleS2 = loadShader(_shader2);
-
- shader = loadProgram(handleS1, handleS2);
-
- glDeleteShader(handleS1);
- glDeleteShader(handleS2);
-
- modelID = glGetUniformLocation(shader, "model");
- viewID = glGetUniformLocation(shader, "view");
- projectionID = glGetUniformLocation(shader, "projection");
-}
-
-void Performer::initModel(const string& _modelpath)
-{
- glUseProgram(shader);
-
- 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;
-
- glGenVertexArrays(1, &vao);
- glBindVertexArray(vao);
-
- bindBuffer(vertexBuffer, "position");
- bindBuffer(uvBuffer, "uv", 2);
- bindBuffer(normalBuffer, "normal");
-
- glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, indexBuffer);
-
- glBindVertexArray(0);
-
- glBindBuffer(GL_ARRAY_BUFFER, 0);
- glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);
-}
-
-
-void Performer::upgradePerspective(const mat4& _view, const mat4& _projection) const
-{
- glUseProgram(shader);
-
- glUniformMatrix4fv(viewID, 1, GL_FALSE, value_ptr(_view));
- glUniformMatrix4fv(projectionID, 1, GL_FALSE, value_ptr(_projection));
-}
-
-void Performer::draw(const mat4& _model, uint _texture) const
-{
- bool invert = false;
-
- glBindVertexArray(vao);
-
- glUseProgram(shader);
-
- //other loading
-
- glUniformMatrix4fv(modelID, 1, GL_FALSE, value_ptr(_model));
-
- glUniform1i(glGetUniformLocation(shader, "inv"), invert ? -1 : 1);
-
- glDrawElements(GL_TRIANGLES, numfaces * 3, GL_UNSIGNED_INT, 0);
-
- glBindVertexArray(0);
-
-}
-
-
-void Performer::useShader() const
-{
- glUseProgram(shader);
-}
-
-uint Performer::getHandle() const
-{
- return shader;
-}
-
-
-uint Performer::loadShader(const string& _shaderPath) const
-{
- uint handle = -1;
- auto type = _shaderPath.substr(_shaderPath.find_last_of('_') + 1);
- GLenum shaderType;
- if (type == "VS.hlsl"){
- shaderType = GL_VERTEX_SHADER;
- }
- else if (type == "FS.hlsl"){
- shaderType = GL_FRAGMENT_SHADER;
- }
- else{
- Message::error((string)"LoadShader: Typ <" + type + (string)"> nicht erkannt.");
- }
-
- ifstream shaderFile(_shaderPath);
-
- if (shaderFile.good()){
- string code = string(istreambuf_iterator<char>(shaderFile), istreambuf_iterator<char>());
- shaderFile.close();
-
- handle = glCreateShader(shaderType);
-
- if (handle == 0){
- Message::error("LoadShader: Shader konnte nicht erstellt werden.");
- }
-
- auto codePtr = code.c_str();
- glShaderSource(handle, 1, &codePtr, NULL);
- glCompileShader(handle);
-
- GLint succeed;
- glGetShaderiv(handle, GL_COMPILE_STATUS, &succeed);
-
- if (succeed == GL_FALSE || !glIsShader(handle)){
- GLint logSize;
- glGetShaderiv(handle, GL_INFO_LOG_LENGTH, &logSize);
- auto message = new char[logSize];
-
- glGetShaderInfoLog(handle, logSize, NULL, message);
- Message::error((string)"LoadShader: Shader konnte nicht kompeliert werden.\n " + message);
- }
- }
- else{
- Message::error((string)"LoadShader: ShaderFile <" + _shaderPath + (string)"> konnte nicht geöffnet werden.");
- }
-
- return handle;
-}
-
-
-uint Performer::loadProgram(uint _shader1, uint _shader2) const
-{
- uint programHandle;
-
- programHandle = glCreateProgram();
-
- if (programHandle == 0){
- Message::error("LoadProgram: Program konnte nicht erstellt werden.");
- }
-
- glAttachShader(programHandle, _shader1);
- glAttachShader(programHandle, _shader2);
-
- glBindFragDataLocation(programHandle, 0, "fragColor");
-
- glLinkProgram(programHandle);
-
- GLint succeded;
-
- glGetProgramiv(programHandle, GL_LINK_STATUS, &succeded);
-
- if (!succeded){
- GLint logSize;
- glGetProgramiv(programHandle, GL_INFO_LOG_LENGTH, &logSize);
- auto message = new char[logSize];
-
- glGetProgramInfoLog(programHandle, logSize, NULL, message);
- Message::error((string)"LoadProgram: Program konnte nicht kompeliert werden.\n" + message);
- }
- return programHandle;
-}
-
-void Performer::genBuffer(uint &buffer, uint size, void* value) const
-{
- glGenBuffers(1, &buffer);
- glBindBuffer(GL_ARRAY_BUFFER, buffer);
- glBufferData(GL_ARRAY_BUFFER, size, value, GL_STATIC_DRAW);
- glBindBuffer(GL_ARRAY_BUFFER, 0);
-}
-
-void Performer::bindBuffer(uint &buffer, const string& name, uint dim) const
-{
- GLint Index = glGetAttribLocation(shader, name.c_str());
- if (Index >= 0)
- {
- glBindBuffer(GL_ARRAY_BUFFER, buffer);
- glEnableVertexAttribArray(Index);
- glVertexAttribPointer(Index, dim, GL_FLOAT, GL_FALSE, 0, 0);
- glBindBuffer(GL_ARRAY_BUFFER, 0);
- }
- else{
- Message::info("GL_GetAttLoc: Kann '" + name + "' nicht finden.");
- }
-}
-
-
-
-bool Performer::import(const string& path, uint& numvertices, uint& numfaces, float*& vertex, float*& uvs, float*& normals, uint*& index) const
-{
- 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;
- }
-
-
-
- //TODO SHOULD BE IVERTED
- //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.");
- }
-
- return true;
-}
\ No newline at end of file
+++ /dev/null
-#pragma once
-
-#include <string>
-#include "GLM.h"
-
-using std::string;
-
-class Shader;
-
-class Performer
-{
-public:
- Performer(const string& _shader1, const string& _shader2, const string& _modelpath);
-
- virtual ~Performer();
-
-
- void upgradePerspective(const mat4& _view, const mat4& _projection) const;
- void upgradeTexture() const;
- void draw(const mat4& _model, unsigned int _texture) const;
- //update(deltaT)
-
- void useShader() const;
- unsigned int getHandle() const;
-
-private:
- //Animation
-
- //SHADER ---------------------------------------------------
- unsigned int shader=-1;
-
- unsigned int loadShader(const string& _shaderPath) const;
- unsigned int loadProgram(unsigned int _shader1, unsigned int _shader2) const;
-
- void initShader(const string& _shader1, const string& _shader2);
-
-
- //MODEL ---------------------------------------------------
- unsigned int modelID=-1;
- unsigned int vertexBuffer = -1, normalBuffer = -1, uvBuffer = -1, indexBuffer = -1, vao=-1;
- unsigned int numvertices=0, numfaces=0;
-
- bool import(const string& path, unsigned int& numvertices, unsigned int& numfaces, float*& vertex, float*& uvs, float*& normals, unsigned int*& index) const;
- void genBuffer(unsigned int &buffer, unsigned int size, void* value) const;
- void bindBuffer(unsigned int &buffer, const string&, unsigned int dim = 3) const;
-
- void initModel(const string& _modelpath);
-
- //VIEWPERSPECTIVE -----------------------------------------
- unsigned int viewID=-1, projectionID=-1;
-
-};
-
-
-
-//DEFINE DEFAULT KONSTRUKTORS
-
-#define PERF_KUH "../shader/basicTexture_VS.hlsl", "../shader/lightingTexture_FS.hlsl","../models/cow/cow.dae"
-#define PERF_SPHERE "../shader/basicTexture_VS.hlsl", "../shader/lightingTexture_FS.hlsl","../models/sphere/sphere.dae"
-#define PERF_BOX "../shader/basicTexture_VS.hlsl", "../shader/lightingTexture_FS.hlsl","../models/box/box.dae"
-
-#define PERF_SKY
\ No newline at end of file
#include "Shader.h"
-#include "Setting.h"
-
/*
Scene::Scene() :
SceneObjects(new list<SceneObject*>),
vec3 pos;
//Focus auf Player
+
+ if (lookat->getMatter()<1e-2)
+ {
+ Message::error("GameOver");
+ }
+ int move_x = Events::getMouseX();
+ int move_y = Events::getMouseY();
+ int shoot = Events::getAction1();
+ int reset = Events::getAction2();
+
+ //cout << move_x << " " << move_y << endl;
+
+ if (move_x)
+ lookat->turn(0.3f *move_x, vec3(0.f, 1.f, 0.f));
+ if (move_y)
+ lookat->turn(0.3f *move_y, vec3(1.f, 0.f, 0.f));
+ if (shoot)
+ {
+ vec3 direction = lookat->push(vec3(0.f, 0.f, shoot*0.1f));
+ //SceneObjects->push_back(self->copy();)
+ }
+ if (reset)
+ lookat->stop();
+
// XYAchse um den Player
if (Events::getViewX() || Events::getViewY())
{
if (lookat != NULL)
view = translate(view,pos - lookat->getPosition());
+
}
void Scene::draw() const
for (auto i = ShaderSet->cbegin(); i != ShaderSet->cend(); ++i)
{
(*i)->useShader();
- glUniformMatrix4fv(glGetUniformLocation((*i)->getHandle(), "projection"), 1, false, value_ptr(projection));
- glUniformMatrix4fv(glGetUniformLocation((*i)->getHandle(), "view"), 1, false, value_ptr(view));
+ glUniformMatrix4fv((*i)->getUniformLocation("projection"), 1, false, value_ptr(projection));
+ glUniformMatrix4fv((*i)->getUniformLocation("view"), 1, false, value_ptr(view));
}
void Scene::addObject(SceneObject* _add)
{
SceneObjects->push_back(_add);
- ShaderSet->insert(_add->getShader());
+// ShaderSet->insert(_add->getShader());
_add->setMainScene(this);
}
return SceneObjects;
}
-void Scene::setProjection(mat4 _projection)
-{
- projection = _projection;
-}
+//void Scene::setProjection(mat4 _projection)
+//{
+// projection = _projection;
+//}
void Scene::setProjection(float fovy, float aspect, float zNear, float zFar)
{
void setViewPort(unsigned int, unsigned int, unsigned int, unsigned int);
- void setProjection(mat4 _projection);
+// void setProjection(mat4 _projection);
void setProjection(float fovy, float aspect, float zNear, float zFar);
//void updateProjection(mat4);
#include "../Message.h"
#include <string>
-#include "../ArtificialI.h"
#include <iostream>
-#include "../Intelligenz.h"
#include "Shader.h"
#include "Scene.h"
#include "Texture.h"
using std::cout;
using std::endl;
-SceneObject::SceneObject(Shader* _shader, mat4& _model, string _modelpath, string texturepath, float _matter, float _speed, float _atack, vec3& _direction, Intelligenz* _will, bool _invert) :
-Model(_modelpath, _shader, _invert),
+SceneObject::SceneObject(Shader* _shader, mat4& _model, string _modelpath, string texturepath, float _matter, float _speed, float _atack, vec3& _direction) :
+Model(_modelpath),
model(_model),
+shader(_shader),
speed(_speed),
matter(_matter),
atack(_atack),
spin(1.0f),
direction(_direction),
-will(_will),
matterDiff(0),
mainScene(NULL),
collision_ignore(false),
-invert(_invert),
isenemy(false),
texture(nullptr)
{
- modelID = glGetUniformLocation(shader->getHandle(), "model");
+ modelID = _shader->getUniformLocation("model");
model = scale(model, vec3(pow(matter,1./3)));
if (texturepath!="")
texture = new Texture(texturepath);
+
+ bindShader(shader);
}
SceneObject::~SceneObject()
{
- //if (will!=NULL)
- delete will;
// delete texture;
}
void SceneObject::update(float deltaT)
{
- if (will!=NULL)
- will->update(deltaT);
//Direction & Speed
model = translate(deltaT * speed * direction)*model;
void SceneObject::draw() const
{
- useModel();
+ useModel(shader);
if (texture!=nullptr)
{
int unit = 0;
texture->bind(unit);
- glUniform1i(glGetUniformLocation(*shader, "ColorTexture"), unit);
+ glUniform1i(shader->getUniformLocation("ColorTexture"), unit);
}
glUniformMatrix4fv(modelID, 1, GL_FALSE, value_ptr(model));
- glUniform1i(glGetUniformLocation(*shader, "inv"), invert ? -1 : 1);
+// glUniform1i(shader->getUniformLocation ("inv"), invert ? -1 : 1);
drawModel();
}
float dir_len = VektorAbs(_direction);
if (dir_len > 0)
{
- SceneObject* copy = this->copy();
- mainScene->addObject(copy);
- copy->setModel(translate(getPosition() - direct * (float)(1.25*pow(matter*_matter, 1. / 3) + pow(matter, 1. / 3))));
- copy->direction = direct * dir_len / -_matter;
- copy->setMatter(_matter*matter*.1);
- copy->matterDiff = _matter*matter*.9;
- copy->setEnemy(true);
+ //SceneObject* copy = this->copy();
+ //mainScene->addObject(copy);
+ //copy->setModel(translate(getPosition() - direct * (float)(1.25*pow(matter*_matter, 1. / 3) + pow(matter, 1. / 3))));
+ //copy->direction = direct * dir_len / -_matter;
+ //copy->setMatter(_matter*matter*.1);
+ //copy->matterDiff = _matter*matter*.9;
+ //copy->setEnemy(true);
- delete copy->texture;
- copy->texture = new Texture("../Textures/enemy.png");
+ //delete copy->texture;
+ //copy->texture = new Texture("../Textures/enemy.png");
direction += direct * dir_len;
matterDiff -= _matter * matter;
}
-bool SceneObject::operator==(SceneObject _ref)
-{
- return (this == &_ref);
-}
-
-SceneObject* SceneObject::copy()
-{
- return new SceneObject(shader, model,modelpath, *texture);
-}
+//bool SceneObject::operator==(SceneObject _ref)
+//{
+// return (this == &_ref);
+//}
+//SceneObject* SceneObject::copy()
+//{
+// return new SceneObject(shader, model, modelpath, *texture);
+//}
+//
-
-
-void SceneObject::setIntelligenz(Intelligenz* _intelligenz)
-{
- will = _intelligenz;
-}
-
float SceneObject::getMatter()
{
return matter;
using std::string;
class Scene;
-class Intelligenz;
class Texture;
+class Shader;
//class string;
public:
//SceneObject(Shader* _shader, mat4& model);
- SceneObject(Shader* _shader, mat4& model, string modelpath, string texturepath, float matter= 1.f, float speed= 1.f, float atack= 1.f, vec3& direction= vec3(0.f), Intelligenz* _will = NULL,bool invert=false);
+ SceneObject(Shader* _shader, mat4& model, string modelpath, string texturepath, float matter= 1.f, float speed= 1.f, float atack= 1.f, vec3& direction= vec3(0.f));
virtual ~SceneObject();
virtual void update(float);
virtual void setModel(mat4&);
virtual void turn(float, vec3&);
- virtual bool operator==(SceneObject);
-
- void setIntelligenz(Intelligenz*);
+ //virtual bool operator==(SceneObject);
void setMainScene(Scene *);
void setMatter(float);
- Intelligenz* will;
-
mat4 model;
unsigned int modelID;
+ Shader* shader;
+
Scene* mainScene;
bool collision_ignore;
- virtual SceneObject* copy();
+ //virtual SceneObject* copy();
float matter;
float speed;
float atack;
- bool invert;
-
float matterDiff;
vec3 direction;
+++ /dev/null
-#include "Setting.h"
-
-#include "Act.h"
-#include "Performer.h"
-
-#include "GLM.h"
-
-#include <list>
-
-using std::list;
-
-Setting::Setting() :viewMatrix(mat4(1)), projectionMatrix(mat4(1))
-{
-
-}
-
-
-Setting::~Setting()
-{
- cleanAct();
- //clearPerformers
-}
-
-
-void Setting::setView(mat4 _view)
-{
- viewMatrix = _view;
-}
-
-void Setting::setProjection(mat4 _projection)
-{
- projectionMatrix = _projection;
-}
-
-void Setting::setProjection(float fovy, float aspect, float zNear, float zFar)
-{
- projectionMatrix = perspective(fovy, aspect, zNear, zFar);
-}
-
-mat4 const Setting::getViewMatrix() const
-{
- return viewMatrix;
-}
-
-
-Act* Setting::newAct()
-{
- Act* _new = new Act(nullptr,mat4(1));
- // Act in actLIST einhängen
-
- actList.push_back(_new);
-
- return _new;
-}
-
-void Setting::deleteAct(Act* _del)
-{
- actList.remove(_del);
- delete _del;
-}
-
-void Setting::cleanAct()
-{
- actList.clear();
-}
-
-void Setting::draw()
-{
-
- //update PerformerStuff
- for (auto i = performerList.begin(); i == performerList.end(); ++i)
- {
- i->second->upgradePerspective(viewMatrix, projectionMatrix);
- }
-
- //frustumCULLING
- mat4 perspective = projectionMatrix*viewMatrix;
- for (auto i = actList.begin(); i == actList.end(); ++i)
- {
- (*i)->updateBoxPos(perspective);
-
- }
-
- //sort ActLIST
- actList.sort(
- [this](const Act* _act1, const Act* _act2)
- {
- mat4 tmp = getViewMatrix();
- return dot((vec3)(tmp[4]) - (vec3)(_act1->getModelMatrix()[4]), (vec3)tmp[3])
- > dot((vec3)(tmp[4]) - (vec3)(_act2->getModelMatrix()[4]),(vec3)tmp[3]);
- }
- ); //sortiere nach Entfernung
-
- //draw ActLIST
- for (auto i = actList.cbegin(); i == actList.cend(); ++i)
- {
- //filter....
- (*i)->draw();
- }
-
-}
\ No newline at end of file
+++ /dev/null
-#pragma once
-
-#include "GLM.h"
-
-#include <string>
-#include <unordered_map>
-#include <list>
-
-class Act;
-class Performer;
-class Texture;
-
-using std::string;
-using std::unordered_map;
-using std::list;
-
-typedef unordered_map<unsigned int, Performer*> id2performer;
-typedef unordered_map<unsigned int, Texture*> id2texture;
-
-class Setting
-{
-public:
- Setting();
- ~Setting();
-
- void setView(mat4 matrix);
- void setProjection(mat4 matrix);
- void setProjection(float fovy, float aspect, float zNear, float zFar);
-
- mat4 const getViewMatrix() const;
-
- //Prepare Setting for Draw
- Act* newAct();
- void deleteAct(Act*);
- void cleanAct();
-
- void draw();
-
-private:
-
- mat4 viewMatrix;
- mat4 projectionMatrix;
-
- //lichtquellen
-
- //ShaderLIST
- id2performer performerList;
-
- //Texturen
- id2texture textureList;
-
- //ActLIST
- list<Act*> actList;
-};
using namespace std;
-//GLuint loadShader(string& _shaderPath);
-//GLuint loadProgram(GLuint _shader1, GLuint _shader2);
-
-
Shader::Shader(string _shader1, string _shader2)
{
- GLuint handleS1 = loadShader(_shader1);
- GLuint handleS2 = loadShader(_shader2);
+ GLuint handleS1 = loadShader("../shader/"+_shader1);
+ GLuint handleS2 = loadShader("../shader/"+_shader2);
handle = loadProgram(handleS1, handleS2);
glUseProgram(handle);
}
+GLuint Shader::getAttribLocation(const string& name) const
+{
+ GLuint ind = glGetAttribLocation(handle, name.c_str());
+ if (ind < 0)
+ Message::info("GL_GetAttLoc: Kann '" + name + "' nicht finden.");
+
+ return ind;
+}
+
+GLuint Shader::getUniformLocation(const string& name) const
+{
+ GLuint ind = glGetUniformLocation(handle, name.c_str());
+ if (ind < 0)
+ Message::info("GL_GetUniLoc: Kann '" + name + "' nicht finden.");
+
+ return ind;
+}
+
GLuint Shader::getHandle() const
{
return handle;
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;
system("pause");
exit(-1);
}
- FIBITMAP* data = FreeImage_Load(format, path.c_str());
+ FIBITMAP* data = FreeImage_Load(format, ("../textures/" + path).c_str());
if (!data)
{
cout << "Couldn't read texture file." << endl;
+++ /dev/null
-#include "PlayerI.h"
-
-#include "Graphix\SceneObject.h"
-#include "Events.h"
-#include "Message.h"
-
-
-PlayerI::PlayerI(SceneObject* _self) : Intelligenz(_self)
-{
-}
-
-
-PlayerI::~PlayerI()
-{
-}
-
-
-void PlayerI::update(float deltaT)
-{
- if (self->getMatter()<1e-2)
- {
- Message::error("GameOver");
- }
- int move_x = Events::getMoveX();
- int move_y = Events::getMoveY();
- int shoot = Events::getAction1();
- int reset = Events::getAction2();
-
- //cout << move_x << " " << move_y << endl;
-
- if (move_x)
- self->turn(0.3f *move_x, vec3(0.f, 1.f, 0.f));
- if (move_y)
- self->turn(0.3f *move_y, vec3(1.f, 0.f, 0.f));
- if (shoot)
- {
- vec3 direction = self->push(vec3(0.f, 0.f, shoot*0.1f));
- //SceneObjects->push_back(self->copy();)
- }
- if (reset)
- self->stop();
-}
\ No newline at end of file
+++ /dev/null
-#pragma once
-
-class PlayerI :
- public Intelligenz
-{
-public:
- PlayerI(SceneObject*);
- ~PlayerI();
-
- void update(float);
-
- SceneObject* self;
- list<SceneObject*>* SceneObjects;
-
-};
-
<ItemGroup>
<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\Scene.cpp" />
+ <ClCompile Include="Graphix\SceneObject.cpp" />
+ <ClCompile Include="Graphix\Shader.cpp" />
+ <ClCompile Include="Graphix\Texture.cpp" />
+ <ClCompile Include="Graphix\ViewPort.cpp" />
<ClCompile Include="main.cpp" />
<ClCompile Include="Message.cpp" />
</ItemGroup>
<ClInclude Include="Average.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\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" />
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ClCompile Include="Graphix\GLM.cpp">
<Filter>Source Files</Filter>
</ClCompile>
+ <ClCompile Include="Graphix\Shader.cpp">
+ <Filter>Source Files</Filter>
+ </ClCompile>
+ <ClCompile Include="Graphix\Drawable.cpp">
+ <Filter>Source Files</Filter>
+ </ClCompile>
+ <ClCompile Include="Graphix\Texture.cpp">
+ <Filter>Source Files</Filter>
+ </ClCompile>
+ <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\Scene.cpp">
+ <Filter>Source Files</Filter>
+ </ClCompile>
+ <ClCompile Include="Graphix\SceneObject.cpp">
+ <Filter>Source Files</Filter>
+ </ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="Fps.h">
<ClInclude Include="Graphix\GLM.h">
<Filter>Header Files</Filter>
</ClInclude>
+ <ClInclude Include="Graphix\Shader.h">
+ <Filter>Header Files</Filter>
+ </ClInclude>
+ <ClInclude Include="Graphix\Drawable.h">
+ <Filter>Header Files</Filter>
+ </ClInclude>
+ <ClInclude Include="Graphix\Texture.h">
+ <Filter>Header Files</Filter>
+ </ClInclude>
+ <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\Scene.h">
+ <Filter>Header Files</Filter>
+ </ClInclude>
+ <ClInclude Include="Graphix\SceneObject.h">
+ <Filter>Header Files</Filter>
+ </ClInclude>
</ItemGroup>
</Project>
\ No newline at end of file
//#include "Fps.h"
-//#include "Game.h"
+#include "Game.h"
//using std::cout;
//using std::endl;
{
Graphix::init();
-// Game spiel1;
+ Game spiel1;
// spiel1.play();