Merge branch 'master' of github.com:sippeangelo/Escape-the-Dawn

Conflicts:
	Escape-the-Dawn/GameWorld.cpp
	Escape-the-Dawn/Systems/CollisionSystem.cpp
	Escape-the-Dawn/Systems/SoundSystem.h
	Escape-the-Dawn/Systems/SoundsSystem.cpp
This commit is contained in:
Adam
2014-03-13 20:09:41 +01:00
42 changed files with 1421 additions and 303 deletions
+3
View File
@@ -10,7 +10,10 @@ namespace Components
struct Collision : Component struct Collision : Component
{ {
Collision() : Phantom(false), Interested(false) { }
bool Phantom; bool Phantom;
bool Interested;
std::vector<EntityID> CollidingEntities; std::vector<EntityID> CollidingEntities;
}; };
+1 -1
View File
@@ -11,7 +11,7 @@ namespace Components
struct SoundEmitter : Component struct SoundEmitter : Component
{ {
float Gain; float Gain;
float MaxDistance; //float MaxDistance;
float ReferenceDistance; float ReferenceDistance;
float Pitch; float Pitch;
bool Loop; bool Loop;
+4 -3
View File
@@ -82,12 +82,12 @@
<Optimization>MaxSpeed</Optimization> <Optimization>MaxSpeed</Optimization>
<FunctionLevelLinking>true</FunctionLevelLinking> <FunctionLevelLinking>true</FunctionLevelLinking>
<IntrinsicFunctions>true</IntrinsicFunctions> <IntrinsicFunctions>true</IntrinsicFunctions>
<PreprocessorDefinitions>GLEW_STATIC;%(PreprocessorDefinitions)</PreprocessorDefinitions> <PreprocessorDefinitions>GLEW_STATIC;DEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<PrecompiledHeader>NotUsing</PrecompiledHeader> <PrecompiledHeader>NotUsing</PrecompiledHeader>
<DebugInformationFormat>None</DebugInformationFormat> <DebugInformationFormat>ProgramDatabase</DebugInformationFormat>
<MinimalRebuild>true</MinimalRebuild>
</ClCompile> </ClCompile>
<Link> <Link>
<GenerateDebugInformation>false</GenerateDebugInformation>
<EnableCOMDATFolding>true</EnableCOMDATFolding> <EnableCOMDATFolding>true</EnableCOMDATFolding>
<OptimizeReferences>true</OptimizeReferences> <OptimizeReferences>true</OptimizeReferences>
<AdditionalDependencies>OpenAL32.lib;opengl32.lib;glu32.lib;SOIL.lib;glew32s.lib;glfw3.lib;%(AdditionalDependencies)</AdditionalDependencies> <AdditionalDependencies>OpenAL32.lib;opengl32.lib;glu32.lib;SOIL.lib;glew32s.lib;glfw3.lib;%(AdditionalDependencies)</AdditionalDependencies>
@@ -148,6 +148,7 @@
<ClInclude Include="glerror.h" /> <ClInclude Include="glerror.h" />
<ClInclude Include="MenuFrame.h" /> <ClInclude Include="MenuFrame.h" />
<ClInclude Include="Model.h" /> <ClInclude Include="Model.h" />
<ClInclude Include="Rectangle.h" />
<ClInclude Include="OBJ.h" /> <ClInclude Include="OBJ.h" />
<ClInclude Include="OpenGL.h" /> <ClInclude Include="OpenGL.h" />
<ClInclude Include="Renderer.h" /> <ClInclude Include="Renderer.h" />
@@ -144,6 +144,7 @@
<Filter>GUI</Filter> <Filter>GUI</Filter>
</ClInclude> </ClInclude>
<ClInclude Include="GameWorld.h" /> <ClInclude Include="GameWorld.h" />
<ClInclude Include="Rectangle.h" />
<ClInclude Include="Camera.h" /> <ClInclude Include="Camera.h" />
<ClInclude Include="OBJ.h" /> <ClInclude Include="OBJ.h" />
<ClInclude Include="OpenGL.h" /> <ClInclude Include="OpenGL.h" />
@@ -0,0 +1,204 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup>
<ClCompile Include="World.cpp" />
<ClCompile Include="Systems\CollisionSystem.cpp">
<Filter>Systems</Filter>
</ClCompile>
<ClCompile Include="Systems\LevelGenerationSystem.cpp">
<Filter>Systems</Filter>
</ClCompile>
<ClCompile Include="Systems\InputSystem.cpp">
<Filter>Systems</Filter>
</ClCompile>
<ClCompile Include="Systems\ParticleSystem.cpp">
<Filter>Systems</Filter>
</ClCompile>
<ClCompile Include="Systems\PlayerSystem.cpp">
<Filter>Systems</Filter>
</ClCompile>
<ClCompile Include="Systems\RenderSystem.cpp">
<Filter>Systems</Filter>
</ClCompile>
<ClCompile Include="Systems\SoundsSystem.cpp">
<Filter>Systems</Filter>
</ClCompile>
<ClCompile Include="Model.cpp" />
<ClCompile Include="Engine.h" />
<ClCompile Include="Texture.cpp" />
<ClCompile Include="GUIManager.cpp">
<Filter>GUI</Filter>
</ClCompile>
<ClCompile Include="Renderer.cpp" />
<ClCompile Include="ShaderProgram.cpp" />
<ClCompile Include="Frame.cpp">
<Filter>GUI</Filter>
</ClCompile>
<ClCompile Include="TextFrame.cpp">
<Filter>GUI</Filter>
</ClCompile>
<ClCompile Include="MenuFrame.cpp">
<Filter>GUI</Filter>
</ClCompile>
<ClCompile Include="GameFrame.cpp">
<Filter>GUI</Filter>
</ClCompile>
<ClCompile Include="Camera.cpp" />
<ClCompile Include="OBJ.cpp" />
<ClCompile Include="main.cpp" />
<ClCompile Include="GameWorld.cpp" />
</ItemGroup>
<ItemGroup>
<ClInclude Include="Component.h" />
<ClInclude Include="Entity.h" />
<ClInclude Include="System.h" />
<ClInclude Include="World.h" />
<ClInclude Include="Systems\CollisionSystem.h">
<Filter>Systems</Filter>
</ClInclude>
<ClInclude Include="Systems\LevelGenerationSystem.h">
<Filter>Systems</Filter>
</ClInclude>
<ClInclude Include="Systems\InputSystem.h">
<Filter>Systems</Filter>
</ClInclude>
<ClInclude Include="Systems\ParticleSystem.h">
<Filter>Systems</Filter>
</ClInclude>
<ClInclude Include="Systems\PlayerSystem.h">
<Filter>Systems</Filter>
</ClInclude>
<ClInclude Include="Systems\RenderSystem.h">
<Filter>Systems</Filter>
</ClInclude>
<ClInclude Include="Systems\SoundSystem.h">
<Filter>Systems</Filter>
</ClInclude>
<ClInclude Include="Model.h" />
<ClInclude Include="Components\Transform.h">
<Filter>Components</Filter>
</ClInclude>
<ClInclude Include="ShaderProgram.h" />
<ClInclude Include="Components\Input.h">
<Filter>Components</Filter>
</ClInclude>
<ClInclude Include="Components\Model.h">
<Filter>Components</Filter>
</ClInclude>
<ClInclude Include="Components\ParticleEmitter.h">
<Filter>Components</Filter>
</ClInclude>
<ClInclude Include="Components\PointLight.h">
<Filter>Components</Filter>
</ClInclude>
<ClInclude Include="Components\PowerUp.h">
<Filter>Components</Filter>
</ClInclude>
<ClInclude Include="Components\Sprite.h">
<Filter>Components</Filter>
</ClInclude>
<ClInclude Include="Components\Stat.h">
<Filter>Components</Filter>
</ClInclude>
<ClInclude Include="Components\Template.h">
<Filter>Components</Filter>
</ClInclude>
<ClInclude Include="Components\SoundEmitter.h">
<Filter>Components</Filter>
</ClInclude>
<ClInclude Include="Color.h" />
<ClInclude Include="Factory.h" />
<ClInclude Include="Components\DirectionalLight.h">
<Filter>Components</Filter>
</ClInclude>
<ClInclude Include="Components\Collision.h">
<Filter>Components</Filter>
</ClInclude>
<ClInclude Include="Components\Camera.h">
<Filter>Components</Filter>
</ClInclude>
<ClInclude Include="Components\Bounds.h">
<Filter>Components</Filter>
</ClInclude>
<ClInclude Include="glerror.h">
<Filter>Util</Filter>
</ClInclude>
<ClInclude Include="logging.h">
<Filter>Util</Filter>
</ClInclude>
<ClInclude Include="Renderer.h" />
<ClInclude Include="Texture.h" />
<ClInclude Include="GUIManager.h">
<Filter>GUI</Filter>
</ClInclude>
<ClInclude Include="Frame.h">
<Filter>GUI</Filter>
</ClInclude>
<ClInclude Include="TextFrame.h">
<Filter>GUI</Filter>
</ClInclude>
<ClInclude Include="MenuFrame.h">
<Filter>GUI</Filter>
</ClInclude>
<ClInclude Include="GameFrame.h">
<Filter>GUI</Filter>
</ClInclude>
<ClInclude Include="GameWorld.h" />
<<<<<<< HEAD
<ClInclude Include="Rectangle.h" />
=======
<ClInclude Include="Camera.h" />
<ClInclude Include="OBJ.h" />
<ClInclude Include="OpenGL.h" />
>>>>>>> d0320477a978a38d87e94afbea65dc08fd10c860
</ItemGroup>
<ItemGroup>
<None Include="Shaders\Fragment.glsl">
<Filter>Shaders</Filter>
</None>
<None Include="Shaders\Vertex.glsl">
<Filter>Shaders</Filter>
</None>
<None Include="Shaders\Normals.geo.glsl">
<Filter>Shaders</Filter>
</None>
<None Include="Shaders\Normals.frag.glsl">
<Filter>Shaders</Filter>
</None>
<None Include="Fragment2.glsl">
<Filter>Shaders</Filter>
</None>
<None Include="Shaders\ShadowMap.frag.glsl">
<Filter>Shaders</Filter>
</None>
<None Include="Shaders\ShadowMap.vert.glsl">
<Filter>Shaders</Filter>
</None>
<None Include="Shaders\VisualizeDepth.frag.glsl">
<Filter>Shaders</Filter>
</None>
<None Include="Shaders\VisualizeDepth.vert.glsl">
<Filter>Shaders</Filter>
</None>
<None Include="Shaders\AABB.frag.glsl">
<Filter>Shaders</Filter>
</None>
</ItemGroup>
<ItemGroup>
<Filter Include="Systems">
<UniqueIdentifier>{657e11f4-52e7-4336-b77f-80f00b85c33f}</UniqueIdentifier>
</Filter>
<Filter Include="Components">
<UniqueIdentifier>{59929465-a139-43b9-9c75-48121d156e78}</UniqueIdentifier>
</Filter>
<Filter Include="Shaders">
<UniqueIdentifier>{54f1eb6f-dc00-4e97-a3ef-ac255d755e2e}</UniqueIdentifier>
</Filter>
<Filter Include="Util">
<UniqueIdentifier>{d985d7a7-c041-46fe-ae03-aa40295a7aad}</UniqueIdentifier>
</Filter>
<Filter Include="GUI">
<UniqueIdentifier>{7bdb0f69-049e-4f16-b271-2495e02e4b28}</UniqueIdentifier>
</Filter>
</ItemGroup>
</Project>
@@ -0,0 +1,183 @@
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup Label="ProjectConfigurations">
<ProjectConfiguration Include="Debug|Win32">
<Configuration>Debug</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Release|Win32">
<Configuration>Release</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
</ItemGroup>
<PropertyGroup Label="Globals">
<ProjectGuid>{FE405CFA-8FCE-4867-92CF-797E73B36482}</ProjectGuid>
<RootNamespace>EscapetheDawn</RootNamespace>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
<CharacterSet>MultiByte</CharacterSet>
<PlatformToolset>v110</PlatformToolset>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<WholeProgramOptimization>true</WholeProgramOptimization>
<CharacterSet>MultiByte</CharacterSet>
<PlatformToolset>v110</PlatformToolset>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
<ImportGroup Label="ExtensionSettings">
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<PropertyGroup Label="UserMacros" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<LibraryPath>$(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)</LibraryPath>
<OutDir>$(SolutionDir)bin\</OutDir>
<IntDir>$(SolutionDir)obj\$(ProjectName)\</IntDir>
<TargetName>$(ProjectName)-$(Configuration)</TargetName>
<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)</IncludePath>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<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)</IncludePath>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<LibraryPath>$(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)</LibraryPath>
<OutDir>$(SolutionDir)bin\</OutDir>
<IntDir>$(SolutionDir)obj\$(ProjectName)\</IntDir>
<TargetName>$(ProjectName)-$(Configuration)</TargetName>
</PropertyGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<Optimization>Disabled</Optimization>
<PreprocessorDefinitions>GLEW_STATIC;DEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<PrecompiledHeader>NotUsing</PrecompiledHeader>
</ClCompile>
<Link>
<GenerateDebugInformation>true</GenerateDebugInformation>
<SubSystem>Console</SubSystem>
<AdditionalDependencies>OpenAL32.lib;opengl32.lib;glu32.lib;SOIL.lib;glew32sd.lib;glfw3.lib;%(AdditionalDependencies)</AdditionalDependencies>
</Link>
<PostBuildEvent />
<PostBuildEvent />
<Lib>
<AdditionalDependencies>OpenAL32.lib;opengl32.lib;glu32.lib;SOIL.lib;glew32sd.lib;glfw3.lib</AdditionalDependencies>
<ForceSymbolReferences>
</ForceSymbolReferences>
</Lib>
<ProjectReference />
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<Optimization>MaxSpeed</Optimization>
<FunctionLevelLinking>true</FunctionLevelLinking>
<IntrinsicFunctions>true</IntrinsicFunctions>
<PreprocessorDefinitions>GLEW_STATIC;DEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<PrecompiledHeader>NotUsing</PrecompiledHeader>
<DebugInformationFormat>ProgramDatabase</DebugInformationFormat>
<MinimalRebuild>true</MinimalRebuild>
</ClCompile>
<Link>
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<OptimizeReferences>true</OptimizeReferences>
<AdditionalDependencies>OpenAL32.lib;opengl32.lib;glu32.lib;SOIL.lib;glew32s.lib;glfw3.lib;%(AdditionalDependencies)</AdditionalDependencies>
</Link>
<Lib>
<AdditionalDependencies>OpenAL32.lib;opengl32.lib;glu32.lib;SOIL.lib;glew32s.lib;glfw3.lib;</AdditionalDependencies>
</Lib>
</ItemDefinitionGroup>
<ItemGroup>
<ClCompile Include="Camera.cpp" />
<ClCompile Include="Engine.h" />
<ClCompile Include="Frame.cpp" />
<ClCompile Include="GameFrame.cpp" />
<ClCompile Include="GameWorld.cpp" />
<ClCompile Include="GUIManager.cpp" />
<ClCompile Include="main.cpp" />
<ClCompile Include="MenuFrame.cpp" />
<ClCompile Include="Model.cpp" />
<ClCompile Include="OBJ.cpp" />
<ClCompile Include="Renderer.cpp" />
<ClCompile Include="ShaderProgram.cpp" />
<ClCompile Include="Systems\CollisionSystem.cpp" />
<ClCompile Include="Texture.cpp" />
<ClCompile Include="TextFrame.cpp" />
<ClCompile Include="World.cpp" />
<ClCompile Include="Systems\InputSystem.cpp" />
<ClCompile Include="Systems\LevelGenerationSystem.cpp" />
<ClCompile Include="Systems\ParticleSystem.cpp" />
<ClCompile Include="Systems\PlayerSystem.cpp" />
<ClCompile Include="Systems\RenderSystem.cpp" />
<ClCompile Include="Systems\SoundsSystem.cpp" />
</ItemGroup>
<ItemGroup>
<ClInclude Include="Camera.h" />
<ClInclude Include="Color.h" />
<ClInclude Include="Component.h" />
<ClInclude Include="Components\Camera.h" />
<ClInclude Include="Factory.h" />
<ClInclude Include="Components\Bounds.h" />
<ClInclude Include="Components\Collision.h" />
<ClInclude Include="Components\DirectionalLight.h" />
<ClInclude Include="Components\Input.h" />
<ClInclude Include="Components\Model.h" />
<ClInclude Include="Components\ParticleEmitter.h" />
<ClInclude Include="Components\PointLight.h" />
<ClInclude Include="Components\PowerUp.h" />
<ClInclude Include="Components\SoundEmitter.h" />
<ClInclude Include="Components\Sprite.h" />
<ClInclude Include="Components\Stat.h" />
<ClInclude Include="Components\Template.h" />
<ClInclude Include="Components\Transform.h" />
<ClInclude Include="Entity.h" />
<ClInclude Include="Frame.h" />
<ClInclude Include="GameFrame.h" />
<ClInclude Include="GameWorld.h" />
<ClInclude Include="GUIManager.h" />
<ClInclude Include="logging.h" />
<ClInclude Include="glerror.h" />
<ClInclude Include="MenuFrame.h" />
<ClInclude Include="Model.h" />
<ClInclude Include="Rectangle.h" />
<ClInclude Include="OBJ.h" />
<ClInclude Include="OpenGL.h" />
<ClInclude Include="Renderer.h" />
<ClInclude Include="ShaderProgram.h" />
<ClInclude Include="Systems\InputSystem.h" />
<ClInclude Include="System.h" />
<ClInclude Include="Systems\CollisionSystem.h" />
<ClInclude Include="Systems\LevelGenerationSystem.h" />
<ClInclude Include="Systems\ParticleSystem.h" />
<ClInclude Include="Systems\PlayerSystem.h" />
<ClInclude Include="Systems\RenderSystem.h" />
<ClInclude Include="Systems\SoundSystem.h" />
<ClInclude Include="Texture.h" />
<ClInclude Include="TextFrame.h" />
<ClInclude Include="World.h" />
</ItemGroup>
<ItemGroup>
<None Include="Fragment2.glsl" />
<None Include="Shaders\AABB.frag.glsl" />
<None Include="Shaders\Fragment.glsl" />
<None Include="Shaders\Normals.frag.glsl" />
<None Include="Shaders\Normals.geo.glsl" />
<None Include="Shaders\VisualizeDepth.frag.glsl" />
<None Include="Shaders\VisualizeDepth.vert.glsl" />
<None Include="Shaders\ShadowMap.frag.glsl" />
<None Include="Shaders\ShadowMap.vert.glsl" />
<None Include="Shaders\Vertex.glsl" />
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
</ImportGroup>
</Project>
+92
View File
@@ -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()
{
}
*/
+51
View File
@@ -0,0 +1,51 @@
/*#ifndef Frame_h__
#define Frame_h__
#include <map>
#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<std::string, void*> Properties = new std::map<std::string, void*>();
void AddChild(Frame childFrame);
void RemoveChild(Frame childFrame);
void Update(double dt);
void Draw();
protected:
virtual void Initialize();
};
}
#endif*/
+8
View File
@@ -0,0 +1,8 @@
/*#include "GUIManager.h"
int GUI::GUIManager::Add(Frame frame)
{
//Frame.Add(frame);
//return CreateUID();
}
*/
+26
View File
@@ -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 */
+1
View File
@@ -0,0 +1 @@
#include "GameFrame.h"
+37 -33
View File
@@ -22,31 +22,16 @@ void GameWorld::Initialize()
std::shared_ptr<Components::SoundEmitter> soundEmitter; std::shared_ptr<Components::SoundEmitter> soundEmitter;
EntityID ent; EntityID ent;
// Camera
entcamera = CreateEntity();
SetProperty(entcamera, "Name", std::string("Camera"));
transform = AddComponent<Components::Transform>(entcamera, "Transform");
AddComponent<Components::Input>(entcamera, "Input");
transform->Position = glm::vec3(0.f, 10.f, 14.f);
camera = AddComponent<Components::Camera>(entcamera, "Camera");
camera->FOV = 45.f;
camera->FarClip = 1000.f;
camera->NearClip = 0.01f;
transform->Orientation = glm::angleAxis<float>(glm::radians(15.0f),glm::vec3(1,0,0));
collision = AddComponent<Components::Collision>(entcamera, "Collision");
collision->Phantom = false;
bounds = AddComponent<Components::Bounds>(entcamera, "Bounds");
bounds->VolumeVector = glm::vec3(0.1f,0.1f,0.1f);
// Fucking lights // Fucking lights
ent = CreateEntity(); ent = CreateEntity();
transform = AddComponent<Components::Transform>(ent, "Transform"); transform = AddComponent<Components::Transform>(ent, "Transform");
transform->Position = glm::vec3(0.f, 4.f, 0.f); transform->Position = glm::vec3(0.f, 7.f, 0.f);
transform->Position = glm::vec3(10.f, 2.f, 5.f);
pointLight = AddComponent<Components::PointLight>(ent, "PointLight"); pointLight = AddComponent<Components::PointLight>(ent, "PointLight");
pointLight->Specular = glm::vec3(1.0, 1.0, 1.0); 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, 0.0, 5.0);
pointLight->Diffuse = glm::vec3(1.0, 1.0, 5.0);
pointLight->constantAttenuation = 0.f; pointLight->constantAttenuation = 0.f;
pointLight->linearAttenuation = 1.f; pointLight->linearAttenuation = 1.f;
pointLight->quadraticAttenuation = 0.f; pointLight->quadraticAttenuation = 0.f;
@@ -55,13 +40,10 @@ void GameWorld::Initialize()
model->ModelFile = "Models/sphere.obj"; model->ModelFile = "Models/sphere.obj";
ent = CreateEntity(); ent = CreateEntity();
transform = AddComponent<Components::Transform>(ent, "Transform"); transform = AddComponent<Components::Transform>(ent, "Transform");
transform->Position = glm::vec3(10.f, 4.f, 0.f); transform->Position = glm::vec3(10.f, 7.f, 0.f);
transform->Position = glm::vec3(0.f, 2.f, 5.f);
pointLight = AddComponent<Components::PointLight>(ent, "PointLight"); pointLight = AddComponent<Components::PointLight>(ent, "PointLight");
pointLight->Specular = glm::vec3(1.0, 1.0, 1.0); 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, 5.0, 0.0);
pointLight->Specular = glm::vec3(3.0, 3.0, 3.0);
pointLight->Diffuse = glm::vec3(3.0, 0.0, 0.0);
pointLight->constantAttenuation = 0.f; pointLight->constantAttenuation = 0.f;
pointLight->linearAttenuation = 1.f; pointLight->linearAttenuation = 1.f;
pointLight->quadraticAttenuation = 0.f; pointLight->quadraticAttenuation = 0.f;
@@ -70,12 +52,10 @@ void GameWorld::Initialize()
model->ModelFile = "Models/sphere.obj"; model->ModelFile = "Models/sphere.obj";
ent = CreateEntity(); ent = CreateEntity();
transform = AddComponent<Components::Transform>(ent, "Transform"); transform = AddComponent<Components::Transform>(ent, "Transform");
transform->Position = glm::vec3(0.f, -4.f, 0.f); transform->Position = glm::vec3(-10.f, 7.f, 0.f);
transform->Position = glm::vec3(-10.f, 2.f, 5.f);
pointLight = AddComponent<Components::PointLight>(ent, "PointLight"); pointLight = AddComponent<Components::PointLight>(ent, "PointLight");
pointLight->Specular = glm::vec3(1.0, 1.0, 1.0); pointLight->Specular = glm::vec3(1.0, 1.0, 1.0);
pointLight->Diffuse = glm::vec3(1.0, 1.0, 1.0); pointLight->Diffuse = glm::vec3(5.0, 0.0, 0.0);
pointLight->Diffuse = glm::vec3(0.0, 3.0, 0.0);
pointLight->constantAttenuation = 0.f; pointLight->constantAttenuation = 0.f;
pointLight->linearAttenuation = 1.f; pointLight->linearAttenuation = 1.f;
pointLight->quadraticAttenuation = 0.f; pointLight->quadraticAttenuation = 0.f;
@@ -94,16 +74,24 @@ void GameWorld::Initialize()
m_Player = CreateEntity(); m_Player = CreateEntity();
SetProperty(m_Player, "Name", std::string("PlayerShip")); SetProperty(m_Player, "Name", std::string("PlayerShip"));
transform = AddComponent<Components::Transform>(m_Player, "Transform"); transform = AddComponent<Components::Transform>(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); transform->Scale = glm::vec3(1.0f);
model = AddComponent<Components::Model>(m_Player, "Model"); model = AddComponent<Components::Model>(m_Player, "Model");
model->ModelFile = "Models/ship.obj"; model->ModelFile = "Models/ship.obj";
pointLight = AddComponent<Components::PointLight>(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<Components::Input>(m_Player, "Input"); AddComponent<Components::Input>(m_Player, "Input");
collision = AddComponent<Components::Collision>(m_Player, "Collision"); collision = AddComponent<Components::Collision>(m_Player, "Collision");
collision->Phantom = false; collision->Phantom = false;
collision->Interested = true;
bounds = AddComponent<Components::Bounds>(m_Player, "Bounds"); bounds = AddComponent<Components::Bounds>(m_Player, "Bounds");
bounds->Origin = glm::vec3(transform->Position.x, transform->Position.y - 4, transform->Position.z + 3); bounds->Origin = glm::vec3(0, 0, 2.f);
bounds->VolumeVector = glm::vec3(4.f,0.7f,4); bounds->VolumeVector = glm::vec3(4.f, 0.7f, 1);
soundEmitter = AddComponent<Components::SoundEmitter>(m_Player, "SoundEmitter"); soundEmitter = AddComponent<Components::SoundEmitter>(m_Player, "SoundEmitter");
soundEmitter->Loop = true; soundEmitter->Loop = true;
soundEmitter->MaxDistance = FLT_MAX; soundEmitter->MaxDistance = FLT_MAX;
@@ -113,7 +101,23 @@ void GameWorld::Initialize()
soundEmitter->Path = "Sounds/hallelujah.wav"; soundEmitter->Path = "Sounds/hallelujah.wav";
GetSystem<Systems::SoundSystem>("SoundSystem")->PlaySound(soundEmitter); GetSystem<Systems::SoundSystem>("SoundSystem")->PlaySound(soundEmitter);
ent = CreateEntity();
// Camera
entcamera = CreateEntity(m_Player);
SetProperty(entcamera, "Name", std::string("Camera"));
transform = AddComponent<Components::Transform>(entcamera, "Transform");
AddComponent<Components::Input>(entcamera, "Input");
transform->Position = glm::vec3(0.f, 10.f, 14.f);
camera = AddComponent<Components::Camera>(entcamera, "Camera");
camera->FOV = 45.f;
camera->FarClip = 1000.f;
camera->NearClip = 0.01f;
transform->Orientation = glm::angleAxis<float>(glm::radians(15.0f),glm::vec3(1,0,0));
/*ent = CreateEntity();
transform = AddComponent<Components::Transform>(ent, "Transform"); transform = AddComponent<Components::Transform>(ent, "Transform");
transform->Position = glm::vec3(10.f, 4.f, 0.f); transform->Position = glm::vec3(10.f, 4.f, 0.f);
model = AddComponent<Components::Model>(ent, "Model"); model = AddComponent<Components::Model>(ent, "Model");
@@ -122,7 +126,7 @@ void GameWorld::Initialize()
collision->Phantom = false; collision->Phantom = false;
bounds = AddComponent<Components::Bounds>(player2, "Bounds"); bounds = AddComponent<Components::Bounds>(player2, "Bounds");
bounds->Origin = transform->Position; 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) void GameWorld::Update(double dt)
+65 -70
View File
@@ -5,7 +5,7 @@ void GameWorld::Initialize()
{ {
World::Initialize(); World::Initialize();
//AddSystem("LevelGenerationSystem"); AddSystem("LevelGenerationSystem");
AddSystem("InputSystem"); AddSystem("InputSystem");
AddSystem("CollisionSystem"); AddSystem("CollisionSystem");
//AddSystem("ParticleSystem"); //AddSystem("ParticleSystem");
@@ -19,129 +19,124 @@ void GameWorld::Initialize()
std::shared_ptr<Components::Camera> camera; std::shared_ptr<Components::Camera> camera;
std::shared_ptr<Components::Bounds> bounds; std::shared_ptr<Components::Bounds> bounds;
std::shared_ptr<Components::Collision> collision; std::shared_ptr<Components::Collision> collision;
std::shared_ptr<Components::SoundEmitter> soundEmitter;
EntityID ent; EntityID ent;
// Camera
entcamera = CreateEntity();
SetProperty(entcamera, "Name", std::string("Camera"));
transform = AddComponent<Components::Transform>(entcamera, "Transform");
AddComponent<Components::Input>(entcamera, "Input");
transform->Position = glm::vec3(0.f, 2.f, 10.f);
camera = AddComponent<Components::Camera>(entcamera, "Camera");
camera->FOV = 45.f;
camera->FarClip = 1000.f;
camera->NearClip = 0.01f;
transform->Orientation = glm::angleAxis<float>(glm::radians(25.0f),glm::vec3(1,0,0));
collision = AddComponent<Components::Collision>(entcamera, "Collision");
collision->Phantom = false;
bounds = AddComponent<Components::Bounds>(entcamera, "Bounds");
bounds->Origin = transform->Position;
bounds->VolumeVector = glm::vec3(4.f,2.f,2.f);
// Fucking lights // Fucking lights
ent = CreateEntity(); ent = CreateEntity();
transform = AddComponent<Components::Transform>(ent, "Transform"); transform = AddComponent<Components::Transform>(ent, "Transform");
transform->Position = glm::vec3(0.f, 4.f, 0.f); transform->Position = glm::vec3(0.f, 7.f, 0.f);
transform->Position = glm::vec3(10.f, 2.f, 5.f);
pointLight = AddComponent<Components::PointLight>(ent, "PointLight"); pointLight = AddComponent<Components::PointLight>(ent, "PointLight");
pointLight->Specular = glm::vec3(1.0, 1.0, 1.0); 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, 0.0, 5.0);
pointLight->Diffuse = glm::vec3(1.0, 1.0, 5.0);
pointLight->constantAttenuation = 0.f; pointLight->constantAttenuation = 0.f;
pointLight->linearAttenuation = 1.f; pointLight->linearAttenuation = 1.f;
pointLight->quadraticAttenuation = 0.f; pointLight->quadraticAttenuation = 0.f;
pointLight->spotExponent = 0.0f; pointLight->spotExponent = 0.0f;
model = AddComponent<Components::Model>(ent, "Model"); model = AddComponent<Components::Model>(ent, "Model");
model->ModelFile = "sphere.obj"; model->ModelFile = "Models/sphere.obj";
ent = CreateEntity(); ent = CreateEntity();
transform = AddComponent<Components::Transform>(ent, "Transform"); transform = AddComponent<Components::Transform>(ent, "Transform");
transform->Position = glm::vec3(10.f, 4.f, 0.f); transform->Position = glm::vec3(10.f, 7.f, 0.f);
transform->Position = glm::vec3(0.f, 2.f, 5.f);
pointLight = AddComponent<Components::PointLight>(ent, "PointLight"); pointLight = AddComponent<Components::PointLight>(ent, "PointLight");
pointLight->Specular = glm::vec3(1.0, 1.0, 1.0); 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, 5.0, 0.0);
pointLight->Specular = glm::vec3(3.0, 3.0, 3.0);
pointLight->Diffuse = glm::vec3(3.0, 0.0, 0.0);
pointLight->constantAttenuation = 0.f; pointLight->constantAttenuation = 0.f;
pointLight->linearAttenuation = 1.f; pointLight->linearAttenuation = 1.f;
pointLight->quadraticAttenuation = 0.f; pointLight->quadraticAttenuation = 0.f;
pointLight->spotExponent = 0.0f; pointLight->spotExponent = 0.0f;
model = AddComponent<Components::Model>(ent, "Model"); model = AddComponent<Components::Model>(ent, "Model");
model->ModelFile = "sphere.obj"; model->ModelFile = "Models/sphere.obj";
ent = CreateEntity(); ent = CreateEntity();
transform = AddComponent<Components::Transform>(ent, "Transform"); transform = AddComponent<Components::Transform>(ent, "Transform");
transform->Position = glm::vec3(0.f, -4.f, 0.f); transform->Position = glm::vec3(-10.f, 7.f, 0.f);
transform->Position = glm::vec3(-10.f, 2.f, 5.f);
pointLight = AddComponent<Components::PointLight>(ent, "PointLight"); pointLight = AddComponent<Components::PointLight>(ent, "PointLight");
pointLight->Specular = glm::vec3(1.0, 1.0, 1.0); pointLight->Specular = glm::vec3(1.0, 1.0, 1.0);
pointLight->Diffuse = glm::vec3(1.0, 1.0, 1.0); pointLight->Diffuse = glm::vec3(5.0, 0.0, 0.0);
pointLight->Diffuse = glm::vec3(0.0, 3.0, 0.0);
pointLight->constantAttenuation = 0.f; pointLight->constantAttenuation = 0.f;
pointLight->linearAttenuation = 1.f; pointLight->linearAttenuation = 1.f;
pointLight->quadraticAttenuation = 0.f; pointLight->quadraticAttenuation = 0.f;
pointLight->spotExponent = 0.0f; pointLight->spotExponent = 0.0f;
model = AddComponent<Components::Model>(ent, "Model"); model = AddComponent<Components::Model>(ent, "Model");
model->ModelFile = "sphere.obj"; model->ModelFile = "Models/sphere.obj";
//ground //ground
ent = CreateEntity(); ent = CreateEntity();
transform = AddComponent<Components::Transform>(ent, "Transform"); transform = AddComponent<Components::Transform>(ent, "Transform");
transform->Position = glm::vec3(0.f, 0.f, 0.f); transform->Position = glm::vec3(0.f, 0.f, 0.f);
model = AddComponent<Components::Model>(ent, "Model"); model = AddComponent<Components::Model>(ent, "Model");
model->ModelFile = "plane.obj"; model->ModelFile = "Models/plane.obj";
// Player // Player
<<<<<<< HEAD
player1 = CreateEntity();
transform = AddComponent<Components::Transform>(player1, "Transform");
transform->Position = glm::vec3(0.f, 0.f, 0.f);
model = AddComponent<Components::Model>(player1, "Model");
model->ModelFile = "ship.obj";
collision = AddComponent<Components::Collision>(player1, "Collision");
collision->Phantom = false;
bounds = AddComponent<Components::Bounds>(player1, "Bounds");
bounds->Origin = transform->Position;
bounds->VolumeVector = glm::vec3(10.f,10.f,5.f);
player2 = CreateEntity();
transform = AddComponent<Components::Transform>(player2, "Transform");
transform->Position = glm::vec3(10.f, 0.f, 0.f);
model = AddComponent<Components::Model>(player2, "Model");
=======
m_Player = CreateEntity(); m_Player = CreateEntity();
SetProperty(m_Player, "Name", std::string("PlayerShip"));
transform = AddComponent<Components::Transform>(m_Player, "Transform"); transform = AddComponent<Components::Transform>(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<Components::Model>(m_Player, "Model"); model = AddComponent<Components::Model>(m_Player, "Model");
model->ModelFile = "ship.obj"; model->ModelFile = "Models/ship.obj";
auto bounds = AddComponent<Components::Bounds>(m_Player, "Bounds"); pointLight = AddComponent<Components::PointLight>(m_Player, "PointLight");
bounds->Origin = glm::vec3(0.f); pointLight->Specular = glm::vec3(1.0, 1.0, 1.0);
bounds->VolumeVector = glm::vec3(1.0f, 2.0f, 3.0f); 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<Components::Input>(m_Player, "Input");
collision = AddComponent<Components::Collision>(m_Player, "Collision");
collision->Phantom = false;
collision->Interested = true;
bounds = AddComponent<Components::Bounds>(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<Components::SoundEmitter>(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<Systems::SoundSystem>("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<Components::Transform>(entcamera, "Transform");
AddComponent<Components::Input>(entcamera, "Input");
transform->Position = glm::vec3(0.f, 10.f, 14.f);
camera = AddComponent<Components::Camera>(entcamera, "Camera");
camera->FOV = 45.f;
camera->FarClip = 1000.f;
camera->NearClip = 0.01f;
transform->Orientation = glm::angleAxis<float>(glm::radians(15.0f),glm::vec3(1,0,0));
/*ent = CreateEntity();
transform = AddComponent<Components::Transform>(ent, "Transform"); transform = AddComponent<Components::Transform>(ent, "Transform");
transform->Position = glm::vec3(10.f, 4.f, 0.f); transform->Position = glm::vec3(10.f, 4.f, 0.f);
model = AddComponent<Components::Model>(ent, "Model"); model = AddComponent<Components::Model>(ent, "Model");
>>>>>>> 21b2e3bdc15ac8b21f027a7f531574f46187ae80 model->ModelFile = "Models/ship.obj";
model->ModelFile = "ship.obj";
collision = AddComponent<Components::Collision>(player2, "Collision"); collision = AddComponent<Components::Collision>(player2, "Collision");
collision->Phantom = false; collision->Phantom = false;
bounds = AddComponent<Components::Bounds>(player2, "Bounds"); bounds = AddComponent<Components::Bounds>(player2, "Bounds");
bounds->Origin = transform->Position; 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) void GameWorld::Update(double dt)
{ {
World::Update(dt); World::Update(dt);
<<<<<<< HEAD
if(GetSystem<Systems::CollisionSystem>("CollisionSystem")->Intersects(player1, entcamera))
assert(false);
=======
auto transform = GetComponent<Components::Transform>(m_Player, "Transform");
transform->Orientation = transform->Orientation * glm::angleAxis<float>(dt, glm::vec3(0, 0, 1));
>>>>>>> 21b2e3bdc15ac8b21f027a7f531574f46187ae80
} }
void GameWorld::RegisterComponents() void GameWorld::RegisterComponents()
@@ -164,7 +159,7 @@ void GameWorld::RegisterComponents()
void GameWorld::RegisterSystems() 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("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("ParticleSystem", [this]() { return new Systems::ParticleSystem(this); });
-53
View File
@@ -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> renderer)
: m_Renderer(renderer), World() { }
void Initialize();
void RegisterSystems() override;
void RegisterComponents() override;
void Update(double dt) ;
private:
std::shared_ptr<Renderer> m_Renderer;
<<<<<<< HEAD
EntityID entcamera, player1, player2;
=======
EntityID m_Player;
>>>>>>> 21b2e3bdc15ac8b21f027a7f531574f46187ae80
};
#endif // GameWorld_h__
+1
View File
@@ -0,0 +1 @@
#include "MenuFrame.h"
+12
View File
@@ -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
Binary file not shown.

After

Width:  |  Height:  |  Size: 6.5 KiB

+32
View File
@@ -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
+105 -49
View File
@@ -3,12 +3,21 @@
Renderer::Renderer() Renderer::Renderer()
{ {
m_VSync = false; m_VSync = false;
#ifdef DEBUG
m_DrawNormals = false; m_DrawNormals = false;
m_DrawWireframe = 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_SunTarget = glm::vec3(0, 0, 0);
m_SunProjection = glm::ortho<float>(-20, 20, -20, 20, -10, 20); m_SunProjection = glm::ortho<float>(-200, 200, -10, 100, -800, 800);
Lights = 0;
} }
void Renderer::Initialize() void Renderer::Initialize()
@@ -92,7 +101,7 @@ void Renderer::LoadContent()
m_DebugAABB = CreateAABB(); m_DebugAABB = CreateAABB();
m_ScreenQuad = CreateQuad(); m_ScreenQuad = CreateQuad();
CreateShadowMap(2048*2); CreateShadowMap(m_ShadowMapRes);
} }
void Renderer::CreateShadowMap(int resolution) void Renderer::CreateShadowMap(int resolution)
@@ -128,22 +137,33 @@ void Renderer::Draw(double dt)
DrawScene(); DrawScene();
#ifdef DEBUG #ifdef DEBUG
glEnable(GL_BLEND); // Draw bounding boxes
glBlendFunc(GL_ONE_MINUS_DST_COLOR, GL_ZERO); if (m_DrawBounds) {
m_ShaderProgramDebugAABB.Bind(); glEnable(GL_BLEND);
for (auto aabbModelMatrix : AABBsToRender) { glBlendFunc(GL_ONE_MINUS_DST_COLOR, GL_ZERO);
glm::mat4 cameraMatrix = m_Camera->ProjectionMatrix() * m_Camera->ViewMatrix(); m_ShaderProgramDebugAABB.Bind();
glm::mat4 MVP = cameraMatrix * aabbModelMatrix; for (auto tuple : AABBsToRender) {
glUniformMatrix4fv(glGetUniformLocation(m_ShaderProgramDebugAABB.GetHandle(), "MVP"), 1, GL_FALSE, glm::value_ptr(MVP)); glm::mat4 modelMatrix;
glBindVertexArray(m_DebugAABB); bool colliding;
glDrawArrays(GL_LINES, 0, 24); 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 #endif
DrawDebugShadowMap(); ClearStuff();
ModelsToRender.clear();
glfwSwapBuffers(m_Window); glfwSwapBuffers(m_Window);
} }
@@ -164,33 +184,53 @@ void Renderer::DrawScene()
#endif #endif
// Draw models // 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 depthCamera = m_SunProjection * depthViewMatrix;
glm::mat4 depthMVP = depthCamera;
glm::mat4 biasMatrix( glm::mat4 biasMatrix(
0.5, 0.0, 0.0, 0.0, 0.5, 0.0, 0.0, 0.0,
0.0, 0.5, 0.0, 0.0, 0.0, 0.5, 0.0, 0.0,
0.0, 0.0, 0.5, 0.0, 0.0, 0.0, 0.5, 0.0,
0.5, 0.5, 0.5, 1.0 0.5, 0.5, 0.5, 1.0
); );
glm::mat4 depthBiasMVP = biasMatrix * depthMVP;
m_ShaderProgram.Bind(); m_ShaderProgram.Bind();
glUniformMatrix4fv(glGetUniformLocation(m_ShaderProgram.GetHandle(), "DepthMVP"), 1, GL_FALSE, glm::value_ptr(depthBiasMVP)); glUniform1i(glGetUniformLocation(m_ShaderProgram.GetHandle(), "numberOfLights"), Lights);
glUniform3fv(glGetUniformLocation(m_ShaderProgram.GetHandle(), "position"), 3, Light_position.data()); glUniform3fv(glGetUniformLocation(m_ShaderProgram.GetHandle(), "position"), Lights, Light_position.data());
glUniform3fv(glGetUniformLocation(m_ShaderProgram.GetHandle(), "specular"), 3, Light_specular.data()); glUniform3fv(glGetUniformLocation(m_ShaderProgram.GetHandle(), "specular"), Lights, Light_specular.data());
glUniform3fv(glGetUniformLocation(m_ShaderProgram.GetHandle(), "diffuse"), 3, Light_diffuse.data()); glUniform3fv(glGetUniformLocation(m_ShaderProgram.GetHandle(), "diffuse"), Lights, Light_diffuse.data());
glUniform1fv(glGetUniformLocation(m_ShaderProgram.GetHandle(), "constantAttenuation"), 3, Light_constantAttenuation.data()); glUniform1fv(glGetUniformLocation(m_ShaderProgram.GetHandle(), "constantAttenuation"), Lights, Light_constantAttenuation.data());
glUniform1fv(glGetUniformLocation(m_ShaderProgram.GetHandle(), "linearAttenuation"), 3, Light_linearAttenuation.data()); glUniform1fv(glGetUniformLocation(m_ShaderProgram.GetHandle(), "linearAttenuation"), Lights, Light_linearAttenuation.data());
glUniform1fv(glGetUniformLocation(m_ShaderProgram.GetHandle(), "quadraticAttenuation"), 3, Light_quadraticAttenuation.data()); glUniform1fv(glGetUniformLocation(m_ShaderProgram.GetHandle(), "quadraticAttenuation"), Lights, Light_quadraticAttenuation.data());
glUniform1fv(glGetUniformLocation(m_ShaderProgram.GetHandle(), "spotExponent"), 3, Light_spotExponent.data()); glUniform1fv(glGetUniformLocation(m_ShaderProgram.GetHandle(), "spotExponent"), Lights, Light_spotExponent.data());
if (m_DrawWireframe) { if (m_DrawWireframe) {
glPolygonMode(GL_FRONT_AND_BACK, GL_LINE); glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
} }
glActiveTexture(GL_TEXTURE1); glActiveTexture(GL_TEXTURE1);
glBindTexture(GL_TEXTURE_2D, m_ShadowDepthTexture); 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 #ifdef DEBUG
// Debug draw model normals // Debug draw model normals
if (m_DrawNormals) { if (m_DrawNormals) {
@@ -205,15 +245,16 @@ void Renderer::DrawShadowMap()
{ {
glEnable(GL_DEPTH_TEST); glEnable(GL_DEPTH_TEST);
glEnable(GL_CULL_FACE); glEnable(GL_CULL_FACE);
glCullFace(GL_BACK); glCullFace(GL_FRONT);
glBindFramebuffer(GL_FRAMEBUFFER, m_ShadowFrameBuffer); glBindFramebuffer(GL_FRAMEBUFFER, m_ShadowFrameBuffer);
glViewport(0, 0, 2048*2, 2048*2); glViewport(0, 0, m_ShadowMapRes, m_ShadowMapRes);
glClear(GL_DEPTH_BUFFER_BIT); glClear(GL_DEPTH_BUFFER_BIT);
//glClearColor(0.0f, 0.0f, 0.0f, 0.0f); //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 depthCamera = m_SunProjection * depthViewMatrix;
//glm::mat4 cameraMatrix = depthProjectionMatrix * m_Camera->ViewMatrix(); //glm::mat4 cameraMatrix = depthProjectionMatrix * m_Camera->ViewMatrix();
@@ -222,12 +263,13 @@ void Renderer::DrawShadowMap()
m_ShaderProgramShadows.Bind(); m_ShaderProgramShadows.Bind();
glPolygonMode(GL_FRONT_AND_BACK, GL_FILL); glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
for (int i = 0; i < ModelsToRender.size(); i++) for (auto tuple : ModelsToRender)
{ {
ModelData* modelData = ModelsToRender.at(i); Model* model;
auto model = modelData->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)); glUniformMatrix4fv(glGetUniformLocation(m_ShaderProgramShadows.GetHandle(), "MVP"), 1, GL_FALSE, glm::value_ptr(MVP));
glBindVertexArray(model->VAO); glBindVertexArray(model->VAO);
@@ -257,14 +299,15 @@ void Renderer::DrawModels(ShaderProgram &shader)
glm::mat4 cameraMatrix = m_Camera->ProjectionMatrix() * m_Camera->ViewMatrix(); glm::mat4 cameraMatrix = m_Camera->ProjectionMatrix() * m_Camera->ViewMatrix();
glm::mat4 MVP; glm::mat4 MVP;
for (int i = 0; i < ModelsToRender.size(); i++) for (auto tuple : ModelsToRender)
{ {
ModelData* modelData = ModelsToRender.at(i); Model* model;
auto model = modelData->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(), "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())); glUniformMatrix4fv(glGetUniformLocation(shader.GetHandle(), "view"), 1, GL_FALSE, glm::value_ptr(m_Camera->ViewMatrix()));
glBindVertexArray(model->VAO); glBindVertexArray(model->VAO);
for (auto texGroup : model->TextureGroups) { for (auto texGroup : model->TextureGroups) {
@@ -287,9 +330,9 @@ void Renderer::AddTextToDraw()
void Renderer::AddModelToDraw(std::shared_ptr<Model> model, glm::vec3 position, glm::quat orientation, glm::vec3 scale) void Renderer::AddModelToDraw(std::shared_ptr<Model> 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 // 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( void Renderer::AddPointLightToDraw(
@@ -315,7 +358,15 @@ void Renderer::AddPointLightToDraw(
Light_linearAttenuation.push_back(_linearAttenuation); Light_linearAttenuation.push_back(_linearAttenuation);
Light_quadraticAttenuation.push_back(_quadraticAttenuation); Light_quadraticAttenuation.push_back(_quadraticAttenuation);
Light_spotExponent.push_back(_spotExponent); 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() GLuint Renderer::CreateQuad()
@@ -410,10 +461,15 @@ GLuint Renderer::CreateAABB()
return vao; return vao;
} }
void Renderer::AddAABBToDraw(glm::vec3 origin, glm::vec3 volumeVector) void Renderer::ClearStuff()
{ {
glm::mat4 model; AABBsToRender.clear();
model *= glm::translate(origin); ModelsToRender.clear();
model *= glm::scale(volumeVector); Light_position.clear();
AABBsToRender.push_back(model); Light_specular.clear();
} Light_diffuse.clear();
Light_constantAttenuation.clear();
Light_linearAttenuation.clear();
Light_quadraticAttenuation.clear();
Light_spotExponent.clear();
}
+10 -12
View File
@@ -30,15 +30,8 @@ public:
int HEIGHT, WIDTH; int HEIGHT, WIDTH;
struct ModelData std::list<std::tuple<Model*, glm::mat4>> ModelsToRender;
{ int Lights;
std::shared_ptr<Model> model;
glm::mat4 ModelMatrix;
ModelData(std::shared_ptr<Model> _model, glm::mat4 _modelMatrix)
: model(_model), ModelMatrix(_modelMatrix) {}
};
std::vector<ModelData*> ModelsToRender;
std::vector<float> Light_position; std::vector<float> Light_position;
std::vector<float> Light_specular; std::vector<float> Light_specular;
std::vector<float> Light_diffuse; std::vector<float> Light_diffuse;
@@ -46,7 +39,7 @@ public:
std::vector<float> Light_linearAttenuation; std::vector<float> Light_linearAttenuation;
std::vector<float> Light_quadraticAttenuation; std::vector<float> Light_quadraticAttenuation;
std::vector<float> Light_spotExponent; std::vector<float> Light_spotExponent;
std::vector<glm::mat4> AABBsToRender; std::list<std::tuple<glm::mat4, bool>> AABBsToRender;
Renderer(); Renderer();
@@ -65,7 +58,7 @@ public:
float _quadraticAttenuation, float _quadraticAttenuation,
float _spotExponent float _spotExponent
); );
void AddAABBToDraw(glm::vec3 origin, glm::vec3 volumeVector); void AddAABBToDraw(glm::vec3 origin, glm::vec3 volumeVector, bool colliding);
void LoadContent(); void LoadContent();
@@ -76,6 +69,8 @@ public:
void DrawNormals(bool val) { m_DrawNormals = val; } void DrawNormals(bool val) { m_DrawNormals = val; }
bool DrawWireframe() const { return m_DrawWireframe; } bool DrawWireframe() const { return m_DrawWireframe; }
void DrawWireframe(bool val) { m_DrawWireframe = val; } void DrawWireframe(bool val) { m_DrawWireframe = val; }
bool DrawBounds() const { return m_DrawBounds; }
void DrawBounds(bool val) { m_DrawBounds = val; }
private: private:
GLFWwindow* m_Window; GLFWwindow* m_Window;
@@ -84,7 +79,9 @@ private:
bool m_VSync; bool m_VSync;
bool m_DrawNormals; bool m_DrawNormals;
bool m_DrawWireframe; bool m_DrawWireframe;
bool m_DrawBounds;
int m_ShadowMapRes;
glm::vec3 m_SunPosition; glm::vec3 m_SunPosition;
glm::vec3 m_SunTarget; glm::vec3 m_SunTarget;
glm::mat4 m_SunProjection; glm::mat4 m_SunProjection;
@@ -101,7 +98,8 @@ private:
ShaderProgram m_ShaderProgramShadows; ShaderProgram m_ShaderProgramShadows;
ShaderProgram m_ShaderProgramShadowsDrawDepth; ShaderProgram m_ShaderProgramShadowsDrawDepth;
ShaderProgram m_ShaderProgramDebugAABB; ShaderProgram m_ShaderProgramDebugAABB;
void ClearStuff();
void DrawScene(); void DrawScene();
void DrawModels(ShaderProgram &shader); void DrawModels(ShaderProgram &shader);
void DrawShadowMap(); void DrawShadowMap();
+3 -1
View File
@@ -1,5 +1,7 @@
#version 430 #version 430
uniform vec4 Color;
in VertexData { in VertexData {
vec3 Position; vec3 Position;
vec3 Normal; vec3 Normal;
@@ -11,5 +13,5 @@ out vec4 FragmentColor;
void main() { 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 - 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;
} }
+17 -15
View File
@@ -6,15 +6,15 @@ uniform mat4 view;
layout(binding=0) uniform sampler2D texture0; layout(binding=0) uniform sampler2D texture0;
layout(binding=1) uniform sampler2D shadowMap; layout(binding=1) uniform sampler2D shadowMap;
const int numberOfLights = 3; const int maxNumberOfLights = 82;
uniform int numberOfLights;
uniform vec3 position[numberOfLights]; uniform vec3 position[maxNumberOfLights];
uniform vec3 specular[numberOfLights]; uniform vec3 specular[maxNumberOfLights];
uniform vec3 diffuse[numberOfLights]; uniform vec3 diffuse[maxNumberOfLights];
uniform float constantAttenuation[numberOfLights]; uniform float constantAttenuation[maxNumberOfLights];
uniform float linearAttenuation[numberOfLights]; uniform float linearAttenuation[maxNumberOfLights];
uniform float quadraticAttenuation[numberOfLights]; uniform float quadraticAttenuation[maxNumberOfLights];
uniform float spotExponent[numberOfLights]; uniform float spotExponent[maxNumberOfLights];
in VertexData { in VertexData {
vec3 Position; vec3 Position;
@@ -23,7 +23,7 @@ in VertexData {
vec3 ShadowCoord; vec3 ShadowCoord;
} Input; } Input;
vec3 scene_ambient = vec3(0.2); vec3 scene_ambient = vec3(0.3);
out vec4 fragmentColor; out vec4 fragmentColor;
@@ -49,18 +49,20 @@ void main() {
//float cosTheta = clamp(dot(Input.Normal, vec3(0, 1, 0)), 0.0, 1.0); //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 //float bias = 0.001 * tan(acos(cosTheta)); // cosTheta is dot( n,l ), clamped between 0 and 1
//bias = clamp(bias, 0.0, 0.01); //bias = clamp(bias, 0.0, 0.01);
float bias = 0.003;
float visibility = 1.0; float visibility = 1.0;
vec4 shadowMapValue = texture(shadowMap, Input.ShadowCoord.xy); if (Input.ShadowCoord.x >= 0.0 && Input.ShadowCoord.x <= 1.0 && Input.ShadowCoord.y >= 0.0 && Input.ShadowCoord.y <= 1.0) {
if (shadowMapValue.z < Input.ShadowCoord.z - bias) { float bias = 0.0005;
visibility = 0.5; 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; vec3 totalLighting = La * Ka * visibility;
float attenuation; float attenuation;
for(int i = 0; i < numberOfLights; i++) for(int i = 0; i < numberOfLights && i < maxNumberOfLights; i++)
{ {
// Light // Light
//vec3 lightPosition = vec3(0, 0, 2); //vec3 lightPosition = vec3(0, 0, 2);
@@ -12,7 +12,7 @@ out vec4 FragmentColor;
float LinearizeDepth(float z) float LinearizeDepth(float z)
{ {
float n = 0.1; // camera z near 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)); return (2.0 * n) / (f + n - z * (f - n));
} }
Binary file not shown.
Binary file not shown.
+3 -1
View File
@@ -19,7 +19,9 @@ public:
virtual void UpdateEntity(double dt, EntityID entity, EntityID parent) { } virtual void UpdateEntity(double dt, EntityID entity, EntityID parent) { }
// Called when a component is created // Called when a component is created
virtual void OnComponentCreated(std::string type, std:: shared_ptr<Component> component) { } virtual void OnComponentCreated(std::string type, std::shared_ptr<Component> component) { }
// Called when a component is removed
virtual void OnComponentRemoved(std::string type, Component* component) { }
protected: protected:
World* m_World; World* m_World;
+15 -3
View File
@@ -3,7 +3,7 @@
void Systems::CollisionSystem::UpdateEntity(double dt, EntityID entity, EntityID parent) void Systems::CollisionSystem::UpdateEntity(double dt, EntityID entity, EntityID parent)
{ {
if (parent != 0) /*if (parent != 0)
{ {
auto transform = m_World->GetComponent<Components::Transform>(entity, "Transform"); auto transform = m_World->GetComponent<Components::Transform>(entity, "Transform");
auto parentTransform = m_World->GetComponent<Components::Transform>(parent, "Transform"); auto parentTransform = m_World->GetComponent<Components::Transform>(parent, "Transform");
@@ -11,7 +11,18 @@ void Systems::CollisionSystem::UpdateEntity(double dt, EntityID entity, EntityID
transform->Position[0] += parentTransform->Position[0]; transform->Position[0] += parentTransform->Position[0];
transform->Position[1] += parentTransform->Position[1]; transform->Position[1] += parentTransform->Position[1];
transform->Position[2] += parentTransform->Position[2]; transform->Position[2] += parentTransform->Position[2];
} }*/
auto collisionComponent = m_World->GetComponent<Components::Collision>(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(); auto entities = m_World->GetEntities();
@@ -36,7 +47,8 @@ void Systems::CollisionSystem::UpdateEntity(double dt, EntityID entity, EntityID
//pair.first, pair.second; //pair.first, pair.second;
if(entity == entity2) if(entity == entity2)
break; continue;
Intersects(entity, entity2); Intersects(entity, entity2);
} }
} }
@@ -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<Components::Transform>(entity, "Transform");
auto parentTransform = m_World->GetComponent<Components::Transform>(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<Components::Collision>(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<Components::Transform>(aEntity, "Transform");
if(aTransform == nullptr)
return;
auto bTransform = m_World->GetComponent<Components::Transform>(bEntity, "Transform");
if(bTransform == nullptr)
return;
auto aCollisionComponent = m_World->GetComponent<Components::Collision>(aEntity, "Collision");
if(aCollisionComponent == nullptr)
return;
auto bCollisionComponent = m_World->GetComponent<Components::Collision>(bEntity, "Collision");
if(bCollisionComponent == nullptr)
return;
auto aBounds = m_World->GetComponent<Components::Bounds>(aEntity, "Bounds");
auto bBounds = m_World->GetComponent<Components::Bounds>(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<Components::Bounds> 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);
}
+4
View File
@@ -47,6 +47,10 @@ void Systems::InputSystem::Update(double dt)
if (m_CurrentKeyState[GLFW_KEY_F2] && !m_LastKeyState[GLFW_KEY_F2]) { if (m_CurrentKeyState[GLFW_KEY_F2] && !m_LastKeyState[GLFW_KEY_F2]) {
m_Renderer->DrawNormals(!m_Renderer->DrawNormals()); 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 #endif
} }
@@ -4,16 +4,15 @@ Systems::LevelGenerationSystem::LevelGenerationSystem( World* world )
: System(world) : System(world)
{ {
elapsedtime = 0; elapsedtime = 0;
velocity = 0;
startx = 0;
startyz = glm::vec2(0, -1000); startyz = glm::vec2(0, -1000);
} }
void Systems::LevelGenerationSystem::SpawnObstacle() void Systems::LevelGenerationSystem::SpawnObstacle()
{ {
typeRandom = 0 + (rand() % 10);
typeRandom = 0 + (rand() % 3);
EntityID ent; EntityID ent;
@@ -24,36 +23,64 @@ void Systems::LevelGenerationSystem::SpawnObstacle()
bounds = m_World->AddComponent<Components::Bounds>(ent, "Bounds"); bounds = m_World->AddComponent<Components::Bounds>(ent, "Bounds");
collision = m_World->AddComponent<Components::Collision>(ent, "Collision"); collision = m_World->AddComponent<Components::Collision>(ent, "Collision");
model = m_World->AddComponent<Components::Model>(ent, "Model"); model = m_World->AddComponent<Components::Model>(ent, "Model");
auto sound = m_World->AddComponent<Components::SoundEmitter>(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) sound->Loop = true;
{ sound->Gain = 1.f;
case 0: sound->ReferenceDistance = 15.f;
transform->Position = glm::vec3( positionRandom, startyz); // fix position m_World->GetSystem<Systems::SoundSystem>("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->VolumeVector = glm::vec3(9, 12, 7);
bounds->Origin = glm::vec3(1,11,-1); bounds->Origin = glm::vec3(1,11,-1);
model->ModelFile = "Models/obstacle_mountain_1.obj"; model->ModelFile = "Models/obstacle_mountain_1.obj";
}
break; else if(typeRandom >= 2 && typeRandom < 5) // Single Mountain :D
case 1: {
transform->Position = glm::vec3( positionRandom, startyz); // fix position float scale = (float)(rand() % 1000) / 200;
transform->Scale = glm::vec3(scale);
bounds->VolumeVector = glm::vec3(3.5f, 7.5f, 3.5f); bounds->VolumeVector = glm::vec3(3.5f, 7.5f, 3.5f);
bounds->Origin = glm::vec3(0,7.5f,0); bounds->Origin = glm::vec3(0,7.5f,0);
model->ModelFile = "Models/obstacle_mountain_2.obj"; model->ModelFile = "Models/obstacle_mountain_2.obj";
}
break; else if(typeRandom >= 5 && typeRandom < 8)
case 2: {
transform->Position = glm::vec3( positionRandom, startyz); // fix position float scale = (float)(rand() % 1000) / 100;
transform->Scale = glm::vec3(scale);
bounds->VolumeVector = glm::vec3(1, 1, 1); bounds->VolumeVector = glm::vec3(1, 1, 1);
bounds->Origin = glm::vec3(0,1,0); bounds->Origin = glm::vec3(0,1,0);
model->ModelFile = "Models/obstacle_cube_1.obj"; 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<Components::PointLight>(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; powerUp = m_World->AddComponent<Components::PowerUp>(ent, "PowerUp");
default: 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; elapsedtime = 0;
} }
std::vector<EntityID> removethis; std::list<EntityID> removethis;
for(auto ent : obstacles) for(auto ent : obstacles)
{ {
auto transformComponent = m_World->GetComponent<Components::Transform>(ent, "Transform"); auto transform = m_World->GetComponent<Components::Transform>(ent, "Transform");
transformComponent->Position.z += 100.f * dt;
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<std::string>(entity, "Name") == "PlayerShip")
{
auto transformComponent = m_World->GetComponent<Components::Transform>(entity, "Transform");
startyz = glm::vec2(0, transformComponent->Position.z - 1000);
startx = transformComponent->Position.x;
velocity = transformComponent->Velocity.z;
}
}
@@ -2,11 +2,15 @@
#define LevelGenerationSystem_h__ #define LevelGenerationSystem_h__
#include "System.h" #include "System.h"
#include "Systems/SoundSystem.h"
#include "World.h" #include "World.h"
#include "Components/Transform.h" #include "Components/Transform.h"
#include "Components/Bounds.h" #include "Components/Bounds.h"
#include "Components/Collision.h" #include "Components/Collision.h"
#include "Components/Model.h" #include "Components/Model.h"
#include "Components/PointLight.h"
#include "Components/SoundEmitter.h"
#include "Components/PowerUp.h"
namespace Systems namespace Systems
@@ -20,20 +24,25 @@ namespace Systems
void SpawnObstacle(); void SpawnObstacle();
void Update(double dt) override; void Update(double dt) override;
void UpdateEntity(double dt, EntityID entity, EntityID parent) override;
private: private:
int typeRandom; int typeRandom;
int positionRandom; int positionRandom;
glm::vec2 startyz; glm::vec2 startyz;
float startx;
double elapsedtime; double elapsedtime;
std::list<EntityID> obstacles; std::list<EntityID> obstacles;
float velocity;
std::shared_ptr<Components::Transform> transform; std::shared_ptr<Components::Transform> transform;
std::shared_ptr<Components::Bounds> bounds; std::shared_ptr<Components::Bounds> bounds;
std::shared_ptr<Components::Collision> collision; std::shared_ptr<Components::Collision> collision;
std::shared_ptr<Components::Model> model; std::shared_ptr<Components::Model> model;
std::shared_ptr<Components::PointLight> pointLight;
std::shared_ptr<Components::PowerUp> powerUp;
}; };
} }
+17 -14
View File
@@ -3,6 +3,8 @@
Systems::PlayerSystem::PlayerSystem( World* world ) : System(world) Systems::PlayerSystem::PlayerSystem( World* world ) : System(world)
{ {
m_PlayerSpeed = 20;
m_PlayerOriginalBounds = glm::vec3(0);
} }
void Systems::PlayerSystem::Update(double dt) void Systems::PlayerSystem::Update(double dt)
@@ -18,14 +20,12 @@ void Systems::PlayerSystem::UpdateEntity(double dt, EntityID entity, EntityID pa
if (input == nullptr) if (input == nullptr)
return; return;
float speed = 20.0f;
auto name = m_World->GetProperty<std::string>(entity, "Name"); auto name = m_World->GetProperty<std::string>(entity, "Name");
if (name == "Camera") { if (name == "Camera") {
glm::vec3 Camera_Right = glm::vec3(glm::vec4(1, 0, 0, 0) * transform->Orientation); 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); 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]) { if(input->KeyState[GLFW_KEY_LEFT_SHIFT]) {
speed *= 4.0f; 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 // TOUCHING THIS CODE MIGHT COUSE THE UNIVERSE TO IMPLODE, ALSO DRAGONS
} }
auto collision = m_World->GetComponent<Components::Collision>(entity, "Collision");
if(collision->CollidingEntities.size() != 0)
int c = 1; // lol
} }
name = m_World->GetProperty<std::string>(entity, "Name");
if (name == "PlayerShip") if (name == "PlayerShip")
{ {
auto bounds = m_World->GetComponent<Components::Bounds>(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_Right = glm::vec3(glm::vec4(1, 0, 0, 0));
glm::vec3 Ship_Forward = glm::vec3(glm::vec4(0, 0, 1, 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); glm::vec3 Euler = glm::eulerAngles(transform->Orientation);
if(input->KeyState[GLFW_KEY_LEFT]) { 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) 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]) { 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) 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) else if(Euler.z > 0.f)
transform->Orientation = transform->Orientation * glm::angleAxis<float>((float)dt,glm::vec3(0,0,-1)); transform->Orientation = transform->Orientation * glm::angleAxis<float>((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));
}
} }
} }
+3 -1
View File
@@ -7,6 +7,7 @@
#include "Components/Transform.h" #include "Components/Transform.h"
#include "Components/Input.h" #include "Components/Input.h"
#include "Components/Collision.h" #include "Components/Collision.h"
#include "Components/Bounds.h"
#include "logging.h" #include "logging.h"
@@ -23,7 +24,8 @@ namespace Systems
void UpdateEntity(double dt, EntityID entity, EntityID parent) override; void UpdateEntity(double dt, EntityID entity, EntityID parent) override;
private: private:
float m_PlayerSpeed;
glm::vec3 m_PlayerOriginalBounds;
}; };
} }
+3 -2
View File
@@ -30,11 +30,12 @@ void Systems::RenderSystem::UpdateEntity( double dt, EntityID entity, EntityID p
// Debug draw bounds // Debug draw bounds
#ifdef DEBUG #ifdef DEBUG
auto collision = m_World->GetComponent<Components::Collision>(entity, "Collision");
auto bounds = m_World->GetComponent<Components::Bounds>(entity, "Bounds"); auto bounds = m_World->GetComponent<Components::Bounds>(entity, "Bounds");
if (bounds != nullptr) { 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; glm::vec3 volumeVector = transformComponent->Scale * bounds->VolumeVector;
m_Renderer->AddAABBToDraw(origin, volumeVector); m_Renderer->AddAABBToDraw(origin, volumeVector, (collision != nullptr && collision->CollidingEntities.size() > 0));
} }
#endif #endif
+1
View File
@@ -10,6 +10,7 @@
#include "Components/Transform.h" #include "Components/Transform.h"
#include "Components/Camera.h" #include "Components/Camera.h"
#include "Components/Bounds.h" #include "Components/Bounds.h"
#include "Components/Collision.h"
#include "Renderer.h" #include "Renderer.h"
namespace Systems namespace Systems
+2 -1
View File
@@ -20,6 +20,7 @@ public:
void Update(double dt) override; void Update(double dt) override;
void UpdateEntity(double dt, EntityID entity, EntityID parent) override; void UpdateEntity(double dt, EntityID entity, EntityID parent) override;
void OnComponentCreated(std::string type, std::shared_ptr<Component> component) override; void OnComponentCreated(std::string type, std::shared_ptr<Component> component) override;
void OnComponentRemoved(std::string type, Component* component) override;
void PlaySound(std::shared_ptr<Components::SoundEmitter> emitter, std::string path); // Use if you want to play a temporary .wav file not from component void PlaySound(std::shared_ptr<Components::SoundEmitter> emitter, std::string path); // Use if you want to play a temporary .wav file not from component
void PlaySound(std::shared_ptr<Components::SoundEmitter> emitter); // Use if you want to play .wav file from component // imon no hate plx T.T void PlaySound(std::shared_ptr<Components::SoundEmitter> emitter); // Use if you want to play .wav file from component // imon no hate plx T.T
void StopSound(std::shared_ptr<Components::SoundEmitter> emitter); void StopSound(std::shared_ptr<Components::SoundEmitter> emitter);
@@ -37,7 +38,7 @@ private:
unsigned long dataSize; unsigned long dataSize;
std::map<Component*, ALuint> m_Source; std::map<Component*, ALuint> m_Sources;
std::map<std::string, ALuint> m_BufferCache; // string = fileName std::map<std::string, ALuint> m_BufferCache; // string = fileName
}; };
@@ -0,0 +1,51 @@
#ifndef SoundEmitter_h__
#define SoundEmitter_h__
#include "System.h"
#include "Components/Transform.h"
#include "Components/SoundEmitter.h"
#include <AL/al.h>
#include <AL/alc.h>
#include <vector>
#include <glm/gtx/quaternion.hpp>
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> component) override;
<<<<<<< HEAD
void PlaySound(std::shared_ptr<Components::SoundEmitter> emitter, std::string path); // Use if you want to play a temporary .wav file not from component
void PlaySound(std::shared_ptr<Components::SoundEmitter> emitter); // Use if you want to play .wav file from component // imon no hate plx T.T
void StopSound(std::shared_ptr<Components::SoundEmitter> emitter);
=======
void OnComponentRemoved(std::string type, Component* component) override;
void PlaySound(std::shared_ptr<Components::SoundEmitter> 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<Component*, ALuint> m_Sources;
std::map<std::string, ALuint> m_BufferCache; // string = fileName
};
}
#endif // !SoundEmitter_h__
+25 -9
View File
@@ -18,6 +18,9 @@ Systems::SoundSystem::SoundSystem(World* world)
} }
alGetError(); alGetError();
alSpeedOfSound(340.29f); // Speed of sound
alDistanceModel(AL_INVERSE_DISTANCE);
} }
void Systems::SoundSystem::Update(double dt) 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<Components::SoundEmitter>(entity, "SoundEmitter"); auto soundEmitter = m_World->GetComponent<Components::SoundEmitter>(entity, "SoundEmitter");
if(soundEmitter != nullptr) if(soundEmitter != nullptr)
{ {
ALuint source = m_Source[soundEmitter.get()]; ALuint source = m_Sources[soundEmitter];
alSourcei(source, AL_GAIN, soundEmitter->Gain); alSourcef(source, AL_GAIN, soundEmitter->Gain);
alSourcei(source, AL_MAX_DISTANCE, soundEmitter->MaxDistance); //alSourcef(source, AL_MAX_DISTANCE, soundEmitter->MaxDistance);
alSourcei(source, AL_REFERENCE_DISTANCE, soundEmitter->ReferenceDistance); alSourcef(source, AL_REFERENCE_DISTANCE, soundEmitter->ReferenceDistance);
alSourcef(source, AL_PITCH, soundEmitter->Pitch); alSourcef(source, AL_PITCH, soundEmitter->Pitch);
alSourcei(source, AL_LOOPING, soundEmitter->Loop); 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<Components::SoundEmitter> emitter, std::string path) void Systems::SoundSystem::PlaySound(std::shared_ptr<Components::SoundEmitter> emitter, std::string fileName)
{ {
ALuint buffer = LoadFile(path); if (m_Sources.find(emitter.get()) == m_Sources.end())
ALuint source = m_Source[emitter.get()]; return;
ALuint buffer = LoadFile(fileName);
ALuint source = m_Sources[emitter.get()];
alSourcei(source, AL_BUFFER, buffer); alSourcei(source, AL_BUFFER, buffer);
alSourcePlay(m_Source[emitter.get()]); alSourcePlay(m_Sources[emitter.get()]);
} }
void Systems::SoundSystem::PlaySound(std::shared_ptr<Components::SoundEmitter> emitter) void Systems::SoundSystem::PlaySound(std::shared_ptr<Components::SoundEmitter> emitter)
@@ -97,7 +103,17 @@ void Systems::SoundSystem::OnComponentCreated(std::string type, std::shared_ptr<
{ {
if(type == "SoundEmitter") { if(type == "SoundEmitter") {
ALuint source = CreateSource(); 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);
}
} }
} }
@@ -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<Components::Transform>(entity, "Transform");
if (transformComponent == nullptr)
return;
auto entityName = m_World->GetProperty<std::string>(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<Components::SoundEmitter>(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<Components::SoundEmitter> 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<Components::SoundEmitter> 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<Components::SoundEmitter> emitter)
{
alSourceStop(m_Source[emitter.get()]);
}
void Systems::SoundSystem::OnComponentCreated(std::string type, std::shared_ptr<Component> 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;
}
+1
View File
@@ -0,0 +1 @@
#include "TextFrame.h"
+8 -1
View File
@@ -61,12 +61,19 @@ bool World::ValidEntity(EntityID entity)
void World::RemoveEntity(EntityID entity) void World::RemoveEntity(EntityID entity)
{ {
m_EntityParents.erase(entity); m_EntityParents.erase(entity);
m_EntityComponents.erase(entity); // Remove components
for (auto pair : m_EntityComponents[entity]) { for (auto pair : m_EntityComponents[entity]) {
auto type = pair.first; auto type = pair.first;
auto component = pair.second; 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_ComponentsOfType[type].remove(component);
} }
m_EntityComponents.erase(entity);
RecycleEntityID(entity); RecycleEntityID(entity);
} }
+3 -3
View File
@@ -60,7 +60,7 @@ public:
std::shared_ptr<T> AddComponent(EntityID entity, std::string componentType); std::shared_ptr<T> AddComponent(EntityID entity, std::string componentType);
std::shared_ptr<Component> AddComponent(EntityID entity, std::string componentType); std::shared_ptr<Component> AddComponent(EntityID entity, std::string componentType);
template <class T> template <class T>
std::shared_ptr<T> GetComponent(EntityID entity, std::string componentType); T* GetComponent(EntityID entity, std::string componentType);
/*std::vector<EntityID> GetEntityChildren(EntityID entity);*/ /*std::vector<EntityID> GetEntityChildren(EntityID entity);*/
@@ -117,9 +117,9 @@ std::shared_ptr<T> World::AddComponent(EntityID entity, std::string componentTyp
template <class T> template <class T>
std::shared_ptr<T> World::GetComponent(EntityID entity, std::string componentType) T* World::GetComponent(EntityID entity, std::string componentType)
{ {
return std::static_pointer_cast<T>(m_EntityComponents[entity][componentType]); return (T*)m_EntityComponents[entity][componentType].get();
} }
#endif // World_h__ #endif // World_h__