diff --git a/Escape-the-Dawn/GameWorld.h b/Escape-the-Dawn/GameWorld.h index 1628205..7b87636 100644 --- a/Escape-the-Dawn/GameWorld.h +++ b/Escape-the-Dawn/GameWorld.h @@ -54,7 +54,7 @@ void GameWorld::Initialize() //AddSystem("LevelGenerationSystem"); AddSystem("InputSystem"); - //AddSystem("CollisionSystem"); + AddSystem("CollisionSystem"); //AddSystem("ParticleSystem"); AddSystem("PlayerSystem"); AddSystem("SoundSystem"); @@ -75,9 +75,12 @@ void GameWorld::Initialize() soundEmitter->MaxDistance = FLT_MAX; soundEmitter->ReferenceDistance = 10; soundEmitter->Loop = true; - soundEmitter->Pitch = 1; GetSystem("SoundSystem")->PlaySound(soundEmitter, "Sounds/hallelujah.wav"); + auto aabb = AddComponent(ent, "Bounds"); + aabb->Origin = transform->Position; + aabb->VolumeVector = glm::vec3(30.f, 20.f, 50.f); + GetSystem("CollisionSystem")->Intersects(ent, ent); ent = CreateEntity(); @@ -96,7 +99,7 @@ void GameWorld::RegisterSystems() { //m_SystemFactory.Register("LevelGenerationSystem", [this]() { return new Systems::LevelGenerationSystem(this); }); m_SystemFactory.Register("InputSystem", [this]() { return new Systems::InputSystem(this, m_Renderer); }); - //m_SystemFactory.Register("CollisionSystem", [this]() { return new Systems::CollisionSystem(this); }); + m_SystemFactory.Register("CollisionSystem", [this]() { return new Systems::CollisionSystem(this); }); //m_SystemFactory.Register("ParticleSystem", [this]() { return new Systems::ParticleSystem(this); }); m_SystemFactory.Register("PlayerSystem", [this]() { return new Systems::PlayerSystem(this); }); m_SystemFactory.Register("SoundSystem", [this]() { return new Systems::SoundSystem(this); }); diff --git a/Escape-the-Dawn/Systems/CollisionSystem.cpp b/Escape-the-Dawn/Systems/CollisionSystem.cpp index f9c5a8a..004f393 100644 --- a/Escape-the-Dawn/Systems/CollisionSystem.cpp +++ b/Escape-the-Dawn/Systems/CollisionSystem.cpp @@ -14,3 +14,46 @@ void Systems::CollisionSystem::UpdateEntity(double dt, EntityID entity, EntityID } LOG_INFO("Updating entity %i with parent %i", entity, parent); } + +bool Systems::CollisionSystem::Intersects(EntityID entity1, EntityID entity2) +{ + auto bounds1 = m_World->GetComponent(entity1, "Bounds"); + auto bounds2 = m_World->GetComponent(entity2, "Bounds"); + + float width = bounds1->VolumeVector.x; + float height = bounds1->VolumeVector.y; + float depth = bounds1->VolumeVector.z; + + GLfloat vertices1[] = { + bounds1->Origin.x - width / 2, bounds1->Origin.y - height / 2, bounds1->Origin.z - depth / 2, 1.0, + bounds1->Origin.x + width / 2, bounds1->Origin.y - height / 2, bounds1->Origin.z - depth / 2, 1.0, + bounds1->Origin.x + width / 2, bounds1->Origin.y + height / 2, bounds1->Origin.z - depth / 2, 1.0, + bounds1->Origin.x - width / 2, bounds1->Origin.y + height / 2, bounds1->Origin.z - depth / 2, 1.0, + bounds1->Origin.x - width / 2, bounds1->Origin.y - height / 2, bounds1->Origin.z + depth / 2, 1.0, + bounds1->Origin.x + width / 2, bounds1->Origin.y - height / 2, bounds1->Origin.z + depth / 2, 1.0, + bounds1->Origin.x + width / 2, bounds1->Origin.y + height / 2, bounds1->Origin.z + depth / 2, 1.0, + bounds1->Origin.x - width / 2, bounds1->Origin.y + height / 2, bounds1->Origin.z + depth / 2, 1.0, + }; + + GLuint vbo_vertices; + glGenBuffers(1, &vbo_vertices); + glBindBuffer(GL_ARRAY_BUFFER, vbo_vertices); + glBufferData(GL_ARRAY_BUFFER, sizeof(vertices1), vertices1, GL_STATIC_DRAW); + glBindBuffer(GL_ARRAY_BUFFER, 0); + + GLushort elements[] = { + 0, 1, 2, 3, + 4, 5, 6, 7, + 0, 4, 1, 5, + 2, 6, 3, 7 + }; + GLuint ibo_elements; + glGenBuffers(1, &ibo_elements); + glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, ibo_elements); + glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(elements), elements, GL_STATIC_DRAW); + glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0); + + + + return true; +} \ No newline at end of file diff --git a/Escape-the-Dawn/Systems/CollisionSystem.h b/Escape-the-Dawn/Systems/CollisionSystem.h index 5c4c448..a4794ba 100644 --- a/Escape-the-Dawn/Systems/CollisionSystem.h +++ b/Escape-the-Dawn/Systems/CollisionSystem.h @@ -3,8 +3,11 @@ #include "System.h" #include "logging.h" +#include #include "Components/Transform.h" +#include "Components/Collision.h" +#include "Components/Bounds.h" namespace Systems { @@ -16,6 +19,7 @@ public: : System(world) { } void UpdateEntity(double dt, EntityID entity, EntityID parent) override; + bool Intersects(EntityID, EntityID); }; } diff --git a/Escape-the-Dawn/Systems/SoundSystem.h b/Escape-the-Dawn/Systems/SoundSystem.h index 7284ad1..4a27d0a 100644 --- a/Escape-the-Dawn/Systems/SoundSystem.h +++ b/Escape-the-Dawn/Systems/SoundSystem.h @@ -6,9 +6,7 @@ #include "Components/SoundEmitter.h" #include #include -#include #include -#include #include namespace Systems @@ -30,11 +28,11 @@ private: //File-info char type[4]; - DWORD size, chunkSize; + unsigned long size, chunkSize; short formatType, channels; - DWORD sampleRate, avgBytesPerSec; + unsigned long sampleRate, avgBytesPerSec; short bytesPerSample, bitsPerSample; - DWORD dataSize; + unsigned long dataSize; std::map m_Source; diff --git a/Escape-the-Dawn/Systems/SoundsSystem.cpp b/Escape-the-Dawn/Systems/SoundsSystem.cpp index d35e322..88789c7 100644 --- a/Escape-the-Dawn/Systems/SoundsSystem.cpp +++ b/Escape-the-Dawn/Systems/SoundsSystem.cpp @@ -103,7 +103,7 @@ ALuint Systems::SoundSystem::LoadFile(std::string fileName) return 0; } - fread(&size, sizeof(DWORD), 1, fp); + fread(&size, sizeof(unsigned long), 1, fp); fread(type, sizeof(char), 4, fp); if(type[0]!='W' || type[1]!='A' || type[2]!='V' || type[3]!='E') { LOG_ERROR("ERROR: Not WAVE-file"); @@ -117,11 +117,11 @@ ALuint Systems::SoundSystem::LoadFile(std::string fileName) } //READ THE DATA FROM WAVE-FILE - fread(&chunkSize, sizeof(DWORD), 1, fp); + fread(&chunkSize, sizeof(unsigned long), 1, fp); fread(&formatType, sizeof(short), 1, fp); fread(&channels, sizeof(short), 1, fp); - fread(&sampleRate, sizeof(DWORD), 1, fp); - fread(&avgBytesPerSec, sizeof(DWORD), 1, fp); + fread(&sampleRate, sizeof(unsigned long), 1, fp); + fread(&avgBytesPerSec, sizeof(unsigned long), 1, fp); fread(&bytesPerSample, sizeof(short), 1, fp); fread(&bitsPerSample, sizeof(short), 1, fp); @@ -132,10 +132,10 @@ ALuint Systems::SoundSystem::LoadFile(std::string fileName) return 0; } - fread(&dataSize, sizeof(DWORD), 1, fp); + fread(&dataSize, sizeof(unsigned long), 1, fp); unsigned char* buf = new unsigned char[dataSize]; - fread(buf, sizeof(BYTE), dataSize, fp); + fread(buf, sizeof(unsigned char), dataSize, fp); fclose(fp); // Create buffer