diff --git a/Escape-the-Dawn/Components/Collision.h b/Escape-the-Dawn/Components/Collision.h index b9f44a5..83450a4 100644 --- a/Escape-the-Dawn/Components/Collision.h +++ b/Escape-the-Dawn/Components/Collision.h @@ -10,7 +10,10 @@ namespace Components struct Collision : Component { + Collision() : Phantom(false), Interested(false) { } + bool Phantom; + bool Interested; std::vector CollidingEntities; }; diff --git a/Escape-the-Dawn/Components/SoundEmitter.h b/Escape-the-Dawn/Components/SoundEmitter.h index 8e471d5..d325dac 100644 --- a/Escape-the-Dawn/Components/SoundEmitter.h +++ b/Escape-the-Dawn/Components/SoundEmitter.h @@ -11,7 +11,7 @@ namespace Components struct SoundEmitter : Component { float Gain; - float MaxDistance; + //float MaxDistance; float ReferenceDistance; float Pitch; bool Loop; diff --git a/Escape-the-Dawn/Escape-the-Dawn.vcxproj b/Escape-the-Dawn/Escape-the-Dawn.vcxproj index cb14255..7f9c2d5 100644 --- a/Escape-the-Dawn/Escape-the-Dawn.vcxproj +++ b/Escape-the-Dawn/Escape-the-Dawn.vcxproj @@ -82,12 +82,12 @@ MaxSpeed true true - GLEW_STATIC;%(PreprocessorDefinitions) + GLEW_STATIC;DEBUG;%(PreprocessorDefinitions) NotUsing - None + ProgramDatabase + true - false true true OpenAL32.lib;opengl32.lib;glu32.lib;SOIL.lib;glew32s.lib;glfw3.lib;%(AdditionalDependencies) @@ -148,6 +148,7 @@ + diff --git a/Escape-the-Dawn/Escape-the-Dawn.vcxproj.filters b/Escape-the-Dawn/Escape-the-Dawn.vcxproj.filters index 94202f3..7740421 100644 --- a/Escape-the-Dawn/Escape-the-Dawn.vcxproj.filters +++ b/Escape-the-Dawn/Escape-the-Dawn.vcxproj.filters @@ -144,6 +144,7 @@ GUI + diff --git a/Escape-the-Dawn/Escape-the-Dawn.vcxproj.filters.orig b/Escape-the-Dawn/Escape-the-Dawn.vcxproj.filters.orig new file mode 100644 index 0000000..80f772b --- /dev/null +++ b/Escape-the-Dawn/Escape-the-Dawn.vcxproj.filters.orig @@ -0,0 +1,204 @@ + + + + + + Systems + + + Systems + + + Systems + + + Systems + + + Systems + + + Systems + + + Systems + + + + + + GUI + + + + + GUI + + + GUI + + + GUI + + + GUI + + + + + + + + + + + + + Systems + + + Systems + + + Systems + + + Systems + + + Systems + + + Systems + + + Systems + + + + Components + + + + Components + + + Components + + + Components + + + Components + + + Components + + + Components + + + Components + + + Components + + + Components + + + + + Components + + + Components + + + Components + + + Components + + + Util + + + Util + + + + + GUI + + + GUI + + + GUI + + + GUI + + + GUI + + +<<<<<<< HEAD + +======= + + + +>>>>>>> d0320477a978a38d87e94afbea65dc08fd10c860 + + + + Shaders + + + Shaders + + + Shaders + + + Shaders + + + Shaders + + + Shaders + + + Shaders + + + Shaders + + + Shaders + + + Shaders + + + + + {657e11f4-52e7-4336-b77f-80f00b85c33f} + + + {59929465-a139-43b9-9c75-48121d156e78} + + + {54f1eb6f-dc00-4e97-a3ef-ac255d755e2e} + + + {d985d7a7-c041-46fe-ae03-aa40295a7aad} + + + {7bdb0f69-049e-4f16-b271-2495e02e4b28} + + + \ No newline at end of file diff --git a/Escape-the-Dawn/Escape-the-Dawn.vcxproj.orig b/Escape-the-Dawn/Escape-the-Dawn.vcxproj.orig new file mode 100644 index 0000000..7f9c2d5 --- /dev/null +++ b/Escape-the-Dawn/Escape-the-Dawn.vcxproj.orig @@ -0,0 +1,183 @@ + + + + + Debug + Win32 + + + Release + Win32 + + + + {FE405CFA-8FCE-4867-92CF-797E73B36482} + EscapetheDawn + + + + Application + true + MultiByte + v110 + + + Application + false + true + MultiByte + v110 + + + + + + + + + + + + + + $(BOOST_ROOT)\lib32-msvc-11.0;$(SolutionDir)\Libraries\openal-soft-1.15.1-bin\lib\Win32\Debug;$(SolutionDir)\Libraries\SOIL\lib\Debug;$(SolutionDir)\Libraries\glew-1.10.0\lib\Debug\Win32;$(SolutionDir)\Libraries\glfw-3.0.4\lib\Debug;$(LibraryPath) + $(SolutionDir)bin\ + $(SolutionDir)obj\$(ProjectName)\ + $(ProjectName)-$(Configuration) + $(BOOST_ROOT);$(SolutionDir)\Libraries\openal-soft-1.15.1-bin\include;$(SolutionDir)\Libraries\SOIL\src;$(ProjectDir);$(SolutionDir)\Libraries;$(SolutionDir)\Libraries\glew-1.10.0\include;$(SolutionDir)\Libraries\glfw-3.0.4\include;$(SolutionDir)\Libraries\glm-0.9.5.2;$(IncludePath) + + + $(BOOST_ROOT);$(SolutionDir)\Libraries\openal-soft-1.15.1-bin\include;$(SolutionDir)\Libraries\SOIL\src;$(ProjectDir);$(SolutionDir)\Libraries;$(SolutionDir)\Libraries\glew-1.10.0\include;$(SolutionDir)\Libraries\glfw-3.0.4\include;$(SolutionDir)\Libraries\glm-0.9.5.2;$(IncludePath) + + + $(BOOST_ROOT)\lib32-msvc-11.0;$(SolutionDir)\Libraries\openal-soft-1.15.1-bin\lib\Win32\Release;$(SolutionDir)\Libraries\SOIL\lib\Release;$(SolutionDir)\Libraries\glew-1.10.0\lib\Release\Win32;$(SolutionDir)\Libraries\glfw-3.0.4\lib\Release;$(LibraryPath) + $(SolutionDir)bin\ + $(SolutionDir)obj\$(ProjectName)\ + $(ProjectName)-$(Configuration) + + + + Level3 + Disabled + GLEW_STATIC;DEBUG;%(PreprocessorDefinitions) + NotUsing + + + true + Console + OpenAL32.lib;opengl32.lib;glu32.lib;SOIL.lib;glew32sd.lib;glfw3.lib;%(AdditionalDependencies) + + + + + OpenAL32.lib;opengl32.lib;glu32.lib;SOIL.lib;glew32sd.lib;glfw3.lib + + + + + + + + Level3 + MaxSpeed + true + true + GLEW_STATIC;DEBUG;%(PreprocessorDefinitions) + NotUsing + ProgramDatabase + true + + + true + true + OpenAL32.lib;opengl32.lib;glu32.lib;SOIL.lib;glew32s.lib;glfw3.lib;%(AdditionalDependencies) + + + OpenAL32.lib;opengl32.lib;glu32.lib;SOIL.lib;glew32s.lib;glfw3.lib; + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/Escape-the-Dawn/Frame.cpp b/Escape-the-Dawn/Frame.cpp index e69de29..bf996ed 100644 --- a/Escape-the-Dawn/Frame.cpp +++ b/Escape-the-Dawn/Frame.cpp @@ -0,0 +1,92 @@ +/*#include "Frame.h" + +GUI::Frame::Frame() +{ + rectangle = new Rectangle(); +} + +int GUI::Frame::GetWidth() +{ + return rectangle; +} + +int GUI::Frame::GetHeight() +{ + return rectangle.Height(); +} + +int GUI::Frame::GetX() +{ + return rectangle; +} + +int GUI::Frame::GetY() +{ + return rectangle.Y(); +} + +void GUI::Frame::SetWidth(int wid) +{ + rectangle.width(wid); +} + +void GUI::Frame::SetHeight(int hei) +{ + rectangle.height(hei); +} + +void GUI::Frame::SetX(int xcord) +{ + rectangle.X(xcord) +} + +void GUI::Frame::SetY(int ycord) +{ + rectangle.Y(ycord) +} + +Rectangle GUI::Frame::AbsouluteRectangle() +{ + +} + +bool GUI::Frame::Visible() +{ + +} + +int GUI::Frame::LayerSum() +{ + +} + +int GUI::Frame::UID() +{ + +} + +void GUI::Frame::AddChild(Frame childFrame) +{ + +} + +void GUI::Frame::RemoveChild(Frame childFrame) +{ + +} + +void GUI::Frame::Initialize() +{ + +} + +void GUI::Frame::Update(double dt) +{ + +} + +void GUI::Frame::Draw() +{ + +} +*/ \ No newline at end of file diff --git a/Escape-the-Dawn/Frame.h b/Escape-the-Dawn/Frame.h index e69de29..2e9a3f4 100644 --- a/Escape-the-Dawn/Frame.h +++ b/Escape-the-Dawn/Frame.h @@ -0,0 +1,51 @@ +/*#ifndef Frame_h__ +#define Frame_h__ + +#include +#include "Renderer.h" +#include "Rectangle.h" +#include "GUIManager.h" +#include "Texture.h" +#include "Color.h" +//#include "Camera.h" + +namespace GUI +{ + +class Frame +{ +public: + Frame(); + GUIManager Manager; + std::string Name; + int GetWidth(); + int GetHeight(); + int GetX(); + int GetY(); + void SetWidth(int wid); + void SetHeight(int hei); + void SetX( int xcord); + void SetY(int ycord); + Rectangle *rectangle; + Rectangle AbsouluteRectangle(); + Texture texture; + Color color; + bool _Visible; + bool Visible(); + int layer; + int layerSum; + int LayerSum(); + int UID(); + Frame *Parent; + std::map Properties = new std::map(); + void AddChild(Frame childFrame); + void RemoveChild(Frame childFrame); + void Update(double dt); + void Draw(); +protected: + virtual void Initialize(); + +}; +} + +#endif*/ \ No newline at end of file diff --git a/Escape-the-Dawn/GUIManager.cpp b/Escape-the-Dawn/GUIManager.cpp index e69de29..40b50d3 100644 --- a/Escape-the-Dawn/GUIManager.cpp +++ b/Escape-the-Dawn/GUIManager.cpp @@ -0,0 +1,8 @@ +/*#include "GUIManager.h" + +int GUI::GUIManager::Add(Frame frame) +{ + //Frame.Add(frame); + //return CreateUID(); +} +*/ \ No newline at end of file diff --git a/Escape-the-Dawn/GUIManager.h b/Escape-the-Dawn/GUIManager.h index e69de29..7b8434a 100644 --- a/Escape-the-Dawn/GUIManager.h +++ b/Escape-the-Dawn/GUIManager.h @@ -0,0 +1,26 @@ +/*#ifndef GUIManager_h__ +#define GUIManager_h__ + +#include "Frame.h" + + +namespace GUI +{ +class GUIManager +{ +public: + int Add(Frame frame); + void Remove(Frame frame); + int CreateUID(); + void Update(double dt); + void Draw(); +private: + static int uidIndex; + +}; + +} + + + +#endif */ \ No newline at end of file diff --git a/Escape-the-Dawn/GameFrame.cpp b/Escape-the-Dawn/GameFrame.cpp index e69de29..43a87af 100644 --- a/Escape-the-Dawn/GameFrame.cpp +++ b/Escape-the-Dawn/GameFrame.cpp @@ -0,0 +1 @@ +#include "GameFrame.h" \ No newline at end of file diff --git a/Escape-the-Dawn/GameWorld.cpp b/Escape-the-Dawn/GameWorld.cpp index d70ddc6..369afbc 100644 --- a/Escape-the-Dawn/GameWorld.cpp +++ b/Escape-the-Dawn/GameWorld.cpp @@ -22,31 +22,16 @@ void GameWorld::Initialize() std::shared_ptr soundEmitter; EntityID ent; - // Camera - entcamera = CreateEntity(); - SetProperty(entcamera, "Name", std::string("Camera")); - transform = AddComponent(entcamera, "Transform"); - AddComponent(entcamera, "Input"); - transform->Position = glm::vec3(0.f, 10.f, 14.f); - camera = AddComponent(entcamera, "Camera"); - camera->FOV = 45.f; - camera->FarClip = 1000.f; - camera->NearClip = 0.01f; - transform->Orientation = glm::angleAxis(glm::radians(15.0f),glm::vec3(1,0,0)); - collision = AddComponent(entcamera, "Collision"); - collision->Phantom = false; - bounds = AddComponent(entcamera, "Bounds"); - bounds->VolumeVector = glm::vec3(0.1f,0.1f,0.1f); + + // Fucking lights ent = CreateEntity(); transform = AddComponent(ent, "Transform"); - transform->Position = glm::vec3(0.f, 4.f, 0.f); - transform->Position = glm::vec3(10.f, 2.f, 5.f); + transform->Position = glm::vec3(0.f, 7.f, 0.f); pointLight = AddComponent(ent, "PointLight"); pointLight->Specular = glm::vec3(1.0, 1.0, 1.0); - pointLight->Diffuse = glm::vec3(1.0, 1.0, 1.0); - pointLight->Diffuse = glm::vec3(1.0, 1.0, 5.0); + pointLight->Diffuse = glm::vec3(0.0, 0.0, 5.0); pointLight->constantAttenuation = 0.f; pointLight->linearAttenuation = 1.f; pointLight->quadraticAttenuation = 0.f; @@ -55,13 +40,10 @@ void GameWorld::Initialize() model->ModelFile = "Models/sphere.obj"; ent = CreateEntity(); transform = AddComponent(ent, "Transform"); - transform->Position = glm::vec3(10.f, 4.f, 0.f); - transform->Position = glm::vec3(0.f, 2.f, 5.f); + transform->Position = glm::vec3(10.f, 7.f, 0.f); pointLight = AddComponent(ent, "PointLight"); pointLight->Specular = glm::vec3(1.0, 1.0, 1.0); - pointLight->Diffuse = glm::vec3(1.0, 1.0, 1.0); - pointLight->Specular = glm::vec3(3.0, 3.0, 3.0); - pointLight->Diffuse = glm::vec3(3.0, 0.0, 0.0); + pointLight->Diffuse = glm::vec3(0.0, 5.0, 0.0); pointLight->constantAttenuation = 0.f; pointLight->linearAttenuation = 1.f; pointLight->quadraticAttenuation = 0.f; @@ -70,12 +52,10 @@ void GameWorld::Initialize() model->ModelFile = "Models/sphere.obj"; ent = CreateEntity(); transform = AddComponent(ent, "Transform"); - transform->Position = glm::vec3(0.f, -4.f, 0.f); - transform->Position = glm::vec3(-10.f, 2.f, 5.f); + transform->Position = glm::vec3(-10.f, 7.f, 0.f); pointLight = AddComponent(ent, "PointLight"); pointLight->Specular = glm::vec3(1.0, 1.0, 1.0); - pointLight->Diffuse = glm::vec3(1.0, 1.0, 1.0); - pointLight->Diffuse = glm::vec3(0.0, 3.0, 0.0); + pointLight->Diffuse = glm::vec3(5.0, 0.0, 0.0); pointLight->constantAttenuation = 0.f; pointLight->linearAttenuation = 1.f; pointLight->quadraticAttenuation = 0.f; @@ -94,16 +74,24 @@ void GameWorld::Initialize() m_Player = CreateEntity(); SetProperty(m_Player, "Name", std::string("PlayerShip")); transform = AddComponent(m_Player, "Transform"); - transform->Position = glm::vec3(0.f, 4.f, -5.f); + transform->Position = glm::vec3(0.f, 2.f, -5.f); transform->Scale = glm::vec3(1.0f); model = AddComponent(m_Player, "Model"); model->ModelFile = "Models/ship.obj"; + pointLight = AddComponent(m_Player, "PointLight"); + pointLight->Specular = glm::vec3(1.0, 1.0, 1.0); + pointLight->Diffuse = glm::vec3(0.4, 0.4, 1.0); + pointLight->constantAttenuation = 0.f; + pointLight->linearAttenuation = 1.f; + pointLight->quadraticAttenuation = 0.f; + pointLight->spotExponent = 0.0f; AddComponent(m_Player, "Input"); collision = AddComponent(m_Player, "Collision"); collision->Phantom = false; + collision->Interested = true; bounds = AddComponent(m_Player, "Bounds"); - bounds->Origin = glm::vec3(transform->Position.x, transform->Position.y - 4, transform->Position.z + 3); - bounds->VolumeVector = glm::vec3(4.f,0.7f,4); + bounds->Origin = glm::vec3(0, 0, 2.f); + bounds->VolumeVector = glm::vec3(4.f, 0.7f, 1); soundEmitter = AddComponent(m_Player, "SoundEmitter"); soundEmitter->Loop = true; soundEmitter->MaxDistance = FLT_MAX; @@ -113,7 +101,23 @@ void GameWorld::Initialize() soundEmitter->Path = "Sounds/hallelujah.wav"; GetSystem("SoundSystem")->PlaySound(soundEmitter); - ent = CreateEntity(); + + // Camera + entcamera = CreateEntity(m_Player); + SetProperty(entcamera, "Name", std::string("Camera")); + transform = AddComponent(entcamera, "Transform"); + AddComponent(entcamera, "Input"); + transform->Position = glm::vec3(0.f, 10.f, 14.f); + camera = AddComponent(entcamera, "Camera"); + camera->FOV = 45.f; + camera->FarClip = 1000.f; + camera->NearClip = 0.01f; + transform->Orientation = glm::angleAxis(glm::radians(15.0f),glm::vec3(1,0,0)); + + + + + /*ent = CreateEntity(); transform = AddComponent(ent, "Transform"); transform->Position = glm::vec3(10.f, 4.f, 0.f); model = AddComponent(ent, "Model"); @@ -122,7 +126,7 @@ void GameWorld::Initialize() collision->Phantom = false; bounds = AddComponent(player2, "Bounds"); bounds->Origin = transform->Position; - bounds->VolumeVector = glm::vec3(2.f,2.f,2.f); + bounds->VolumeVector = glm::vec3(2.f,2.f,2.f);*/ } void GameWorld::Update(double dt) diff --git a/Escape-the-Dawn/GameWorld.cpp.orig b/Escape-the-Dawn/GameWorld.cpp.orig index 4de26d7..12d11a3 100644 --- a/Escape-the-Dawn/GameWorld.cpp.orig +++ b/Escape-the-Dawn/GameWorld.cpp.orig @@ -5,7 +5,7 @@ void GameWorld::Initialize() { World::Initialize(); - //AddSystem("LevelGenerationSystem"); + AddSystem("LevelGenerationSystem"); AddSystem("InputSystem"); AddSystem("CollisionSystem"); //AddSystem("ParticleSystem"); @@ -19,129 +19,124 @@ void GameWorld::Initialize() std::shared_ptr camera; std::shared_ptr bounds; std::shared_ptr collision; + std::shared_ptr soundEmitter; EntityID ent; - // Camera - entcamera = CreateEntity(); - SetProperty(entcamera, "Name", std::string("Camera")); - transform = AddComponent(entcamera, "Transform"); - AddComponent(entcamera, "Input"); - transform->Position = glm::vec3(0.f, 2.f, 10.f); - camera = AddComponent(entcamera, "Camera"); - camera->FOV = 45.f; - camera->FarClip = 1000.f; - camera->NearClip = 0.01f; - transform->Orientation = glm::angleAxis(glm::radians(25.0f),glm::vec3(1,0,0)); - collision = AddComponent(entcamera, "Collision"); - collision->Phantom = false; - bounds = AddComponent(entcamera, "Bounds"); - bounds->Origin = transform->Position; - bounds->VolumeVector = glm::vec3(4.f,2.f,2.f); + + // Fucking lights ent = CreateEntity(); transform = AddComponent(ent, "Transform"); - transform->Position = glm::vec3(0.f, 4.f, 0.f); - transform->Position = glm::vec3(10.f, 2.f, 5.f); + transform->Position = glm::vec3(0.f, 7.f, 0.f); pointLight = AddComponent(ent, "PointLight"); pointLight->Specular = glm::vec3(1.0, 1.0, 1.0); - pointLight->Diffuse = glm::vec3(1.0, 1.0, 1.0); - pointLight->Diffuse = glm::vec3(1.0, 1.0, 5.0); + pointLight->Diffuse = glm::vec3(0.0, 0.0, 5.0); pointLight->constantAttenuation = 0.f; pointLight->linearAttenuation = 1.f; pointLight->quadraticAttenuation = 0.f; pointLight->spotExponent = 0.0f; model = AddComponent(ent, "Model"); - model->ModelFile = "sphere.obj"; + model->ModelFile = "Models/sphere.obj"; ent = CreateEntity(); transform = AddComponent(ent, "Transform"); - transform->Position = glm::vec3(10.f, 4.f, 0.f); - transform->Position = glm::vec3(0.f, 2.f, 5.f); + transform->Position = glm::vec3(10.f, 7.f, 0.f); pointLight = AddComponent(ent, "PointLight"); pointLight->Specular = glm::vec3(1.0, 1.0, 1.0); - pointLight->Diffuse = glm::vec3(1.0, 1.0, 1.0); - pointLight->Specular = glm::vec3(3.0, 3.0, 3.0); - pointLight->Diffuse = glm::vec3(3.0, 0.0, 0.0); + pointLight->Diffuse = glm::vec3(0.0, 5.0, 0.0); pointLight->constantAttenuation = 0.f; pointLight->linearAttenuation = 1.f; pointLight->quadraticAttenuation = 0.f; pointLight->spotExponent = 0.0f; model = AddComponent(ent, "Model"); - model->ModelFile = "sphere.obj"; + model->ModelFile = "Models/sphere.obj"; ent = CreateEntity(); transform = AddComponent(ent, "Transform"); - transform->Position = glm::vec3(0.f, -4.f, 0.f); - transform->Position = glm::vec3(-10.f, 2.f, 5.f); + transform->Position = glm::vec3(-10.f, 7.f, 0.f); pointLight = AddComponent(ent, "PointLight"); pointLight->Specular = glm::vec3(1.0, 1.0, 1.0); - pointLight->Diffuse = glm::vec3(1.0, 1.0, 1.0); - pointLight->Diffuse = glm::vec3(0.0, 3.0, 0.0); + pointLight->Diffuse = glm::vec3(5.0, 0.0, 0.0); pointLight->constantAttenuation = 0.f; pointLight->linearAttenuation = 1.f; pointLight->quadraticAttenuation = 0.f; pointLight->spotExponent = 0.0f; model = AddComponent(ent, "Model"); - model->ModelFile = "sphere.obj"; + model->ModelFile = "Models/sphere.obj"; //ground ent = CreateEntity(); transform = AddComponent(ent, "Transform"); transform->Position = glm::vec3(0.f, 0.f, 0.f); model = AddComponent(ent, "Model"); - model->ModelFile = "plane.obj"; + model->ModelFile = "Models/plane.obj"; // Player -<<<<<<< HEAD - player1 = CreateEntity(); - transform = AddComponent(player1, "Transform"); - transform->Position = glm::vec3(0.f, 0.f, 0.f); - model = AddComponent(player1, "Model"); - model->ModelFile = "ship.obj"; - collision = AddComponent(player1, "Collision"); - collision->Phantom = false; - bounds = AddComponent(player1, "Bounds"); - bounds->Origin = transform->Position; - bounds->VolumeVector = glm::vec3(10.f,10.f,5.f); - - - player2 = CreateEntity(); - transform = AddComponent(player2, "Transform"); - transform->Position = glm::vec3(10.f, 0.f, 0.f); - model = AddComponent(player2, "Model"); -======= m_Player = CreateEntity(); + SetProperty(m_Player, "Name", std::string("PlayerShip")); transform = AddComponent(m_Player, "Transform"); - transform->Position = glm::vec3(0.f, 4.f, 0.f); + transform->Position = glm::vec3(0.f, 2.f, -5.f); + transform->Scale = glm::vec3(1.0f); model = AddComponent(m_Player, "Model"); - model->ModelFile = "ship.obj"; - auto bounds = AddComponent(m_Player, "Bounds"); - bounds->Origin = glm::vec3(0.f); - bounds->VolumeVector = glm::vec3(1.0f, 2.0f, 3.0f); + model->ModelFile = "Models/ship.obj"; + pointLight = AddComponent(m_Player, "PointLight"); + pointLight->Specular = glm::vec3(1.0, 1.0, 1.0); + pointLight->Diffuse = glm::vec3(0.4, 0.4, 1.0); + pointLight->constantAttenuation = 0.f; + pointLight->linearAttenuation = 1.f; + pointLight->quadraticAttenuation = 0.f; + pointLight->spotExponent = 0.0f; + AddComponent(m_Player, "Input"); + collision = AddComponent(m_Player, "Collision"); + collision->Phantom = false; + collision->Interested = true; + bounds = AddComponent(m_Player, "Bounds"); +<<<<<<< HEAD + bounds->Origin = glm::vec3(transform->Position.x, transform->Position.y - 4, transform->Position.z + 3); + bounds->VolumeVector = glm::vec3(4.f,0.7f,4); + soundEmitter = AddComponent(m_Player, "SoundEmitter"); + soundEmitter->Loop = true; + soundEmitter->MaxDistance = FLT_MAX; + soundEmitter->ReferenceDistance = 10; + soundEmitter->Gain = 1; + soundEmitter->Pitch = 1; + soundEmitter->Path = "Sounds/hallelujah.wav"; + GetSystem("SoundSystem")->PlaySound(soundEmitter); +======= + bounds->Origin = glm::vec3(0, 0, 2.f); + bounds->VolumeVector = glm::vec3(4.f, 0.7f, 1); +>>>>>>> f76c0b336f87a259a7eabf3c532fc885f155a605 - ent = CreateEntity(); + + // Camera + entcamera = CreateEntity(m_Player); + SetProperty(entcamera, "Name", std::string("Camera")); + transform = AddComponent(entcamera, "Transform"); + AddComponent(entcamera, "Input"); + transform->Position = glm::vec3(0.f, 10.f, 14.f); + camera = AddComponent(entcamera, "Camera"); + camera->FOV = 45.f; + camera->FarClip = 1000.f; + camera->NearClip = 0.01f; + transform->Orientation = glm::angleAxis(glm::radians(15.0f),glm::vec3(1,0,0)); + + + + + /*ent = CreateEntity(); transform = AddComponent(ent, "Transform"); transform->Position = glm::vec3(10.f, 4.f, 0.f); model = AddComponent(ent, "Model"); ->>>>>>> 21b2e3bdc15ac8b21f027a7f531574f46187ae80 - model->ModelFile = "ship.obj"; + model->ModelFile = "Models/ship.obj"; collision = AddComponent(player2, "Collision"); collision->Phantom = false; bounds = AddComponent(player2, "Bounds"); bounds->Origin = transform->Position; - bounds->VolumeVector = glm::vec3(2.f,2.f,2.f); + bounds->VolumeVector = glm::vec3(2.f,2.f,2.f);*/ } void GameWorld::Update(double dt) { World::Update(dt); -<<<<<<< HEAD - if(GetSystem("CollisionSystem")->Intersects(player1, entcamera)) - assert(false); -======= - - auto transform = GetComponent(m_Player, "Transform"); - transform->Orientation = transform->Orientation * glm::angleAxis(dt, glm::vec3(0, 0, 1)); ->>>>>>> 21b2e3bdc15ac8b21f027a7f531574f46187ae80 } void GameWorld::RegisterComponents() @@ -164,7 +159,7 @@ void GameWorld::RegisterComponents() void GameWorld::RegisterSystems() { - //m_SystemFactory.Register("LevelGenerationSystem", [this]() { return new Systems::LevelGenerationSystem(this); }); + 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("ParticleSystem", [this]() { return new Systems::ParticleSystem(this); }); diff --git a/Escape-the-Dawn/GameWorld.h.orig b/Escape-the-Dawn/GameWorld.h.orig deleted file mode 100644 index c281acc..0000000 --- a/Escape-the-Dawn/GameWorld.h.orig +++ /dev/null @@ -1,53 +0,0 @@ -#ifndef GameWorld_h__ -#define GameWorld_h__ - -#include "World.h" -#include "Renderer.h" - -#include "Systems/CollisionSystem.h" -#include "Systems/InputSystem.h" -#include "Systems/LevelGenerationSystem.h" -#include "Systems/ParticleSystem.h" -#include "Systems/PlayerSystem.h" -#include "Systems/RenderSystem.h" -#include "Systems/SoundSystem.h" - -#include "Components/Bounds.h" -#include "Components/Camera.h" -#include "Components/Collision.h" -#include "Components/DirectionalLight.h" -#include "Components/Input.h" -#include "Components/Model.h" -#include "Components/ParticleEmitter.h" -#include "Components/PointLight.h" -#include "Components/PowerUp.h" -#include "Components/SoundEmitter.h" -#include "Components/Sprite.h" -#include "Components/Stat.h" -#include "Components/Template.h" -#include "Components/Transform.h" - -class GameWorld : public World -{ -public: - GameWorld(std::shared_ptr renderer) - : m_Renderer(renderer), World() { } - - void Initialize(); - - void RegisterSystems() override; - void RegisterComponents() override; - - void Update(double dt) ; - -private: - std::shared_ptr m_Renderer; -<<<<<<< HEAD - EntityID entcamera, player1, player2; -======= - - EntityID m_Player; ->>>>>>> 21b2e3bdc15ac8b21f027a7f531574f46187ae80 -}; - -#endif // GameWorld_h__ diff --git a/Escape-the-Dawn/MenuFrame.cpp b/Escape-the-Dawn/MenuFrame.cpp index e69de29..4c89382 100644 --- a/Escape-the-Dawn/MenuFrame.cpp +++ b/Escape-the-Dawn/MenuFrame.cpp @@ -0,0 +1 @@ +#include "MenuFrame.h" diff --git a/Escape-the-Dawn/Models/powerup.mtl b/Escape-the-Dawn/Models/powerup.mtl new file mode 100644 index 0000000..2ec2034 --- /dev/null +++ b/Escape-the-Dawn/Models/powerup.mtl @@ -0,0 +1,12 @@ +# Blender MTL File: 'powerup.blend' +# Material Count: 1 + +newmtl Material.001 +Ns 96.078431 +Ka 0.000000 0.000000 0.000000 +Kd 0.640000 0.640000 0.640000 +Ks 0.500000 0.500000 0.500000 +Ni 1.000000 +d 1.000000 +illum 2 +map_Kd powerupTexture.png diff --git a/Escape-the-Dawn/Models/powerupTexture.png b/Escape-the-Dawn/Models/powerupTexture.png new file mode 100644 index 0000000..4a0b586 Binary files /dev/null and b/Escape-the-Dawn/Models/powerupTexture.png differ diff --git a/Escape-the-Dawn/Rectangle.h b/Escape-the-Dawn/Rectangle.h new file mode 100644 index 0000000..2f6d0cd --- /dev/null +++ b/Escape-the-Dawn/Rectangle.h @@ -0,0 +1,32 @@ +#ifndef Rectangle_h__ +#define Rectangle_h__ + +class Rectangle +{ +private: + int height; + int width; + int x; + int y; + +public: + Rectangle(); + int Height() const { return height; } + void Height(float val) { height = val; } + + int Width() const { return width; } + void Width(float val) { width = val; } + + int X() const { return x; } + void X(int val) { x = val; } + + int Y() const { return y; } + void Y(int val) { y = val; } +}; + +Rectangle::Rectangle() +{ + +} + +#endif \ No newline at end of file diff --git a/Escape-the-Dawn/Renderer.cpp b/Escape-the-Dawn/Renderer.cpp index 0948515..87a7e79 100644 --- a/Escape-the-Dawn/Renderer.cpp +++ b/Escape-the-Dawn/Renderer.cpp @@ -3,12 +3,21 @@ Renderer::Renderer() { m_VSync = false; +#ifdef DEBUG m_DrawNormals = false; m_DrawWireframe = false; + m_DrawBounds = true; +#else + m_DrawNormals = false; + m_DrawWireframe = false; + m_DrawBounds = false; +#endif - m_SunPosition = glm::vec3(0, 10, 10); + m_ShadowMapRes = 2048*2; + m_SunPosition = glm::vec3(0, 0.3f, 10); m_SunTarget = glm::vec3(0, 0, 0); - m_SunProjection = glm::ortho(-20, 20, -20, 20, -10, 20); + m_SunProjection = glm::ortho(-200, 200, -10, 100, -800, 800); + Lights = 0; } void Renderer::Initialize() @@ -92,7 +101,7 @@ void Renderer::LoadContent() m_DebugAABB = CreateAABB(); m_ScreenQuad = CreateQuad(); - CreateShadowMap(2048*2); + CreateShadowMap(m_ShadowMapRes); } void Renderer::CreateShadowMap(int resolution) @@ -128,22 +137,33 @@ void Renderer::Draw(double dt) DrawScene(); #ifdef DEBUG - glEnable(GL_BLEND); - glBlendFunc(GL_ONE_MINUS_DST_COLOR, GL_ZERO); - m_ShaderProgramDebugAABB.Bind(); - for (auto aabbModelMatrix : AABBsToRender) { - glm::mat4 cameraMatrix = m_Camera->ProjectionMatrix() * m_Camera->ViewMatrix(); - glm::mat4 MVP = cameraMatrix * aabbModelMatrix; - glUniformMatrix4fv(glGetUniformLocation(m_ShaderProgramDebugAABB.GetHandle(), "MVP"), 1, GL_FALSE, glm::value_ptr(MVP)); - glBindVertexArray(m_DebugAABB); - glDrawArrays(GL_LINES, 0, 24); + // Draw bounding boxes + if (m_DrawBounds) { + glEnable(GL_BLEND); + glBlendFunc(GL_ONE_MINUS_DST_COLOR, GL_ZERO); + m_ShaderProgramDebugAABB.Bind(); + for (auto tuple : AABBsToRender) { + glm::mat4 modelMatrix; + bool colliding; + std::tie(modelMatrix, colliding) = tuple; + // Model matrix + glm::mat4 cameraMatrix = m_Camera->ProjectionMatrix() * m_Camera->ViewMatrix(); + glm::mat4 MVP = cameraMatrix * modelMatrix; + glUniformMatrix4fv(glGetUniformLocation(m_ShaderProgramDebugAABB.GetHandle(), "MVP"), 1, GL_FALSE, glm::value_ptr(MVP)); + // Color + glm::vec4 color(1.f, 1.f, 1.f, 0.f); + if (colliding) + color = glm::vec4(1.f, 0.f, 0.f, 0.f); + glUniform4fv(glGetUniformLocation(m_ShaderProgramDebugAABB.GetHandle(), "Color"), 1, glm::value_ptr(color)); + glBindVertexArray(m_DebugAABB); + glDrawArrays(GL_LINES, 0, 24); + } } - AABBsToRender.clear(); + + //DrawDebugShadowMap(); #endif - DrawDebugShadowMap(); - - ModelsToRender.clear(); + ClearStuff(); glfwSwapBuffers(m_Window); } @@ -164,33 +184,53 @@ void Renderer::DrawScene() #endif // Draw models - glm::mat4 depthViewMatrix = glm::lookAt(m_SunPosition, m_SunTarget, glm::vec3(0, 1, 0)); + glm::mat4 depthViewMatrix = glm::lookAt(m_SunPosition, m_SunTarget, glm::vec3(0, 1, 0)) * glm::translate(-m_Camera->Position() * glm::vec3(1, 0, 0)); glm::mat4 depthCamera = m_SunProjection * depthViewMatrix; - glm::mat4 depthMVP = depthCamera; glm::mat4 biasMatrix( 0.5, 0.0, 0.0, 0.0, 0.0, 0.5, 0.0, 0.0, 0.0, 0.0, 0.5, 0.0, 0.5, 0.5, 0.5, 1.0 ); - glm::mat4 depthBiasMVP = biasMatrix * depthMVP; m_ShaderProgram.Bind(); - glUniformMatrix4fv(glGetUniformLocation(m_ShaderProgram.GetHandle(), "DepthMVP"), 1, GL_FALSE, glm::value_ptr(depthBiasMVP)); - glUniform3fv(glGetUniformLocation(m_ShaderProgram.GetHandle(), "position"), 3, Light_position.data()); - glUniform3fv(glGetUniformLocation(m_ShaderProgram.GetHandle(), "specular"), 3, Light_specular.data()); - glUniform3fv(glGetUniformLocation(m_ShaderProgram.GetHandle(), "diffuse"), 3, Light_diffuse.data()); - glUniform1fv(glGetUniformLocation(m_ShaderProgram.GetHandle(), "constantAttenuation"), 3, Light_constantAttenuation.data()); - glUniform1fv(glGetUniformLocation(m_ShaderProgram.GetHandle(), "linearAttenuation"), 3, Light_linearAttenuation.data()); - glUniform1fv(glGetUniformLocation(m_ShaderProgram.GetHandle(), "quadraticAttenuation"), 3, Light_quadraticAttenuation.data()); - glUniform1fv(glGetUniformLocation(m_ShaderProgram.GetHandle(), "spotExponent"), 3, Light_spotExponent.data()); + glUniform1i(glGetUniformLocation(m_ShaderProgram.GetHandle(), "numberOfLights"), Lights); + glUniform3fv(glGetUniformLocation(m_ShaderProgram.GetHandle(), "position"), Lights, Light_position.data()); + glUniform3fv(glGetUniformLocation(m_ShaderProgram.GetHandle(), "specular"), Lights, Light_specular.data()); + glUniform3fv(glGetUniformLocation(m_ShaderProgram.GetHandle(), "diffuse"), Lights, Light_diffuse.data()); + glUniform1fv(glGetUniformLocation(m_ShaderProgram.GetHandle(), "constantAttenuation"), Lights, Light_constantAttenuation.data()); + glUniform1fv(glGetUniformLocation(m_ShaderProgram.GetHandle(), "linearAttenuation"), Lights, Light_linearAttenuation.data()); + glUniform1fv(glGetUniformLocation(m_ShaderProgram.GetHandle(), "quadraticAttenuation"), Lights, Light_quadraticAttenuation.data()); + glUniform1fv(glGetUniformLocation(m_ShaderProgram.GetHandle(), "spotExponent"), Lights, Light_spotExponent.data()); if (m_DrawWireframe) { glPolygonMode(GL_FRONT_AND_BACK, GL_LINE); } glActiveTexture(GL_TEXTURE1); glBindTexture(GL_TEXTURE_2D, m_ShadowDepthTexture); - DrawModels(m_ShaderProgram); - + //DrawModels(m_ShaderProgram); + glm::mat4 cameraMatrix = m_Camera->ProjectionMatrix() * m_Camera->ViewMatrix(); + glm::mat4 depthCameraMatrix = biasMatrix * depthCamera; + glm::mat4 MVP; + glm::mat4 depthMVP; + for (auto tuple : ModelsToRender) + { + Model* model; + glm::mat4 modelMatrix; + std::tie(model, modelMatrix) = tuple; + MVP = cameraMatrix * modelMatrix; + depthMVP = depthCameraMatrix * modelMatrix; + glUniformMatrix4fv(glGetUniformLocation(m_ShaderProgram.GetHandle(), "MVP"), 1, GL_FALSE, glm::value_ptr(MVP)); + glUniformMatrix4fv(glGetUniformLocation(m_ShaderProgram.GetHandle(), "DepthMVP"), 1, GL_FALSE, glm::value_ptr(depthMVP)); + glUniformMatrix4fv(glGetUniformLocation(m_ShaderProgram.GetHandle(), "model"), 1, GL_FALSE, glm::value_ptr(modelMatrix)); + glUniformMatrix4fv(glGetUniformLocation(m_ShaderProgram.GetHandle(), "view"), 1, GL_FALSE, glm::value_ptr(m_Camera->ViewMatrix())); + glBindVertexArray(model->VAO); + for (auto texGroup : model->TextureGroups) { + glActiveTexture(GL_TEXTURE0); + glBindTexture(GL_TEXTURE_2D, texGroup.Texture->texture); + glDrawArrays(GL_TRIANGLES, texGroup.StartIndex, texGroup.EndIndex - texGroup.StartIndex + 1); + } + } + #ifdef DEBUG // Debug draw model normals if (m_DrawNormals) { @@ -205,15 +245,16 @@ void Renderer::DrawShadowMap() { glEnable(GL_DEPTH_TEST); glEnable(GL_CULL_FACE); - glCullFace(GL_BACK); + glCullFace(GL_FRONT); glBindFramebuffer(GL_FRAMEBUFFER, m_ShadowFrameBuffer); - glViewport(0, 0, 2048*2, 2048*2); + glViewport(0, 0, m_ShadowMapRes, m_ShadowMapRes); glClear(GL_DEPTH_BUFFER_BIT); //glClearColor(0.0f, 0.0f, 0.0f, 0.0f); - glm::mat4 depthViewMatrix = glm::lookAt(m_SunPosition, m_SunTarget, glm::vec3(0, 1, 0)); + glm::mat4 depthViewMatrix = glm::lookAt(m_SunPosition, m_SunTarget, glm::vec3(0, 1, 0)) * glm::translate(-m_Camera->Position() * glm::vec3(1, 0, 0)); +// glm::mat4 depthViewMatrix = glm::lookAt(m_SunPosition, m_SunTarget, glm::vec3(0, 1, 0)); glm::mat4 depthCamera = m_SunProjection * depthViewMatrix; //glm::mat4 cameraMatrix = depthProjectionMatrix * m_Camera->ViewMatrix(); @@ -222,12 +263,13 @@ void Renderer::DrawShadowMap() m_ShaderProgramShadows.Bind(); glPolygonMode(GL_FRONT_AND_BACK, GL_FILL); - for (int i = 0; i < ModelsToRender.size(); i++) + for (auto tuple : ModelsToRender) { - ModelData* modelData = ModelsToRender.at(i); - auto model = modelData->model; + Model* model; + glm::mat4 modelMatrix; + std::tie(model, modelMatrix) = tuple; - MVP = depthCamera * modelData->ModelMatrix; + MVP = depthCamera * modelMatrix; glUniformMatrix4fv(glGetUniformLocation(m_ShaderProgramShadows.GetHandle(), "MVP"), 1, GL_FALSE, glm::value_ptr(MVP)); glBindVertexArray(model->VAO); @@ -257,14 +299,15 @@ void Renderer::DrawModels(ShaderProgram &shader) glm::mat4 cameraMatrix = m_Camera->ProjectionMatrix() * m_Camera->ViewMatrix(); glm::mat4 MVP; - for (int i = 0; i < ModelsToRender.size(); i++) + for (auto tuple : ModelsToRender) { - ModelData* modelData = ModelsToRender.at(i); - auto model = modelData->model; + Model* model; + glm::mat4 modelMatrix; + std::tie(model, modelMatrix) = tuple; - MVP = cameraMatrix * modelData->ModelMatrix; + MVP = cameraMatrix * modelMatrix; glUniformMatrix4fv(glGetUniformLocation(shader.GetHandle(), "MVP"), 1, GL_FALSE, glm::value_ptr(MVP)); - glUniformMatrix4fv(glGetUniformLocation(shader.GetHandle(), "model"), 1, GL_FALSE, glm::value_ptr(modelData->ModelMatrix)); + glUniformMatrix4fv(glGetUniformLocation(shader.GetHandle(), "model"), 1, GL_FALSE, glm::value_ptr(modelMatrix)); glUniformMatrix4fv(glGetUniformLocation(shader.GetHandle(), "view"), 1, GL_FALSE, glm::value_ptr(m_Camera->ViewMatrix())); glBindVertexArray(model->VAO); for (auto texGroup : model->TextureGroups) { @@ -287,9 +330,9 @@ void Renderer::AddTextToDraw() void Renderer::AddModelToDraw(std::shared_ptr model, glm::vec3 position, glm::quat orientation, glm::vec3 scale) { - glm::mat4 ModelMatrix = glm::translate(glm::mat4(), position) * glm::toMat4(orientation) * glm::scale(scale); + glm::mat4 modelMatrix = glm::translate(glm::mat4(), position) * glm::toMat4(orientation) * glm::scale(scale); // You can now use ModelMatrix to build the MVP matrix - ModelsToRender.push_back(new ModelData(model, ModelMatrix)); + ModelsToRender.push_back(std::make_tuple(model.get(), modelMatrix)); } void Renderer::AddPointLightToDraw( @@ -315,7 +358,15 @@ void Renderer::AddPointLightToDraw( Light_linearAttenuation.push_back(_linearAttenuation); Light_quadraticAttenuation.push_back(_quadraticAttenuation); Light_spotExponent.push_back(_spotExponent); + Lights = Light_constantAttenuation.size(); +} +void Renderer::AddAABBToDraw(glm::vec3 origin, glm::vec3 volumeVector, bool colliding) +{ + glm::mat4 model; + model *= glm::translate(origin); + model *= glm::scale(volumeVector); + AABBsToRender.push_back(std::make_tuple(model, colliding)); } GLuint Renderer::CreateQuad() @@ -410,10 +461,15 @@ GLuint Renderer::CreateAABB() return vao; } -void Renderer::AddAABBToDraw(glm::vec3 origin, glm::vec3 volumeVector) +void Renderer::ClearStuff() { - glm::mat4 model; - model *= glm::translate(origin); - model *= glm::scale(volumeVector); - AABBsToRender.push_back(model); -} + AABBsToRender.clear(); + ModelsToRender.clear(); + Light_position.clear(); + Light_specular.clear(); + Light_diffuse.clear(); + Light_constantAttenuation.clear(); + Light_linearAttenuation.clear(); + Light_quadraticAttenuation.clear(); + Light_spotExponent.clear(); +} \ No newline at end of file diff --git a/Escape-the-Dawn/Renderer.h b/Escape-the-Dawn/Renderer.h index 1f4ef77..2c4c492 100644 --- a/Escape-the-Dawn/Renderer.h +++ b/Escape-the-Dawn/Renderer.h @@ -30,15 +30,8 @@ public: int HEIGHT, WIDTH; - struct ModelData - { - std::shared_ptr model; - glm::mat4 ModelMatrix; - ModelData(std::shared_ptr _model, glm::mat4 _modelMatrix) - : model(_model), ModelMatrix(_modelMatrix) {} - }; - - std::vector ModelsToRender; + std::list> ModelsToRender; + int Lights; std::vector Light_position; std::vector Light_specular; std::vector Light_diffuse; @@ -46,7 +39,7 @@ public: std::vector Light_linearAttenuation; std::vector Light_quadraticAttenuation; std::vector Light_spotExponent; - std::vector AABBsToRender; + std::list> AABBsToRender; Renderer(); @@ -65,7 +58,7 @@ public: float _quadraticAttenuation, float _spotExponent ); - void AddAABBToDraw(glm::vec3 origin, glm::vec3 volumeVector); + void AddAABBToDraw(glm::vec3 origin, glm::vec3 volumeVector, bool colliding); void LoadContent(); @@ -76,6 +69,8 @@ public: void DrawNormals(bool val) { m_DrawNormals = val; } bool DrawWireframe() const { return m_DrawWireframe; } void DrawWireframe(bool val) { m_DrawWireframe = val; } + bool DrawBounds() const { return m_DrawBounds; } + void DrawBounds(bool val) { m_DrawBounds = val; } private: GLFWwindow* m_Window; @@ -84,7 +79,9 @@ private: bool m_VSync; bool m_DrawNormals; bool m_DrawWireframe; + bool m_DrawBounds; + int m_ShadowMapRes; glm::vec3 m_SunPosition; glm::vec3 m_SunTarget; glm::mat4 m_SunProjection; @@ -101,7 +98,8 @@ private: ShaderProgram m_ShaderProgramShadows; ShaderProgram m_ShaderProgramShadowsDrawDepth; ShaderProgram m_ShaderProgramDebugAABB; - + + void ClearStuff(); void DrawScene(); void DrawModels(ShaderProgram &shader); void DrawShadowMap(); diff --git a/Escape-the-Dawn/Shaders/AABB.frag.glsl b/Escape-the-Dawn/Shaders/AABB.frag.glsl index 00cb7ab..16bbb30 100644 --- a/Escape-the-Dawn/Shaders/AABB.frag.glsl +++ b/Escape-the-Dawn/Shaders/AABB.frag.glsl @@ -1,5 +1,7 @@ #version 430 +uniform vec4 Color; + in VertexData { vec3 Position; vec3 Normal; @@ -11,5 +13,5 @@ out vec4 FragmentColor; void main() { //FragmentColor = vec4(1.0 - gl_Color.r, 1.0 - gl_Color.g, 1.0 - gl_Color.b, 0.0); - FragmentColor = vec4(1.0, 1.0, 1.0, 1.0); + FragmentColor = Color; } \ No newline at end of file diff --git a/Escape-the-Dawn/Shaders/Fragment.glsl b/Escape-the-Dawn/Shaders/Fragment.glsl index a852e1b..a16878d 100644 --- a/Escape-the-Dawn/Shaders/Fragment.glsl +++ b/Escape-the-Dawn/Shaders/Fragment.glsl @@ -6,15 +6,15 @@ uniform mat4 view; layout(binding=0) uniform sampler2D texture0; layout(binding=1) uniform sampler2D shadowMap; -const int numberOfLights = 3; - -uniform vec3 position[numberOfLights]; -uniform vec3 specular[numberOfLights]; -uniform vec3 diffuse[numberOfLights]; -uniform float constantAttenuation[numberOfLights]; -uniform float linearAttenuation[numberOfLights]; -uniform float quadraticAttenuation[numberOfLights]; -uniform float spotExponent[numberOfLights]; +const int maxNumberOfLights = 82; +uniform int numberOfLights; +uniform vec3 position[maxNumberOfLights]; +uniform vec3 specular[maxNumberOfLights]; +uniform vec3 diffuse[maxNumberOfLights]; +uniform float constantAttenuation[maxNumberOfLights]; +uniform float linearAttenuation[maxNumberOfLights]; +uniform float quadraticAttenuation[maxNumberOfLights]; +uniform float spotExponent[maxNumberOfLights]; in VertexData { vec3 Position; @@ -23,7 +23,7 @@ in VertexData { vec3 ShadowCoord; } Input; -vec3 scene_ambient = vec3(0.2); +vec3 scene_ambient = vec3(0.3); out vec4 fragmentColor; @@ -49,18 +49,20 @@ void main() { //float cosTheta = clamp(dot(Input.Normal, vec3(0, 1, 0)), 0.0, 1.0); //float bias = 0.001 * tan(acos(cosTheta)); // cosTheta is dot( n,l ), clamped between 0 and 1 //bias = clamp(bias, 0.0, 0.01); - float bias = 0.003; float visibility = 1.0; - vec4 shadowMapValue = texture(shadowMap, Input.ShadowCoord.xy); - if (shadowMapValue.z < Input.ShadowCoord.z - bias) { - visibility = 0.5; + if (Input.ShadowCoord.x >= 0.0 && Input.ShadowCoord.x <= 1.0 && Input.ShadowCoord.y >= 0.0 && Input.ShadowCoord.y <= 1.0) { + float bias = 0.0005; + vec4 shadowMapValue = texture(shadowMap, Input.ShadowCoord.xy); + if (shadowMapValue.z < clamp(Input.ShadowCoord.z - bias, 0, 1)) { + visibility = 0.5; + } } vec3 totalLighting = La * Ka * visibility; float attenuation; - for(int i = 0; i < numberOfLights; i++) + for(int i = 0; i < numberOfLights && i < maxNumberOfLights; i++) { // Light //vec3 lightPosition = vec3(0, 0, 2); diff --git a/Escape-the-Dawn/Shaders/VisualizeDepth.frag.glsl b/Escape-the-Dawn/Shaders/VisualizeDepth.frag.glsl index eef8e6e..42e55f3 100644 --- a/Escape-the-Dawn/Shaders/VisualizeDepth.frag.glsl +++ b/Escape-the-Dawn/Shaders/VisualizeDepth.frag.glsl @@ -12,7 +12,7 @@ out vec4 FragmentColor; float LinearizeDepth(float z) { float n = 0.1; // camera z near - float f = 10.0; // camera z far + float f = 800.0; // camera z far return (2.0 * n) / (f + n - z * (f - n)); } diff --git a/Escape-the-Dawn/Sounds/hum.wav b/Escape-the-Dawn/Sounds/hum.wav new file mode 100644 index 0000000..30601bf Binary files /dev/null and b/Escape-the-Dawn/Sounds/hum.wav differ diff --git a/Escape-the-Dawn/Sounds/siren.wav b/Escape-the-Dawn/Sounds/siren.wav new file mode 100644 index 0000000..54a0238 Binary files /dev/null and b/Escape-the-Dawn/Sounds/siren.wav differ diff --git a/Escape-the-Dawn/System.h b/Escape-the-Dawn/System.h index f295857..f62eda9 100644 --- a/Escape-the-Dawn/System.h +++ b/Escape-the-Dawn/System.h @@ -19,7 +19,9 @@ public: virtual void UpdateEntity(double dt, EntityID entity, EntityID parent) { } // Called when a component is created - virtual void OnComponentCreated(std::string type, std:: shared_ptr component) { } + virtual void OnComponentCreated(std::string type, std::shared_ptr component) { } + // Called when a component is removed + virtual void OnComponentRemoved(std::string type, Component* component) { } protected: World* m_World; diff --git a/Escape-the-Dawn/Systems/CollisionSystem.cpp b/Escape-the-Dawn/Systems/CollisionSystem.cpp index 1bdd10a..ab91656 100644 --- a/Escape-the-Dawn/Systems/CollisionSystem.cpp +++ b/Escape-the-Dawn/Systems/CollisionSystem.cpp @@ -3,7 +3,7 @@ void Systems::CollisionSystem::UpdateEntity(double dt, EntityID entity, EntityID parent) { - if (parent != 0) + /*if (parent != 0) { auto transform = m_World->GetComponent(entity, "Transform"); auto parentTransform = m_World->GetComponent(parent, "Transform"); @@ -11,7 +11,18 @@ void Systems::CollisionSystem::UpdateEntity(double dt, EntityID entity, EntityID transform->Position[0] += parentTransform->Position[0]; transform->Position[1] += parentTransform->Position[1]; transform->Position[2] += parentTransform->Position[2]; - } + }*/ + + auto collisionComponent = m_World->GetComponent(entity, "Collision"); + if (!collisionComponent) + return; + + // Clear old collisions + collisionComponent->CollidingEntities.clear(); + + // Quit out if we're not interested in collision events + if (!collisionComponent->Interested) + return; auto entities = m_World->GetEntities(); @@ -36,7 +47,8 @@ void Systems::CollisionSystem::UpdateEntity(double dt, EntityID entity, EntityID //pair.first, pair.second; if(entity == entity2) - break; + continue; + Intersects(entity, entity2); } } diff --git a/Escape-the-Dawn/Systems/CollisionSystem.cpp.orig b/Escape-the-Dawn/Systems/CollisionSystem.cpp.orig new file mode 100644 index 0000000..572fc4a --- /dev/null +++ b/Escape-the-Dawn/Systems/CollisionSystem.cpp.orig @@ -0,0 +1,134 @@ +#include "CollisionSystem.h" +#include "World.h" + +void Systems::CollisionSystem::UpdateEntity(double dt, EntityID entity, EntityID parent) +{ + /*if (parent != 0) + { + auto transform = m_World->GetComponent(entity, "Transform"); + auto parentTransform = m_World->GetComponent(parent, "Transform"); + + transform->Position[0] += parentTransform->Position[0]; + transform->Position[1] += parentTransform->Position[1]; + transform->Position[2] += parentTransform->Position[2]; +<<<<<<< HEAD + } +======= + }*/ + + auto collisionComponent = m_World->GetComponent(entity, "Collision"); + if (!collisionComponent) + return; + + // Clear old collisions + collisionComponent->CollidingEntities.clear(); + + // Quit out if we're not interested in collision events + if (!collisionComponent->Interested) + return; +>>>>>>> f76c0b336f87a259a7eabf3c532fc885f155a605 + + auto entities = m_World->GetEntities(); + + for (auto pair : *entities) { + EntityID entity2 = pair.first; + EntityID parent2 = pair.second; + + // Check if entity2 is a child of entity + /*auto currentParent = parent; + bool childOfEntity2 = false; + while (currentParent != 0) { + if (currentParent == entity2) { + childOfEntity2 = true; + break; + } + currentParent = entities[currentParent]; + } + if (childOfEntity2) + continue;*/ + + // Check if we're the parent to entity2 + + //pair.first, pair.second; + if(entity == entity2) + continue; + + Intersects(entity, entity2); + } +} + +void Systems::CollisionSystem::Intersects(EntityID aEntity, EntityID bEntity) +{ + auto aTransform = m_World->GetComponent(aEntity, "Transform"); + if(aTransform == nullptr) + return; + auto bTransform = m_World->GetComponent(bEntity, "Transform"); + if(bTransform == nullptr) + return; + + auto aCollisionComponent = m_World->GetComponent(aEntity, "Collision"); + if(aCollisionComponent == nullptr) + return; + auto bCollisionComponent = m_World->GetComponent(bEntity, "Collision"); + if(bCollisionComponent == nullptr) + return; + + + auto aBounds = m_World->GetComponent(aEntity, "Bounds"); + + auto bBounds = m_World->GetComponent(bEntity, "Bounds"); + + glm::vec3 aPos = aTransform->Position + (aBounds->Origin * aTransform->Scale); + glm::vec3 bPos = bTransform->Position + (bBounds->Origin * bTransform->Scale); + + glm::vec3 aMax = aPos + aBounds->VolumeVector * aTransform->Scale; + glm::vec3 aMin = aPos - aBounds->VolumeVector * aTransform->Scale; + glm::vec3 bMax = bPos + bBounds->VolumeVector * bTransform->Scale; + glm::vec3 bMin = bPos - bBounds->VolumeVector * bTransform->Scale; + + if (aMin.x <= bMax.x && bMin.x <= aMax.x) { + if (aMin.y <= bMax.y && bMin.y <= aMax.y) { + if (aMin.z <= bMax.z && bMin.z <= aMax.z) { + aCollisionComponent->CollidingEntities.push_back(aEntity); + bCollisionComponent->CollidingEntities.push_back(bEntity); + return; + } + } + } +} + +void Systems::CollisionSystem::CreateBoundingBox(std::shared_ptr bounds) +{ + float width = abs(bounds->VolumeVector.x); + float height = abs(bounds->VolumeVector.y); + float depth = abs(bounds->VolumeVector.z); + + GLfloat vertices[] = { + bounds->Origin.x - width, bounds->Origin.y - height, bounds->Origin.z - depth, 1.0, + bounds->Origin.x + width, bounds->Origin.y - height, bounds->Origin.z - depth, 1.0, + bounds->Origin.x + width, bounds->Origin.y + height, bounds->Origin.z - depth, 1.0, + bounds->Origin.x - width, bounds->Origin.y + height, bounds->Origin.z - depth, 1.0, + bounds->Origin.x - width, bounds->Origin.y - height, bounds->Origin.z + depth, 1.0, + bounds->Origin.x + width, bounds->Origin.y - height, bounds->Origin.z + depth, 1.0, + bounds->Origin.x + width, bounds->Origin.y + height, bounds->Origin.z + depth, 1.0, + bounds->Origin.x - width, bounds->Origin.y + height, bounds->Origin.z + depth, 1.0, + }; + + GLuint vbo_vertices; + glGenBuffers(1, &vbo_vertices); + glBindBuffer(GL_ARRAY_BUFFER, vbo_vertices); + glBufferData(GL_ARRAY_BUFFER, sizeof(vertices), vertices, 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); +} \ No newline at end of file diff --git a/Escape-the-Dawn/Systems/InputSystem.cpp b/Escape-the-Dawn/Systems/InputSystem.cpp index ef7f17d..495cc55 100644 --- a/Escape-the-Dawn/Systems/InputSystem.cpp +++ b/Escape-the-Dawn/Systems/InputSystem.cpp @@ -47,6 +47,10 @@ void Systems::InputSystem::Update(double dt) if (m_CurrentKeyState[GLFW_KEY_F2] && !m_LastKeyState[GLFW_KEY_F2]) { m_Renderer->DrawNormals(!m_Renderer->DrawNormals()); } + // Bounds + if (m_CurrentKeyState[GLFW_KEY_F3] && !m_LastKeyState[GLFW_KEY_F3]) { + m_Renderer->DrawBounds(!m_Renderer->DrawBounds()); + } #endif } diff --git a/Escape-the-Dawn/Systems/LevelGenerationSystem.cpp b/Escape-the-Dawn/Systems/LevelGenerationSystem.cpp index 70f9166..2e71570 100644 --- a/Escape-the-Dawn/Systems/LevelGenerationSystem.cpp +++ b/Escape-the-Dawn/Systems/LevelGenerationSystem.cpp @@ -4,16 +4,15 @@ Systems::LevelGenerationSystem::LevelGenerationSystem( World* world ) : System(world) { elapsedtime = 0; + + velocity = 0; + startx = 0; startyz = glm::vec2(0, -1000); } void Systems::LevelGenerationSystem::SpawnObstacle() { - - - - typeRandom = 0 + (rand() % 3); - + typeRandom = 0 + (rand() % 10); EntityID ent; @@ -24,36 +23,64 @@ void Systems::LevelGenerationSystem::SpawnObstacle() bounds = m_World->AddComponent(ent, "Bounds"); collision = m_World->AddComponent(ent, "Collision"); model = m_World->AddComponent(ent, "Model"); + auto sound = m_World->AddComponent(ent, "SoundEmitter"); + - positionRandom = -500 + (rand() % 1000); + positionRandom = -500 + startx + (rand() % 1000); + transform->Position = glm::vec3(positionRandom, startyz); + //transform->Velocity = glm::vec3(0.f, 10.f, 100.f); - switch (typeRandom) - { - case 0: - transform->Position = glm::vec3( positionRandom, startyz); // fix position + sound->Loop = true; + sound->Gain = 1.f; + sound->ReferenceDistance = 15.f; + m_World->GetSystem("SoundSystem")->PlaySound(sound, "Sounds/hum.wav"); + + if(typeRandom >= 0 && typeRandom < 2) // Mountain stuff :D + { + float scale = (float)(rand() % 1000) / 250; + transform->Scale = glm::vec3(scale); bounds->VolumeVector = glm::vec3(9, 12, 7); bounds->Origin = glm::vec3(1,11,-1); model->ModelFile = "Models/obstacle_mountain_1.obj"; - - break; - case 1: - transform->Position = glm::vec3( positionRandom, startyz); // fix position + } + else if(typeRandom >= 2 && typeRandom < 5) // Single Mountain :D + { + float scale = (float)(rand() % 1000) / 200; + transform->Scale = glm::vec3(scale); bounds->VolumeVector = glm::vec3(3.5f, 7.5f, 3.5f); bounds->Origin = glm::vec3(0,7.5f,0); model->ModelFile = "Models/obstacle_mountain_2.obj"; - - break; - case 2: - transform->Position = glm::vec3( positionRandom, startyz); // fix position + } + else if(typeRandom >= 5 && typeRandom < 8) + { + float scale = (float)(rand() % 1000) / 100; + transform->Scale = glm::vec3(scale); bounds->VolumeVector = glm::vec3(1, 1, 1); bounds->Origin = glm::vec3(0,1,0); model->ModelFile = "Models/obstacle_cube_1.obj"; + } + if(typeRandom >= 8 && typeRandom < 10) + { + float scale = (float)(rand() % 1000) / 100; + bounds->VolumeVector = glm::vec3(4, 4, 4); + bounds->Origin = glm::vec3(0,4,0); + pointLight = m_World->AddComponent(ent, "PointLight"); + pointLight->Specular = glm::vec3(1.0, 1.0, 1.0); + pointLight->Diffuse = glm::vec3(0.3, 1.0, 0.3); + pointLight->constantAttenuation = 0.f; + pointLight->linearAttenuation = 1.f; + pointLight->quadraticAttenuation = 0.f; + pointLight->spotExponent = 0.0f; - break; - default: + powerUp = m_World->AddComponent(ent, "PowerUp"); + powerUp->Speed = 10.f; - break; - } + model->ModelFile = "Models/powerup.obj"; + } + + + // Put it below ground level + transform->Position.y -= bounds->VolumeVector.y * 2.f; } @@ -67,17 +94,24 @@ void Systems::LevelGenerationSystem::Update( double dt ) elapsedtime = 0; } - std::vector removethis; + std::list removethis; for(auto ent : obstacles) { - auto transformComponent = m_World->GetComponent(ent, "Transform"); - transformComponent->Position.z += 100.f * dt; + auto transform = m_World->GetComponent(ent, "Transform"); - if(transformComponent->Position.z > 100) + transform->Velocity.z = -velocity; + transform->Position += transform->Velocity * (float)dt; + + // Stop raising obstacles when they reach ground level + if (transform->Velocity.y > 0 && transform->Position.y >= 0) { + transform->Position.y = 0; + transform->Velocity.y = 0; + } + + if(transform->Position.z > 800) { - removethis.push_back(ent); - + removethis.push_back(ent); } } @@ -90,4 +124,15 @@ void Systems::LevelGenerationSystem::Update( double dt ) } +void Systems::LevelGenerationSystem::UpdateEntity( double dt, EntityID entity, EntityID parent ) +{ + if( m_World->GetProperty(entity, "Name") == "PlayerShip") + { + auto transformComponent = m_World->GetComponent(entity, "Transform"); + startyz = glm::vec2(0, transformComponent->Position.z - 1000); + startx = transformComponent->Position.x; + velocity = transformComponent->Velocity.z; + } +} + diff --git a/Escape-the-Dawn/Systems/LevelGenerationSystem.h b/Escape-the-Dawn/Systems/LevelGenerationSystem.h index 5bf91d6..864c047 100644 --- a/Escape-the-Dawn/Systems/LevelGenerationSystem.h +++ b/Escape-the-Dawn/Systems/LevelGenerationSystem.h @@ -2,11 +2,15 @@ #define LevelGenerationSystem_h__ #include "System.h" +#include "Systems/SoundSystem.h" #include "World.h" #include "Components/Transform.h" #include "Components/Bounds.h" #include "Components/Collision.h" #include "Components/Model.h" +#include "Components/PointLight.h" +#include "Components/SoundEmitter.h" +#include "Components/PowerUp.h" namespace Systems @@ -20,20 +24,25 @@ namespace Systems void SpawnObstacle(); void Update(double dt) override; - + void UpdateEntity(double dt, EntityID entity, EntityID parent) override; + private: int typeRandom; int positionRandom; glm::vec2 startyz; + float startx; + double elapsedtime; std::list obstacles; - + float velocity; std::shared_ptr transform; std::shared_ptr bounds; std::shared_ptr collision; std::shared_ptr model; + std::shared_ptr pointLight; + std::shared_ptr powerUp; }; } diff --git a/Escape-the-Dawn/Systems/PlayerSystem.cpp b/Escape-the-Dawn/Systems/PlayerSystem.cpp index 91e0731..6e44d64 100644 --- a/Escape-the-Dawn/Systems/PlayerSystem.cpp +++ b/Escape-the-Dawn/Systems/PlayerSystem.cpp @@ -3,6 +3,8 @@ Systems::PlayerSystem::PlayerSystem( World* world ) : System(world) { + m_PlayerSpeed = 20; + m_PlayerOriginalBounds = glm::vec3(0); } void Systems::PlayerSystem::Update(double dt) @@ -18,14 +20,12 @@ void Systems::PlayerSystem::UpdateEntity(double dt, EntityID entity, EntityID pa if (input == nullptr) return; - float speed = 20.0f; - auto name = m_World->GetProperty(entity, "Name"); if (name == "Camera") { - glm::vec3 Camera_Right = glm::vec3(glm::vec4(1, 0, 0, 0) * transform->Orientation); glm::vec3 Camera_Forward = glm::vec3(glm::vec4(0, 0, 1, 0) * transform->Orientation); + float speed = m_PlayerSpeed; if(input->KeyState[GLFW_KEY_LEFT_SHIFT]) { speed *= 4.0f; } @@ -59,26 +59,23 @@ void Systems::PlayerSystem::UpdateEntity(double dt, EntityID entity, EntityID pa //--------------------------------------------------------------------- // TOUCHING THIS CODE MIGHT COUSE THE UNIVERSE TO IMPLODE, ALSO DRAGONS } - - auto collision = m_World->GetComponent(entity, "Collision"); - if(collision->CollidingEntities.size() != 0) - int c = 1; // lol } - - - - name = m_World->GetProperty(entity, "Name"); if (name == "PlayerShip") { + auto bounds = m_World->GetComponent(entity, "Bounds"); + if (bounds && m_PlayerOriginalBounds == glm::vec3(0)) { + m_PlayerOriginalBounds = bounds->VolumeVector; + } + glm::vec3 Ship_Right = glm::vec3(glm::vec4(1, 0, 0, 0)); glm::vec3 Ship_Forward = glm::vec3(glm::vec4(0, 0, 1, 0)); - float TurnSpeed = 2.0f; + float TurnSpeed = 1.0f; glm::vec3 Euler = glm::eulerAngles(transform->Orientation); if(input->KeyState[GLFW_KEY_LEFT]) { - transform->Position -= Ship_Right * (float)dt * speed; + transform->Position -= Ship_Right * (float)dt * (m_PlayerSpeed + Euler.z); if(Euler.z < 10.f) { @@ -94,7 +91,7 @@ void Systems::PlayerSystem::UpdateEntity(double dt, EntityID entity, EntityID pa } } else if(input->KeyState[GLFW_KEY_RIGHT]) { - transform->Position += Ship_Right * (float)dt * speed; + transform->Position += Ship_Right * (float)dt * (m_PlayerSpeed - Euler.z); if(Euler.z > -10.f) { @@ -118,6 +115,12 @@ void Systems::PlayerSystem::UpdateEntity(double dt, EntityID entity, EntityID pa else if(Euler.z > 0.f) transform->Orientation = transform->Orientation * glm::angleAxis((float)dt,glm::vec3(0,0,-1)); } + + // Update player bounds based on rotation + if (bounds) { + Euler = glm::eulerAngles(transform->Orientation); + bounds->VolumeVector.x = m_PlayerOriginalBounds.x * glm::cos(glm::radians(Euler.z)); + } } } diff --git a/Escape-the-Dawn/Systems/PlayerSystem.h b/Escape-the-Dawn/Systems/PlayerSystem.h index f0dd0db..0d5ccad 100644 --- a/Escape-the-Dawn/Systems/PlayerSystem.h +++ b/Escape-the-Dawn/Systems/PlayerSystem.h @@ -7,6 +7,7 @@ #include "Components/Transform.h" #include "Components/Input.h" #include "Components/Collision.h" +#include "Components/Bounds.h" #include "logging.h" @@ -23,7 +24,8 @@ namespace Systems void UpdateEntity(double dt, EntityID entity, EntityID parent) override; private: - + float m_PlayerSpeed; + glm::vec3 m_PlayerOriginalBounds; }; } diff --git a/Escape-the-Dawn/Systems/RenderSystem.cpp b/Escape-the-Dawn/Systems/RenderSystem.cpp index bed895a..3165a0f 100644 --- a/Escape-the-Dawn/Systems/RenderSystem.cpp +++ b/Escape-the-Dawn/Systems/RenderSystem.cpp @@ -30,11 +30,12 @@ void Systems::RenderSystem::UpdateEntity( double dt, EntityID entity, EntityID p // Debug draw bounds #ifdef DEBUG + auto collision = m_World->GetComponent(entity, "Collision"); auto bounds = m_World->GetComponent(entity, "Bounds"); if (bounds != nullptr) { - glm::vec3 origin = transformComponent->Scale * (transformComponent->Position + bounds->Origin); + glm::vec3 origin = transformComponent->Position + (transformComponent->Scale * bounds->Origin); glm::vec3 volumeVector = transformComponent->Scale * bounds->VolumeVector; - m_Renderer->AddAABBToDraw(origin, volumeVector); + m_Renderer->AddAABBToDraw(origin, volumeVector, (collision != nullptr && collision->CollidingEntities.size() > 0)); } #endif diff --git a/Escape-the-Dawn/Systems/RenderSystem.h b/Escape-the-Dawn/Systems/RenderSystem.h index 85ac40e..d2a182f 100644 --- a/Escape-the-Dawn/Systems/RenderSystem.h +++ b/Escape-the-Dawn/Systems/RenderSystem.h @@ -10,6 +10,7 @@ #include "Components/Transform.h" #include "Components/Camera.h" #include "Components/Bounds.h" +#include "Components/Collision.h" #include "Renderer.h" namespace Systems diff --git a/Escape-the-Dawn/Systems/SoundSystem.h b/Escape-the-Dawn/Systems/SoundSystem.h index a0396a6..88373d4 100644 --- a/Escape-the-Dawn/Systems/SoundSystem.h +++ b/Escape-the-Dawn/Systems/SoundSystem.h @@ -20,6 +20,7 @@ public: void Update(double dt) override; void UpdateEntity(double dt, EntityID entity, EntityID parent) override; void OnComponentCreated(std::string type, std::shared_ptr component) override; + void OnComponentRemoved(std::string type, Component* component) override; void PlaySound(std::shared_ptr emitter, std::string path); // Use if you want to play a temporary .wav file not from component void PlaySound(std::shared_ptr emitter); // Use if you want to play .wav file from component // imon no hate plx T.T void StopSound(std::shared_ptr emitter); @@ -37,7 +38,7 @@ private: unsigned long dataSize; - std::map m_Source; + std::map m_Sources; std::map m_BufferCache; // string = fileName }; diff --git a/Escape-the-Dawn/Systems/SoundSystem.h.orig b/Escape-the-Dawn/Systems/SoundSystem.h.orig new file mode 100644 index 0000000..b6ccbfb --- /dev/null +++ b/Escape-the-Dawn/Systems/SoundSystem.h.orig @@ -0,0 +1,51 @@ +#ifndef SoundEmitter_h__ +#define SoundEmitter_h__ + +#include "System.h" +#include "Components/Transform.h" +#include "Components/SoundEmitter.h" +#include +#include +#include +#include + +namespace Systems +{ + +class SoundSystem : public System +{ +public: + SoundSystem(World* world); + + void Update(double dt) override; + void UpdateEntity(double dt, EntityID entity, EntityID parent) override; + void OnComponentCreated(std::string type, std::shared_ptr component) override; +<<<<<<< HEAD + void PlaySound(std::shared_ptr emitter, std::string path); // Use if you want to play a temporary .wav file not from component + void PlaySound(std::shared_ptr emitter); // Use if you want to play .wav file from component // imon no hate plx T.T + void StopSound(std::shared_ptr emitter); +======= + void OnComponentRemoved(std::string type, Component* component) override; + void PlaySound(std::shared_ptr emitter, std::string fileName); +>>>>>>> f76c0b336f87a259a7eabf3c532fc885f155a605 + +private: + ALuint LoadFile(std::string fileName); + ALuint CreateSource(); + + //File-info + char type[4]; + unsigned long size, chunkSize; + short formatType, channels; + unsigned long sampleRate, avgBytesPerSec; + short bytesPerSample, bitsPerSample; + unsigned long dataSize; + + + std::map m_Sources; + std::map m_BufferCache; // string = fileName +}; + +} +#endif // !SoundEmitter_h__ + diff --git a/Escape-the-Dawn/Systems/SoundsSystem.cpp b/Escape-the-Dawn/Systems/SoundsSystem.cpp index 2073a64..b66a738 100644 --- a/Escape-the-Dawn/Systems/SoundsSystem.cpp +++ b/Escape-the-Dawn/Systems/SoundsSystem.cpp @@ -18,6 +18,9 @@ Systems::SoundSystem::SoundSystem(World* world) } alGetError(); + + alSpeedOfSound(340.29f); // Speed of sound + alDistanceModel(AL_INVERSE_DISTANCE); } void Systems::SoundSystem::Update(double dt) @@ -54,10 +57,10 @@ void Systems::SoundSystem::UpdateEntity(double dt, EntityID entity, EntityID par auto soundEmitter = m_World->GetComponent(entity, "SoundEmitter"); if(soundEmitter != nullptr) { - ALuint source = m_Source[soundEmitter.get()]; - alSourcei(source, AL_GAIN, soundEmitter->Gain); - alSourcei(source, AL_MAX_DISTANCE, soundEmitter->MaxDistance); - alSourcei(source, AL_REFERENCE_DISTANCE, soundEmitter->ReferenceDistance); + ALuint source = m_Sources[soundEmitter]; + alSourcef(source, AL_GAIN, soundEmitter->Gain); + //alSourcef(source, AL_MAX_DISTANCE, soundEmitter->MaxDistance); + alSourcef(source, AL_REFERENCE_DISTANCE, soundEmitter->ReferenceDistance); alSourcef(source, AL_PITCH, soundEmitter->Pitch); alSourcei(source, AL_LOOPING, soundEmitter->Loop); @@ -72,12 +75,15 @@ void Systems::SoundSystem::UpdateEntity(double dt, EntityID entity, EntityID par } } -void Systems::SoundSystem::PlaySound(std::shared_ptr emitter, std::string path) +void Systems::SoundSystem::PlaySound(std::shared_ptr emitter, std::string fileName) { - ALuint buffer = LoadFile(path); - ALuint source = m_Source[emitter.get()]; + if (m_Sources.find(emitter.get()) == m_Sources.end()) + return; + + ALuint buffer = LoadFile(fileName); + ALuint source = m_Sources[emitter.get()]; alSourcei(source, AL_BUFFER, buffer); - alSourcePlay(m_Source[emitter.get()]); + alSourcePlay(m_Sources[emitter.get()]); } void Systems::SoundSystem::PlaySound(std::shared_ptr emitter) @@ -97,7 +103,17 @@ void Systems::SoundSystem::OnComponentCreated(std::string type, std::shared_ptr< { if(type == "SoundEmitter") { ALuint source = CreateSource(); - m_Source[component.get()] = source; + m_Sources[component.get()] = source; + } +} + +void Systems::SoundSystem::OnComponentRemoved(std::string type, Component* component) +{ + if(type == "SoundEmitter") { + if (m_Sources.find(component) != m_Sources.end()) { + ALuint source = m_Sources[component]; + alDeleteSources(1, &source); + } } } diff --git a/Escape-the-Dawn/Systems/SoundsSystem.cpp.orig b/Escape-the-Dawn/Systems/SoundsSystem.cpp.orig new file mode 100644 index 0000000..0cf29de --- /dev/null +++ b/Escape-the-Dawn/Systems/SoundsSystem.cpp.orig @@ -0,0 +1,210 @@ +#include "SoundSystem.h" +#include "World.h" + +Systems::SoundSystem::SoundSystem(World* world) + : System(world) +{ + //initialize OpenAL + ALCdevice* Device = alcOpenDevice(NULL); + ALCcontext* context; + if(Device) + { + context = alcCreateContext(Device, NULL); + alcMakeContextCurrent(context); + } + else + { + LOG_ERROR("OMG OPEN AL FAIL"); + } + + alGetError(); + + alSpeedOfSound(340.29f); // Speed of sound + alDistanceModel(AL_INVERSE_DISTANCE); +} + +void Systems::SoundSystem::Update(double dt) +{ + +} + +void Systems::SoundSystem::UpdateEntity(double dt, EntityID entity, EntityID parent) +{ + auto transformComponent = m_World->GetComponent(entity, "Transform"); + if (transformComponent == nullptr) + return; + + auto entityName = m_World->GetProperty(entity, "Name"); + if (entityName == "Camera") + { + glm::vec3 playerPos = transformComponent->Position; + ALfloat listenerPos[3] = { playerPos.x, playerPos.y, -playerPos.z }; + + glm::vec3 playerVel = transformComponent->Velocity; + ALfloat listenerVel[3] = { playerVel.x, playerVel.y, -playerVel.z }; + + glm::fquat playerQuatOri = transformComponent->Orientation; + glm::vec3 playerOriFW = glm::rotate(playerQuatOri, glm::vec3(0, 0, -1)); + glm::vec3 playerOriUP = glm::rotate(playerQuatOri, glm::vec3(0, 1, 0)); + ALfloat listenerOri[6] = { playerOriFW.x, playerOriFW.y, playerOriFW.z, playerOriUP.x, playerOriUP.y, playerOriUP.z }; + + //Listener + alListenerfv(AL_POSITION, listenerPos); + alListenerfv(AL_VELOCITY, listenerVel); + alListenerfv(AL_ORIENTATION, listenerOri); + } + + auto soundEmitter = m_World->GetComponent(entity, "SoundEmitter"); + if(soundEmitter != nullptr) + { + ALuint source = m_Sources[soundEmitter]; + alSourcef(source, AL_GAIN, soundEmitter->Gain); + //alSourcef(source, AL_MAX_DISTANCE, soundEmitter->MaxDistance); + alSourcef(source, AL_REFERENCE_DISTANCE, soundEmitter->ReferenceDistance); + alSourcef(source, AL_PITCH, soundEmitter->Pitch); + alSourcei(source, AL_LOOPING, soundEmitter->Loop); + + glm::vec3 emitterPos = transformComponent->Position; + ALfloat sourcePos[3] = { emitterPos.x, emitterPos.y, -emitterPos.z }; + + glm::vec3 emitterVel= transformComponent->Velocity; + ALfloat sourceVel[3] = { emitterVel.x, emitterVel.y, -emitterVel.z }; + + alSourcefv(source, AL_POSITION, sourcePos); + alSourcefv(source, AL_VELOCITY, sourceVel); + } +} + +void Systems::SoundSystem::PlaySound(std::shared_ptr emitter, std::string path) +{ +<<<<<<< HEAD + ALuint buffer = LoadFile(path); + ALuint source = m_Source[emitter.get()]; +======= + if (m_Sources.find(emitter.get()) == m_Sources.end()) + return; + + ALuint buffer = LoadFile(fileName); + ALuint source = m_Sources[emitter.get()]; +>>>>>>> f76c0b336f87a259a7eabf3c532fc885f155a605 + alSourcei(source, AL_BUFFER, buffer); + alSourcePlay(m_Sources[emitter.get()]); +} + +void Systems::SoundSystem::PlaySound(std::shared_ptr emitter) +{ + ALuint buffer = LoadFile(emitter->Path); + ALuint source = m_Source[emitter.get()]; + alSourcei(source, AL_BUFFER, buffer); + alSourcePlay(m_Source[emitter.get()]); +} + +void Systems::SoundSystem::StopSound(std::shared_ptr emitter) +{ + alSourceStop(m_Source[emitter.get()]); +} + +void Systems::SoundSystem::OnComponentCreated(std::string type, std::shared_ptr component) +{ + if(type == "SoundEmitter") { + ALuint source = CreateSource(); + m_Sources[component.get()] = source; + } +} + +void Systems::SoundSystem::OnComponentRemoved(std::string type, Component* component) +{ + if(type == "SoundEmitter") { + if (m_Sources.find(component) != m_Sources.end()) { + ALuint source = m_Sources[component]; + alDeleteSources(1, &source); + } + } +} + +ALuint Systems::SoundSystem::LoadFile(std::string path) +{ + if (m_BufferCache.find(path) != m_BufferCache.end()) + return m_BufferCache[path]; + + FILE *fp = NULL; + fp = fopen(path.c_str(), "rb"); + + //CHECK FOR VALID WAVE-FILE + fread(type, sizeof(char), 4, fp); + if(type[0]!='R' || type[1]!='I' || type[2]!='F' || type[3]!='F') { + LOG_ERROR("ERROR: No RIFF in WAVE-file"); + return 0; + } + + 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"); + return 0; + } + + fread(type, sizeof(char), 4, fp); + if(type[0]!='f' || type[1]!='m' || type[2]!='t' || type[3]!=' ') { + LOG_ERROR("ERROR: No fmt in WAVE-file"); + return 0; + } + + //READ THE DATA FROM WAVE-FILE + fread(&chunkSize, sizeof(unsigned long), 1, fp); + fread(&formatType, sizeof(short), 1, fp); + fread(&channels, sizeof(short), 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); + + fread(type, sizeof(char), 4, fp); + if(type[0]!='d' || type[1]!='a' || type[2]!='t' || type[3]!='a') + { + LOG_ERROR("ERROR: WAVE-file Missing data"); + return 0; + } + + fread(&dataSize, sizeof(unsigned long), 1, fp); + + unsigned char* buf = new unsigned char[dataSize]; + fread(buf, sizeof(unsigned char), dataSize, fp); + fclose(fp); + + // Create buffer + ALuint format = 0; + if(bitsPerSample == 8) + { + if(channels == 1) + format = AL_FORMAT_MONO8; + else if(channels == 2) + format = AL_FORMAT_STEREO8; + } + if(bitsPerSample == 16) + { + if (channels == 1) + format = AL_FORMAT_MONO16; + else if (channels == 2) + format = AL_FORMAT_STEREO16; + } + + ALuint buffer; + alGenBuffers(1, &buffer); + alBufferData(buffer, format, buf, dataSize, sampleRate); + delete[] buf; + + m_BufferCache[path] = buffer; + return buffer; +} + +ALuint Systems::SoundSystem::CreateSource() +{ + ALuint source; + alGenSources((ALuint)1, &source); + + alDopplerFactor(2.f); // Numbers greater than 1 will increase Doppler effect, numbers lower than 1 will decrease the Doppler effect + alDopplerVelocity(350.f); // Defines the velocity of the sound + + return source; +} \ No newline at end of file diff --git a/Escape-the-Dawn/TextFrame.cpp b/Escape-the-Dawn/TextFrame.cpp index e69de29..bc52864 100644 --- a/Escape-the-Dawn/TextFrame.cpp +++ b/Escape-the-Dawn/TextFrame.cpp @@ -0,0 +1 @@ +#include "TextFrame.h" \ No newline at end of file diff --git a/Escape-the-Dawn/World.cpp b/Escape-the-Dawn/World.cpp index e52c803..500395e 100644 --- a/Escape-the-Dawn/World.cpp +++ b/Escape-the-Dawn/World.cpp @@ -61,12 +61,19 @@ bool World::ValidEntity(EntityID entity) void World::RemoveEntity(EntityID entity) { m_EntityParents.erase(entity); - m_EntityComponents.erase(entity); + // Remove components for (auto pair : m_EntityComponents[entity]) { auto type = pair.first; auto component = pair.second; + // Trigger events + for (auto pair : m_Systems) { + auto system = pair.second; + system->OnComponentRemoved(type, component.get()); + } m_ComponentsOfType[type].remove(component); } + m_EntityComponents.erase(entity); + RecycleEntityID(entity); } diff --git a/Escape-the-Dawn/World.h b/Escape-the-Dawn/World.h index ce8ca37..add6ae3 100644 --- a/Escape-the-Dawn/World.h +++ b/Escape-the-Dawn/World.h @@ -60,7 +60,7 @@ public: std::shared_ptr AddComponent(EntityID entity, std::string componentType); std::shared_ptr AddComponent(EntityID entity, std::string componentType); template - std::shared_ptr GetComponent(EntityID entity, std::string componentType); + T* GetComponent(EntityID entity, std::string componentType); /*std::vector GetEntityChildren(EntityID entity);*/ @@ -117,9 +117,9 @@ std::shared_ptr World::AddComponent(EntityID entity, std::string componentTyp template -std::shared_ptr World::GetComponent(EntityID entity, std::string componentType) +T* World::GetComponent(EntityID entity, std::string componentType) { - return std::static_pointer_cast(m_EntityComponents[entity][componentType]); + return (T*)m_EntityComponents[entity][componentType].get(); } #endif // World_h__ \ No newline at end of file