-#include "Game.h"
-
-#include <string>
-
-#include "GLM.h"
-#include <Windows.h>
-
-#include <assimp/Importer.hpp>
-#include <assimp/scene.h>
-#include <assimp/postprocess.h>
-
-#include <GL\glew.h>
-
-#include "Scene.h"
-
-#include "Graphix\Shader.h"
-#include "Graphix\Graphix.h"
-#include "Graphix\Texture.h"
-#include "Fps.h"
-#include "Events.h"
-
-#include "Graphix\Model.h"
-
-#include "Message.h"
-
-//#include "PlayerI.h"
-
-#include <iostream>
-#include <time.h>
-
-//#define FRAMERATE_FIX 60
-
-using std::cout;
-using std::endl;
-
-using std::string;
-
-typedef unsigned int uint;
-
-Game::Game() : playing(true)
-{
- srand((int)time(NULL));
- // Hauptfenster
- current_world = new Scene(0, 0, Graphix::getWindowWidth(), Graphix::getWindowHeight(), 45, 0.1f, 40, vec3(0.0f, 0.0f, 0.f));
-
- //Allg Shader
- Shader* shader1 = new Shader("basicTexture_VS.hlsl", "lightingTexture_FS.hlsl");
-
- // load LVL
-
- SceneObject* tmp_world = new Level(shader1, "level_1.dae", "model_levelTest_2D.jpg");
-
- //tmp_world->ignore = true;
- current_world->addObject(tmp_world);
-
-// current_world->addObject(new SceneObject(shader1, translate(vec3(-3.f, 1.f, 0.f)), vec4(1.0f, 1.0f, 1.0f, 3.0f), new BBox(), ""));
-
- //Player
- SceneObject* tmp_playerObject = new Marvin(shader1, translate(vec3(1.f, 3.f, 1.f))*rotate((float)M_PI_4,vec3(0.f,1.f,0.f)));
-
- tmp_playerObject->yStatic= false;
-
- current_world->addObject(tmp_playerObject);
- current_world->setLookAt(tmp_playerObject);
-
- //current_world->addObject(new SceneObject(shader1, glm::mat4(1.0f), "Player.dae", "model_player.png"));
- //current_world->addObject(new SceneObject(shader1, translate(vec3(-3.f, .4f, 0.f))*scale(vec3(3.f)), "cow/cow.dae", "model_cow_2D.jpg"));
- current_world->addObject(new SceneObject(shader1, translate(vec3(-3.f, .4f, 0.f)), vec4(3.0f, 0.5f, 0.4f, 1.5f), "duck.dae", "model_duck_2D.png"));
- current_world->addObject(new SceneObject(shader1, translate(vec3(-5.f, .4f, 0.f)), vec4(3.0f, 3.f, 0.4f, 1.5f), "duck.dae", "model_duck_2D.png"));
- current_world->addObject(new SceneObject(shader1, translate(vec3(0.f, .4f, 0.f)), vec4(3.0f, 3.f, 0.4f, 1.5f), "lever.dae", "model_duck_2D.png"));
-
- current_world->addObject(new SceneObject(shader1, translate(vec3(-5.f, 3.f, 0.f)), vec4(3.0f, 3.f, 0.4f, 1.5f), "SkyBox.dae", "model_SkyBox_2D.png"));
-
- //current_world->addObject(new EventBox(translate(vec3(3.f, .4f, 0.f)),EB_LOSTZONE));
- current_world->addObject(new EventBox(translate(vec3(3.f, .4f, -15.f)), EB_WINZONE));
-
-}
-
-
-Game::~Game()
-{
- delete current_world;
-
- //RALLLY BAD HACK!!!! No Texture will be freed!!!!
- //Texture::clean();
-}
-
-
-void Game::play()
-{
- Fps fps(0.3f);
- int sleep_time=0;
- float message_time=0;
- int framecount = 0;
-
- while (!Events::halt){
- fps.step();
-
-#ifdef FRAMERATE_FIX
- sleep_time += (int)(1000./ FRAMERATE_FIX - fps.getTicks());
-
- if (sleep_time < 0)
- sleep_time = 0;
-
- Sleep(sleep_time);
-#endif
- if (Events::isKToggleActive(SDLK_F2))
- {
- ++framecount;
- message_time += fps.getDelta();
- if (message_time >= 1.5)
- {
- Message::info((string)"Fps: " + std::to_string((float)framecount/message_time));
- message_time = 0;
- framecount = 0;
- }
-
- }
-
-
-
- Events::processEvents();
- //Message::info(std::to_string(fps.getDelta()));
- update(fps.getCappedDelta());
-
- Graphix::clear();
-
- draw();
-
- Graphix::swap();
-
- Graphix::getGlError();
-
-// system("pause");
- }
-}
-
-void Game::update(float deltaT)
-{
-
- if (Graphix::getWindowHeight() != current_world->getViewport().getHeight() || Graphix::getWindowWidth() != current_world->getViewport().getWidth())
- current_world->getViewport().setView(0, 0, Graphix::getWindowWidth(), Graphix::getWindowHeight());
- if (playing){
- current_world->update(deltaT);
-
- // l_interface->update(deltaT);
- }
-// else
-// l_menu->update(deltaT);
-}
-
-void Game::draw() const
-{
- if (playing){
-
- //viewPort->bindView(*i, lookat->getPosition() + vec3(0.0f, 1.0f, 0.0f));
- //SkyBox->draw();
-
- current_world->draw();
-
- // l_interface->draw();
- }
- //else
- // l_menu->draw();
-
+#include "Game.h"\r
+\r
+#include <string>\r
+\r
+#include "GLM.h"\r
+#include <Windows.h>\r
+\r
+#include <assimp/Importer.hpp>\r
+#include <assimp/scene.h>\r
+#include <assimp/postprocess.h>\r
+\r
+#include <GL\glew.h>\r
+\r
+#include "Scene.h"\r
+\r
+#include "Graphix\Shader.h"\r
+#include "Graphix\Graphix.h"\r
+#include "Graphix\Texture.h"\r
+#include "Fps.h"\r
+#include "Events.h"\r
+\r
+#include "Graphix\Model.h"\r
+\r
+#include "Message.h"\r
+\r
+//#include "PlayerI.h"\r
+\r
+#include <iostream>\r
+#include <time.h>\r
+\r
+//#define FRAMERATE_FIX 60\r
+\r
+using std::cout;\r
+using std::endl;\r
+\r
+using std::string;\r
+\r
+typedef unsigned int uint;\r
+\r
+Game::Game() : playing(true)\r
+{\r
+ srand((int)time(NULL));\r
+ // Hauptfenster\r
+ current_world = new Scene(0, 0, Graphix::getWindowWidth(), Graphix::getWindowHeight(), 45, 0.1f, 40, vec3(0.0f, 0.0f, 0.f));\r
+\r
+ //Allg Shader\r
+ Shader* shader1 = new Shader("basicTexture_VS.hlsl", "lightingTexture_FS.hlsl");\r
+\r
+ // load LVL\r
+\r
+ SceneObject* tmp_world = new Level(shader1, "level_1.dae", "model_levelTest_2D.jpg");\r
+\r
+ //tmp_world->ignore = true;\r
+ current_world->addObject(tmp_world);\r
+\r
+// current_world->addObject(new SceneObject(shader1, translate(vec3(-3.f, 1.f, 0.f)), vec4(1.0f, 1.0f, 1.0f, 3.0f), new BBox(), ""));\r
+\r
+ //Player\r
+ SceneObject* tmp_playerObject = new Marvin(shader1, translate(vec3(1.f, 3.f, 1.f))*rotate((float)M_PI_4,vec3(0.f,1.f,0.f)));\r
+\r
+ tmp_playerObject->yStatic= false;\r
+\r
+ current_world->addObject(tmp_playerObject);\r
+ current_world->setLookAt(tmp_playerObject);\r
+\r
+ //current_world->addObject(new SceneObject(shader1, glm::mat4(1.0f), "Player.dae", "model_player.png"));\r
+ //current_world->addObject(new SceneObject(shader1, translate(vec3(-3.f, .4f, 0.f))*scale(vec3(3.f)), "cow/cow.dae", "model_cow_2D.jpg"));\r
+ current_world->addObject(new SceneObject(shader1, translate(vec3(-3.f, .4f, 0.f)), vec4(3.0f, 0.5f, 0.4f, 1.5f), "duck.dae", "model_duck_2D.png"));\r
+ current_world->addObject(new SceneObject(shader1, translate(vec3(-5.f, .4f, 0.f)), vec4(3.0f, 3.f, 0.4f, 1.5f), "duck.dae", "model_duck_2D.png"));\r
+ current_world->addObject(new SceneObject(shader1, translate(vec3(0.f, .4f, 0.f)), vec4(3.0f, 3.f, 0.4f, 1.5f), "lever.dae", "model_duck_2D.png"));\r
+\r
+ current_world->addObject(new SceneObject(shader1, translate(vec3(-5.f, 3.f, 0.f)), vec4(3.0f, 3.f, 0.4f, 1.5f), "SkyBox.dae", "model_SkyBox_2D.png"));\r
+\r
+ //current_world->addObject(new EventBox(translate(vec3(3.f, .4f, 0.f)),EB_LOSTZONE));\r
+ current_world->addObject(new EventBox(translate(vec3(3.f, .4f, -15.f)), EB_WINZONE));\r
+\r
+}\r
+\r
+\r
+Game::~Game()\r
+{ \r
+ delete current_world;\r
+\r
+ //RALLLY BAD HACK!!!! No Texture will be freed!!!!\r
+ //Texture::clean();\r
+}\r
+\r
+\r
+void Game::play()\r
+{\r
+ Fps fps(0.3f);\r
+ int sleep_time=0;\r
+ float message_time=0;\r
+ int framecount = 0;\r
+\r
+ while (!Events::halt){\r
+ fps.step();\r
+\r
+#ifdef FRAMERATE_FIX\r
+ sleep_time += (int)(1000./ FRAMERATE_FIX - fps.getTicks());\r
+\r
+ if (sleep_time < 0)\r
+ sleep_time = 0;\r
+\r
+ Sleep(sleep_time);\r
+#endif\r
+ if (Events::isKToggleActive(SDLK_F2))\r
+ {\r
+ ++framecount;\r
+ message_time += fps.getDelta();\r
+ if (message_time >= 1.5)\r
+ {\r
+ Message::info((string)"Fps: " + std::to_string((float)framecount/message_time));\r
+ message_time = 0;\r
+ framecount = 0;\r
+ }\r
+\r
+ }\r
+\r
+\r
+\r
+ Events::processEvents();\r
+ //Message::info(std::to_string(fps.getDelta()));\r
+ update(fps.getCappedDelta());\r
+\r
+ Graphix::clear();\r
+\r
+ draw();\r
+\r
+ Graphix::swap();\r
+\r
+ Graphix::getGlError();\r
+\r
+// system("pause");\r
+ }\r
+}\r
+\r
+void Game::update(float deltaT)\r
+{\r
+\r
+ if (Graphix::getWindowHeight() != current_world->getViewport().getHeight() || Graphix::getWindowWidth() != current_world->getViewport().getWidth())\r
+ current_world->getViewport().setView(0, 0, Graphix::getWindowWidth(), Graphix::getWindowHeight());\r
+ if (playing){\r
+ current_world->update(deltaT);\r
+ \r
+ // l_interface->update(deltaT);\r
+ }\r
+// else\r
+// l_menu->update(deltaT);\r
+}\r
+\r
+void Game::draw() const\r
+{\r
+ if (playing){\r
+\r
+ //viewPort->bindView(*i, lookat->getPosition() + vec3(0.0f, 1.0f, 0.0f));\r
+ //SkyBox->draw();\r
+\r
+ current_world->draw();\r
+ \r
+ // l_interface->draw();\r
+ }\r
+ //else\r
+ // l_menu->draw();\r
+\r
}
\ No newline at end of file
-#include "BBox.h"
-
-#include "GL\glew.h"
-#include "../../GLM.h"
-
-
-BBox::BBox()
-{
- numvertices = 8;
-
- float vertex[] { -.5f, -.5f, -.5f, .5f, -.5f, -.5f, .5f, .5f, -.5f, -.5f, .5f, -.5f, -.5f, -.5f, .5f, .5f, -.5f, .5f, .5f, .5f, .5f, -.5f, .5f, .5f };
-
- //import("skybox.dae", numvertices, numfaces, vertex, uvs, normals, index, 0);
-
- genBuffer(vertexBuffer, numvertices * 3 * sizeof(float), (void*)vertex);
-// genBuffer(indexBuffer, 4 * sizeof(float), (void*)indexL1);
-
- bt_collision_shape = new btBoxShape(btVector3(.5f,.5f,.5f));
-
-}
-
-BBox::~BBox()
-{
- //delete bt_collision_shape; //done inside Model.cpp
-
- glDeleteBuffers(1, &vertexBuffer);
- //glDeleteBuffers(1, &indexBuffer);
- //glDeleteBuffers(1, &normalBuffer);
- //glDeleteBuffers(1, &uvBuffer);
-}
-
-
-void BBox::drawModel() const
-{
- uint indexL1[4]{ 0, 1, 2, 3 },
- indexL2[4]{ 4, 5, 6, 7},
- indexS1[8]{0, 4, 1, 5, 2, 6, 3, 7};
-
- //glDrawElements(GL_LINE_LOOP, 4, GL_UNSIGNED_INT, 0);
- glDrawElements(GL_LINE_LOOP, 4, GL_UNSIGNED_INT, indexL1);
- glDrawElements(GL_LINE_LOOP, 4, GL_UNSIGNED_INT, indexL2);
- glDrawElements(GL_LINES, 8, GL_UNSIGNED_INT, indexS1);
- glBindVertexArray(0);
-}
-
-
-BBox::operator std::string() const
-{
- return "BBox";
-}
+#include "BBox.h"\r
+\r
+#include "GL\glew.h"\r
+#include "../../GLM.h"\r
+\r
+\r
+BBox::BBox()\r
+{\r
+ numvertices = 8;\r
+\r
+ float vertex[] { -.5f, -.5f, -.5f, .5f, -.5f, -.5f, .5f, .5f, -.5f, -.5f, .5f, -.5f, -.5f, -.5f, .5f, .5f, -.5f, .5f, .5f, .5f, .5f, -.5f, .5f, .5f };\r
+\r
+ //import("skybox.dae", numvertices, numfaces, vertex, uvs, normals, index, 0);\r
+\r
+ bindModel();\r
+\r
+ name = "BBox";\r
+\r
+ bt_collision_shape = new btBoxShape(btVector3(.5f,.5f,.5f));\r
+\r
+}\r
+\r
+BBox::~BBox()\r
+{\r
+ //delete bt_collision_shape; //done inside Model.cpp\r
+}\r
+\r
+\r
+void BBox::drawModel() const\r
+{\r
+ uint indexL1[4]{ 0, 1, 2, 3 },\r
+ indexL2[4]{ 4, 5, 6, 7},\r
+ indexS1[8]{0, 4, 1, 5, 2, 6, 3, 7};\r
+\r
+ //glDrawElements(GL_LINE_LOOP, 4, GL_UNSIGNED_INT, 0);\r
+ glDrawElements(GL_LINE_LOOP, 4, GL_UNSIGNED_INT, indexL1);\r
+ glDrawElements(GL_LINE_LOOP, 4, GL_UNSIGNED_INT, indexL2);\r
+ glDrawElements(GL_LINES, 8, GL_UNSIGNED_INT, indexS1);\r
+ glBindVertexArray(0);\r
+}\r
+\r
+\r
+std::string BBox::type2str() const\r
+{\r
+ return "BBox";\r
+}\r
-#pragma once
-
-#include "Model.h"
-
-class BBox :
- public Model
-{
-public:
- BBox();
- ~BBox();
-
- void drawModel() const override;
-
- operator std::string() const override;
-};
-
+#pragma once\r
+\r
+#include "Model.h"\r
+\r
+class BBox :\r
+ public Model\r
+{\r
+public:\r
+ BBox();\r
+ ~BBox();\r
+\r
+ void drawModel() const override;\r
+\r
+ std::string type2str() const override;\r
+};\r
+\r
-#include "IMesh.h"
-
-#include <GL/glew.h>
-
-
-#include "../../GLM.h"
-
-#include <list>
-#include <array>
-
-#include "../Shader.h"
-#include "../Texture.h"
-#include "../../Message.h"
-
-#include "../Graphix.h"
-
-using std::string;
-using std::list;
-using std::array;
-
-//IMesh::IMesh(const string& _modelpath, uint _mindex) : modelpath(_modelpath), root(nullptr)
-//{
-//
-// import(_modelpath, numvertices, numfaces, vertex, uvs, normals, index, _mindex);
-//
-// btConvexHullShape* tmp_shape = new btConvexHullShape();
-//
-// for (uint i = 0; i < numvertices; i += 3)
-// tmp_shape->addPoint(btVector3(vertex[i], vertex[i + 1], vertex[i + 2]));
-//
-// bt_collision_shape = tmp_shape;
-//
-// setBB(numvertices, vertex);
-//
-// 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);
-//
-//}
-
-IMesh::IMesh(const aiMesh* _mesh, const vec3& _scale, bool _isConvex) : modelpath("IMesh")
-{
- import(_mesh, numvertices, numfaces, vertex, uvs, normals, index, _scale);
-
- btTriangleIndexVertexArray* meshInterface = new btTriangleIndexVertexArray();
- btIndexedMesh part;
- part.m_vertexBase = (const unsigned char*)vertex;
- part.m_vertexStride = sizeof(float) * 3;
- part.m_numVertices = numvertices;
- part.m_triangleIndexBase = (const unsigned char*)index;
- part.m_triangleIndexStride = sizeof(uint) * 3;
- part.m_numTriangles = numfaces;
- part.m_indexType = PHY_INTEGER;
-
- meshInterface->addIndexedMesh(part, PHY_INTEGER);
-
- if (_isConvex)
- bt_collision_shape = new btConvexTriangleMeshShape(meshInterface, true);
- else
- bt_collision_shape = new btBvhTriangleMeshShape(meshInterface, true);
-
- 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);
-
-}
-
-IMesh::~IMesh()
-{
- delete vertex, normals, uvs, index;
-
- glDeleteBuffers(1, &vertexBuffer);
- glDeleteBuffers(1, &indexBuffer);
- glDeleteBuffers(1, &normalBuffer);
- glDeleteBuffers(1, &uvBuffer);
-}
-
-//void IMesh::useModelMat(const mat4& _model, Shader* _shader) const
-//{
-// // Model::useModelMat(_model, _shader);
-// // Model::useModelMat(_model * modelMat, _shader);
-// int tmp = _shader->getUniformLocation("uModel");
-// if (tmp >= 0)
-// glUniformMatrix4fv(tmp, 1, GL_FALSE, value_ptr(_model* modelMat));
-//}
-
-
-void IMesh::drawBBox(const mat4& _modelMat, const vec4& _color) const
-{
- Model::drawBBox(_modelMat, _color);
-}
-
-
-IMesh::operator string() const
-{
- return "IMesh";
-}
+#include "IMesh.h"\r
+\r
+#include <GL/glew.h>\r
+\r
+\r
+#include "../../GLM.h"\r
+\r
+#include <list>\r
+#include <array>\r
+\r
+#include "../Shader.h"\r
+#include "../Texture.h"\r
+#include "../../Message.h"\r
+\r
+#include "../Graphix.h"\r
+\r
+using std::string;\r
+using std::list;\r
+using std::array;\r
+\r
+//IMesh::IMesh(const string& _modelpath, uint _mindex) : modelpath(_modelpath), root(nullptr)\r
+//{\r
+//\r
+// import(_modelpath, numvertices, numfaces, vertex, uvs, normals, index, _mindex);\r
+//\r
+// btConvexHullShape* tmp_shape = new btConvexHullShape();\r
+//\r
+// for (uint i = 0; i < numvertices; i += 3)\r
+// tmp_shape->addPoint(btVector3(vertex[i], vertex[i + 1], vertex[i + 2]));\r
+//\r
+// bt_collision_shape = tmp_shape;\r
+//\r
+// setBB(numvertices, vertex);\r
+//\r
+// genBuffer(vertexBuffer, numvertices * 3 * sizeof(float), (void*)vertex);\r
+// genBuffer(normalBuffer, numvertices * 3 * sizeof(float), (void*)normals);\r
+// genBuffer(uvBuffer, numvertices * 2 * sizeof(float), (void*)uvs);\r
+// genBuffer(indexBuffer, numfaces * 3 * sizeof(uint), (void*)index);\r
+//\r
+//}\r
+\r
+IMesh::IMesh(const aiMesh* _mesh, const vec3& _scale, bool _isConvex) : modelpath("IMesh")\r
+{\r
+ loadMesh(_mesh, numvertices, numfaces, vertex, uvs, normals, index, name, _scale);\r
+ btTriangleIndexVertexArray* meshInterface = new btTriangleIndexVertexArray();\r
+ btIndexedMesh part;\r
+ part.m_vertexBase = (const unsigned char*)vertex;\r
+ part.m_vertexStride = sizeof(float) * 3;\r
+ part.m_numVertices = numvertices;\r
+ part.m_triangleIndexBase = (const unsigned char*)index;\r
+ part.m_triangleIndexStride = sizeof(uint) * 3;\r
+ part.m_numTriangles = numfaces;\r
+ part.m_indexType = PHY_INTEGER;\r
+ meshInterface->addIndexedMesh(part, PHY_INTEGER);\r
+\r
+ if (_isConvex)\r
+ bt_collision_shape = new btConvexTriangleMeshShape(meshInterface, true);\r
+ else\r
+ bt_collision_shape = new btBvhTriangleMeshShape(meshInterface, true);\r
+\r
+ bindModel();\r
+\r
+\r
+}\r
+\r
+IMesh::~IMesh()\r
+{\r
+ unbindModel();\r
+}\r
+\r
+//void IMesh::useModelMat(const mat4& _model, Shader* _shader) const\r
+//{\r
+// // Model::useModelMat(_model, _shader);\r
+// // Model::useModelMat(_model * modelMat, _shader);\r
+// int tmp = _shader->getUniformLocation("uModel");\r
+// if (tmp >= 0)\r
+// glUniformMatrix4fv(tmp, 1, GL_FALSE, value_ptr(_model* modelMat));\r
+//}\r
+\r
+\r
+void IMesh::drawBBox(const mat4& _modelMat, const vec4& _color) const\r
+{\r
+ Model::drawBBox(_modelMat, _color);\r
+}\r
+\r
+\r
+string IMesh::type2str() const\r
+{\r
+ return "IMesh";\r
+}\r
-#pragma once
-
-#include <string>
-#include <list>
-#include "../../GLM.h"
-#include "../../Overlap.h"
-
-#include "Model.h"
-
-class Shader;
-class Texture;
-
-class IMesh : public Model
-{
-public:
-// class Node;
-
-// IMesh(const std::string& modelpath, uint index=0);
- IMesh(const aiMesh* mesh, const vec3& scale = vec3(1.f), bool isConvex=true);
-
- virtual ~IMesh();
-
- //void useModelMat(const mat4& model, Shader* shader) const override;
-
- void drawBBox(const mat4& modelMat, const vec4& color = vec4(0.9f, 0.f, 0.f, 1.f)) const override;
-
- operator std::string() const override;
-
-protected:
-
- std::string modelpath;
-
- float *vertex = nullptr, *normals = nullptr, *uvs = nullptr;
- uint *index = nullptr;
-
+#pragma once\r
+\r
+#include <string>\r
+#include <list>\r
+#include "../../GLM.h"\r
+#include "../../Overlap.h"\r
+\r
+#include "Model.h"\r
+\r
+class Shader;\r
+class Texture;\r
+\r
+class IMesh : public Model\r
+{\r
+public:\r
+// class Node;\r
+\r
+// IMesh(const std::string& modelpath, uint index=0);\r
+ IMesh(const aiMesh* mesh, const vec3& scale = vec3(1.f), bool isConvex=true);\r
+\r
+ virtual ~IMesh();\r
+\r
+ //void useModelMat(const mat4& model, Shader* shader) const override;\r
+\r
+ void drawBBox(const mat4& modelMat, const vec4& color = vec4(0.9f, 0.f, 0.f, 1.f)) const override;\r
+\r
+ std::string type2str() const override;\r
+\r
+protected:\r
+\r
+ std::string modelpath;\r
+\r
};
\ No newline at end of file
-#include "IMetaMesh.h"
-
-#include <assimp/Importer.hpp>
-#include <assimp/scene.h>
-#include <assimp/postprocess.h>
-
-#include "../../GLM.h"
-
-#include "IMesh.h"
-#include "IAnimMesh.h"
-#include "../Shader.h"
-#include "../../Message.h"
-
-
-using std::string;
-
-IMetaMesh::IMetaMesh(const string& _modelpath, const vec3& _scale, bool _isConvex) : modelpath(_modelpath)
-{
- Assimp::Importer importer;
-
- const aiScene* scene = importer.ReadFile("../models/" + _modelpath, aiProcess_GenUVCoords | aiProcess_Triangulate | aiProcess_JoinIdenticalVertices | aiProcess_SortByPType);
- if (!scene)
- {
- Message::error("The file " + _modelpath + " couldn't be read.\n" + importer.GetErrorString());
- return;
- }
-
- const aiNode* root = scene->mRootNode;
-
-
- if (scene->HasMeshes())// && scene->mNumMeshes > mindex)
- {
- aiMatrix4x4* aimat;
- mat4 tmpModelMat, tmpModelMatClean;
- btTransform tmpModelMatBT;
- //vec3 BBmin, BBmax, tmpMin, tmpMax;
-
- btCompoundShape* tmp_shape = new btCompoundShape();
-
- aimat = &(root->mChildren[0]->mTransformation);
-
- tmpModelMat = mat4(aimat->a1, aimat->c1, -aimat->b1, aimat->d1, aimat->a2, aimat->c2, -aimat->b2, aimat->d2, aimat->a3, aimat->c3, -aimat->b3, aimat->d3, aimat->a4, aimat->c4, -aimat->b4, aimat->d4);
- tmpModelMatClean = removeScale(tmpModelMat);
- tmpModelMatBT.setFromOpenGLMatrix(value_ptr(tmpModelMatClean));
-
-
- if (!scene->HasAnimations())
- {
-
- IMesh* tmpIMesh;
- tmpIMesh = new IMesh(scene->mMeshes[0], _scale* getScale(tmpModelMat), _isConvex);
- models.push_back(std::pair<IMesh*, mat4>(tmpIMesh, tmpModelMatClean));
- tmp_shape->addChildShape(tmpModelMatBT, *tmpIMesh);
-
- for (uint i = 1; i < scene->mNumMeshes; i++)
- {
- aimat = &(root->mChildren[i]->mTransformation);
-
- tmpModelMat = mat4(aimat->a1, aimat->c1, -aimat->b1, aimat->d1, aimat->a2, aimat->c2, -aimat->b2, aimat->d2, aimat->a3, aimat->c3, -aimat->b3, aimat->d3, aimat->a4, aimat->c4, -aimat->b4, aimat->d4);
- tmpModelMatClean = removeScale(tmpModelMat);
- tmpModelMatBT.setFromOpenGLMatrix(value_ptr(tmpModelMatClean));
- tmpIMesh = new IMesh(scene->mMeshes[i], _scale* getScale(tmpModelMat), _isConvex);
- models.push_back(std::pair<IMesh*, mat4>(tmpIMesh, tmpModelMatClean));
-
- tmp_shape->addChildShape(tmpModelMatBT, *tmpIMesh);
- }
-
- bt_collision_shape = tmp_shape;
-
- }
- else
- {
- IAnimMesh* tmpIMesh;
- tmpIMesh = new IAnimMesh(scene->mMeshes[0], _scale* getScale(tmpModelMat), _isConvex);
-
- for (uint l = 0; l < scene->mNumAnimations; l++)
- {
- aiAnimation* tmpanimation = scene->mAnimations[l];
- for (uint j = 0; j < tmpanimation->mNumChannels; j++)
- {
- if (tmpanimation->mChannels[j]->mNodeName == root->mChildren[0]->mName)
- {
- tmpIMesh->addanimation(tmpanimation->mChannels[j]);
- }
- }
- }
-
- models.push_back(std::pair<IAnimMesh*, mat4>(tmpIMesh, tmpModelMatClean));
- tmp_shape->addChildShape(tmpModelMatBT, *tmpIMesh);
-
-
-
- for (uint i = 1; i < scene->mNumMeshes; i++)
- {
- aimat = &(root->mChildren[i]->mTransformation);
-
- tmpModelMat = mat4(aimat->a1, aimat->c1, -aimat->b1, aimat->d1, aimat->a2, aimat->c2, -aimat->b2, aimat->d2, aimat->a3, aimat->c3, -aimat->b3, aimat->d3, aimat->a4, aimat->c4, -aimat->b4, aimat->d4);
- tmpModelMatClean = removeScale(tmpModelMat);
- tmpModelMatBT.setFromOpenGLMatrix(value_ptr(tmpModelMatClean));
- tmpIMesh = new IAnimMesh(scene->mMeshes[i], _scale* getScale(tmpModelMat), _isConvex);
-
- for (uint l = 0; l < scene->mNumAnimations; l++)
- {
- aiAnimation* tmpanimation = scene->mAnimations[l];
- for (uint j = 0; j < tmpanimation->mNumChannels; j++)
- {
- if (tmpanimation->mChannels[j]->mNodeName == root->mChildren[i]->mName)
- {
- tmpIMesh->addanimation(tmpanimation->mChannels[j]);
- }
- }
- }
-
- models.push_back(std::pair<IAnimMesh*, mat4>(tmpIMesh, tmpModelMatClean));
- tmp_shape->addChildShape(tmpModelMatBT, *tmpIMesh);
- }
-
- bt_collision_shape = tmp_shape;
- }
- }
- else
- {
- Message::error("The file " + _modelpath + " doesn't contain any nodes.");
- return;
- }
-}
-
-IMetaMesh::~IMetaMesh()
-{
- for (auto i = models.begin(); i != models.end(); ++i)
- {
- delete i->first;
- }
-}
-
-void IMetaMesh::bindShader(Shader* _shader)
-{
- for (auto i = models.begin(); i != models.end(); ++i)
- {
- i->first->bindShader(_shader);
- }
-}
-
-void IMetaMesh::drawModel(Shader* _shader, Texture* _texture, const mat4& _modelMat) const
-{
- for (auto i = models.begin(); i != models.end(); ++i)
- {
- i->first->drawModel(_shader, _texture, _modelMat* i->second);
- }
-}
-
-
-void IMetaMesh::drawBBox(const mat4& _modelMat, const vec4& _color) const
-{
- // Model::drawBBox(_modelMat, vec4(0.f,.3f,.9f,1.f));
- if (models.size() == 1)
- {
- auto i = models.front();
- i.first->drawBBox(_modelMat* i.second, _color);
- }
- else
- {
- Model::drawBBox(_modelMat, _color);
- if (models.size() > 1)
- {
- for (auto i = models.begin(); i != models.end(); ++i)
- {
- i->first->drawBBox(_modelMat* i->second, _color*0.8f);
- }
- }
- }
-}
-
-
-IMetaMesh::operator string() const
-{
- return modelpath;
-}
-
-void IMetaMesh::setMargin(btScalar _margin)
-{
- for (auto i = models.begin(); i != models.end(); ++i)
- {
- i->first->setMargin(_margin);
- }
+#include "IMetaMesh.h"\r
+\r
+#include <assimp/Importer.hpp>\r
+#include <assimp/scene.h>\r
+#include <assimp/postprocess.h>\r
+\r
+#include "../../GLM.h"\r
+\r
+#include "IMesh.h"\r
+#include "IAnimMesh.h"\r
+#include "../Shader.h"\r
+#include "../../Message.h"\r
+\r
+\r
+using std::string;\r
+\r
+IMetaMesh::IMetaMesh(const string& _modelpath, const vec3& _scale, bool _isConvex) : modelpath(_modelpath)\r
+{\r
+ Assimp::Importer importer;\r
+\r
+ const aiScene* scene = importer.ReadFile("../models/" + _modelpath, aiProcess_GenUVCoords | aiProcess_Triangulate | aiProcess_JoinIdenticalVertices | aiProcess_SortByPType);\r
+ if (!scene)\r
+ {\r
+ Message::error("The file " + _modelpath + " couldn't be read.\n" + importer.GetErrorString());\r
+ return;\r
+ }\r
+\r
+ const aiNode* root = scene->mRootNode;\r
+\r
+\r
+ if (scene->HasMeshes())// && scene->mNumMeshes > mindex)\r
+ {\r
+ aiMatrix4x4* aimat;\r
+ mat4 tmpModelMat, tmpModelMatClean;\r
+ btTransform tmpModelMatBT;\r
+ //vec3 BBmin, BBmax, tmpMin, tmpMax;\r
+\r
+ btCompoundShape* tmp_shape = new btCompoundShape();\r
+\r
+ aimat = &(root->mChildren[0]->mTransformation);\r
+\r
+ tmpModelMat = mat4(aimat->a1, aimat->c1, -aimat->b1, aimat->d1, aimat->a2, aimat->c2, -aimat->b2, aimat->d2, aimat->a3, aimat->c3, -aimat->b3, aimat->d3, aimat->a4, aimat->c4, -aimat->b4, aimat->d4);\r
+ tmpModelMatClean = removeScale(tmpModelMat);\r
+ tmpModelMatBT.setFromOpenGLMatrix(value_ptr(tmpModelMatClean));\r
+\r
+\r
+ //if (!scene->HasAnimations())\r
+ {\r
+\r
+ IMesh* tmpIMesh;\r
+ tmpIMesh = new IMesh(scene->mMeshes[0], _scale* getScale(tmpModelMat), _isConvex);\r
+ models.push_back(std::pair<IMesh*, mat4>(tmpIMesh, tmpModelMatClean));\r
+ tmp_shape->addChildShape(tmpModelMatBT, *tmpIMesh);\r
+\r
+ for (uint i = 1; i < scene->mNumMeshes; i++)\r
+ {\r
+ aimat = &(root->mChildren[i]->mTransformation);\r
+\r
+ tmpModelMat = mat4(aimat->a1, aimat->c1, -aimat->b1, aimat->d1, aimat->a2, aimat->c2, -aimat->b2, aimat->d2, aimat->a3, aimat->c3, -aimat->b3, aimat->d3, aimat->a4, aimat->c4, -aimat->b4, aimat->d4);\r
+ tmpModelMatClean = removeScale(tmpModelMat);\r
+ tmpModelMatBT.setFromOpenGLMatrix(value_ptr(tmpModelMatClean));\r
+ tmpIMesh = new IMesh(scene->mMeshes[i], _scale* getScale(tmpModelMat), _isConvex);\r
+ models.push_back(std::pair<IMesh*, mat4>(tmpIMesh, tmpModelMatClean));\r
+\r
+ tmp_shape->addChildShape(tmpModelMatBT, *tmpIMesh);\r
+ }\r
+\r
+ bt_collision_shape = tmp_shape;\r
+\r
+ }\r
+ /*\r
+ else\r
+ {\r
+ IAnimMesh* tmpIMesh;\r
+ tmpIMesh = new IAnimMesh(scene->mMeshes[0], _scale* getScale(tmpModelMat), _isConvex);\r
+\r
+ for (uint l = 0; l < scene->mNumAnimations; l++)\r
+ {\r
+ aiAnimation* tmpanimation = scene->mAnimations[l];\r
+ for (uint j = 0; j < tmpanimation->mNumChannels; j++)\r
+ {\r
+ if (tmpanimation->mChannels[j]->mNodeName == root->mChildren[0]->mName)\r
+ {\r
+ tmpIMesh->addanimation(tmpanimation->mChannels[j]);\r
+ }\r
+ }\r
+ }\r
+\r
+ models.push_back(std::pair<IAnimMesh*, mat4>(tmpIMesh, tmpModelMatClean));\r
+ tmp_shape->addChildShape(tmpModelMatBT, *tmpIMesh);\r
+\r
+\r
+\r
+ for (uint i = 1; i < scene->mNumMeshes; i++)\r
+ {\r
+ aimat = &(root->mChildren[i]->mTransformation);\r
+\r
+ tmpModelMat = mat4(aimat->a1, aimat->c1, -aimat->b1, aimat->d1, aimat->a2, aimat->c2, -aimat->b2, aimat->d2, aimat->a3, aimat->c3, -aimat->b3, aimat->d3, aimat->a4, aimat->c4, -aimat->b4, aimat->d4);\r
+ tmpModelMatClean = removeScale(tmpModelMat);\r
+ tmpModelMatBT.setFromOpenGLMatrix(value_ptr(tmpModelMatClean));\r
+ tmpIMesh = new IAnimMesh(scene->mMeshes[i], _scale* getScale(tmpModelMat), _isConvex);\r
+\r
+ for (uint l = 0; l < scene->mNumAnimations; l++)\r
+ {\r
+ aiAnimation* tmpanimation = scene->mAnimations[l];\r
+ for (uint j = 0; j < tmpanimation->mNumChannels; j++)\r
+ {\r
+ if (tmpanimation->mChannels[j]->mNodeName == root->mChildren[i]->mName)\r
+ {\r
+ tmpIMesh->addanimation(tmpanimation->mChannels[j]);\r
+ }\r
+ }\r
+ }\r
+\r
+ models.push_back(std::pair<IAnimMesh*, mat4>(tmpIMesh, tmpModelMatClean));\r
+ tmp_shape->addChildShape(tmpModelMatBT, *tmpIMesh);\r
+ }\r
+\r
+ bt_collision_shape = tmp_shape;\r
+ }*/\r
+ }\r
+ else\r
+ {\r
+ Message::error("The file " + _modelpath + " doesn't contain any nodes.");\r
+ return;\r
+ }\r
+}\r
+\r
+IMetaMesh::~IMetaMesh()\r
+{\r
+ for (auto i = models.begin(); i != models.end(); ++i)\r
+ {\r
+ delete i->first;\r
+ }\r
+}\r
+\r
+void IMetaMesh::bindModel()\r
+{\r
+ for (auto i = models.begin(); i != models.end(); ++i)\r
+ {\r
+ i->first->bindModel();\r
+ }\r
+}\r
+\r
+void IMetaMesh::unbindModel()\r
+{\r
+ for (auto i = models.begin(); i != models.end(); ++i)\r
+ {\r
+ i->first->unbindModel();\r
+ }\r
+}\r
+\r
+void IMetaMesh::bindShader(Shader* _shader)\r
+{\r
+ for (auto i = models.begin(); i != models.end(); ++i)\r
+ {\r
+ i->first->bindShader(_shader);\r
+ }\r
+}\r
+\r
+void IMetaMesh::unbindShader(Shader* _shader)\r
+{\r
+ for (auto i = models.begin(); i != models.end(); ++i)\r
+ {\r
+ i->first->unbindShader(_shader);\r
+ }\r
+}\r
+\r
+void IMetaMesh::drawModel(Shader* _shader, Texture* _texture, const mat4& _modelMat) const\r
+{\r
+ for (auto i = models.begin(); i != models.end(); ++i)\r
+ {\r
+ i->first->drawModel(_shader, _texture, _modelMat* i->second);\r
+ }\r
+}\r
+\r
+\r
+void IMetaMesh::drawBBox(const mat4& _modelMat, const vec4& _color) const\r
+{\r
+ // Model::drawBBox(_modelMat, vec4(0.f,.3f,.9f,1.f));\r
+ if (models.size() == 1)\r
+ {\r
+ auto i = models.front();\r
+ i.first->drawBBox(_modelMat* i.second, _color);\r
+ }\r
+ else\r
+ {\r
+ Model::drawBBox(_modelMat, _color);\r
+ if (models.size() > 1)\r
+ {\r
+ for (auto i = models.begin(); i != models.end(); ++i)\r
+ {\r
+ i->first->drawBBox(_modelMat* i->second, _color*0.8f);\r
+ }\r
+ }\r
+ }\r
+}\r
+\r
+\r
+string IMetaMesh::type2str() const\r
+{\r
+ return "IMetaMesh";\r
+}\r
+\r
+void IMetaMesh::setMargin(btScalar _margin)\r
+{\r
+ for (auto i = models.begin(); i != models.end(); ++i)\r
+ {\r
+ i->first->setMargin(_margin);\r
+ }\r
}
\ No newline at end of file
-#pragma once
-
-#include "Model.h"
-
-#include <string>
-#include <list>
-#include "../../GLM.h"
-#include "../../Overlap.h"
-
-class IMesh;
-class Shader;
-class Texture;
-
-class IMetaMesh : public Model
-{
-public:
- IMetaMesh(const std::string& modelpath, const vec3& scale = vec3(1.f), bool isConvex = true);
- ~IMetaMesh();
-
- void bindShader(Shader* shader) override;
-
- void drawModel(Shader* shader, Texture* texture, const mat4& modelMat) const override;
-
- void drawBBox(const mat4& modelMat, const vec4& color = vec4(0.9f, 0.f, 0.f, 1.f)) const override;
-
- operator std::string() const override;
-
- void setMargin(btScalar margin) override;
-
-protected:
-
- std::string modelpath;
- //std::list<IMesh*> models;
- std::list<std::pair<IMesh*, mat4>> models;
-};
-
+#pragma once\r
+\r
+#include "Model.h"\r
+\r
+#include <string>\r
+#include <list>\r
+#include "../../GLM.h"\r
+#include "../../Overlap.h"\r
+\r
+class IMesh;\r
+class Shader;\r
+class Texture;\r
+\r
+class IMetaMesh : public Model\r
+{\r
+public:\r
+ IMetaMesh(const std::string& modelpath, const vec3& scale = vec3(1.f), bool isConvex = true);\r
+ ~IMetaMesh();\r
+\r
+ void bindShader(Shader* shader) override;\r
+\r
+ void bindModel() override;\r
+\r
+ void unbindModel() override;\r
+ void unbindShader(Shader* shader) override;\r
+\r
+ void drawModel(Shader* shader, Texture* texture, const mat4& modelMat) const override;\r
+\r
+ void drawBBox(const mat4& modelMat, const vec4& color = vec4(0.9f, 0.f, 0.f, 1.f)) const override;\r
+\r
+ std::string type2str() const override;\r
+\r
+ void setMargin(btScalar margin) override;\r
+\r
+protected:\r
+\r
+ std::string modelpath;\r
+ //std::list<IMesh*> models;\r
+ std::list<std::pair<IMesh*, mat4>> models;\r
+};\r
+\r
-#include "Model.h"
-
-#include <GL/glew.h>
-#include "../../Message.h"
-
-#include "../Shader.h"
-#include "../Texture.h"
-
-#include "../Graphix.h"
-
-#include <assimp/Importer.hpp>
-#include <assimp/scene.h>
-#include <assimp/postprocess.h>
-
-#include "BBox.h"
-#include "SkyBox.h"
-#include "IMetaMesh.h"
-
-#include "../../Events.h"
-
-Model::Model() :
-numfaces(0),
-numvertices(0),
-vertexBuffer(-1),
-normalBuffer(-1),
-uvBuffer(-1),
-indexBuffer(-1),
-bt_collision_shape(nullptr)
-{
-}
-
-Model::~Model()
-{
- if (bt_collision_shape!=nullptr)
- delete bt_collision_shape;
- for (auto i = shader_map.begin(); i != shader_map.end(); ++i){
- glDeleteVertexArrays(1, &(i->second));
- }
-}
-
-
-void Model::bindShader(Shader* _shader)
-{
- //Message::info("bindShader");
- //Graphix::getGlError();
- //Message::info("Do Stuff");
-
- uint vao;
- glGenVertexArrays(1, &vao);
- glBindVertexArray(vao);
-
- //Message::info("bindVAO");
- //Graphix::getGlError();
- 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();
-
- if (indexBuffer != (uint)-1)
- 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() const
-{
- if (Events::isKToggleActive(SDLK_F3))
- glDrawElements(GL_LINE_LOOP, numfaces * 3, GL_UNSIGNED_INT, 0);
- else
- glDrawElements(GL_TRIANGLES, numfaces * 3, GL_UNSIGNED_INT, 0);
- glBindVertexArray(0);
-}
-
-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();
- drawModel();
- //Message::info("IMesh drawing Elements");
- //Graphix::getGlError();
- //system("pause");
-}
-
-void Model::drawBBox(const mat4& _modelMat, const vec4& _color) const
-{
- Graphix::getGlError();
- Graphix::shader_BBox->useShader();
- int tmp = Graphix::shader_BBox->getUniformLocation("uFragmentColor");
- if (tmp >= 0)
- glUniform4fv(tmp, 1, value_ptr(_color));
- Graphix::getGlError();
-
- btVector3 minB, maxB;
- btTransform trans;
- trans.setIdentity();
- bt_collision_shape->getAabb(trans, minB, maxB);
-
- vec3 min = vec3(minB.getX(), minB.getY(), minB.getZ());
- vec3 max = vec3(maxB.getX(), maxB.getY(), maxB.getZ());
-
- vec3 size = (max - min);
- vec3 center = (max + min) * .5f;
-
- getBBoxModel()->drawModel(Graphix::shader_BBox, NULL, _modelMat*translate(center)*glm::scale(size)); //
-}
-
-void Model::getBBcs(vec3& _center, vec3& _size) const
-{
- btVector3 minB, maxB;
- btTransform trans;
- trans.setIdentity();
- bt_collision_shape->getAabb(trans, minB, maxB);
-
- vec3 min = vec3(minB.getX(), minB.getY(), minB.getZ());
- vec3 max = vec3(maxB.getX(), maxB.getY(), maxB.getZ());
-
- _size = (max - min) * .5f;
- _center = (max + min) * .5f;
-}
-
-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);
-
- int tmp2 = _shader->getUniformLocation("material");
- if (tmp2 >= 0)
- glUniform4fv(tmp2, 1, value_ptr(_texture->material));
- }
-}
-
-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));
-}
-
-Model::operator btCollisionShape*() const
-{
- return bt_collision_shape;
-}
-
-vec3 Model::rotateSize(const vec3& _size, const mat4& _modelMat)
-{
- vec3 newSize(0.f);
- mat3 tmpModelMat(_modelMat);
- for (auto i = 0; i < 3; ++i)
- newSize += abs(tmpModelMat[i]) * _size[i];
- return newSize;
-}
-
-float Model::directSize(const vec3& _size, const vec3& _direction)
-{
- float ret(0.f);
- for (auto i = 0; i < 3; ++i)
- {
- ret += abs(_size[i]*_direction[i]);
- }
- return ret;
-}
-
-Model* Model::getBBoxModel()
-{
- if (BoundingBox == nullptr)
- {
- BoundingBox = new BBox();
- BoundingBox->bindShader(Graphix::shader_BBox);
- }
- return BoundingBox;
-}
-
-Model* Model::getSkyBoxModel()
-{
- if (SkyBoxModel == nullptr)
- {
- SkyBoxModel = new SkyBox();
- //SkyBoxModel->bindShader(Graphix::shader_);
- }
- return SkyBoxModel;
-}
-
-Model* Model::newIMetaModel(const string& _modelpath, bool _isConvex)
-{
- Model*& ptr = IMetaModel[_modelpath];
- if (ptr == nullptr)
- {
- ptr = new IMetaMesh(_modelpath,vec3(1.f),_isConvex);
- //ptr->bindShader(Graphix::shader_BBox);
- }
- ++IMetaModel_count[_modelpath];
- return ptr;
-}
-
-void Model::deleteBBoxModel()
-{
- delete BoundingBox;
- BoundingBox = nullptr;
-}
-
-void Model::deleteSkyBoxModel()
-{
- delete SkyBoxModel;
- SkyBoxModel = nullptr;
-}
-
-void Model::deleteIMetaModel(const string& _modelpath)
-{
- if (_modelpath == "SkyBox" || _modelpath == "BBox" || _modelpath == "IMesh")
- {
- Message::warning("deleteIMetaModel: dont use deleteIMetaModel with " + _modelpath);
- return;
- }
-
- uint& count = IMetaModel_count[_modelpath];
- --count;
-
- if (!count)
- {
- Model*& ptr = IMetaModel[_modelpath];
- delete ptr;
- ptr = nullptr;
- }
-
-
-}
-
-
-float Model::getPDistHit(const vec3& _P, const vec3& _direction) const
-{
-
- vec3 posA, sizeA;
- getBBcs(posA, sizeA);
-
- //vec3 posAR = (vec3)(modelAR*vec4(posA, 1.f));
- //vec3 posBR = (vec3)(modelBR*vec4(posB, 1.f));
-
-
- return 1;
-}
-
-
-bool Model::import(const string& _modelpath, uint& numvertices, uint& numfaces, float*& vertex, float*& uvs, float*& normals, uint*& index, uint _mindex)
-{
- Assimp::Importer importer;
-
- const aiScene* scene = importer.ReadFile("../models/" + _modelpath, aiProcess_GenUVCoords | aiProcess_Triangulate | aiProcess_JoinIdenticalVertices | aiProcess_SortByPType); //aiProcess_PreTransformVertices
- if (!scene)
- {
- Message::error("The file " + _modelpath + " couldn't be read.\n" + importer.GetErrorString());
- return false;
- }
-
- if (!scene->HasMeshes() || scene->mNumMeshes <= _mindex)
- {
- Message::error("The file " + _modelpath + " doesn't contain any nodes.");
- return false;
- }
-
- return import(scene->mMeshes[_mindex], numvertices, numfaces, vertex, uvs, normals, index);
-}
-
-bool Model::import(const aiMesh* mesh, uint& numvertices, uint& numfaces, float*& vertex, float*& uvs, float*& normals, uint*& index, const vec3& _scale)
-{
-
- numvertices = mesh->mNumVertices;
- numfaces = mesh->mNumFaces;
- vertex = new float[numvertices * 3];
- uvs = new float[numvertices * 2];
- index = new uint[numfaces * 3];
- normals = new float[numvertices * 3];
- //aiFace* faces = mesh->mFaces;
-
-
- //load vertices from Mesh
- for (uint i = 0; i < numvertices; i++)
- {
- vertex[3 * i] = _scale.x * mesh->mVertices[i].x;
- vertex[3 * i + 1] = _scale.y * mesh->mVertices[i].y;
- vertex[3 * i + 2] = _scale.z * mesh->mVertices[i].z;
- }
-
- //load UVs from Mesh
- for (uint i = 0; i < numvertices; i++)
- {
- uvs[2 * i] = mesh->mTextureCoords[0][i].x;//[i]->x;
- uvs[2 * i + 1] = mesh->mTextureCoords[0][i].y;//[i]->y;
- }
-
- //load indices from Mesh
- for (uint i = 0; i < numfaces; i++)
- {
- index[3 * i] = mesh->mFaces[i].mIndices[0];
- index[3 * i + 1] = mesh->mFaces[i].mIndices[1];
- index[3 * i + 2] = mesh->mFaces[i].mIndices[2];
- }
-
- //load normals from Mesh
- for (uint i = 0; i < numvertices; i++)
- {
- normals[3 * i] = mesh->mNormals[i].x;// / _scale.x;
- normals[3 * i + 1] = mesh->mNormals[i].y;// / _scale.y;
- normals[3 * i + 2] = mesh->mNormals[i].z;// / _scale.z;
- }
-
- return true;
-}
-
-void Model::setMargin(btScalar _margin)
-{
- bt_collision_shape->setMargin(_margin);
-}
-
-
-Model* Model::BoundingBox = nullptr;
-Model* Model::SkyBoxModel = nullptr;
-std::unordered_map<string, Model*> Model::IMetaModel;
-std::unordered_map<string, uint> Model::IMetaModel_count;
+#include "Model.h"\r
+\r
+#include <GL/glew.h>\r
+#include "../../Message.h"\r
+\r
+#include "../Shader.h"\r
+#include "../Texture.h"\r
+\r
+#include "../Graphix.h"\r
+\r
+#include <assimp/Importer.hpp>\r
+#include <assimp/scene.h>\r
+#include <assimp/postprocess.h>\r
+\r
+#include "BBox.h"\r
+#include "SkyBox.h"\r
+#include "IMetaMesh.h"\r
+\r
+#include "../../Events.h"\r
+\r
+using namespace std;\r
+\r
+Model::Model() :\r
+numfaces(0),\r
+numvertices(0),\r
+vertexBuffer(-1),\r
+normalBuffer(-1),\r
+uvBuffer(-1),\r
+indexBuffer(-1),\r
+bt_collision_shape(nullptr)\r
+{\r
+}\r
+\r
+Model::~Model()\r
+{\r
+ if (bt_collision_shape!=nullptr)\r
+ delete bt_collision_shape;\r
+ for (auto i = shader_map.begin(); i != shader_map.end(); ++i) {\r
+ glDeleteVertexArrays(1, &(i->second));\r
+ }\r
+}\r
+\r
+\r
+Model::operator std::string() const\r
+{\r
+ return name;\r
+}\r
+\r
+void Model::bindModel()\r
+{\r
+ if(vertex!=nullptr)\r
+ genBuffer(vertexBuffer, numvertices * 3 * sizeof(float), (void*)vertex);\r
+ if (normals != nullptr)\r
+ genBuffer(normalBuffer, numvertices * 3 * sizeof(float), (void*)normals);\r
+ if (uvs != nullptr)\r
+ genBuffer(uvBuffer, numvertices * 2 * sizeof(float), (void*)uvs);\r
+ if (index != nullptr)\r
+ genBuffer(indexBuffer, numfaces * 3 * sizeof(uint), (void*)index);\r
+}\r
+\r
+void Model::unbindModel()\r
+{\r
+ if(vertexBuffer!= (uint)-1)\r
+ glDeleteBuffers(1, &vertexBuffer);\r
+ if (indexBuffer != (uint)-1)\r
+ glDeleteBuffers(1, &indexBuffer);\r
+ if (normalBuffer != (uint)-1)\r
+ glDeleteBuffers(1, &normalBuffer);\r
+ if (uvBuffer != (uint)-1)\r
+ glDeleteBuffers(1, &uvBuffer);\r
+}\r
+\r
+\r
+void Model::bindShader(Shader* _shader)\r
+{\r
+\r
+ uint vao;\r
+ glGenVertexArrays(1, &vao);\r
+ glBindVertexArray(vao);\r
+\r
+\r
+ if (vertexBuffer != (uint)-1)\r
+ bindBuffer(vertexBuffer, _shader->getAttribLocation("aPosition"));\r
+\r
+ if (uvBuffer != (uint)-1)\r
+ bindBuffer(uvBuffer, _shader->getAttribLocation("aUV"), 2);\r
+\r
+ if (normalBuffer != (uint)-1)\r
+ bindBuffer(normalBuffer, _shader->getAttribLocation("aNormal"));\r
+\r
+ if (indexBuffer != (uint)-1)\r
+ glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, indexBuffer);\r
+\r
+ shader_map[*_shader] = vao;\r
+\r
+ glBindVertexArray(0);\r
+\r
+ glBindBuffer(GL_ARRAY_BUFFER, 0);\r
+ glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);\r
+\r
+}\r
+\r
+void Model::unbindShader(Shader* _shader)\r
+{\r
+ glDeleteVertexArrays(1, &(shader_map[*_shader]));\r
+ shader_map.erase(*_shader);\r
+ \r
+}\r
+\r
+void Model::drawModel() const\r
+{\r
+ if (Events::isKToggleActive(SDLK_F3))\r
+ glDrawElements(GL_LINE_LOOP, numfaces * 3, GL_UNSIGNED_INT, 0);\r
+ else\r
+ glDrawElements(GL_TRIANGLES, numfaces * 3, GL_UNSIGNED_INT, 0);\r
+ glBindVertexArray(0);\r
+}\r
+\r
+void Model::drawModel(Shader* _shader, Texture* _texture, const mat4& _modelMat) const\r
+{\r
+ //Message::info("Error from before?");\r
+ //Graphix::getGlError();\r
+ useModel(_shader);\r
+ //Message::info("IMesh loading Coordinates");\r
+ //Graphix::getGlError();\r
+ useTexture(_texture, _shader);\r
+ //Message::info("IMesh loading Texture");\r
+ //Graphix::getGlError();\r
+ useModelMat(_modelMat, _shader);\r
+ //Message::info("IMesh loading MMatrix");\r
+ //Graphix::getGlError();\r
+ drawModel();\r
+ //Message::info("IMesh drawing Elements");\r
+ //Graphix::getGlError();\r
+ //system("pause");\r
+}\r
+\r
+void Model::drawBBox(const mat4& _modelMat, const vec4& _color) const\r
+{\r
+ Graphix::getGlError();\r
+ Graphix::shader_BBox->useShader();\r
+ int tmp = Graphix::shader_BBox->getUniformLocation("uFragmentColor");\r
+ if (tmp >= 0)\r
+ glUniform4fv(tmp, 1, value_ptr(_color));\r
+ Graphix::getGlError();\r
+\r
+ btVector3 minB, maxB;\r
+ btTransform trans;\r
+ trans.setIdentity();\r
+ bt_collision_shape->getAabb(trans, minB, maxB);\r
+\r
+ vec3 min = vec3(minB.getX(), minB.getY(), minB.getZ());\r
+ vec3 max = vec3(maxB.getX(), maxB.getY(), maxB.getZ());\r
+\r
+ vec3 size = (max - min);\r
+ vec3 center = (max + min) * .5f;\r
+\r
+ getBBoxModel()->drawModel(Graphix::shader_BBox, NULL, _modelMat*translate(center)*glm::scale(size)); //\r
+}\r
+\r
+void Model::getBBcs(vec3& _center, vec3& _size) const\r
+{\r
+ btVector3 minB, maxB;\r
+ btTransform trans;\r
+ trans.setIdentity();\r
+ bt_collision_shape->getAabb(trans, minB, maxB);\r
+\r
+ vec3 min = vec3(minB.getX(), minB.getY(), minB.getZ());\r
+ vec3 max = vec3(maxB.getX(), maxB.getY(), maxB.getZ());\r
+\r
+ _size = (max - min) * .5f;\r
+ _center = (max + min) * .5f;\r
+}\r
+\r
+void Model::genBuffer(uint &buffer, uint size, void* value)\r
+{\r
+ glGenBuffers(1, &buffer);\r
+ glBindBuffer(GL_ARRAY_BUFFER, buffer);\r
+ glBufferData(GL_ARRAY_BUFFER, size, value, GL_STATIC_DRAW);\r
+ glBindBuffer(GL_ARRAY_BUFFER, 0);\r
+}\r
+\r
+void Model::bindBuffer(const uint &buffer, const uint index, const uint dim)\r
+{\r
+ //Falls index nicht gefunden werden konnte\r
+ if (index == (uint)-1)\r
+ {\r
+ Message::info("Model: BindBuffer wird ausgelassen da index fehlerhaft ist.");\r
+ return;\r
+ }\r
+\r
+ glBindBuffer(GL_ARRAY_BUFFER, buffer);\r
+ glEnableVertexAttribArray(index);\r
+ glVertexAttribPointer(index, dim, GL_FLOAT, GL_FALSE, 0, 0);\r
+ glBindBuffer(GL_ARRAY_BUFFER, 0);\r
+}\r
+\r
+\r
+void Model::useModel(Shader* _shader) const\r
+{\r
+ _shader->useShader();\r
+ uint vao = -1;\r
+ auto i = shader_map.find(*_shader);\r
+ if (i == shader_map.end())\r
+ Message::error("Model: Shader wurde nicht an das Model gebunden.");\r
+ else\r
+ vao = i->second;\r
+\r
+ glBindVertexArray(vao);\r
+\r
+}\r
+\r
+void Model::useTexture(Texture* _texture, Shader* _shader) const\r
+{\r
+ if (_texture != nullptr)\r
+ {\r
+ auto tmp = _shader->getUniformLocation("uColorTexture");\r
+ if (tmp < 0){\r
+ return;\r
+ }\r
+ int unit = 0;\r
+ _texture->bind(unit);\r
+ glUniform1i(tmp, unit);\r
+\r
+ int tmp2 = _shader->getUniformLocation("material");\r
+ if (tmp2 >= 0)\r
+ glUniform4fv(tmp2, 1, value_ptr(_texture->material));\r
+ }\r
+}\r
+\r
+void Model::useModelMat(const mat4& _model, Shader* _shader) const\r
+{\r
+ int tmp = _shader->getUniformLocation("uModel");\r
+ if (tmp >= 0)\r
+ glUniformMatrix4fv(tmp, 1, GL_FALSE, value_ptr(_model));\r
+}\r
+\r
+Model::operator btCollisionShape*() const\r
+{\r
+ return bt_collision_shape;\r
+}\r
+\r
+vec3 Model::rotateSize(const vec3& _size, const mat4& _modelMat)\r
+{\r
+ vec3 newSize(0.f);\r
+ mat3 tmpModelMat(_modelMat);\r
+ for (auto i = 0; i < 3; ++i)\r
+ newSize += abs(tmpModelMat[i]) * _size[i];\r
+ return newSize;\r
+}\r
+\r
+float Model::directSize(const vec3& _size, const vec3& _direction)\r
+{\r
+ float ret(0.f);\r
+ for (auto i = 0; i < 3; ++i)\r
+ {\r
+ ret += abs(_size[i]*_direction[i]);\r
+ }\r
+ return ret;\r
+}\r
+\r
+Model* Model::getBBoxModel()\r
+{\r
+ if (BoundingBox == nullptr)\r
+ {\r
+ BoundingBox = new BBox();\r
+ BoundingBox->bindShader(Graphix::shader_BBox);\r
+ }\r
+ return BoundingBox;\r
+}\r
+\r
+Model* Model::getSkyBoxModel()\r
+{\r
+ if (SkyBoxModel == nullptr)\r
+ {\r
+ SkyBoxModel = new SkyBox();\r
+ //SkyBoxModel->bindShader(Graphix::shader_);\r
+ }\r
+ return SkyBoxModel;\r
+}\r
+\r
+Model* Model::newIMetaModel(const string& _modelpath, bool _isConvex)\r
+{\r
+ Model*& ptr = IMetaModel[_modelpath];\r
+ if (ptr == nullptr)\r
+ {\r
+ ptr = new IMetaMesh(_modelpath,vec3(1.f),_isConvex);\r
+ //ptr->bindShader(Graphix::shader_BBox);\r
+ }\r
+ ++IMetaModel_count[_modelpath];\r
+ return ptr;\r
+}\r
+\r
+void Model::deleteBBoxModel()\r
+{\r
+ delete BoundingBox;\r
+ BoundingBox = nullptr;\r
+}\r
+\r
+void Model::deleteSkyBoxModel()\r
+{\r
+ delete SkyBoxModel;\r
+ SkyBoxModel = nullptr;\r
+}\r
+\r
+void Model::deleteIMetaModel(const string& _modelpath)\r
+{\r
+ if (_modelpath == "SkyBox" || _modelpath == "BBox" || _modelpath == "IMesh")\r
+ {\r
+ Message::warning("deleteIMetaModel: dont use deleteIMetaModel with " + _modelpath);\r
+ return;\r
+ }\r
+\r
+ uint& count = IMetaModel_count[_modelpath];\r
+ --count;\r
+\r
+ if (!count)\r
+ {\r
+ Model*& ptr = IMetaModel[_modelpath];\r
+ delete ptr;\r
+ ptr = nullptr;\r
+ }\r
+\r
+\r
+}\r
+\r
+\r
+float Model::getPDistHit(const vec3& _P, const vec3& _direction) const\r
+{\r
+\r
+ vec3 posA, sizeA;\r
+ getBBcs(posA, sizeA);\r
+\r
+ //vec3 posAR = (vec3)(modelAR*vec4(posA, 1.f));\r
+ //vec3 posBR = (vec3)(modelBR*vec4(posB, 1.f));\r
+\r
+\r
+ return 1;\r
+}\r
+\r
+\r
+bool Model::loadMesh(const string& _modelpath, uint& numvertices, uint& numfaces, float*& vertex, float*& uvs, float*& normals, uint*& index, string& name, uint _mindex)\r
+{\r
+ Assimp::Importer importer;\r
+\r
+ const aiScene* scene = importer.ReadFile("../models/" + _modelpath, aiProcess_GenUVCoords | aiProcess_Triangulate | aiProcess_JoinIdenticalVertices | aiProcess_SortByPType); //aiProcess_PreTransformVertices\r
+ if (!scene)\r
+ {\r
+ Message::error("The file " + _modelpath + " couldn't be read.\n" + importer.GetErrorString());\r
+ return false;\r
+ }\r
+\r
+ if (!scene->HasMeshes() || scene->mNumMeshes <= _mindex)\r
+ {\r
+ Message::error("The file " + _modelpath + " doesn't contain any nodes.");\r
+ return false;\r
+ }\r
+\r
+ return loadMesh(scene->mMeshes[_mindex], numvertices, numfaces, vertex, uvs, normals, index, name);\r
+}\r
+\r
+bool Model::loadMesh(const aiMesh* mesh, uint& numvertices, uint& numfaces, float*& vertex, float*& uvs, float*& normals, uint*& index, string& name, const vec3& _scale)\r
+{\r
+\r
+ name = std::string((char*) (mesh->mName.data),(uint) (mesh->mName.length));\r
+ numvertices = mesh->mNumVertices;\r
+ numfaces = mesh->mNumFaces;\r
+ vertex = new float[numvertices * 3];\r
+ uvs = new float[numvertices * 2];\r
+ index = new uint[numfaces * 3];\r
+ normals = new float[numvertices * 3];\r
+ //aiFace* faces = mesh->mFaces;\r
+\r
+\r
+ //load vertices from Mesh\r
+ for (uint i = 0; i < numvertices; i++)\r
+ {\r
+ vertex[3 * i] = _scale.x * mesh->mVertices[i].x;\r
+ vertex[3 * i + 1] = _scale.y * mesh->mVertices[i].y;\r
+ vertex[3 * i + 2] = _scale.z * mesh->mVertices[i].z;\r
+ }\r
+\r
+ //load UVs from Mesh\r
+ for (uint i = 0; i < numvertices; i++)\r
+ {\r
+ uvs[2 * i] = mesh->mTextureCoords[0][i].x;//[i]->x;\r
+ uvs[2 * i + 1] = mesh->mTextureCoords[0][i].y;//[i]->y;\r
+ }\r
+\r
+ //load indices from Mesh\r
+ for (uint i = 0; i < numfaces; i++)\r
+ {\r
+ index[3 * i] = mesh->mFaces[i].mIndices[0];\r
+ index[3 * i + 1] = mesh->mFaces[i].mIndices[1];\r
+ index[3 * i + 2] = mesh->mFaces[i].mIndices[2];\r
+ }\r
+\r
+ //load normals from Mesh\r
+ for (uint i = 0; i < numvertices; i++)\r
+ {\r
+ normals[3 * i] = mesh->mNormals[i].x;// / _scale.x;\r
+ normals[3 * i + 1] = mesh->mNormals[i].y;// / _scale.y;\r
+ normals[3 * i + 2] = mesh->mNormals[i].z;// / _scale.z;\r
+ }\r
+\r
+ return true;\r
+}\r
+\r
+void Model::setMargin(btScalar _margin)\r
+{\r
+ bt_collision_shape->setMargin(_margin);\r
+}\r
+\r
+\r
+Model* Model::BoundingBox = nullptr;\r
+Model* Model::SkyBoxModel = nullptr;\r
+std::unordered_map<string, Model*> Model::IMetaModel;\r
+std::unordered_map<string, uint> Model::IMetaModel_count;\r
-#pragma once
-
-#include "../../GLM.h"
-#include <unordered_map>
-#include <string>
-
-#include "../../Overlap.h"
-
-#include <btBulletDynamicsCommon.h>
-
-class Shader;
-class Texture;
-class Overlap;
-struct aiMesh;
-
-typedef unsigned int uint;
-
-class Model
-{
-public:
-
- /* Binds Model to the Model*/
- virtual void bindShader(Shader* shader);
-
- /* Draws Model */
- virtual void drawModel(Shader* shader, Texture* texture, const mat4& modelMat) const;
-
- /* Draws a BoundingBox around the Model */
- virtual void drawBBox(const mat4& modelMat, const vec4& color = vec4(0.9f, 0.f, 0.f, 1.f)) const;
-
- /* Get min&max from BBox */
-// virtual void getBBmm(vec3& min, vec3& max) const;
- /* Get size&position from BBox */
- void getBBcs(vec3& center, vec3& size) const;
-
- virtual void setMargin(btScalar margin);
-
- static Model* getBBoxModel();
- static Model* getSkyBoxModel();
- static Model* newIMetaModel(const std::string& modelpath,bool isConvex=true);
-
- static void deleteBBoxModel();
- static void deleteSkyBoxModel();
- static void deleteIMetaModel(const std::string& modelpath);
-
- virtual float getPDistHit(const vec3& P, const vec3& direction) const;
-
- virtual operator std::string() const = 0;
-
- virtual operator btCollisionShape*() const;
-
- // Mesh Speichern?
- static bool import(const std::string& modelpath, uint& numvertices, uint& numfaces, float*& vertex, float*& uvs, float*& normals, uint*& index, uint mindex = 0);
- static bool import(const aiMesh* mesh, uint& numvertices, uint& numfaces, float*& vertex, float*& uvs, float*& normals, uint*& index, const vec3& scale = vec3(1.f));
-
-protected:
- Model();
- virtual ~Model();
-
- uint numvertices, numfaces;
- uint vertexBuffer, indexBuffer, normalBuffer, uvBuffer;
-
- std::unordered_map<uint, uint> shader_map;
-
- 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;
- virtual void drawModel() const;
-
- static Model* BoundingBox;
- static Model* SkyBoxModel;
- static std::unordered_map<std::string, Model*> IMetaModel;
- static std::unordered_map<std::string, uint> IMetaModel_count;
-
- static vec3 rotateSize(const vec3& size, const mat4& modelMat);
- static float directSize(const vec3& size, const vec3& direction);
-
- //Bullet
- btCollisionShape* bt_collision_shape;
-
-private:
-
+#pragma once\r
+\r
+#include "../../GLM.h"\r
+#include <unordered_map>\r
+#include <string>\r
+\r
+#include "../../Overlap.h"\r
+\r
+#include <btBulletDynamicsCommon.h>\r
+\r
+class Shader;\r
+class Texture;\r
+class Overlap;\r
+struct aiMesh;\r
+\r
+typedef unsigned int uint;\r
+\r
+class Model\r
+{\r
+public:\r
+\r
+ /* Binds Model to GL*/\r
+ virtual void bindModel();\r
+\r
+ /* Binds Model to the Shader*/\r
+ virtual void bindShader(Shader* shader);\r
+\r
+ virtual void unbindModel();\r
+ virtual void unbindShader(Shader* shader);\r
+\r
+ /* Draws Model */\r
+ virtual void drawModel(Shader* shader, Texture* texture, const mat4& modelMat) const;\r
+\r
+ /* Draws a BoundingBox around the Model */\r
+ virtual void drawBBox(const mat4& modelMat, const vec4& color = vec4(0.9f, 0.f, 0.f, 1.f)) const;\r
+\r
+ /* Get min&max from BBox */\r
+// virtual void getBBmm(vec3& min, vec3& max) const;\r
+ /* Get size&position from BBox */\r
+ void getBBcs(vec3& center, vec3& size) const;\r
+\r
+ virtual void setMargin(btScalar margin);\r
+\r
+ static Model* getBBoxModel();\r
+ static Model* getSkyBoxModel();\r
+ static Model* newIMetaModel(const std::string& modelpath,bool isConvex=true);\r
+\r
+ static void deleteBBoxModel();\r
+ static void deleteSkyBoxModel();\r
+ static void deleteIMetaModel(const std::string& modelpath);\r
+\r
+ virtual float getPDistHit(const vec3& P, const vec3& direction) const;\r
+\r
+ virtual operator std::string() const;\r
+ virtual std::string type2str() const = 0;\r
+\r
+ virtual operator btCollisionShape*() const;\r
+\r
+ // Mesh Speichern?\r
+ static bool loadMesh(const std::string& modelpath, uint& numvertices, uint& numfaces, float*& vertex, float*& uvs, float*& normals, uint*& index, std::string& name, uint mindex = 0);\r
+ static bool loadMesh(const aiMesh* mesh, uint& numvertices, uint& numfaces, float*& vertex, float*& uvs, float*& normals, uint*& index, std::string& name, const vec3& scale = vec3(1.f));\r
+\r
+protected:\r
+ Model();\r
+ virtual ~Model();\r
+\r
+ std::string name="";\r
+\r
+ uint numvertices=0, numfaces=0;\r
+ uint vertexBuffer=-1, indexBuffer=-1, normalBuffer=-1, uvBuffer=-1;\r
+\r
+ float *vertex = nullptr, *normals = nullptr, *uvs = nullptr;\r
+ uint *index = nullptr;\r
+\r
+ std::unordered_map<uint, uint> shader_map;\r
+\r
+ void genBuffer(uint &buffer, uint size, void* value);\r
+ void bindBuffer(const uint &buffer, const uint index, const uint dim = 3);\r
+\r
+ virtual void useModel(Shader* shader) const;\r
+ virtual void useTexture(Texture* texture, Shader* shader) const; \r
+ virtual void useModelMat(const mat4& model, Shader* shader) const;\r
+ virtual void drawModel() const;\r
+\r
+ static Model* BoundingBox;\r
+ static Model* SkyBoxModel;\r
+ static std::unordered_map<std::string, Model*> IMetaModel;\r
+ static std::unordered_map<std::string, uint> IMetaModel_count;\r
+\r
+ static vec3 rotateSize(const vec3& size, const mat4& modelMat);\r
+ static float directSize(const vec3& size, const vec3& direction);\r
+\r
+ //Bullet\r
+ btCollisionShape* bt_collision_shape;\r
+\r
+private:\r
+\r
};
\ No newline at end of file
-#include "SkyBox.h"
-
-#include "GL/glew.h"
-#include "../Graphix.h"
-#include "../../GLM.h"
-#include "../Shader.h"
-
-
-SkyBox::SkyBox()
-{
-
- float *vertex = nullptr, *normals = nullptr, *uvs = nullptr;
- uint *index = nullptr;
-
- import("SkyBox.dae", numvertices, numfaces, vertex, uvs, normals, index, 0);
-
- 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, index, normals, uvs;
-}
-
-
-SkyBox::~SkyBox()
-{
-}
-
-void SkyBox::drawModel(Shader* _shader, Texture* _texture, const mat4& _modelMat) const
-{
- //_shader->useShader();
- //GLint OldCullFaceMode;
- //glGetIntegerv(GL_CULL_FACE_MODE, &OldCullFaceMode);
- GLint OldDepthFuncMode;
- glGetIntegerv(GL_DEPTH_FUNC, &OldDepthFuncMode);
- //glCullFace(GL_FRONT);
- glDepthFunc(GL_LEQUAL);
- //glDisable(GL_DEPTH_TEST);
- Model::drawModel(_shader, _texture, _modelMat);
- //glEnable(GL_DEPTH_TEST);
- //glCullFace(OldCullFaceMode);
- glDepthFunc(OldDepthFuncMode);
-}
-
-//void SkyBox::useModelMat(const mat4& _model, Shader* _shader) const
-//{
-//}
-
-//void SkyBox::useTexture(Texture* _texture, Shader* _shader) const
-//{
-//}
-
-void SkyBox::drawBBox(const mat4& _modelMat, const vec4& _color) const
-{
-}
-
-SkyBox::operator std::string() const
-{
- return "SkyBox";
+#include "SkyBox.h"\r
+\r
+#include "GL/glew.h"\r
+#include "../Graphix.h"\r
+#include "../../GLM.h"\r
+#include "../Shader.h"\r
+\r
+\r
+SkyBox::SkyBox()\r
+{\r
+\r
+ loadMesh("SkyBox.dae", numvertices, numfaces, vertex, uvs, normals, index, name, 0);\r
+\r
+ name = "SkyBox";\r
+\r
+ delete normals;\r
+\r
+ bindModel();\r
+\r
+}\r
+\r
+\r
+SkyBox::~SkyBox()\r
+{\r
+}\r
+\r
+void SkyBox::drawModel(Shader* _shader, Texture* _texture, const mat4& _modelMat) const\r
+{\r
+ //_shader->useShader();\r
+ //GLint OldCullFaceMode;\r
+ //glGetIntegerv(GL_CULL_FACE_MODE, &OldCullFaceMode);\r
+ GLint OldDepthFuncMode;\r
+ glGetIntegerv(GL_DEPTH_FUNC, &OldDepthFuncMode);\r
+ //glCullFace(GL_FRONT);\r
+ glDepthFunc(GL_LEQUAL);\r
+ //glDisable(GL_DEPTH_TEST);\r
+ Model::drawModel(_shader, _texture, _modelMat);\r
+ //glEnable(GL_DEPTH_TEST);\r
+ //glCullFace(OldCullFaceMode);\r
+ glDepthFunc(OldDepthFuncMode);\r
+}\r
+\r
+//void SkyBox::useModelMat(const mat4& _model, Shader* _shader) const\r
+//{\r
+//}\r
+\r
+//void SkyBox::useTexture(Texture* _texture, Shader* _shader) const\r
+//{\r
+//}\r
+\r
+void SkyBox::drawBBox(const mat4& _modelMat, const vec4& _color) const\r
+{\r
+}\r
+\r
+std::string SkyBox::type2str() const\r
+{\r
+ return "SkyBox";\r
}
\ No newline at end of file
-#pragma once
-
-#include "Model.h"
-#include "../../GLM.h"
-
-class SkyBox :
- public Model
-{
-public:
- SkyBox();
- ~SkyBox();
-
- void drawModel(Shader* shader, Texture* texture, const mat4& modelMat) const override;
-
- //uncommend following lines to use default Loaders
- //void useModelMat(const mat4& model, Shader* shader) const override;
- //void useTexture(Texture* texture, Shader* shader) const override;
-
- void drawBBox(const mat4& modelMat, const vec4& color = vec4(0.f)) const override;
-
- operator std::string() const override;
-
-};
+#pragma once\r
+\r
+#include "Model.h"\r
+#include "../../GLM.h"\r
+\r
+class SkyBox :\r
+ public Model\r
+{\r
+public:\r
+ SkyBox();\r
+ ~SkyBox();\r
+\r
+ void drawModel(Shader* shader, Texture* texture, const mat4& modelMat) const override;\r
+\r
+ //uncommend following lines to use default Loaders\r
+ //void useModelMat(const mat4& model, Shader* shader) const override;\r
+ //void useTexture(Texture* texture, Shader* shader) const override;\r
+\r
+ void drawBBox(const mat4& modelMat, const vec4& color = vec4(0.f)) const override;\r
+\r
+ std::string type2str() const override;\r
+\r
+};\r
- Building Custom Rule C:/Daten/Visual Studio 2015/Projects/CGUE2015_Weave/res/bullet3/src/BulletCollision/CMakeLists.txt
- CMake does not need to re-run because C:\Daten\Visual Studio 2015\Projects\CGUE2015_Weave\res\bulletMAKE\src\BulletCollision\CMakeFiles\generate.stamp is up-to-date.
- btAxisSweep3.cpp
- btBroadphaseProxy.cpp
- btCollisionAlgorithm.cpp
- btDbvt.cpp
- btDbvtBroadphase.cpp
- btDispatcher.cpp
- btMultiSapBroadphase.cpp
- btOverlappingPairCache.cpp
- btQuantizedBvh.cpp
- btSimpleBroadphase.cpp
- btActivatingCollisionAlgorithm.cpp
- btBoxBoxCollisionAlgorithm.cpp
- btBox2dBox2dCollisionAlgorithm.cpp
- btBoxBoxDetector.cpp
- btCollisionDispatcher.cpp
- btCollisionObject.cpp
- btCollisionWorld.cpp
- btCollisionWorldImporter.cpp
- btCompoundCollisionAlgorithm.cpp
- btCompoundCompoundCollisionAlgorithm.cpp
- Generating Code...
- Compiling...
- btConvexConcaveCollisionAlgorithm.cpp
- btConvexConvexAlgorithm.cpp
- btConvexPlaneCollisionAlgorithm.cpp
- btConvex2dConvex2dAlgorithm.cpp
- btDefaultCollisionConfiguration.cpp
- btEmptyCollisionAlgorithm.cpp
- btGhostObject.cpp
- btHashedSimplePairCache.cpp
- btInternalEdgeUtility.cpp
- btManifoldResult.cpp
- btSimulationIslandManager.cpp
- btSphereBoxCollisionAlgorithm.cpp
- btSphereSphereCollisionAlgorithm.cpp
- btSphereTriangleCollisionAlgorithm.cpp
- btUnionFind.cpp
- SphereTriangleDetector.cpp
- btBoxShape.cpp
- btBox2dShape.cpp
- btBvhTriangleMeshShape.cpp
- btCapsuleShape.cpp
- Generating Code...
- Compiling...
- btCollisionShape.cpp
- btCompoundShape.cpp
- btConcaveShape.cpp
- btConeShape.cpp
- btConvexHullShape.cpp
- btConvexInternalShape.cpp
- btConvexPointCloudShape.cpp
- btConvexPolyhedron.cpp
- btConvexShape.cpp
- btConvex2dShape.cpp
- btConvexTriangleMeshShape.cpp
- btCylinderShape.cpp
- btEmptyShape.cpp
- btHeightfieldTerrainShape.cpp
- btMinkowskiSumShape.cpp
- btMultimaterialTriangleMeshShape.cpp
- btMultiSphereShape.cpp
- btOptimizedBvh.cpp
- btPolyhedralConvexShape.cpp
- btScaledBvhTriangleMeshShape.cpp
- Generating Code...
- Compiling...
- btShapeHull.cpp
- btSphereShape.cpp
- btStaticPlaneShape.cpp
- btStridingMeshInterface.cpp
- btTetrahedronShape.cpp
- btTriangleBuffer.cpp
- btTriangleCallback.cpp
- btTriangleIndexVertexArray.cpp
- btTriangleIndexVertexMaterialArray.cpp
- btTriangleMesh.cpp
- btTriangleMeshShape.cpp
- btUniformScalingShape.cpp
- btContactProcessing.cpp
- btGenericPoolAllocator.cpp
- btGImpactBvh.cpp
- btGImpactCollisionAlgorithm.cpp
- btGImpactQuantizedBvh.cpp
- btGImpactShape.cpp
- btTriangleShapeEx.cpp
- gim_box_set.cpp
- Generating Code...
- Compiling...
- gim_contact.cpp
- gim_memory.cpp
- gim_tri_collision.cpp
- btContinuousConvexCollision.cpp
- btConvexCast.cpp
- btGjkConvexCast.cpp
- btGjkEpa2.cpp
- btGjkEpaPenetrationDepthSolver.cpp
- btGjkPairDetector.cpp
- btMinkowskiPenetrationDepthSolver.cpp
- btPersistentManifold.cpp
- btRaycastCallback.cpp
- btSubSimplexConvexCast.cpp
- btVoronoiSimplexSolver.cpp
- btPolyhedralContactClipping.cpp
- Generating Code...
-btBroadphaseProxy.obj : warning LNK4221: This object file does not define any previously undefined public symbols, so it will not be used by any link operation that consumes this library
- BulletCollision.vcxproj -> C:\Daten\Visual Studio 2015\Projects\CGUE2015_Weave\res\bulletMAKE\lib\Debug\BulletCollision_Debug.lib
+btBroadphaseProxy.obj : warning LNK4221: This object file does not define any previously undefined public symbols, so it will not be used by any link operation that consumes this library\r
+ BulletCollision.vcxproj -> C:\Daten\Visual Studio 2015\Projects\CGUE2015_Weave\res\bulletMAKE\lib\Debug\BulletCollision_Debug.lib\r
-#TargetFrameworkVersion=v4.0:PlatformToolSet=v140:EnableManagedIncrementalBuild=false:VCToolArchitecture=Native32Bit:WindowsTargetPlatformVersion=8.1
-Debug|Win32|C:\Daten\Visual Studio 2015\Projects\CGUE2015_Weave\|
+#TargetFrameworkVersion=v4.0:PlatformToolSet=v140:EnableManagedIncrementalBuild=false:VCToolArchitecture=Native32Bit:WindowsTargetPlatformVersion=8.1\r
+Debug|Win32|C:\Daten\Visual Studio 2015\Projects\CGUE2015_Weave\|\r
- Building Custom Rule C:/Daten/Visual Studio 2015/Projects/CGUE2015_Weave/res/bullet3/src/BulletDynamics/CMakeLists.txt
- CMake does not need to re-run because C:\Daten\Visual Studio 2015\Projects\CGUE2015_Weave\res\bulletMAKE\src\BulletDynamics\CMakeFiles\generate.stamp is up-to-date.
- btKinematicCharacterController.cpp
- btConeTwistConstraint.cpp
-C:\Daten\Visual Studio 2015\Projects\CGUE2015_Weave\res\bullet3\src\BulletDynamics\ConstraintSolver\btConeTwistConstraint.cpp(868): warning C4244: '=': conversion from 'double' to 'btScalar', possible loss of data
-C:\Daten\Visual Studio 2015\Projects\CGUE2015_Weave\res\bullet3\src\BulletDynamics\ConstraintSolver\btConeTwistConstraint.cpp(913): warning C4244: '=': conversion from 'double' to 'float', possible loss of data
-C:\Daten\Visual Studio 2015\Projects\CGUE2015_Weave\res\bullet3\src\BulletDynamics\ConstraintSolver\btConeTwistConstraint.cpp(973): warning C4244: '=': conversion from 'double' to 'btScalar', possible loss of data
-C:\Daten\Visual Studio 2015\Projects\CGUE2015_Weave\res\bullet3\src\BulletDynamics\ConstraintSolver\btConeTwistConstraint.cpp(975): warning C4244: '=': conversion from 'double' to 'btScalar', possible loss of data
- btContactConstraint.cpp
-c:\daten\visual studio 2015\projects\cgue2015_weave\res\bullet3\src\bulletdynamics\constraintsolver\btContactConstraint.h(25): warning C4359: 'btContactConstraint': Alignment specifier is less than actual alignment (128), and will be ignored.
- btFixedConstraint.cpp
- btGearConstraint.cpp
- btGeneric6DofConstraint.cpp
- btGeneric6DofSpringConstraint.cpp
- btGeneric6DofSpring2Constraint.cpp
-C:\Daten\Visual Studio 2015\Projects\CGUE2015_Weave\res\bullet3\src\BulletDynamics\ConstraintSolver\btGeneric6DofSpring2Constraint.cpp(786): warning C4244: 'initializing': conversion from 'double' to 'btScalar', possible loss of data
- btHinge2Constraint.cpp
- btHingeConstraint.cpp
- btPoint2PointConstraint.cpp
- btSequentialImpulseConstraintSolver.cpp
- btNNCGConstraintSolver.cpp
- btSliderConstraint.cpp
- btSolve2LinearConstraint.cpp
- btTypedConstraint.cpp
- btUniversalConstraint.cpp
- btDiscreteDynamicsWorld.cpp
-C:\Daten\Visual Studio 2015\Projects\CGUE2015_Weave\res\bullet3\src\BulletDynamics/ConstraintSolver/btContactConstraint.h(25): warning C4359: 'btContactConstraint': Alignment specifier is less than actual alignment (128), and will be ignored.
- btRigidBody.cpp
- btSimpleDynamicsWorld.cpp
- Generating Code...
- Compiling...
- btRaycastVehicle.cpp
-C:\Daten\Visual Studio 2015\Projects\CGUE2015_Weave\res\bullet3\src\BulletDynamics/ConstraintSolver/btContactConstraint.h(25): warning C4359: 'btContactConstraint': Alignment specifier is less than actual alignment (128), and will be ignored.
- btWheelInfo.cpp
- btMultiBody.cpp
- btMultiBodyConstraintSolver.cpp
- btMultiBodyDynamicsWorld.cpp
- btMultiBodyJointLimitConstraint.cpp
-C:\Daten\Visual Studio 2015\Projects\CGUE2015_Weave\res\bullet3\src\BulletDynamics\Featherstone\btMultiBodyJointLimitConstraint.cpp(114): warning C4244: 'initializing': conversion from 'int' to 'btScalar', possible loss of data
- btMultiBodyConstraint.cpp
- btMultiBodyPoint2Point.cpp
- btMultiBodyJointMotor.cpp
- btDantzigLCP.cpp
-C:\Daten\Visual Studio 2015\Projects\CGUE2015_Weave\res\bullet3\src\BulletDynamics\MLCPSolvers\btDantzigLCP.cpp(1568): warning C4473: 'printf' : not enough arguments passed for format string
- C:\Daten\Visual Studio 2015\Projects\CGUE2015_Weave\res\bullet3\src\BulletDynamics\MLCPSolvers\btDantzigLCP.cpp(1568): note: placeholders and their parameters expect 2 variadic arguments, but 1 were provided
- C:\Daten\Visual Studio 2015\Projects\CGUE2015_Weave\res\bullet3\src\BulletDynamics\MLCPSolvers\btDantzigLCP.cpp(1568): note: the missing variadic argument 2 is required by format string '% s'
- btMLCPSolver.cpp
- btLemkeAlgorithm.cpp
- Generating Code...
- BulletDynamics.vcxproj -> C:\Daten\Visual Studio 2015\Projects\CGUE2015_Weave\res\bulletMAKE\lib\Debug\BulletDynamics_Debug.lib
+ BulletDynamics.vcxproj -> C:\Daten\Visual Studio 2015\Projects\CGUE2015_Weave\res\bulletMAKE\lib\Debug\BulletDynamics_Debug.lib\r
-#TargetFrameworkVersion=v4.0:PlatformToolSet=v140:EnableManagedIncrementalBuild=false:VCToolArchitecture=Native32Bit:WindowsTargetPlatformVersion=8.1
-Debug|Win32|C:\Daten\Visual Studio 2015\Projects\CGUE2015_Weave\|
+#TargetFrameworkVersion=v4.0:PlatformToolSet=v140:EnableManagedIncrementalBuild=false:VCToolArchitecture=Native32Bit:WindowsTargetPlatformVersion=8.1\r
+Debug|Win32|C:\Daten\Visual Studio 2015\Projects\CGUE2015_Weave\|\r
- Building Custom Rule C:/Daten/Visual Studio 2015/Projects/CGUE2015_Weave/res/bullet3/src/LinearMath/CMakeLists.txt
- CMake does not need to re-run because C:\Daten\Visual Studio 2015\Projects\CGUE2015_Weave\res\bulletMAKE\src\LinearMath\CMakeFiles\generate.stamp is up-to-date.
- btAlignedAllocator.cpp
- btConvexHull.cpp
- btConvexHullComputer.cpp
- btGeometryUtil.cpp
- btPolarDecomposition.cpp
- btQuickprof.cpp
- btSerializer.cpp
- btVector3.cpp
- Generating Code...
- LinearMath.vcxproj -> C:\Daten\Visual Studio 2015\Projects\CGUE2015_Weave\res\bulletMAKE\lib\Debug\LinearMath_Debug.lib
+ LinearMath.vcxproj -> C:\Daten\Visual Studio 2015\Projects\CGUE2015_Weave\res\bulletMAKE\lib\Debug\LinearMath_Debug.lib\r
-#TargetFrameworkVersion=v4.0:PlatformToolSet=v140:EnableManagedIncrementalBuild=false:VCToolArchitecture=Native32Bit:WindowsTargetPlatformVersion=8.1
-Debug|Win32|C:\Daten\Visual Studio 2015\Projects\CGUE2015_Weave\|
+#TargetFrameworkVersion=v4.0:PlatformToolSet=v140:EnableManagedIncrementalBuild=false:VCToolArchitecture=Native32Bit:WindowsTargetPlatformVersion=8.1\r
+Debug|Win32|C:\Daten\Visual Studio 2015\Projects\CGUE2015_Weave\|\r