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

This commit is contained in:
ViktorLjung
2014-03-09 21:08:07 +01:00
20 changed files with 299 additions and 19 deletions
+74
View File
@@ -0,0 +1,74 @@
#include "Camera.h"
Camera::Camera(float yFOV, float aspectRatio, float nearClip, float farClip)
{
m_FOV = yFOV;
m_AspectRatio = aspectRatio;
m_NearClip = nearClip;
m_FarClip = farClip;
m_Position = glm::vec3(0.0);
m_Pitch = 0.f;
m_Yaw = 0.f;
UpdateProjectionMatrix();
UpdateViewMatrix();
}
glm::vec3 Camera::Forward()
{
return glm::rotate(glm::vec3(0.f, 0.f, -1.f), -m_Yaw, glm::vec3(0.f, 1.f, 0.f));
}
glm::vec3 Camera::Right()
{
return glm::rotate(glm::vec3(1.f, 0.f, 0.f), -m_Yaw, glm::vec3(0.f, 1.f, 0.f));
}
glm::mat4 Camera::Orientation()
{
glm::mat4 orientation(1.f);
orientation = glm::rotate(orientation, m_Pitch, glm::vec3(1.f, 0.f, 0.f));
orientation = glm::rotate(orientation, m_Yaw, glm::vec3(0.f, 1.f, 0.f));
return orientation;
}
void Camera::AspectRatio(float val)
{
m_AspectRatio = val;
UpdateProjectionMatrix();
}
void Camera::Position(glm::vec3 val)
{
m_Position = val;
UpdateViewMatrix();
}
void Camera::Pitch(float val)
{
m_Pitch = val;
UpdateViewMatrix();
}
void Camera::Yaw(float val)
{
m_Yaw = val;
UpdateViewMatrix();
}
void Camera::UpdateProjectionMatrix()
{
m_ProjectionMatrix = glm::perspective(
m_FOV,
m_AspectRatio,
m_NearClip,
m_FarClip
);
}
void Camera::UpdateViewMatrix()
{
m_ViewMatrix = glm::translate(Orientation(), -m_Position);
}
+53
View File
@@ -0,0 +1,53 @@
#ifndef Camera_h__
#define Camera_h__
#define GLM_FORCE_RADIANS
#include <glm/glm.hpp>
#include <glm/gtc/constants.hpp>
#include <glm/gtc/matrix_transform.hpp>
#include <glm/gtx/rotate_vector.hpp>
class Camera
{
public:
Camera(float yFOV, float aspectRatio, float nearClip, float farClip);
glm::vec3 Forward();
glm::vec3 Right();
glm::mat4 Orientation();
float AspectRatio() const { return m_AspectRatio; }
void AspectRatio(float val);
glm::vec3 Position() const { return m_Position; }
void Position(glm::vec3 val);
float Pitch() const { return m_Pitch; }
void Pitch(float val);
float Yaw() const { return m_Yaw; }
void Yaw(float val);
glm::mat4 ProjectionMatrix() const { return m_ProjectionMatrix; }
void ProjectionMatrix(glm::mat4 val) { m_ProjectionMatrix = val; }
glm::mat4 ViewMatrix() const { return m_ViewMatrix; }
void ViewMatrix(glm::mat4 val) { m_ViewMatrix = val; }
private:
void UpdateProjectionMatrix();
void UpdateViewMatrix();
float m_FOV;
float m_AspectRatio;
float m_NearClip;
float m_FarClip;
glm::vec3 m_Position;
float m_Pitch;
float m_Yaw;
glm::mat4 m_ProjectionMatrix;
glm::mat4 m_ViewMatrix;
};
#endif // Camera_h__
+2 -3
View File
@@ -4,15 +4,14 @@
#include "Component.h"
#include <glm/common.hpp>
namespace Components
{
struct Bounds : Component
{
//Axis Aligned Bounding Box
glm::vec3 origin;
glm::vec3 volumeVector; //The vector that defines the volume of the BB, it goes from one corner to the opposite one
glm::vec3 Origin;
glm::vec3 VolumeVector; //The vector that defines the volume of the BB, it goes from one corner to the opposite one
};
}
@@ -10,7 +10,6 @@ namespace Components
struct SoundEmitter : Component
{
std::string SoundFile;
float Volume;
float MaxRange;
};
+5 -3
View File
@@ -40,14 +40,14 @@
<PropertyGroup Label="UserMacros" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<LibraryPath>$(SolutionDir)\Libraries\SOIL\lib\Debug;$(SolutionDir)\Libraries\glew-1.10.0\lib\Debug\Win32;$(SolutionDir)\Libraries\glfw-3.0.4\lib\Debug;$(LibraryPath)</LibraryPath>
<LibraryPath>$(SolutionDir)\Libraries\openal-soft-1.15.1-bin\lib\Win32;$(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>$(SolutionDir)\Libraries\SOIL\src;\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>
<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>$(SolutionDir)\Libraries\SOIL\src;\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>
<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>$(SolutionDir)\Libraries\SOIL\lib\Release;$(SolutionDir)\Libraries\glew-1.10.0\lib\Release\Win32;$(SolutionDir)\Libraries\glfw-3.0.4\lib\Release;$(LibraryPath)</LibraryPath>
@@ -97,6 +97,7 @@
</Lib>
</ItemDefinitionGroup>
<ItemGroup>
<ClCompile Include="Camera.cpp" />
<ClCompile Include="Engine.h" />
<ClCompile Include="Frame.cpp" />
<ClCompile Include="GameFrame.cpp" />
@@ -117,6 +118,7 @@
<ClCompile Include="Systems\SoundsSystem.cpp" />
</ItemGroup>
<ItemGroup>
<ClInclude Include="Camera.h" />
<ClInclude Include="Color.h" />
<ClInclude Include="Component.h" />
<ClInclude Include="Components\Camera.h" />
@@ -43,6 +43,7 @@
<ClCompile Include="GameFrame.cpp">
<Filter>GUI</Filter>
</ClCompile>
<ClCompile Include="Camera.cpp" />
</ItemGroup>
<ItemGroup>
<ClInclude Include="Component.h" />
@@ -140,6 +141,7 @@
<Filter>GUI</Filter>
</ClInclude>
<ClInclude Include="GameWorld.h" />
<ClInclude Include="Camera.h" />
</ItemGroup>
<ItemGroup>
<None Include="Shaders\Fragment.glsl">
+1
View File
@@ -142,6 +142,7 @@ bool Model::Loadobj(const char* path, std::vector <glm::vec3> & out_vertices, st
}
void Model::CreateBuffers( std::vector<glm::vec3> _Vertices, std::vector<glm::vec3> _Normals, std::vector<glm::vec2>_TextureCoords)
{
+2
View File
@@ -47,6 +47,8 @@ public:
std::vector <glm::vec2> & out_TextureCoords
);
glm::mat4 GetMatrix();
void CreateBuffers(
std::vector<glm::vec3> _Vertices,
std::vector<glm::vec3> _Normals,
+27 -2
View File
@@ -13,7 +13,9 @@ void Renderer::Initialize()
}
// Create a window
m_Window = glfwCreateWindow(1280, 720, "OpenGL", nullptr, nullptr);
WIDTH = 1280;
HEIGHT = 720;
m_Window = glfwCreateWindow(WIDTH, HEIGHT, "OpenGL", nullptr, nullptr);
if (!m_Window) {
LOG_ERROR("GLFW: Failed to create window");
exit(EXIT_FAILURE);
@@ -39,6 +41,9 @@ void Renderer::Initialize()
}
glEnable(GL_DEPTH_TEST);
// Create Camera
m_Camera = std::make_shared<Camera>(90.f, WIDTH / HEIGHT, 0.01f, 1000.f);
LoadContent();
}
@@ -47,7 +52,25 @@ void Renderer::Draw(double _dt)
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glClearColor(1.0f, 1.0f, 0.0f, 1.0f);
//m_ShaderProgram->Bind();
m_ShaderProgram.Bind();
glm::mat4 cameraMatrix = m_Camera->ProjectionMatrix() * m_Camera->ViewMatrix();
glm::mat4 MVP;
for(int i = 0; i < ModelsToRender.size(); i++)
{
glActiveTexture(GL_TEXTURE0);
//FIXA MED FLERA TEXTURER
glBindTexture(GL_TEXTURE_2D, ModelsToRender[i]->texture[0]->texture);
MVP = cameraMatrix; // * ModelMatrix;
glUniformMatrix4fv(glGetUniformLocation(m_ShaderProgram.GetHandle(), "MVP"), 1, GL_FALSE, glm::value_ptr(MVP));
glBindVertexArray(ModelsToRender[i]->VAO);
glDrawArrays(GL_TRIANGLES, 0, ModelsToRender[i]->Vertices.size());
}
// Vertices;
// std::vector<glm::vec3> Normals;
// std::vector<glm::vec2> TextureCoords;
glfwSwapBuffers(m_Window);
}
@@ -75,4 +98,6 @@ void Renderer::LoadContent()
m_ShaderProgram.AddShader(std::unique_ptr<Shader>(new FragmentShader("Shaders/Fragment.glsl")));
m_ShaderProgram.Compile();
m_ShaderProgram.Link();
projectionMatrix = glm::perspective(45.0f, (float)WIDTH / HEIGHT, 0.01f, 100.0f);
}
+8
View File
@@ -19,6 +19,7 @@
#include <glm/gtc/type_ptr.hpp>
#include "glerror.h"
#include "Camera.h"
#include "ShaderProgram.h"
#include "Model.h"
@@ -26,6 +27,10 @@ class Renderer
{
public:
ShaderProgram m_ShaderProgram;
glm::mat4 viewMatrix;
glm::mat4 projectionMatrix;
int HEIGHT, WIDTH;
std::vector<Model*> ModelsToRender;
@@ -41,11 +46,14 @@ public:
void LoadContent();
GLFWwindow* GetWindow() const { return m_Window; }
std::shared_ptr<Camera> GetCamera() const { return m_Camera; }
private:
GLFWwindow* m_Window;
GLint m_glVersion[2];
GLchar* m_glVendor;
std::shared_ptr<Camera> m_Camera;
};
#endif // Renderer_h__
+5
View File
@@ -128,6 +128,11 @@ GLuint ShaderProgram::Link()
return m_ShaderProgramHandle;
}
GLuint ShaderProgram::GetHandle()
{
return m_ShaderProgramHandle;
}
void ShaderProgram::Bind()
{
if (m_ShaderProgramHandle == 0)
+2
View File
@@ -76,6 +76,8 @@ public:
void Compile();
GLuint Link();
GLuint GetHandle();
void Bind();
void Unbind();
+1 -1
View File
@@ -1,4 +1,4 @@
#version 440
#version 430
uniform mat4 MVP;
uniform sampler2D texture0;
+1 -1
View File
@@ -1,4 +1,4 @@
#version 440
#version 430
uniform mat4 MVP;
+30
View File
@@ -0,0 +1,30 @@
#ifndef SoundEmitter_h__
#define SoundEmitter_h__
#include "AL/al.h"
#include "AL/alc.h"
#include "System.h"
#include "Components/SoundEmitter.h"
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;
void PlaySound(std::shared_ptr<Components::SoundEmitter> emitter, std::string fileName);
void LoadFile(std::string fileName);
private:
ALCcontext* context;
};
}
#endif // !SoundEmitter_h__
+42
View File
@@ -0,0 +1,42 @@
#include "SoundSystem.h"
#include "World.h"
#include <AL/al.h>
#include <AL/alc.h>
Systems::SoundSystem::SoundSystem(World* world)
: System(world)
{
ALCdevice* Device = alcOpenDevice(nullptr);
if(Device)
{
context = alcCreateContext(Device, nullptr);
alcMakeContextCurrent(context);
}
}
void Systems::SoundSystem::Update(double dt)
{
}
void Systems::SoundSystem::UpdateEntity(double dt, EntityID entity, EntityID parent)
{
auto soundEmitter = m_World->GetComponent<Components::SoundEmitter>(entity, "SoundEmitter");
if(soundEmitter == nullptr)
return;
}
void Systems::SoundSystem::PlaySound(std::shared_ptr<Components::SoundEmitter> emitter, std::string fileName)
{
LoadFile(fileName);
}
void Systems::SoundSystem::LoadFile(std::string fileName)
{
//loadWavFile()
}
+16
View File
@@ -2,10 +2,13 @@
#define World_h__
#include <stack>
#include <map>
#include <unordered_map>
#include <vector>
#include <string>
#include <boost/any.hpp>
#include "logging.h"
#include "Factory.h"
@@ -36,6 +39,17 @@ public:
EntityID GetEntityParent(EntityID entity);
template <class T>
T GetProperty(EntityID entity, std::string property)
{
return boost::any_cast<T>(m_EntityProperties[entity][property]);
}
void SetProperty(EntityID entity, std::string property, boost::any value)
{
m_EntityProperties[entity][property] = value;
}
template <class T>
std::shared_ptr<T> AddComponent(EntityID entity, std::string componentType);
std::shared_ptr<Component> AddComponent(EntityID entity, std::string componentType);
@@ -59,6 +73,8 @@ protected:
// A bottom to top tree. A map of child entities to parent entities.
std::unordered_map<EntityID, EntityID> m_EntityParents;
std::unordered_map<EntityID, std::unordered_map<std::string, boost::any>> m_EntityProperties;
std::unordered_map<std::string, std::vector<std::shared_ptr<Component>>> m_ComponentsOfType;
std::unordered_map<EntityID, std::map<std::string, std::shared_ptr<Component>>> m_EntityComponents;
+2 -2
View File
@@ -39,13 +39,13 @@
</ImportGroup>
<PropertyGroup Label="UserMacros" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<IncludePath>$(SolutionDir)\Escape-the-Dawn;$(SolutionDir)\Libraries\SOIL\src;\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>
<IncludePath>$(SolutionDir)\Escape-the-Dawn;$(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>
<OutDir>$(SolutionDir)bin\</OutDir>
<TargetName>$(SolutionName)-$(Configuration)</TargetName>
<IntDir>$(SolutionDir)obj\$(ProjectName)\</IntDir>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<IncludePath>$(SolutionDir)\Escape-the-Dawn;$(SolutionDir)\Libraries\SOIL\src;\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>
<IncludePath>$(SolutionDir)\Escape-the-Dawn;$(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>
<OutDir>$(SolutionDir)bin\</OutDir>
<TargetName>$(SolutionName)-$(Configuration)</TargetName>
<IntDir>$(SolutionDir)obj\$(ProjectName)\</IntDir>
+4 -4
View File
@@ -39,13 +39,13 @@
</ImportGroup>
<PropertyGroup Label="UserMacros" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<IncludePath>$(BOOST_ROOT);$(SolutionDir)\Escape-the-Dawn;$(SolutionDir)\Libraries\SOIL\src;\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>
<IncludePath>$(SolutionDir)\Escape-the-Dawn;$(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>
<LibraryPath>$(BOOST_ROOT)\lib32-msvc-11.0;$(LibraryPath)</LibraryPath>
<OutDir>$(ProjectDir)$(Configuration)\</OutDir>
<IntDir>$(SolutionDir)obj\$(ProjectName)\</IntDir>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<IncludePath>$(BOOST_ROOT);$(SolutionDir)\Escape-the-Dawn;$(SolutionDir)\Libraries\SOIL\src;\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>
<IncludePath>$(SolutionDir)\Escape-the-Dawn;$(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>
<LibraryPath>$(BOOST_ROOT)\lib32-msvc-11.0;$(LibraryPath)</LibraryPath>
<OutDir>$(ProjectDir)$(Configuration)\</OutDir>
<IntDir>$(SolutionDir)obj\$(ProjectName)\</IntDir>
@@ -65,7 +65,7 @@
<PostBuildEvent />
<PreBuildEvent />
<PostBuildEvent>
<Command>$(OutDir)$(TargetName)$(TargetExt) --log_level=test_suite</Command>
<Command>"$(OutDir)$(TargetName)$(TargetExt)" --log_level=test_suite</Command>
</PostBuildEvent>
<PostBuildEvent>
<Message>Running tests</Message>
@@ -87,7 +87,7 @@
</Link>
<PreBuildEvent />
<PostBuildEvent>
<Command>$(OutDir)$(TargetName)$(TargetExt) --log_level=test_suite</Command>
<Command>"$(OutDir)$(TargetName)$(TargetExt)" --log_level=test_suite</Command>
</PostBuildEvent>
<PostBuildEvent>
<Message>Running tests</Message>
+21 -1
View File
@@ -1,6 +1,7 @@
#include "logging.h"
#include "World.h"
#include "GameWorld.h"
#include "Components/Transform.h"
#define BOOST_TEST_MODULE World
@@ -24,15 +25,19 @@ BOOST_AUTO_TEST_CASE(Parenting)
BOOST_AUTO_TEST_CASE(SceneGraphTraversal)
{
World world;
std::shared_ptr<Renderer> renderer(new Renderer());
renderer->Initialize();
GameWorld world(renderer);
EntityID ent1 = world.CreateEntity();
auto t1 = world.AddComponent<Components::Transform>(ent1, "Transform");
BOOST_REQUIRE(t1 != nullptr);
t1->Position[0] = 1.0f;
t1->Position[1] = 1.0f;
t1->Position[2] = 1.0f;
EntityID ent2 = world.CreateEntity(ent1);
auto t2 = world.AddComponent<Components::Transform>(ent2, "Transform");
BOOST_REQUIRE(t2 != nullptr);
t2->Position[0] = 1.0f;
t2->Position[1] = 1.0f;
t2->Position[2] = 1.0f;
@@ -62,3 +67,18 @@ BOOST_AUTO_TEST_CASE(ComponentCreation)
BOOST_CHECK(world.AddComponent(ent, "Transform") != nullptr);
BOOST_CHECK(world.AddComponent(ent, "Input") != nullptr);
}
BOOST_AUTO_TEST_CASE(Properties)
{
World world;
EntityID ent = world.CreateEntity();
world.SetProperty(ent, "String", std::string("derpfish"));
world.SetProperty(ent, "Integer", 123);
world.SetProperty(ent, "Float", 0.04f);
BOOST_CHECK(world.GetProperty<std::string>(ent, "String") == "derpfish");
BOOST_CHECK(world.GetProperty<int>(ent, "Integer") == 123);
BOOST_CHECK(world.GetProperty<float>(ent, "Float") == 0.04f);
}