Merge branch 'master' of github.com:sippeangelo/Escape-the-Dawn
Conflicts: Escape-the-Dawn/Escape-the-Dawn.vcxproj Escape-the-Dawn/Escape-the-Dawn.vcxproj.filters
This commit is contained in:
@@ -0,0 +1,80 @@
|
||||
#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::Orientation(glm::quat val)
|
||||
{
|
||||
m_Orientation = 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(glm::toMat4(m_Orientation), -m_Position);
|
||||
}
|
||||
@@ -0,0 +1,69 @@
|
||||
#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>
|
||||
#include <glm/gtc/quaternion.hpp>
|
||||
#include <glm/gtx/quaternion.hpp>
|
||||
|
||||
class Camera
|
||||
{
|
||||
public:
|
||||
Camera(float yFOV, float aspectRatio, float nearClip, float farClip);
|
||||
|
||||
glm::vec3 Forward();
|
||||
glm::vec3 Right();
|
||||
glm::quat Orientation();
|
||||
|
||||
float AspectRatio() const { return m_AspectRatio; }
|
||||
void AspectRatio(float val);
|
||||
|
||||
glm::vec3 Position() const { return m_Position; }
|
||||
void Position(glm::vec3 val);
|
||||
|
||||
glm::quat Orientation() const { return m_Orientation; }
|
||||
void Orientation(glm::quat 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; }
|
||||
|
||||
float FOV() const { return m_FOV; }
|
||||
void FOV(float val) { m_FOV = val; }
|
||||
|
||||
float NearClip() const { return m_NearClip; }
|
||||
void NearClip(float val) { m_NearClip = val; }
|
||||
|
||||
float FarClip() const { return m_FarClip; }
|
||||
void FarClip(float val) { m_FarClip = val; }
|
||||
|
||||
private:
|
||||
void UpdateProjectionMatrix();
|
||||
void UpdateViewMatrix();
|
||||
|
||||
float m_FOV;
|
||||
float m_AspectRatio;
|
||||
float m_NearClip;
|
||||
float m_FarClip;
|
||||
|
||||
|
||||
glm::vec3 m_Position;
|
||||
glm::quat m_Orientation;
|
||||
//float m_Pitch;
|
||||
//float m_Yaw;
|
||||
|
||||
glm::mat4 m_ProjectionMatrix;
|
||||
glm::mat4 m_ViewMatrix;
|
||||
};
|
||||
|
||||
#endif // Camera_h__
|
||||
@@ -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
|
||||
//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
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
@@ -8,9 +8,9 @@ namespace Components
|
||||
|
||||
struct Camera : Component
|
||||
{
|
||||
int FOV;
|
||||
int NearClip;
|
||||
int FarClip;
|
||||
float FOV;
|
||||
float NearClip;
|
||||
float FarClip;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
@@ -10,7 +10,10 @@ namespace Components
|
||||
|
||||
struct Collision : Component
|
||||
{
|
||||
Collision() : Phantom(false), Interested(false) { }
|
||||
|
||||
bool Phantom;
|
||||
bool Interested;
|
||||
std::vector<EntityID> CollidingEntities;
|
||||
};
|
||||
|
||||
|
||||
@@ -11,7 +11,7 @@ namespace Components
|
||||
|
||||
struct Model : Component
|
||||
{
|
||||
std::string ModelFile;
|
||||
const char* ModelFile;
|
||||
Color Color;
|
||||
};
|
||||
|
||||
|
||||
@@ -11,8 +11,11 @@ struct PointLight : Component
|
||||
{
|
||||
float Intensity;
|
||||
float MaxRange;
|
||||
float SpecularIntensity;
|
||||
Color Color;
|
||||
glm::vec3 Specular;
|
||||
glm::vec3 Diffuse;
|
||||
float constantAttenuation, linearAttenuation, quadraticAttenuation;
|
||||
float spotExponent;
|
||||
Color color;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
@@ -10,9 +10,12 @@ namespace Components
|
||||
|
||||
struct SoundEmitter : Component
|
||||
{
|
||||
std::string SoundFile;
|
||||
float Volume;
|
||||
float MaxRange;
|
||||
float Gain;
|
||||
//float MaxDistance;
|
||||
float ReferenceDistance;
|
||||
float Pitch;
|
||||
bool Loop;
|
||||
std::string Path;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
@@ -9,9 +9,13 @@ namespace Components
|
||||
|
||||
struct Transform : Component
|
||||
{
|
||||
Transform()
|
||||
: Scale(glm::vec3(1.f)) { }
|
||||
|
||||
glm::vec3 Position;
|
||||
glm::quat Orientation;
|
||||
glm::vec3 Velocity;
|
||||
glm::vec3 Scale;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
@@ -1,17 +1,12 @@
|
||||
#include <string>
|
||||
#include <sstream>
|
||||
|
||||
#include <GL/glew.h>
|
||||
#define GLFW_INCLUDE_GLU
|
||||
#include <GLFW/glfw3.h>
|
||||
#include <glext.h>
|
||||
#include "Renderer.h"
|
||||
#include "GameWorld.h"
|
||||
|
||||
#include "logging.h"
|
||||
#include "glerror.h"
|
||||
|
||||
#include "Renderer.h"
|
||||
#include "GameWorld.h"
|
||||
|
||||
class Engine
|
||||
{
|
||||
public:
|
||||
|
||||
@@ -16,13 +16,13 @@
|
||||
</PropertyGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
|
||||
<ConfigurationType>StaticLibrary</ConfigurationType>
|
||||
<ConfigurationType>Application</ConfigurationType>
|
||||
<UseDebugLibraries>true</UseDebugLibraries>
|
||||
<CharacterSet>MultiByte</CharacterSet>
|
||||
<PlatformToolset>v110</PlatformToolset>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
|
||||
<ConfigurationType>StaticLibrary</ConfigurationType>
|
||||
<ConfigurationType>Application</ConfigurationType>
|
||||
<UseDebugLibraries>false</UseDebugLibraries>
|
||||
<WholeProgramOptimization>true</WholeProgramOptimization>
|
||||
<CharacterSet>MultiByte</CharacterSet>
|
||||
@@ -40,17 +40,17 @@
|
||||
<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>$(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>$(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>
|
||||
<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>
|
||||
@@ -65,12 +65,12 @@
|
||||
<Link>
|
||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||
<SubSystem>Console</SubSystem>
|
||||
<AdditionalDependencies>opengl32.lib;glu32.lib;glew32sd.lib;glfw3.lib;%(AdditionalDependencies)</AdditionalDependencies>
|
||||
<AdditionalDependencies>OpenAL32.lib;opengl32.lib;glu32.lib;SOIL.lib;glew32sd.lib;glfw3.lib;%(AdditionalDependencies)</AdditionalDependencies>
|
||||
</Link>
|
||||
<PostBuildEvent />
|
||||
<PostBuildEvent />
|
||||
<Lib>
|
||||
<AdditionalDependencies>opengl32.lib;glu32.lib;SOIL.lib;glew32sd.lib;glfw3.lib</AdditionalDependencies>
|
||||
<AdditionalDependencies>OpenAL32.lib;opengl32.lib;glu32.lib;SOIL.lib;glew32sd.lib;glfw3.lib</AdditionalDependencies>
|
||||
<ForceSymbolReferences>
|
||||
</ForceSymbolReferences>
|
||||
</Lib>
|
||||
@@ -82,27 +82,31 @@
|
||||
<Optimization>MaxSpeed</Optimization>
|
||||
<FunctionLevelLinking>true</FunctionLevelLinking>
|
||||
<IntrinsicFunctions>true</IntrinsicFunctions>
|
||||
<PreprocessorDefinitions>GLEW_STATIC;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<PreprocessorDefinitions>GLEW_STATIC;DEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<PrecompiledHeader>NotUsing</PrecompiledHeader>
|
||||
<DebugInformationFormat>None</DebugInformationFormat>
|
||||
<DebugInformationFormat>ProgramDatabase</DebugInformationFormat>
|
||||
<MinimalRebuild>true</MinimalRebuild>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<GenerateDebugInformation>false</GenerateDebugInformation>
|
||||
<EnableCOMDATFolding>true</EnableCOMDATFolding>
|
||||
<OptimizeReferences>true</OptimizeReferences>
|
||||
<AdditionalDependencies>opengl32.lib;glu32.lib;glew32s.lib;glfw3.lib;%(AdditionalDependencies)</AdditionalDependencies>
|
||||
<AdditionalDependencies>OpenAL32.lib;opengl32.lib;glu32.lib;SOIL.lib;glew32s.lib;glfw3.lib;%(AdditionalDependencies)</AdditionalDependencies>
|
||||
</Link>
|
||||
<Lib>
|
||||
<AdditionalDependencies>opengl32.lib;glu32.lib;SOIL.lib;glew32s.lib;glfw3.lib;</AdditionalDependencies>
|
||||
<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" />
|
||||
@@ -117,6 +121,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" />
|
||||
@@ -144,6 +149,8 @@
|
||||
<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" />
|
||||
@@ -159,7 +166,15 @@
|
||||
<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" />
|
||||
|
||||
@@ -43,6 +43,10 @@
|
||||
<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" />
|
||||
@@ -141,6 +145,9 @@
|
||||
</ClInclude>
|
||||
<ClInclude Include="GameWorld.h" />
|
||||
<ClInclude Include="Rectangle.h" />
|
||||
<ClInclude Include="Camera.h" />
|
||||
<ClInclude Include="OBJ.h" />
|
||||
<ClInclude Include="OpenGL.h" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<None Include="Shaders\Fragment.glsl">
|
||||
@@ -149,6 +156,30 @@
|
||||
<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">
|
||||
|
||||
@@ -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>
|
||||
@@ -0,0 +1,71 @@
|
||||
uniform mat4 model;
|
||||
uniform mat4 view;
|
||||
|
||||
layout(binding=0) uniform sampler2D texture;
|
||||
|
||||
const int numberOfLights = 2;
|
||||
lightSource lights[numberOfLights];
|
||||
|
||||
uniform vec4 position[numberOfLights];
|
||||
uniform vec4 specular[numberOfLights];
|
||||
uniform vec4 diffuse[numberOfLights];
|
||||
uniform float constantAttenuation[numberOfLights];
|
||||
uniform float linearAttenuation[numberOfLights];
|
||||
uniform float quadraticAttenuation[numberOfLights];
|
||||
uniform float spotExponent[numberOfLights];
|
||||
|
||||
in VertexData {
|
||||
vec3 Position;
|
||||
vec3 Normal;
|
||||
vec2 TextureCoord;
|
||||
} Input;
|
||||
|
||||
vec4 scene_ambient = vec4(0.2, 0.2, 0.2, 1.0);
|
||||
|
||||
out vec4 fragmentColor;
|
||||
|
||||
void main()
|
||||
{
|
||||
|
||||
vec4 texel = texture2D(texture, Input.TextureCoord);
|
||||
|
||||
vec3 normalDirection = normalize(Normal);
|
||||
vec3 viewDirection = normalize(vec3(v_inv * vec4(0.0, 0.0, 0.0, 1.0) - Position));
|
||||
vec3 lightDirection;
|
||||
float attenuation;
|
||||
|
||||
// initialize total lighting with ambient lighting
|
||||
vec3 totalLighting = vec3(scene_ambient) * vec3(frontMaterial.ambient);
|
||||
|
||||
for (int index = 0; index < numberOfLights; index++) // for all light sources
|
||||
{
|
||||
vec3 positionToLightSource = vec3(position[index] - Position);
|
||||
float distance = length(positionToLightSource);
|
||||
lightDirection = normalize(positionToLightSource);
|
||||
|
||||
attenuation = 1.0 / (constantAttenuation[index]
|
||||
+ linearAttenuation[index] * distance
|
||||
+ quadraticAttenuation[index] * distance * distance);
|
||||
|
||||
attenuation = attenuation * pow(clampedCosine, spotExponent[index]);
|
||||
|
||||
vec3 diffuseReflection = attenuation
|
||||
* vec3(diffuse[index]) * vec3(frontMaterial.diffuse)
|
||||
* max(0.0, dot(normalDirection, lightDirection));
|
||||
|
||||
vec3 specularReflection;
|
||||
if (dot(normalDirection, lightDirection) < 0.0) // light source on the wrong side?
|
||||
{
|
||||
specularReflection = vec3(0.0, 0.0, 0.0); // no specular reflection
|
||||
}
|
||||
else // light source on the right side
|
||||
{
|
||||
specularReflection = attenuation * vec3(specular[index]) * vec3(frontMaterial.specular)
|
||||
* pow(max(0.0, dot(reflect(-lightDirection, normalDirection), viewDirection)), frontMaterial.shininess);
|
||||
}
|
||||
|
||||
totalLighting = totalLighting + diffuseReflection + specularReflection;
|
||||
}
|
||||
|
||||
fragmentColor = vec4(totalLighting, 1.0) * texel;
|
||||
}
|
||||
@@ -0,0 +1,155 @@
|
||||
#include "GameWorld.h"
|
||||
|
||||
|
||||
void GameWorld::Initialize()
|
||||
{
|
||||
World::Initialize();
|
||||
|
||||
AddSystem("LevelGenerationSystem");
|
||||
AddSystem("InputSystem");
|
||||
AddSystem("CollisionSystem");
|
||||
//AddSystem("ParticleSystem");
|
||||
AddSystem("PlayerSystem");
|
||||
AddSystem("SoundSystem");
|
||||
AddSystem("RenderSystem");
|
||||
|
||||
std::shared_ptr<Components::Transform> transform;
|
||||
std::shared_ptr<Components::Model> model;
|
||||
std::shared_ptr<Components::PointLight> pointLight;
|
||||
std::shared_ptr<Components::Camera> camera;
|
||||
std::shared_ptr<Components::Bounds> bounds;
|
||||
std::shared_ptr<Components::Collision> collision;
|
||||
EntityID ent;
|
||||
|
||||
|
||||
|
||||
|
||||
// Fucking lights
|
||||
ent = CreateEntity();
|
||||
transform = AddComponent<Components::Transform>(ent, "Transform");
|
||||
transform->Position = glm::vec3(0.f, 7.f, 0.f);
|
||||
pointLight = AddComponent<Components::PointLight>(ent, "PointLight");
|
||||
pointLight->Specular = glm::vec3(1.0, 1.0, 1.0);
|
||||
pointLight->Diffuse = glm::vec3(0.0, 0.0, 5.0);
|
||||
pointLight->constantAttenuation = 0.f;
|
||||
pointLight->linearAttenuation = 1.f;
|
||||
pointLight->quadraticAttenuation = 0.f;
|
||||
pointLight->spotExponent = 0.0f;
|
||||
model = AddComponent<Components::Model>(ent, "Model");
|
||||
model->ModelFile = "Models/sphere.obj";
|
||||
ent = CreateEntity();
|
||||
transform = AddComponent<Components::Transform>(ent, "Transform");
|
||||
transform->Position = glm::vec3(10.f, 7.f, 0.f);
|
||||
pointLight = AddComponent<Components::PointLight>(ent, "PointLight");
|
||||
pointLight->Specular = glm::vec3(1.0, 1.0, 1.0);
|
||||
pointLight->Diffuse = glm::vec3(0.0, 5.0, 0.0);
|
||||
pointLight->constantAttenuation = 0.f;
|
||||
pointLight->linearAttenuation = 1.f;
|
||||
pointLight->quadraticAttenuation = 0.f;
|
||||
pointLight->spotExponent = 0.0f;
|
||||
model = AddComponent<Components::Model>(ent, "Model");
|
||||
model->ModelFile = "Models/sphere.obj";
|
||||
ent = CreateEntity();
|
||||
transform = AddComponent<Components::Transform>(ent, "Transform");
|
||||
transform->Position = glm::vec3(-10.f, 7.f, 0.f);
|
||||
pointLight = AddComponent<Components::PointLight>(ent, "PointLight");
|
||||
pointLight->Specular = glm::vec3(1.0, 1.0, 1.0);
|
||||
pointLight->Diffuse = glm::vec3(5.0, 0.0, 0.0);
|
||||
pointLight->constantAttenuation = 0.f;
|
||||
pointLight->linearAttenuation = 1.f;
|
||||
pointLight->quadraticAttenuation = 0.f;
|
||||
pointLight->spotExponent = 0.0f;
|
||||
model = AddComponent<Components::Model>(ent, "Model");
|
||||
model->ModelFile = "Models/sphere.obj";
|
||||
|
||||
//ground
|
||||
ent = CreateEntity();
|
||||
transform = AddComponent<Components::Transform>(ent, "Transform");
|
||||
transform->Position = glm::vec3(0.f, 0.f, 0.f);
|
||||
model = AddComponent<Components::Model>(ent, "Model");
|
||||
model->ModelFile = "Models/plane.obj";
|
||||
|
||||
// Player
|
||||
m_Player = CreateEntity();
|
||||
SetProperty(m_Player, "Name", std::string("PlayerShip"));
|
||||
transform = AddComponent<Components::Transform>(m_Player, "Transform");
|
||||
transform->Position = glm::vec3(0.f, 2.f, -5.f);
|
||||
transform->Scale = glm::vec3(1.0f);
|
||||
model = AddComponent<Components::Model>(m_Player, "Model");
|
||||
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");
|
||||
collision = AddComponent<Components::Collision>(m_Player, "Collision");
|
||||
collision->Phantom = false;
|
||||
collision->Interested = true;
|
||||
bounds = AddComponent<Components::Bounds>(m_Player, "Bounds");
|
||||
bounds->Origin = glm::vec3(0, 0, 2.f);
|
||||
bounds->VolumeVector = glm::vec3(4.f, 0.7f, 1);
|
||||
|
||||
|
||||
// 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->Position = glm::vec3(10.f, 4.f, 0.f);
|
||||
model = AddComponent<Components::Model>(ent, "Model");
|
||||
model->ModelFile = "Models/ship.obj";
|
||||
collision = AddComponent<Components::Collision>(player2, "Collision");
|
||||
collision->Phantom = false;
|
||||
bounds = AddComponent<Components::Bounds>(player2, "Bounds");
|
||||
bounds->Origin = transform->Position;
|
||||
bounds->VolumeVector = glm::vec3(2.f,2.f,2.f);*/
|
||||
}
|
||||
|
||||
void GameWorld::Update(double dt)
|
||||
{
|
||||
World::Update(dt);
|
||||
}
|
||||
|
||||
void GameWorld::RegisterComponents()
|
||||
{
|
||||
m_ComponentFactory.Register("Bounds", []() { return new Components::Bounds(); });
|
||||
m_ComponentFactory.Register("Camera", []() { return new Components::Camera(); });
|
||||
m_ComponentFactory.Register("Collision", []() { return new Components::Collision(); });
|
||||
m_ComponentFactory.Register("DirectionalLight", []() { return new Components::DirectionalLight(); });
|
||||
m_ComponentFactory.Register("Input", []() { return new Components::Input(); });
|
||||
m_ComponentFactory.Register("Model", []() { return new Components::Model(); });
|
||||
m_ComponentFactory.Register("ParticleEmitter", []() { return new Components::ParticleEmitter(); });
|
||||
m_ComponentFactory.Register("PointLight", []() { return new Components::PointLight(); });
|
||||
m_ComponentFactory.Register("PowerUp", []() { return new Components::PowerUp(); });
|
||||
m_ComponentFactory.Register("SoundEmitter", []() { return new Components::SoundEmitter(); });
|
||||
m_ComponentFactory.Register("Sprite", []() { return new Components::Sprite(); });
|
||||
m_ComponentFactory.Register("Stat", []() { return new Components::Stat(); });
|
||||
m_ComponentFactory.Register("Template", []() { return new Components::Template(); });
|
||||
m_ComponentFactory.Register("Transform", []() { return new Components::Transform(); });
|
||||
}
|
||||
|
||||
void GameWorld::RegisterSystems()
|
||||
{
|
||||
m_SystemFactory.Register("LevelGenerationSystem", [this]() { return new Systems::LevelGenerationSystem(this); });
|
||||
m_SystemFactory.Register("InputSystem", [this]() { return new Systems::InputSystem(this, m_Renderer); });
|
||||
m_SystemFactory.Register("CollisionSystem", [this]() { return new Systems::CollisionSystem(this); });
|
||||
//m_SystemFactory.Register("ParticleSystem", [this]() { return new Systems::ParticleSystem(this); });
|
||||
m_SystemFactory.Register("PlayerSystem", [this]() { return new Systems::PlayerSystem(this); });
|
||||
m_SystemFactory.Register("SoundSystem", [this]() { return new Systems::SoundSystem(this); });
|
||||
m_SystemFactory.Register("RenderSystem", [this]() { return new Systems::RenderSystem(this, m_Renderer); });
|
||||
}
|
||||
@@ -30,63 +30,20 @@
|
||||
class GameWorld : public World
|
||||
{
|
||||
public:
|
||||
GameWorld(std::shared_ptr<Renderer> renderer);
|
||||
void Initialize() override;
|
||||
GameWorld(std::shared_ptr<Renderer> renderer)
|
||||
: m_Renderer(renderer), World() { }
|
||||
|
||||
void Initialize();
|
||||
|
||||
void RegisterSystems() override;
|
||||
void RegisterComponents() override;
|
||||
|
||||
void Update(double dt) override;
|
||||
void Update(double dt) ;
|
||||
|
||||
private:
|
||||
std::shared_ptr<Renderer> m_Renderer;
|
||||
EntityID entcamera, player2;
|
||||
EntityID m_Player;
|
||||
};
|
||||
|
||||
GameWorld::GameWorld(std::shared_ptr<Renderer> renderer)
|
||||
: m_Renderer(renderer), World()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void GameWorld::Initialize()
|
||||
{
|
||||
World::Initialize();
|
||||
|
||||
AddSystem("InputSystem");
|
||||
}
|
||||
|
||||
void GameWorld::RegisterSystems()
|
||||
{
|
||||
//m_SystemFactory.Register("LevelGenerationSystem", [this]() { return new Systems::LevelGenerationSystem(this); });
|
||||
m_SystemFactory.Register("InputSystem", [this]() { return new Systems::InputSystem(this, m_Renderer); });
|
||||
//m_SystemFactory.Register("CollisionSystem", [this]() { return new Systems::CollisionSystem(this); });
|
||||
//m_SystemFactory.Register("ParticleSystem", [this]() { return new Systems::ParticleSystem(this); });
|
||||
//m_SystemFactory.Register("PlayerSystem", [this]() { return new Systems::PlayerSystem(this); });
|
||||
//m_SystemFactory.Register("SoundSystem", [this]() { return new Systems::SoundSystem(this); });
|
||||
//m_SystemFactory.Register("RenderSystem", [this]() { return new Systems::RenderSystem(this, m_Renderer); });
|
||||
}
|
||||
|
||||
void GameWorld::RegisterComponents()
|
||||
{
|
||||
m_ComponentFactory.Register("Bounds", []() { return new Components::Bounds(); });
|
||||
m_ComponentFactory.Register("Camera", []() { return new Components::Camera(); });
|
||||
m_ComponentFactory.Register("Collision", []() { return new Components::Collision(); });
|
||||
m_ComponentFactory.Register("DirectionalLight", []() { return new Components::DirectionalLight(); });
|
||||
m_ComponentFactory.Register("Input", []() { return new Components::Input(); });
|
||||
m_ComponentFactory.Register("Model", []() { return new Components::Model(); });
|
||||
m_ComponentFactory.Register("ParticleEmitter", []() { return new Components::ParticleEmitter(); });
|
||||
m_ComponentFactory.Register("PointLight", []() { return new Components::PointLight(); });
|
||||
m_ComponentFactory.Register("PowerUp", []() { return new Components::PowerUp(); });
|
||||
m_ComponentFactory.Register("SoundEmitter", []() { return new Components::SoundEmitter(); });
|
||||
m_ComponentFactory.Register("Sprite", []() { return new Components::Sprite(); });
|
||||
m_ComponentFactory.Register("Stat", []() { return new Components::Stat(); });
|
||||
m_ComponentFactory.Register("Template", []() { return new Components::Template(); });
|
||||
m_ComponentFactory.Register("Transform", []() { return new Components::Transform(); });
|
||||
}
|
||||
|
||||
void GameWorld::Update(double dt)
|
||||
{
|
||||
World::Update(dt);
|
||||
}
|
||||
|
||||
#endif // GameWorld_h__
|
||||
|
||||
+83
-17
@@ -3,12 +3,61 @@
|
||||
|
||||
Model::Model(const char* path)
|
||||
{
|
||||
|
||||
|
||||
Loadobj(path, Vertices, Normals, TextureCoords);
|
||||
CreateBuffers(Vertices, Normals, TextureCoords);
|
||||
}
|
||||
|
||||
Model::Model(OBJ &obj)
|
||||
{
|
||||
OBJ::MaterialInfo* currentMaterial = nullptr;
|
||||
TextureGroup* currentTexGroup = nullptr;
|
||||
int index = 0;
|
||||
for (auto face : obj.Faces) {
|
||||
if (face.Material == nullptr) {
|
||||
LOG_ERROR("Missing material for .obj file \"%s\"", obj.Path().string().c_str());
|
||||
return;
|
||||
}
|
||||
// New material
|
||||
if (face.Material != currentMaterial) {
|
||||
currentMaterial = face.Material;
|
||||
// Load texture
|
||||
std::shared_ptr<Texture> texture = std::make_shared<Texture>(currentMaterial->TextureFile);
|
||||
// TODO: Load material parameters
|
||||
// Create new texture group (start index of new group is upcoming index)
|
||||
TextureGroup texGroup = { texture, index, index };
|
||||
TextureGroups.push_back(texGroup);
|
||||
currentTexGroup = &TextureGroups.back();
|
||||
}
|
||||
|
||||
// Face definitions
|
||||
for (auto faceDef : face.Definitions) {
|
||||
glm::vec3 vertex;
|
||||
std::tie(vertex.x, vertex.y, vertex.z) = obj.Vertices.at(faceDef.VertexIndex - 1);
|
||||
Vertices.push_back(vertex);
|
||||
|
||||
if (faceDef.NormalIndex != 0) {
|
||||
glm::vec3 normal;
|
||||
std::tie(normal.x, normal.y, normal.z) = obj.Normals.at(faceDef.NormalIndex - 1);
|
||||
Normals.push_back(normal);
|
||||
}
|
||||
|
||||
if (faceDef.TextureCoordIndex != 0) {
|
||||
glm::vec2 texCoord;
|
||||
// TODO: W-coord?
|
||||
std::tie(texCoord.x, texCoord.y, std::ignore) = obj.TextureCoords.at(faceDef.TextureCoordIndex - 1);
|
||||
TextureCoords.push_back(texCoord);
|
||||
}
|
||||
|
||||
currentTexGroup->EndIndex = index;
|
||||
index++;
|
||||
}
|
||||
}
|
||||
|
||||
if (Vertices.size() > 0) {
|
||||
CreateBuffers(Vertices, Normals, TextureCoords);
|
||||
}
|
||||
}
|
||||
|
||||
bool Model::Loadobj(const char* path, std::vector <glm::vec3> & out_vertices, std::vector <glm::vec3> &out_normals, std::vector <glm::vec2> & out_TextureCoords)
|
||||
{
|
||||
std::vector< unsigned int > vertexIndices, TextureCoordIndices, normalIndices;
|
||||
@@ -101,7 +150,7 @@ bool Model::Loadobj(const char* path, std::vector <glm::vec3> & out_vertices, st
|
||||
else if ( strcmp( lineHeader, "mtllib" ) == 0 )
|
||||
{
|
||||
|
||||
const char* fileName;
|
||||
char fileName[512];
|
||||
fscanf(file, "%s\n", &fileName);
|
||||
|
||||
|
||||
@@ -127,7 +176,7 @@ bool Model::Loadobj(const char* path, std::vector <glm::vec3> & out_vertices, st
|
||||
}
|
||||
else if ( strcmp( mtllineHeader, "map_Kd" ) == 0 )
|
||||
{
|
||||
const char* textureFileName;
|
||||
char textureFileName[512];
|
||||
fscanf(mtlfile, "%s", textureFileName);
|
||||
texture.push_back(std::make_shared<Texture>(textureFileName));
|
||||
LOG_INFO("Texture Loaded\n");
|
||||
@@ -142,27 +191,40 @@ 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)
|
||||
|
||||
void Model::CreateBuffers( std::vector<glm::vec3> vertices, std::vector<glm::vec3> normals, std::vector<glm::vec2>textureCoords)
|
||||
{
|
||||
|
||||
LOG_INFO("Generating VertexBuffer");
|
||||
glGenBuffers(1, &VertexBuffer);
|
||||
glBindBuffer(GL_ARRAY_BUFFER, VertexBuffer);
|
||||
glBufferData(GL_ARRAY_BUFFER, _Vertices.size() * sizeof(glm::vec3), &_Vertices[0], GL_STATIC_DRAW);
|
||||
GLERROR("GLEW: BufferFail, VertexBuffer");
|
||||
if (vertices.size() > 0) {
|
||||
glBindBuffer(GL_ARRAY_BUFFER, VertexBuffer);
|
||||
glBufferData(GL_ARRAY_BUFFER, vertices.size() * sizeof(glm::vec3), &vertices[0], GL_STATIC_DRAW);
|
||||
GLERROR("GLEW: BufferFail, VertexBuffer");
|
||||
} else {
|
||||
LOG_WARNING("Created empty vertex buffer!");
|
||||
}
|
||||
|
||||
LOG_INFO("Generating NormalBuffer");
|
||||
glGenBuffers(1, &NormalBuffer);
|
||||
glBindBuffer(GL_ARRAY_BUFFER, NormalBuffer);
|
||||
glBufferData(GL_ARRAY_BUFFER, _Normals.size() * sizeof(glm::vec3), &_Normals[0], GL_STATIC_DRAW);
|
||||
GLERROR("GLEW: BufferFail, NormalBuffer");
|
||||
if (normals.size() > 0) {
|
||||
glBindBuffer(GL_ARRAY_BUFFER, NormalBuffer);
|
||||
glBufferData(GL_ARRAY_BUFFER, normals.size() * sizeof(glm::vec3), &normals[0], GL_STATIC_DRAW);
|
||||
GLERROR("GLEW: BufferFail, NormalBuffer");
|
||||
} else {
|
||||
LOG_WARNING("Created empty normal buffer!");
|
||||
}
|
||||
|
||||
|
||||
LOG_INFO("Generating textureCoordBuffer");
|
||||
glGenBuffers(1, &TextureCoordBuffer);
|
||||
glBindBuffer(GL_ARRAY_BUFFER, TextureCoordBuffer);
|
||||
glBufferData(GL_ARRAY_BUFFER, _TextureCoords.size() * sizeof(glm::vec2), &_TextureCoords[0], GL_STATIC_DRAW);
|
||||
GLERROR("GLEW: BufferFail, TextureCoordBuffer");
|
||||
if (textureCoords.size() > 0) {
|
||||
glBindBuffer(GL_ARRAY_BUFFER, TextureCoordBuffer);
|
||||
glBufferData(GL_ARRAY_BUFFER, textureCoords.size() * sizeof(glm::vec2), &textureCoords[0], GL_STATIC_DRAW);
|
||||
GLERROR("GLEW: BufferFail, TextureCoordBuffer");
|
||||
} else {
|
||||
LOG_WARNING("Created empty texture coordinate buffer!");
|
||||
}
|
||||
|
||||
glGenVertexArrays(1, &VAO);
|
||||
glBindVertexArray(VAO);
|
||||
@@ -172,13 +234,17 @@ void Model::CreateBuffers( std::vector<glm::vec3> _Vertices, std::vector<glm::ve
|
||||
glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 0, 0);
|
||||
GLERROR("GLEW: BufferFail5");
|
||||
|
||||
glBindBuffer(GL_ARRAY_BUFFER, NormalBuffer);
|
||||
glVertexAttribPointer(1, 3, GL_FLOAT, GL_FALSE, 0, 0);
|
||||
GLERROR("GLEW: BufferFail5");
|
||||
|
||||
// glBindBuffer(GL_ARRAY_BUFFER, TextureCoordBuffer);
|
||||
// glVertexAttribPointer(2, 2, GL_FLOAT, GL_FALSE, 0, 0);
|
||||
glBindBuffer(GL_ARRAY_BUFFER, TextureCoordBuffer);
|
||||
glVertexAttribPointer(2, 2, GL_FLOAT, GL_FALSE, 0, 0);
|
||||
GLERROR("GLEW: BufferFail5");
|
||||
|
||||
glEnableVertexAttribArray(0);
|
||||
glEnableVertexAttribArray(1);
|
||||
/* glEnableVertexAttribArray(2);*/
|
||||
glEnableVertexAttribArray(2);
|
||||
GLERROR("GLEW: BufferFail5");
|
||||
}
|
||||
|
||||
|
||||
+24
-13
@@ -8,37 +8,48 @@
|
||||
#include <vector>
|
||||
#include <memory>
|
||||
|
||||
#define _CRT_SECURE_NO_WARNINGS
|
||||
#include <GL/glew.h>
|
||||
#define GLFW_INCLUDE_GLU
|
||||
#include <GLFW/glfw3.h>
|
||||
#include <glext.h>
|
||||
#define GLM_FORCE_RADIANS
|
||||
#include "OpenGL.h"
|
||||
#include <glm/glm.hpp>
|
||||
#include <glm/gtc/constants.hpp>
|
||||
#include <glm/gtc/matrix_transform.hpp>
|
||||
#include <glm/gtc/type_ptr.hpp>
|
||||
|
||||
#include "glerror.h"
|
||||
#include <cstdlib>
|
||||
#include <stack>
|
||||
|
||||
#include "glerror.h"
|
||||
|
||||
#include "Texture.h"
|
||||
#include "OBJ.h"
|
||||
|
||||
class Model
|
||||
{
|
||||
public:
|
||||
Model(OBJ &obj);
|
||||
Model(const char* path);
|
||||
|
||||
struct TextureGroup
|
||||
{
|
||||
std::shared_ptr<Texture> Texture;
|
||||
unsigned int StartIndex;
|
||||
unsigned int EndIndex;
|
||||
};
|
||||
|
||||
GLuint VAO;
|
||||
std::vector<TextureGroup> TextureGroups;
|
||||
|
||||
std::vector<std::shared_ptr<Texture>> texture;
|
||||
glm::mat4 GetMatrix();
|
||||
std::vector<glm::vec3> Vertices;
|
||||
|
||||
private:
|
||||
|
||||
std::vector<glm::vec3> Normals;
|
||||
std::vector<glm::vec2> TextureCoords;
|
||||
|
||||
GLuint VertexBuffer;
|
||||
GLuint NormalBuffer;
|
||||
GLuint TextureCoordBuffer;
|
||||
GLuint VAO;
|
||||
|
||||
std::vector<std::shared_ptr<Texture>> texture;
|
||||
|
||||
Model(const char* path);
|
||||
|
||||
bool Loadobj(
|
||||
const char* path,
|
||||
@@ -46,7 +57,7 @@ public:
|
||||
std::vector <glm::vec3> &out_normals,
|
||||
std::vector <glm::vec2> & out_TextureCoords
|
||||
);
|
||||
|
||||
|
||||
void CreateBuffers(
|
||||
std::vector<glm::vec3> _Vertices,
|
||||
std::vector<glm::vec3> _Normals,
|
||||
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 6.8 KiB |
@@ -0,0 +1,12 @@
|
||||
# Blender MTL File: 'obstaclesandstuff.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 ObstacleTexture.png
|
||||
@@ -0,0 +1,36 @@
|
||||
# Blender v2.69 (sub 0) OBJ File: 'obstaclesandstuff.blend'
|
||||
# www.blender.org
|
||||
mtllib obstacle_cube_1.mtl
|
||||
o Cube.001_Cube.018
|
||||
v -1.000000 -0.019077 1.000000
|
||||
v -1.000000 -0.019077 -1.000000
|
||||
v 1.000000 -0.019077 -1.000000
|
||||
v 1.000000 -0.019077 1.000000
|
||||
v -1.000000 1.980923 1.000000
|
||||
v -1.000000 1.980923 -1.000000
|
||||
v 1.000000 1.980923 -1.000000
|
||||
v 1.000000 1.980923 1.000000
|
||||
vt 0.000000 0.000000
|
||||
vt 1.000000 0.000000
|
||||
vt 0.000000 1.000000
|
||||
vt 1.000000 1.000000
|
||||
vn -1.000000 0.000000 0.000000
|
||||
vn 0.000000 0.000000 -1.000000
|
||||
vn 1.000000 0.000000 0.000000
|
||||
vn 0.000000 0.000000 1.000000
|
||||
vn 0.000000 -1.000000 0.000000
|
||||
vn 0.000000 1.000000 0.000000
|
||||
usemtl Material.001
|
||||
s off
|
||||
f 5/1/1 6/2/1 1/3/1
|
||||
f 6/1/2 7/2/2 2/3/2
|
||||
f 7/1/3 8/2/3 3/3/3
|
||||
f 8/1/4 5/2/4 4/3/4
|
||||
f 1/1/5 2/2/5 4/3/5
|
||||
f 8/1/6 7/2/6 5/3/6
|
||||
f 6/2/1 2/4/1 1/3/1
|
||||
f 7/2/2 3/4/2 2/3/2
|
||||
f 8/2/3 4/4/3 3/3/3
|
||||
f 5/2/4 1/4/4 4/3/4
|
||||
f 2/2/5 3/4/5 4/3/5
|
||||
f 7/2/6 6/4/6 5/3/6
|
||||
@@ -0,0 +1,12 @@
|
||||
# Blender MTL File: 'obstaclesandstuff.blend'
|
||||
# Material Count: 1
|
||||
|
||||
newmtl Material
|
||||
Ns 96.078431
|
||||
Ka 0.000000 0.000000 0.000000
|
||||
Kd 0.559600 0.559600 0.559600
|
||||
Ks 0.500000 0.500000 0.500000
|
||||
Ni 1.000000
|
||||
d 1.000000
|
||||
illum 2
|
||||
map_Kd ObstacleTexture.png
|
||||
@@ -0,0 +1,127 @@
|
||||
# Blender v2.69 (sub 0) OBJ File: 'obstaclesandstuff.blend'
|
||||
# www.blender.org
|
||||
mtllib obstacle_mountain_1.mtl
|
||||
o Cube.004
|
||||
v 1.698819 0.000000 2.036847
|
||||
v 1.698819 0.000000 5.330842
|
||||
v -1.595176 0.000000 5.330841
|
||||
v -1.595175 0.000000 2.036846
|
||||
v 0.051821 8.843084 3.683845
|
||||
v 1.278842 0.000000 4.358418
|
||||
v 10.046223 0.000000 4.358419
|
||||
v 10.046223 0.000000 -4.408960
|
||||
v 1.278844 0.000000 -4.408961
|
||||
v 5.662531 17.390135 -0.025270
|
||||
v -6.655907 0.000000 1.637957
|
||||
v 2.108382 0.000000 1.637958
|
||||
v 2.108382 0.000000 -7.126330
|
||||
v -6.655905 0.000000 -7.126331
|
||||
v -2.273763 25.648932 -2.744185
|
||||
v -0.900829 0.000000 0.659354
|
||||
v 5.318377 0.000000 0.659354
|
||||
v 5.318377 0.000000 -5.559852
|
||||
v -0.900827 0.000000 -5.559853
|
||||
v 2.208774 24.324408 -2.450248
|
||||
v -2.753737 0.000000 -1.359767
|
||||
v -2.753737 0.000000 4.431494
|
||||
v -8.544997 0.000000 4.431493
|
||||
v -8.544996 0.000000 -1.359768
|
||||
v -5.649367 18.211798 1.535864
|
||||
vt 0.465364 0.552468
|
||||
vt 0.391639 0.552468
|
||||
vt 0.465364 0.478743
|
||||
vt 0.239247 0.239247
|
||||
vt 0.000250 0.000250
|
||||
vt 0.478243 0.000250
|
||||
vt 0.677193 0.198700
|
||||
vt 0.478743 0.000250
|
||||
vt 0.875642 0.000250
|
||||
vt 0.875643 0.397149
|
||||
vt 0.478743 0.397149
|
||||
vt 0.674971 0.725248
|
||||
vt 0.674971 0.921475
|
||||
vt 0.478743 0.725248
|
||||
vt 0.806342 0.397649
|
||||
vt 0.892489 0.483796
|
||||
vt 0.806342 0.569944
|
||||
vt 0.978636 0.569944
|
||||
vt 0.978636 0.397649
|
||||
vt 0.478243 0.478243
|
||||
vt 0.000250 0.478243
|
||||
vt 0.871629 0.921406
|
||||
vt 0.675471 0.921406
|
||||
vt 0.871629 0.725248
|
||||
vt 0.195695 0.674188
|
||||
vt 0.000250 0.478743
|
||||
vt 0.391139 0.478743
|
||||
vt 0.391139 0.869632
|
||||
vt 0.000250 0.869633
|
||||
vt 0.945537 0.724748
|
||||
vt 0.806342 0.724748
|
||||
vt 0.945537 0.585552
|
||||
vt 0.129867 0.999750
|
||||
vt 0.000250 0.999750
|
||||
vt 0.129867 0.870133
|
||||
vt 0.805842 0.397649
|
||||
vt 0.642293 0.561199
|
||||
vt 0.478743 0.397649
|
||||
vt 0.478743 0.724748
|
||||
vt 0.805842 0.724748
|
||||
vt 0.391639 0.478743
|
||||
vt 0.478743 0.921475
|
||||
vt 0.675471 0.725248
|
||||
vt 0.806342 0.585552
|
||||
vt 0.000250 0.870133
|
||||
vn 0.000000 -1.000000 0.000000
|
||||
vn 0.000000 0.168411 -0.985717
|
||||
vn 0.000000 0.244433 -0.969666
|
||||
vn -0.969666 0.244432 -0.000000
|
||||
vn -0.000000 0.244433 0.969666
|
||||
vn 0.969666 0.244433 0.000000
|
||||
vn 0.983095 0.183098 0.000000
|
||||
vn -0.000001 0.183098 0.983095
|
||||
vn -0.983095 0.183098 -0.000000
|
||||
vn 0.000000 0.183098 -0.983095
|
||||
vn -0.985717 0.168411 -0.000000
|
||||
vn -0.000000 0.168411 0.985717
|
||||
vn 0.985717 0.168411 0.000000
|
||||
vn 0.000000 0.126807 -0.991927
|
||||
vn -0.991927 0.126807 -0.000000
|
||||
vn -0.000000 0.126807 0.991928
|
||||
vn 0.991928 0.126807 0.000000
|
||||
vn 0.987595 0.157025 0.000000
|
||||
vn -0.000000 0.157025 0.987595
|
||||
vn -0.987595 0.157025 -0.000000
|
||||
vn 0.000000 0.157025 -0.987595
|
||||
usemtl Material
|
||||
s off
|
||||
f 1/1/1 2/2/1 4/3/1
|
||||
f 15/4/2 13/5/2 14/6/2
|
||||
f 10/7/3 8/8/3 9/9/3
|
||||
f 6/10/4 10/7/4 9/9/4
|
||||
f 7/11/5 10/7/5 6/10/5
|
||||
f 8/8/6 10/7/6 7/11/6
|
||||
f 8/12/1 7/13/1 9/14/1
|
||||
f 1/15/7 5/16/7 2/17/7
|
||||
f 2/17/8 5/16/8 3/18/8
|
||||
f 3/18/9 5/16/9 4/19/9
|
||||
f 5/16/10 1/15/10 4/19/10
|
||||
f 11/20/11 15/4/11 14/6/11
|
||||
f 12/21/12 15/4/12 11/20/12
|
||||
f 13/5/13 15/4/13 12/21/13
|
||||
f 13/22/1 12/23/1 14/24/1
|
||||
f 20/25/14 18/26/14 19/27/14
|
||||
f 16/28/15 20/25/15 19/27/15
|
||||
f 17/29/16 20/25/16 16/28/16
|
||||
f 18/26/17 20/25/17 17/29/17
|
||||
f 18/30/1 17/31/1 19/32/1
|
||||
f 21/33/1 22/34/1 24/35/1
|
||||
f 21/36/18 25/37/18 22/38/18
|
||||
f 22/38/19 25/37/19 23/39/19
|
||||
f 23/39/20 25/37/20 24/40/20
|
||||
f 25/37/21 21/36/21 24/40/21
|
||||
f 2/2/1 3/41/1 4/3/1
|
||||
f 7/13/1 6/42/1 9/14/1
|
||||
f 12/23/1 11/43/1 14/24/1
|
||||
f 17/31/1 16/44/1 19/32/1
|
||||
f 22/34/1 23/45/1 24/35/1
|
||||
@@ -0,0 +1,12 @@
|
||||
# Blender MTL File: 'obstaclesandstuff.blend'
|
||||
# Material Count: 1
|
||||
|
||||
newmtl Material
|
||||
Ns 96.078431
|
||||
Ka 0.000000 0.000000 0.000000
|
||||
Kd 0.559600 0.559600 0.559600
|
||||
Ks 0.500000 0.500000 0.500000
|
||||
Ni 1.000000
|
||||
d 1.000000
|
||||
illum 2
|
||||
map_Kd ObstacleTexture.png
|
||||
@@ -0,0 +1,31 @@
|
||||
# Blender v2.69 (sub 0) OBJ File: 'obstaclesandstuff.blend'
|
||||
# www.blender.org
|
||||
mtllib obstacle_mountain_2.mtl
|
||||
o Cube.011_Cube.026
|
||||
v -3.450152 0.000000 3.450150
|
||||
v 3.450150 0.000000 3.450151
|
||||
v 3.450150 0.000000 -3.450150
|
||||
v -3.450150 0.000000 -3.450152
|
||||
v -0.000001 15.531238 0.000001
|
||||
vt 0.341102 0.341102
|
||||
vt 0.682105 0.000100
|
||||
vt 0.682105 0.682105
|
||||
vt 0.000100 0.682105
|
||||
vt 0.000100 0.000100
|
||||
vt 0.999900 0.317695
|
||||
vt 0.682305 0.317695
|
||||
vt 0.999900 0.000100
|
||||
vt 0.682305 0.000100
|
||||
vn 0.000000 0.216857 -0.976204
|
||||
vn -0.976204 0.216856 -0.000000
|
||||
vn -0.000000 0.216856 0.976204
|
||||
vn 0.976204 0.216856 0.000000
|
||||
vn 0.000000 -1.000000 0.000000
|
||||
usemtl Material
|
||||
s off
|
||||
f 5/1/1 3/2/1 4/3/1
|
||||
f 1/4/2 5/1/2 4/3/2
|
||||
f 2/5/3 5/1/3 1/4/3
|
||||
f 3/2/4 5/1/4 2/5/4
|
||||
f 3/6/5 2/7/5 4/8/5
|
||||
f 2/7/5 1/9/5 4/8/5
|
||||
@@ -0,0 +1,12 @@
|
||||
# Blender MTL File: 'None'
|
||||
# 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 ObstacleTexture.png
|
||||
@@ -0,0 +1,14 @@
|
||||
mtllib plane.mtl
|
||||
o Plane
|
||||
v -1000 0 1000
|
||||
v 1000 0 1000
|
||||
v 1000 0 -1000
|
||||
v -1000 0 -1000
|
||||
vn 0.000000 1.000000 0.000000
|
||||
vt 0 0
|
||||
vt 1 0
|
||||
vt 1 1
|
||||
vt 0 1
|
||||
usemtl Material.001
|
||||
f 1/1/1 3/3/1 4/4/1
|
||||
f 1/1/1 2/2/1 3/3/1
|
||||
@@ -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 |
@@ -0,0 +1,22 @@
|
||||
# Blender MTL File: 'tobbeljus.blend'
|
||||
# Material Count: 2
|
||||
|
||||
newmtl Material
|
||||
Ns 96.078431
|
||||
Ka 0.000000 0.000000 0.000000
|
||||
Kd 1.000000 1.000000 1.000000
|
||||
Ks 0.500000 0.500000 0.500000
|
||||
Ni 1.000000
|
||||
d 1.000000
|
||||
illum 2
|
||||
map_Kd shiptexture.png
|
||||
|
||||
newmtl Material.001
|
||||
Ns 96.078431
|
||||
Ka 0.000000 0.000000 0.000000
|
||||
Kd 0.000000 0.185023 0.800000
|
||||
Ks 1.000000 1.000000 1.000000
|
||||
Ni 1.000000
|
||||
d 1.000000
|
||||
illum 2
|
||||
map_Kd shiptexture.png
|
||||
File diff suppressed because it is too large
Load Diff
Binary file not shown.
|
After Width: | Height: | Size: 69 KiB |
@@ -0,0 +1,12 @@
|
||||
# Blender MTL File: 'obstaclesandstuff.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 ObstacleTexture.png
|
||||
@@ -0,0 +1,211 @@
|
||||
# Blender v2.69 (sub 0) OBJ File: 'obstaclesandstuff.blend'
|
||||
# www.blender.org
|
||||
mtllib sphere.mtl
|
||||
o Icosphere
|
||||
v -0.000000 -0.184854 -0.000000
|
||||
v 0.133761 -0.082670 0.097182
|
||||
v -0.051091 -0.082670 0.157246
|
||||
v -0.165338 -0.082669 -0.000000
|
||||
v -0.051091 -0.082670 -0.157246
|
||||
v 0.133761 -0.082670 -0.097182
|
||||
v 0.051091 0.082670 0.157246
|
||||
v -0.133761 0.082670 0.097182
|
||||
v -0.133761 0.082670 -0.097182
|
||||
v 0.051091 0.082670 -0.157246
|
||||
v 0.165338 0.082669 -0.000000
|
||||
v -0.000000 0.184854 -0.000000
|
||||
v -0.030031 -0.157247 0.092426
|
||||
v 0.078622 -0.157247 0.057122
|
||||
v 0.048592 -0.097185 0.149549
|
||||
v 0.157245 -0.097184 -0.000000
|
||||
v 0.078622 -0.157247 -0.057122
|
||||
v -0.097183 -0.157246 -0.000000
|
||||
v -0.127214 -0.097184 0.092426
|
||||
v -0.030031 -0.157247 -0.092426
|
||||
v -0.127214 -0.097184 -0.092426
|
||||
v 0.048592 -0.097185 -0.149549
|
||||
v 0.175807 0.000000 0.057122
|
||||
v 0.175807 0.000000 -0.057122
|
||||
v -0.000000 0.000000 0.184854
|
||||
v 0.108654 0.000000 0.149550
|
||||
v -0.175807 0.000000 0.057122
|
||||
v -0.108654 0.000000 0.149550
|
||||
v -0.108654 0.000000 -0.149550
|
||||
v -0.175807 0.000000 -0.057122
|
||||
v 0.108654 0.000000 -0.149550
|
||||
v -0.000000 0.000000 -0.184854
|
||||
v 0.127214 0.097184 0.092426
|
||||
v -0.048592 0.097185 0.149549
|
||||
v -0.157245 0.097184 -0.000000
|
||||
v -0.048592 0.097185 -0.149549
|
||||
v 0.127214 0.097184 -0.092426
|
||||
v 0.030031 0.157247 0.092426
|
||||
v 0.097183 0.157246 -0.000000
|
||||
v -0.078622 0.157247 0.057122
|
||||
v -0.078622 0.157247 -0.057122
|
||||
v 0.030031 0.157247 -0.092426
|
||||
vt 0.000000 0.000000
|
||||
vt 1.000000 0.000000
|
||||
vt 1.000000 1.000000
|
||||
vn 0.102381 -0.943523 0.315090
|
||||
vn 0.700224 -0.661699 0.268032
|
||||
vn -0.268034 -0.943523 0.194737
|
||||
vn -0.268034 -0.943523 -0.194737
|
||||
vn 0.102381 -0.943523 -0.315090
|
||||
vn 0.904989 -0.330385 0.268031
|
||||
vn 0.024747 -0.330386 0.943521
|
||||
vn -0.889697 -0.330385 0.315095
|
||||
vn -0.574602 -0.330387 -0.748784
|
||||
vn 0.534576 -0.330386 -0.777865
|
||||
vn 0.802609 -0.125627 0.583127
|
||||
vn -0.306569 -0.125628 0.943522
|
||||
vn -0.992077 -0.125629 0.000000
|
||||
vn -0.306569 -0.125628 -0.943522
|
||||
vn 0.802609 -0.125627 -0.583127
|
||||
vn 0.408946 0.661699 0.628425
|
||||
vn -0.471300 0.661699 0.583122
|
||||
vn -0.700224 0.661699 -0.268032
|
||||
vn 0.038530 0.661699 -0.748779
|
||||
vn 0.724042 0.661695 -0.194736
|
||||
vn -0.038530 -0.661699 0.748779
|
||||
vn 0.187594 -0.794658 0.577345
|
||||
vn 0.471300 -0.661699 0.583122
|
||||
vn 0.700224 -0.661699 -0.268032
|
||||
vn 0.607060 -0.794656 0.000000
|
||||
vn 0.331304 -0.943524 0.000000
|
||||
vn -0.724042 -0.661695 0.194736
|
||||
vn -0.491119 -0.794658 0.356821
|
||||
vn -0.408946 -0.661699 0.628425
|
||||
vn -0.408946 -0.661699 -0.628425
|
||||
vn -0.491119 -0.794657 -0.356821
|
||||
vn -0.724042 -0.661695 -0.194736
|
||||
vn 0.471300 -0.661699 -0.583122
|
||||
vn 0.187594 -0.794658 -0.577345
|
||||
vn -0.038530 -0.661699 -0.748779
|
||||
vn 0.992077 0.125629 0.000000
|
||||
vn 0.982246 -0.187599 0.000000
|
||||
vn 0.904989 -0.330385 -0.268031
|
||||
vn 0.306569 0.125628 0.943522
|
||||
vn 0.303531 -0.187597 0.934171
|
||||
vn 0.534576 -0.330386 0.777865
|
||||
vn -0.802609 0.125627 0.583127
|
||||
vn -0.794655 -0.187595 0.577348
|
||||
vn -0.574602 -0.330387 0.748783
|
||||
vn -0.802609 0.125627 -0.583127
|
||||
vn -0.794655 -0.187595 -0.577348
|
||||
vn -0.889697 -0.330385 -0.315095
|
||||
vn 0.306569 0.125628 -0.943522
|
||||
vn 0.303531 -0.187597 -0.934171
|
||||
vn 0.024747 -0.330386 -0.943521
|
||||
vn 0.574602 0.330387 0.748784
|
||||
vn 0.794656 0.187595 0.577348
|
||||
vn 0.889697 0.330385 0.315095
|
||||
vn -0.534576 0.330386 0.777864
|
||||
vn -0.303531 0.187597 0.934171
|
||||
vn -0.024747 0.330386 0.943521
|
||||
vn -0.904989 0.330385 -0.268031
|
||||
vn -0.982246 0.187599 0.000000
|
||||
vn -0.904989 0.330384 0.268031
|
||||
vn -0.024747 0.330386 -0.943521
|
||||
vn -0.303531 0.187597 -0.934171
|
||||
vn -0.534576 0.330386 -0.777865
|
||||
vn 0.889697 0.330385 -0.315095
|
||||
vn 0.794655 0.187595 -0.577348
|
||||
vn 0.574602 0.330387 -0.748784
|
||||
vn 0.268034 0.943523 0.194737
|
||||
vn 0.491120 0.794657 0.356821
|
||||
vn 0.724042 0.661695 0.194736
|
||||
vn -0.102381 0.943523 0.315090
|
||||
vn -0.187594 0.794658 0.577345
|
||||
vn 0.038530 0.661699 0.748779
|
||||
vn -0.331304 0.943524 0.000000
|
||||
vn -0.607060 0.794656 0.000000
|
||||
vn -0.700224 0.661699 0.268032
|
||||
vn -0.102381 0.943524 -0.315090
|
||||
vn -0.187594 0.794658 -0.577345
|
||||
vn -0.471300 0.661699 -0.583122
|
||||
vn 0.268034 0.943523 -0.194736
|
||||
vn 0.491120 0.794657 -0.356821
|
||||
vn 0.408947 0.661699 -0.628425
|
||||
usemtl Material.001
|
||||
s off
|
||||
f 1/1/1 14/2/1 13/3/1
|
||||
f 2/1/2 14/2/2 16/3/2
|
||||
f 1/1/3 13/2/3 18/3/3
|
||||
f 1/1/4 18/2/4 20/3/4
|
||||
f 1/1/5 20/2/5 17/3/5
|
||||
f 2/1/6 16/2/6 23/3/6
|
||||
f 3/1/7 15/2/7 25/3/7
|
||||
f 4/1/8 19/2/8 27/3/8
|
||||
f 5/1/9 21/2/9 29/3/9
|
||||
f 6/1/10 22/2/10 31/3/10
|
||||
f 2/1/11 23/2/11 26/3/11
|
||||
f 3/1/12 25/2/12 28/3/12
|
||||
f 4/1/13 27/2/13 30/3/13
|
||||
f 5/1/14 29/2/14 32/3/14
|
||||
f 6/1/15 31/2/15 24/3/15
|
||||
f 7/1/16 33/2/16 38/3/16
|
||||
f 8/1/17 34/2/17 40/3/17
|
||||
f 9/1/18 35/2/18 41/3/18
|
||||
f 10/1/19 36/2/19 42/3/19
|
||||
f 11/1/20 37/2/20 39/3/20
|
||||
f 13/1/21 15/2/21 3/3/21
|
||||
f 13/1/22 14/2/22 15/3/22
|
||||
f 14/1/23 2/2/23 15/3/23
|
||||
f 16/1/24 17/2/24 6/3/24
|
||||
f 16/1/25 14/2/25 17/3/25
|
||||
f 14/1/26 1/2/26 17/3/26
|
||||
f 18/1/27 19/2/27 4/3/27
|
||||
f 18/1/28 13/2/28 19/3/28
|
||||
f 13/1/29 3/2/29 19/3/29
|
||||
f 20/1/30 21/2/30 5/3/30
|
||||
f 20/1/31 18/2/31 21/3/31
|
||||
f 18/1/32 4/2/32 21/3/32
|
||||
f 17/1/33 22/2/33 6/3/33
|
||||
f 17/1/34 20/2/34 22/3/34
|
||||
f 20/1/35 5/2/35 22/3/35
|
||||
f 23/1/36 24/2/36 11/3/36
|
||||
f 23/1/37 16/2/37 24/3/37
|
||||
f 16/1/38 6/2/38 24/3/38
|
||||
f 25/1/39 26/2/39 7/3/39
|
||||
f 25/1/40 15/2/40 26/3/40
|
||||
f 15/1/41 2/2/41 26/3/41
|
||||
f 27/1/42 28/2/42 8/3/42
|
||||
f 27/1/43 19/2/43 28/3/43
|
||||
f 19/1/44 3/2/44 28/3/44
|
||||
f 29/1/45 30/2/45 9/3/45
|
||||
f 29/1/46 21/2/46 30/3/46
|
||||
f 21/1/47 4/2/47 30/3/47
|
||||
f 31/1/48 32/2/48 10/3/48
|
||||
f 31/1/49 22/2/49 32/3/49
|
||||
f 22/1/50 5/2/50 32/3/50
|
||||
f 26/1/51 33/2/51 7/3/51
|
||||
f 26/1/52 23/2/52 33/3/52
|
||||
f 23/1/53 11/2/53 33/3/53
|
||||
f 28/1/54 34/2/54 8/3/54
|
||||
f 28/1/55 25/2/55 34/3/55
|
||||
f 25/1/56 7/2/56 34/3/56
|
||||
f 30/1/57 35/2/57 9/3/57
|
||||
f 30/1/58 27/2/58 35/3/58
|
||||
f 27/1/59 8/2/59 35/3/59
|
||||
f 32/1/60 36/2/60 10/3/60
|
||||
f 32/1/61 29/2/61 36/3/61
|
||||
f 29/1/62 9/2/62 36/3/62
|
||||
f 24/1/63 37/2/63 11/3/63
|
||||
f 24/1/64 31/2/64 37/3/64
|
||||
f 31/1/65 10/2/65 37/3/65
|
||||
f 38/1/66 39/2/66 12/3/66
|
||||
f 38/1/67 33/2/67 39/3/67
|
||||
f 33/1/68 11/2/68 39/3/68
|
||||
f 40/1/69 38/2/69 12/3/69
|
||||
f 40/1/70 34/2/70 38/3/70
|
||||
f 34/1/71 7/2/71 38/3/71
|
||||
f 41/1/72 40/2/72 12/3/72
|
||||
f 41/1/73 35/2/73 40/3/73
|
||||
f 35/1/74 8/2/74 40/3/74
|
||||
f 42/1/75 41/2/75 12/3/75
|
||||
f 42/1/76 36/2/76 41/3/76
|
||||
f 36/1/77 9/2/77 41/3/77
|
||||
f 39/1/78 42/2/78 12/3/78
|
||||
f 39/1/79 37/2/79 42/3/79
|
||||
f 37/1/80 10/2/80 42/3/80
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 12 KiB |
@@ -0,0 +1,227 @@
|
||||
#include "OBJ.h"
|
||||
|
||||
bool OBJ::LoadFromFile(std::string filename)
|
||||
{
|
||||
m_Path = boost::filesystem::path(filename);
|
||||
|
||||
// http://paulbourke.net/dataformats/obj/
|
||||
std::ifstream file(m_Path.string());
|
||||
if (!file.is_open()) {
|
||||
LOG_ERROR("Failed to open .obj \"%s\"", m_Path.string().c_str());
|
||||
return false;
|
||||
}
|
||||
|
||||
LOG_INFO("Parsing .obj \"%s\"", m_Path.string().c_str());
|
||||
|
||||
std::string line;
|
||||
while (std::getline(file, line)) {
|
||||
if (line.length() == 0)
|
||||
continue;
|
||||
|
||||
std::stringstream ss(line);
|
||||
|
||||
std::string prefix;
|
||||
ss >> prefix;
|
||||
|
||||
// Ignore comments
|
||||
if (prefix == "#")
|
||||
continue;
|
||||
|
||||
// Material files
|
||||
if (prefix == "mtllib") {
|
||||
std::string materialFilename;
|
||||
ss >> materialFilename;
|
||||
m_MaterialPath = m_Path.branch_path() / materialFilename;
|
||||
ParseMaterial();
|
||||
continue;
|
||||
}
|
||||
|
||||
// Material statement
|
||||
if (prefix == "usemtl") {
|
||||
std::string material;
|
||||
ss >> material;
|
||||
m_CurrentMaterial = &Materials[material];
|
||||
continue;
|
||||
}
|
||||
|
||||
// Vertices
|
||||
if (prefix == "v") {
|
||||
float x, y, z;
|
||||
ss >> x >> y >> z;
|
||||
Vertices.push_back(std::make_tuple(x, y, z));
|
||||
continue;
|
||||
}
|
||||
|
||||
// Normals
|
||||
if (prefix == "vn") {
|
||||
float x, y, z;
|
||||
ss >> x >> y >> z;
|
||||
Normals.push_back(std::make_tuple(x, y, z));
|
||||
}
|
||||
|
||||
// Texture coordinates
|
||||
if (prefix == "vt") {
|
||||
float u, v, w;
|
||||
ss >> u >> v >> w;
|
||||
TextureCoords.push_back(std::make_tuple(u, v, w));
|
||||
}
|
||||
|
||||
// Face definitions
|
||||
if (prefix == "f") {
|
||||
Face face;
|
||||
face.Material = m_CurrentMaterial;
|
||||
|
||||
std::string faceDefString;
|
||||
while (ss >> faceDefString) {
|
||||
std::stringstream ss2(faceDefString);
|
||||
FaceDefinition faceDef = { 0, 0, 0 };
|
||||
|
||||
ss2 >> faceDef.VertexIndex;
|
||||
ss2.ignore(); // Ignore first delimiter
|
||||
if (!ss2)
|
||||
continue;
|
||||
|
||||
if (ss2.peek() == '/') {
|
||||
ss2.ignore();
|
||||
ss2 >> faceDef.NormalIndex;
|
||||
} else {
|
||||
ss2 >> faceDef.TextureCoordIndex;
|
||||
ss2.ignore();
|
||||
ss2 >> faceDef.NormalIndex;
|
||||
}
|
||||
face.Definitions.push_back(faceDef);
|
||||
}
|
||||
Faces.push_back(face);
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void OBJ::ParseMaterial()
|
||||
{
|
||||
// http://paulbourke.net/dataformats/mtl/
|
||||
std::ifstream file(m_MaterialPath.string());
|
||||
if (!file.is_open()) {
|
||||
LOG_ERROR("Failed to open .mtl \"%s\"", m_MaterialPath.string().c_str());
|
||||
return;
|
||||
}
|
||||
|
||||
LOG_INFO("Parsing .mtl \"%s\"", m_MaterialPath.string().c_str());
|
||||
|
||||
std::string currentMaterialName;
|
||||
MaterialInfo* currentMaterial = nullptr;
|
||||
|
||||
std::string line;
|
||||
while (std::getline(file, line)) {
|
||||
if (line.length() == 0)
|
||||
continue;
|
||||
|
||||
std::stringstream ss(line);
|
||||
|
||||
std::string prefix;
|
||||
ss >> prefix;
|
||||
|
||||
// Create a new material definition
|
||||
if (prefix == "newmtl") {
|
||||
MaterialInfo mat =
|
||||
{
|
||||
"",
|
||||
std::make_tuple(0.2f, 0.2f, 0.2f),
|
||||
std::make_tuple(0.8f, 0.8f, 0.8f),
|
||||
std::make_tuple(1.0f, 1.0f, 1.0f),
|
||||
std::make_tuple(1.0f, 1.0f, 1.0f),
|
||||
1.0f,
|
||||
1.0f,
|
||||
0.0f,
|
||||
0,
|
||||
};
|
||||
|
||||
ss >> currentMaterialName;
|
||||
LOG_INFO("Parsing material %s", currentMaterialName.c_str());
|
||||
Materials[currentMaterialName] = mat;
|
||||
currentMaterial = &Materials[currentMaterialName];
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!currentMaterial)
|
||||
continue;
|
||||
|
||||
// Ambient color
|
||||
if (prefix == "Ka") {
|
||||
float r, g, b;
|
||||
ss >> r >> g >> b;
|
||||
currentMaterial->AmbientColor = std::make_tuple(r, g, b);
|
||||
continue;
|
||||
}
|
||||
// Diffuse color
|
||||
if (prefix == "Kd") {
|
||||
float r, g, b;
|
||||
ss >> r >> g >> b;
|
||||
currentMaterial->DiffuseColor = std::make_tuple(r, g, b);
|
||||
continue;
|
||||
}
|
||||
// Specular color
|
||||
if (prefix == "Ks") {
|
||||
float r, g, b;
|
||||
ss >> r >> g >> b;
|
||||
currentMaterial->SpecularColor = std::make_tuple(r, g, b);
|
||||
continue;
|
||||
}
|
||||
// Transmission filter
|
||||
if (prefix == "Tf") {
|
||||
std::stringstream ss2;
|
||||
ss2 << ss.str();
|
||||
|
||||
std::string command;
|
||||
ss2 >> command;
|
||||
if (command == "xyz") {
|
||||
// TODO: "The "Ks xyz" statement specifies the specular reflectivity using CIEXYZ values."
|
||||
}
|
||||
else if (command == "spectral") {
|
||||
// TODO: "The "Tf spectral" statement specifies the transmission filter using a spectral curve."
|
||||
} else {
|
||||
float r, g, b;
|
||||
ss >> r;
|
||||
// G and B are optional
|
||||
if (!(ss >> g >> b))
|
||||
{
|
||||
g = r;
|
||||
b = r;
|
||||
}
|
||||
currentMaterial->TransmissionFilter = std::make_tuple(r, g, b);
|
||||
}
|
||||
continue;
|
||||
}
|
||||
// Optical density
|
||||
if (prefix == "Ni") {
|
||||
ss >> currentMaterial->OpticalDensity;
|
||||
continue;
|
||||
}
|
||||
// Alpha
|
||||
if (prefix == "d" || prefix == "Tr") {
|
||||
ss >> currentMaterial->Alpha;
|
||||
continue;
|
||||
}
|
||||
// Shininess
|
||||
if (prefix == "Ns") {
|
||||
ss >> currentMaterial->Shininess;
|
||||
continue;
|
||||
}
|
||||
// Illumination model
|
||||
if (prefix == "illum") {
|
||||
int illum = 0;
|
||||
ss >> illum;
|
||||
currentMaterial->IlluminationModel = illum;
|
||||
continue;
|
||||
}
|
||||
// Texture file
|
||||
// TODO:
|
||||
if (prefix == "map_Ka" || prefix == "map_Kd") {
|
||||
std::string textureFile;
|
||||
ss >> textureFile;
|
||||
currentMaterial->TextureFile = (m_MaterialPath.branch_path() / textureFile).string();
|
||||
continue;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,66 @@
|
||||
#ifndef OBJ_h__
|
||||
#define OBJ_h__
|
||||
|
||||
#include <fstream>
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
#include <sstream>
|
||||
#include <vector>
|
||||
#include <tuple>
|
||||
#include <map>
|
||||
|
||||
#include <boost/filesystem/path.hpp>
|
||||
|
||||
#include "logging.h"
|
||||
|
||||
class OBJ
|
||||
{
|
||||
public:
|
||||
struct MaterialInfo
|
||||
{
|
||||
std::string TextureFile;
|
||||
std::tuple<float, float, float> AmbientColor;
|
||||
std::tuple<float, float, float> DiffuseColor;
|
||||
std::tuple<float, float, float> SpecularColor;
|
||||
std::tuple<float, float, float> TransmissionFilter;
|
||||
float OpticalDensity;
|
||||
float Alpha;
|
||||
float Shininess;
|
||||
int IlluminationModel;
|
||||
};
|
||||
|
||||
struct FaceDefinition
|
||||
{
|
||||
int VertexIndex;
|
||||
int TextureCoordIndex;
|
||||
int NormalIndex;
|
||||
};
|
||||
|
||||
struct Face
|
||||
{
|
||||
Face() : Material(nullptr) { }
|
||||
std::vector<FaceDefinition> Definitions;
|
||||
MaterialInfo* Material;
|
||||
};
|
||||
|
||||
OBJ() : m_CurrentMaterial(nullptr) { }
|
||||
OBJ(std::string filename) : m_CurrentMaterial(nullptr) { LoadFromFile(filename); }
|
||||
|
||||
std::vector<std::tuple<float, float, float>> Vertices;
|
||||
std::vector<std::tuple<float, float, float>> Normals;
|
||||
std::vector<std::tuple<float, float, float>> TextureCoords;
|
||||
std::vector<Face> Faces;
|
||||
std::map<std::string, MaterialInfo> Materials;
|
||||
|
||||
bool LoadFromFile(std::string filename);
|
||||
boost::filesystem::path Path() const { return m_Path; }
|
||||
|
||||
private:
|
||||
boost::filesystem::path m_Path;
|
||||
boost::filesystem::path m_MaterialPath;
|
||||
MaterialInfo* m_CurrentMaterial;
|
||||
|
||||
void ParseMaterial();
|
||||
};
|
||||
|
||||
#endif // OBJ_h__
|
||||
Binary file not shown.
@@ -0,0 +1,5 @@
|
||||
#include <GL/glew.h>
|
||||
#define GLFW_INCLUDE_GLU
|
||||
#include <GLFW/glfw3.h>
|
||||
#include <glext.h>
|
||||
#define GLM_FORCE_RADIANS
|
||||
+410
-13
@@ -2,6 +2,22 @@
|
||||
|
||||
Renderer::Renderer()
|
||||
{
|
||||
m_VSync = false;
|
||||
#ifdef DEBUG
|
||||
m_DrawNormals = false;
|
||||
m_DrawWireframe = false;
|
||||
m_DrawBounds = true;
|
||||
#else
|
||||
m_DrawNormals = false;
|
||||
m_DrawWireframe = false;
|
||||
m_DrawBounds = false;
|
||||
#endif
|
||||
|
||||
m_ShadowMapRes = 2048*2;
|
||||
m_SunPosition = glm::vec3(0, 0.3f, 10);
|
||||
m_SunTarget = glm::vec3(0, 0, 0);
|
||||
m_SunProjection = glm::ortho<float>(-200, 200, -10, 100, -800, 800);
|
||||
Lights = 0;
|
||||
}
|
||||
|
||||
void Renderer::Initialize()
|
||||
@@ -13,7 +29,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);
|
||||
@@ -37,19 +55,267 @@ void Renderer::Initialize()
|
||||
LOG_ERROR("GLEW: Initialization failed");
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
// Create Camera
|
||||
m_Camera = std::make_shared<Camera>(45.f, (float)WIDTH / HEIGHT, 0.01f, 1000.f);
|
||||
m_Camera->Position(glm::vec3(0.0f, 0.0f, 2.f));
|
||||
|
||||
glfwSwapInterval(m_VSync);
|
||||
glEnable(GL_CULL_FACE);
|
||||
glCullFace(GL_BACK);
|
||||
glEnable(GL_DEPTH_TEST);
|
||||
|
||||
LoadContent();
|
||||
}
|
||||
|
||||
void Renderer::Draw(double _dt)
|
||||
void Renderer::LoadContent()
|
||||
{
|
||||
auto standardVS = std::shared_ptr<Shader>(new VertexShader("Shaders/Vertex.glsl"));
|
||||
auto standardFS = std::shared_ptr<Shader>(new FragmentShader("Shaders/Fragment.glsl"));
|
||||
|
||||
m_ShaderProgram.AddShader(standardVS);
|
||||
m_ShaderProgram.AddShader(standardFS);
|
||||
m_ShaderProgram.Compile();
|
||||
m_ShaderProgram.Link();
|
||||
|
||||
m_ShaderProgramNormals.AddShader(std::shared_ptr<Shader>(new GeometryShader("Shaders/Normals.geo.glsl")));
|
||||
m_ShaderProgramNormals.AddShader(standardVS);
|
||||
m_ShaderProgramNormals.AddShader(std::shared_ptr<Shader>(new FragmentShader("Shaders/Normals.frag.glsl")));
|
||||
m_ShaderProgramNormals.Compile();
|
||||
m_ShaderProgramNormals.Link();
|
||||
|
||||
m_ShaderProgramShadows.AddShader(std::shared_ptr<Shader>(new VertexShader("Shaders/ShadowMap.vert.glsl")));
|
||||
m_ShaderProgramShadows.AddShader(std::shared_ptr<Shader>(new FragmentShader("Shaders/ShadowMap.frag.glsl")));
|
||||
m_ShaderProgramShadows.Compile();
|
||||
m_ShaderProgramShadows.Link();
|
||||
|
||||
m_ShaderProgramShadowsDrawDepth.AddShader(std::shared_ptr<Shader>(new VertexShader("Shaders/VisualizeDepth.vert.glsl")));
|
||||
m_ShaderProgramShadowsDrawDepth.AddShader(std::shared_ptr<Shader>(new FragmentShader("Shaders/VisualizeDepth.frag.glsl")));
|
||||
m_ShaderProgramShadowsDrawDepth.Compile();
|
||||
m_ShaderProgramShadowsDrawDepth.Link();
|
||||
|
||||
m_ShaderProgramDebugAABB.AddShader(standardVS);
|
||||
m_ShaderProgramDebugAABB.AddShader(std::shared_ptr<Shader>(new FragmentShader("Shaders/AABB.frag.glsl")));
|
||||
m_ShaderProgramDebugAABB.Compile();
|
||||
m_ShaderProgramDebugAABB.Link();
|
||||
|
||||
m_DebugAABB = CreateAABB();
|
||||
m_ScreenQuad = CreateQuad();
|
||||
CreateShadowMap(m_ShadowMapRes);
|
||||
}
|
||||
|
||||
void Renderer::CreateShadowMap(int resolution)
|
||||
{
|
||||
glGenFramebuffers(1, &m_ShadowFrameBuffer);
|
||||
glBindFramebuffer(GL_FRAMEBUFFER, m_ShadowFrameBuffer);
|
||||
|
||||
// Depth texture
|
||||
glGenTextures(1, &m_ShadowDepthTexture);
|
||||
glBindTexture(GL_TEXTURE_2D, m_ShadowDepthTexture);
|
||||
glTexImage2D(GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT16, resolution, resolution, 0, GL_DEPTH_COMPONENT, GL_FLOAT, nullptr);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_BORDER);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_BORDER);
|
||||
|
||||
//glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_COMPARE_MODE, GL_NONE );
|
||||
//glTexParameteri( GL_TEXTURE_2D, GL_DEPTH_TEXTURE_MODE, GL_INTENSITY );
|
||||
|
||||
glFramebufferTexture(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, m_ShadowDepthTexture, 0);
|
||||
glDrawBuffer(GL_NONE);
|
||||
|
||||
if (glCheckFramebufferStatus(GL_FRAMEBUFFER) != GL_FRAMEBUFFER_COMPLETE) {
|
||||
LOG_ERROR("Framebuffer incomplete!");
|
||||
return;
|
||||
}
|
||||
}
|
||||
void Renderer::Draw(double dt)
|
||||
{
|
||||
glDisable(GL_BLEND);
|
||||
|
||||
DrawShadowMap();
|
||||
DrawScene();
|
||||
|
||||
#ifdef DEBUG
|
||||
// Draw bounding boxes
|
||||
if (m_DrawBounds) {
|
||||
glEnable(GL_BLEND);
|
||||
glBlendFunc(GL_ONE_MINUS_DST_COLOR, GL_ZERO);
|
||||
m_ShaderProgramDebugAABB.Bind();
|
||||
for (auto tuple : AABBsToRender) {
|
||||
glm::mat4 modelMatrix;
|
||||
bool colliding;
|
||||
std::tie(modelMatrix, colliding) = tuple;
|
||||
// Model matrix
|
||||
glm::mat4 cameraMatrix = m_Camera->ProjectionMatrix() * m_Camera->ViewMatrix();
|
||||
glm::mat4 MVP = cameraMatrix * modelMatrix;
|
||||
glUniformMatrix4fv(glGetUniformLocation(m_ShaderProgramDebugAABB.GetHandle(), "MVP"), 1, GL_FALSE, glm::value_ptr(MVP));
|
||||
// Color
|
||||
glm::vec4 color(1.f, 1.f, 1.f, 0.f);
|
||||
if (colliding)
|
||||
color = glm::vec4(1.f, 0.f, 0.f, 0.f);
|
||||
glUniform4fv(glGetUniformLocation(m_ShaderProgramDebugAABB.GetHandle(), "Color"), 1, glm::value_ptr(color));
|
||||
glBindVertexArray(m_DebugAABB);
|
||||
glDrawArrays(GL_LINES, 0, 24);
|
||||
}
|
||||
}
|
||||
|
||||
//DrawDebugShadowMap();
|
||||
#endif
|
||||
|
||||
ClearStuff();
|
||||
glfwSwapBuffers(m_Window);
|
||||
}
|
||||
|
||||
void Renderer::DrawScene()
|
||||
{
|
||||
glBindFramebuffer(GL_FRAMEBUFFER, 0);
|
||||
glViewport(0, 0, WIDTH, HEIGHT);
|
||||
|
||||
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
||||
glClearColor(1.0f, 1.0f, 0.0f, 1.0f);
|
||||
|
||||
//m_ShaderProgram->Bind();
|
||||
glEnable(GL_DEPTH_TEST);
|
||||
glEnable(GL_CULL_FACE);
|
||||
glCullFace(GL_BACK);
|
||||
#ifdef DEBUG
|
||||
glDisable(GL_CULL_FACE);
|
||||
glPolygonMode(GL_BACK, GL_LINE);
|
||||
#endif
|
||||
|
||||
glfwSwapBuffers(m_Window);
|
||||
// Draw models
|
||||
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 biasMatrix(
|
||||
0.5, 0.0, 0.0, 0.0,
|
||||
0.0, 0.5, 0.0, 0.0,
|
||||
0.0, 0.0, 0.5, 0.0,
|
||||
0.5, 0.5, 0.5, 1.0
|
||||
);
|
||||
|
||||
m_ShaderProgram.Bind();
|
||||
glUniform1i(glGetUniformLocation(m_ShaderProgram.GetHandle(), "numberOfLights"), Lights);
|
||||
glUniform3fv(glGetUniformLocation(m_ShaderProgram.GetHandle(), "position"), Lights, Light_position.data());
|
||||
glUniform3fv(glGetUniformLocation(m_ShaderProgram.GetHandle(), "specular"), Lights, Light_specular.data());
|
||||
glUniform3fv(glGetUniformLocation(m_ShaderProgram.GetHandle(), "diffuse"), Lights, Light_diffuse.data());
|
||||
glUniform1fv(glGetUniformLocation(m_ShaderProgram.GetHandle(), "constantAttenuation"), Lights, Light_constantAttenuation.data());
|
||||
glUniform1fv(glGetUniformLocation(m_ShaderProgram.GetHandle(), "linearAttenuation"), Lights, Light_linearAttenuation.data());
|
||||
glUniform1fv(glGetUniformLocation(m_ShaderProgram.GetHandle(), "quadraticAttenuation"), Lights, Light_quadraticAttenuation.data());
|
||||
glUniform1fv(glGetUniformLocation(m_ShaderProgram.GetHandle(), "spotExponent"), Lights, Light_spotExponent.data());
|
||||
if (m_DrawWireframe) {
|
||||
glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
|
||||
}
|
||||
glActiveTexture(GL_TEXTURE1);
|
||||
glBindTexture(GL_TEXTURE_2D, m_ShadowDepthTexture);
|
||||
//DrawModels(m_ShaderProgram);
|
||||
glm::mat4 cameraMatrix = m_Camera->ProjectionMatrix() * m_Camera->ViewMatrix();
|
||||
glm::mat4 depthCameraMatrix = biasMatrix * depthCamera;
|
||||
glm::mat4 MVP;
|
||||
glm::mat4 depthMVP;
|
||||
for (auto tuple : ModelsToRender)
|
||||
{
|
||||
Model* model;
|
||||
glm::mat4 modelMatrix;
|
||||
std::tie(model, modelMatrix) = tuple;
|
||||
MVP = cameraMatrix * modelMatrix;
|
||||
depthMVP = depthCameraMatrix * modelMatrix;
|
||||
glUniformMatrix4fv(glGetUniformLocation(m_ShaderProgram.GetHandle(), "MVP"), 1, GL_FALSE, glm::value_ptr(MVP));
|
||||
glUniformMatrix4fv(glGetUniformLocation(m_ShaderProgram.GetHandle(), "DepthMVP"), 1, GL_FALSE, glm::value_ptr(depthMVP));
|
||||
glUniformMatrix4fv(glGetUniformLocation(m_ShaderProgram.GetHandle(), "model"), 1, GL_FALSE, glm::value_ptr(modelMatrix));
|
||||
glUniformMatrix4fv(glGetUniformLocation(m_ShaderProgram.GetHandle(), "view"), 1, GL_FALSE, glm::value_ptr(m_Camera->ViewMatrix()));
|
||||
glBindVertexArray(model->VAO);
|
||||
for (auto texGroup : model->TextureGroups) {
|
||||
glActiveTexture(GL_TEXTURE0);
|
||||
glBindTexture(GL_TEXTURE_2D, texGroup.Texture->texture);
|
||||
glDrawArrays(GL_TRIANGLES, texGroup.StartIndex, texGroup.EndIndex - texGroup.StartIndex + 1);
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef DEBUG
|
||||
// Debug draw model normals
|
||||
if (m_DrawNormals) {
|
||||
m_ShaderProgramNormals.Bind();
|
||||
glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
|
||||
DrawModels(m_ShaderProgramNormals);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
void Renderer::DrawShadowMap()
|
||||
{
|
||||
glEnable(GL_DEPTH_TEST);
|
||||
glEnable(GL_CULL_FACE);
|
||||
glCullFace(GL_FRONT);
|
||||
|
||||
glBindFramebuffer(GL_FRAMEBUFFER, m_ShadowFrameBuffer);
|
||||
glViewport(0, 0, m_ShadowMapRes, m_ShadowMapRes);
|
||||
|
||||
glClear(GL_DEPTH_BUFFER_BIT);
|
||||
//glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
|
||||
|
||||
glm::mat4 depthViewMatrix = glm::lookAt(m_SunPosition, m_SunTarget, glm::vec3(0, 1, 0)) * glm::translate(-m_Camera->Position() * glm::vec3(1, 0, 0));
|
||||
// glm::mat4 depthViewMatrix = glm::lookAt(m_SunPosition, m_SunTarget, glm::vec3(0, 1, 0));
|
||||
glm::mat4 depthCamera = m_SunProjection * depthViewMatrix;
|
||||
|
||||
//glm::mat4 cameraMatrix = depthProjectionMatrix * m_Camera->ViewMatrix();
|
||||
|
||||
glm::mat4 MVP;
|
||||
|
||||
m_ShaderProgramShadows.Bind();
|
||||
glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
|
||||
for (auto tuple : ModelsToRender)
|
||||
{
|
||||
Model* model;
|
||||
glm::mat4 modelMatrix;
|
||||
std::tie(model, modelMatrix) = tuple;
|
||||
|
||||
MVP = depthCamera * modelMatrix;
|
||||
glUniformMatrix4fv(glGetUniformLocation(m_ShaderProgramShadows.GetHandle(), "MVP"), 1, GL_FALSE, glm::value_ptr(MVP));
|
||||
|
||||
glBindVertexArray(model->VAO);
|
||||
for (auto texGroup : model->TextureGroups) {
|
||||
glDrawArrays(GL_TRIANGLES, texGroup.StartIndex, texGroup.EndIndex - texGroup.StartIndex + 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void Renderer::DrawDebugShadowMap()
|
||||
{
|
||||
glBindFramebuffer(GL_FRAMEBUFFER, 0);
|
||||
glViewport(0, 0, 200*(16.f/9.f), 200);
|
||||
|
||||
glClear(GL_DEPTH_BUFFER_BIT);
|
||||
//glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
|
||||
|
||||
m_ShaderProgramShadowsDrawDepth.Bind();
|
||||
glActiveTexture(GL_TEXTURE0);
|
||||
glBindTexture(GL_TEXTURE_2D, m_ShadowDepthTexture);
|
||||
glBindVertexArray(m_ScreenQuad);
|
||||
glDrawArrays(GL_TRIANGLES, 0, 6);
|
||||
}
|
||||
|
||||
void Renderer::DrawModels(ShaderProgram &shader)
|
||||
{
|
||||
glm::mat4 cameraMatrix = m_Camera->ProjectionMatrix() * m_Camera->ViewMatrix();
|
||||
|
||||
glm::mat4 MVP;
|
||||
for (auto tuple : ModelsToRender)
|
||||
{
|
||||
Model* model;
|
||||
glm::mat4 modelMatrix;
|
||||
std::tie(model, modelMatrix) = tuple;
|
||||
|
||||
MVP = cameraMatrix * modelMatrix;
|
||||
glUniformMatrix4fv(glGetUniformLocation(shader.GetHandle(), "MVP"), 1, GL_FALSE, glm::value_ptr(MVP));
|
||||
glUniformMatrix4fv(glGetUniformLocation(shader.GetHandle(), "model"), 1, GL_FALSE, glm::value_ptr(modelMatrix));
|
||||
glUniformMatrix4fv(glGetUniformLocation(shader.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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void Renderer::DrawText()
|
||||
@@ -62,17 +328,148 @@ void Renderer::AddTextToDraw()
|
||||
//Add to draw shit vector
|
||||
}
|
||||
|
||||
void Renderer::AddModelToDraw(Model* _model)
|
||||
void Renderer::AddModelToDraw(std::shared_ptr<Model> model, glm::vec3 position, glm::quat orientation, glm::vec3 scale)
|
||||
{
|
||||
ModelsToRender.push_back(_model);
|
||||
glm::mat4 modelMatrix = glm::translate(glm::mat4(), position) * glm::toMat4(orientation) * glm::scale(scale);
|
||||
// You can now use ModelMatrix to build the MVP matrix
|
||||
ModelsToRender.push_back(std::make_tuple(model.get(), modelMatrix));
|
||||
}
|
||||
|
||||
//Fixa med shaders, lägga in alla verts osv.
|
||||
|
||||
void Renderer::LoadContent()
|
||||
void Renderer::AddPointLightToDraw(
|
||||
glm::vec3 _position,
|
||||
glm::vec3 _specular,
|
||||
glm::vec3 _diffuse,
|
||||
float _constantAttenuation,
|
||||
float _linearAttenuation,
|
||||
float _quadraticAttenuation,
|
||||
float _spotExponent
|
||||
)
|
||||
{
|
||||
m_ShaderProgram.AddShader(std::unique_ptr<Shader>(new VertexShader("Shaders/Vertex.glsl")));
|
||||
m_ShaderProgram.AddShader(std::unique_ptr<Shader>(new FragmentShader("Shaders/Fragment.glsl")));
|
||||
m_ShaderProgram.Compile();
|
||||
m_ShaderProgram.Link();
|
||||
Light_position.push_back(_position.x);
|
||||
Light_position.push_back(_position.y);
|
||||
Light_position.push_back(_position.z);
|
||||
Light_specular.push_back(_specular.x);
|
||||
Light_specular.push_back(_specular.y);
|
||||
Light_specular.push_back(_specular.z);
|
||||
Light_diffuse.push_back(_diffuse.x);
|
||||
Light_diffuse.push_back(_diffuse.y);
|
||||
Light_diffuse.push_back(_diffuse.z);
|
||||
Light_constantAttenuation.push_back(_constantAttenuation);
|
||||
Light_linearAttenuation.push_back(_linearAttenuation);
|
||||
Light_quadraticAttenuation.push_back(_quadraticAttenuation);
|
||||
Light_spotExponent.push_back(_spotExponent);
|
||||
Lights = Light_constantAttenuation.size();
|
||||
}
|
||||
|
||||
void Renderer::AddAABBToDraw(glm::vec3 origin, glm::vec3 volumeVector, bool colliding)
|
||||
{
|
||||
glm::mat4 model;
|
||||
model *= glm::translate(origin);
|
||||
model *= glm::scale(volumeVector);
|
||||
AABBsToRender.push_back(std::make_tuple(model, colliding));
|
||||
}
|
||||
|
||||
GLuint Renderer::CreateQuad()
|
||||
{
|
||||
float quadVertices[] = {
|
||||
-1.0f, -1.0f, 0.0f,
|
||||
1.0f, 1.0f, 0.0f,
|
||||
-1.0f, 1.0f, 0.0f,
|
||||
|
||||
-1.0f, -1.0f, 0.0f,
|
||||
1.0f, -1.0f, 0.0f,
|
||||
1.0f, 1.0f, 0.0f,
|
||||
};
|
||||
float quadTexCoords[] = {
|
||||
0.0f, 0.0f,
|
||||
1.0f, 1.0f,
|
||||
0.0f, 1.0f,
|
||||
|
||||
0.0f, 0.0f,
|
||||
1.0f, 0.0f,
|
||||
1.0f, 1.0f,
|
||||
};
|
||||
GLuint vbo[2], vao;
|
||||
glGenBuffers(2, vbo);
|
||||
glBindBuffer(GL_ARRAY_BUFFER, vbo[0]);
|
||||
glBufferData(GL_ARRAY_BUFFER, 3 * 6 * sizeof(float), quadVertices, GL_STATIC_DRAW);
|
||||
glBindBuffer(GL_ARRAY_BUFFER, vbo[1]);
|
||||
glBufferData(GL_ARRAY_BUFFER, 2 * 6 * sizeof(float), quadTexCoords, GL_STATIC_DRAW);
|
||||
glGenVertexArrays(1, &vao);
|
||||
glBindVertexArray(vao);
|
||||
glBindBuffer(GL_ARRAY_BUFFER, vbo[0]);
|
||||
glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 0, 0);
|
||||
glBindBuffer(GL_ARRAY_BUFFER, vbo[1]);
|
||||
glVertexAttribPointer(2, 2, GL_FLOAT, GL_FALSE, 0, 0);
|
||||
glEnableVertexAttribArray(0);
|
||||
glEnableVertexAttribArray(2);
|
||||
|
||||
glBindVertexArray(0);
|
||||
glBindBuffer(GL_ARRAY_BUFFER, 0);
|
||||
|
||||
return vao;
|
||||
}
|
||||
|
||||
GLuint Renderer::CreateAABB()
|
||||
{
|
||||
float vertices[] = {
|
||||
// Bottom
|
||||
-1.0f, -1.0f, 1.0f, // 0
|
||||
1.0f, -1.0f, 1.0f, // 1
|
||||
1.0f, -1.0f, 1.0f, // 1
|
||||
1.0f, -1.0f, -1.0f, // 2
|
||||
1.0f, -1.0f, -1.0f, // 2
|
||||
-1.0f, -1.0f, -1.0f, // 3
|
||||
-1.0f, -1.0f, -1.0f, // 3
|
||||
-1.0f, -1.0f, 1.0f, // 0
|
||||
|
||||
// Top
|
||||
-1.0f, 1.0f, 1.0f, // 4
|
||||
1.0f, 1.0f, 1.0f, // 5
|
||||
1.0f, 1.0f, 1.0f, // 5
|
||||
1.0f, 1.0f, -1.0f, // 6
|
||||
1.0f, 1.0f, -1.0f, // 6
|
||||
-1.0f, 1.0f, -1.0f, // 7
|
||||
-1.0f, 1.0f, -1.0f, // 7
|
||||
-1.0f, 1.0f, 1.0f, // 4
|
||||
|
||||
// Connectors
|
||||
-1.0f, -1.0f, 1.0f, // 0
|
||||
-1.0f, 1.0f, 1.0f, // 4
|
||||
1.0f, -1.0f, 1.0f, // 1
|
||||
1.0f, 1.0f, 1.0f, // 5
|
||||
1.0f, -1.0f, -1.0f, // 2
|
||||
1.0f, 1.0f, -1.0f, // 6
|
||||
-1.0f, -1.0f, -1.0f, // 3
|
||||
-1.0f, 1.0f, -1.0f, // 7
|
||||
};
|
||||
|
||||
GLuint vbo, vao;
|
||||
glGenBuffers(1, &vbo);
|
||||
glBindBuffer(GL_ARRAY_BUFFER, vbo);
|
||||
glBufferData(GL_ARRAY_BUFFER, sizeof(vertices), vertices, GL_STATIC_DRAW);
|
||||
|
||||
glGenVertexArrays(1, &vao);
|
||||
glBindVertexArray(vao);
|
||||
glBindBuffer(GL_ARRAY_BUFFER, vbo);
|
||||
glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 0, 0);
|
||||
glEnableVertexAttribArray(0);
|
||||
|
||||
glBindVertexArray(0);
|
||||
glBindBuffer(GL_ARRAY_BUFFER, 0);
|
||||
|
||||
return vao;
|
||||
}
|
||||
|
||||
void Renderer::ClearStuff()
|
||||
{
|
||||
AABBsToRender.clear();
|
||||
ModelsToRender.clear();
|
||||
Light_position.clear();
|
||||
Light_specular.clear();
|
||||
Light_diffuse.clear();
|
||||
Light_constantAttenuation.clear();
|
||||
Light_linearAttenuation.clear();
|
||||
Light_quadraticAttenuation.clear();
|
||||
Light_spotExponent.clear();
|
||||
}
|
||||
@@ -7,27 +7,39 @@
|
||||
#include <sstream>
|
||||
#include <vector>
|
||||
|
||||
#define _CRT_SECURE_NO_WARNINGS
|
||||
#include <GL/glew.h>
|
||||
#define GLFW_INCLUDE_GLU
|
||||
#include <GLFW/glfw3.h>
|
||||
#include <glext.h>
|
||||
#define GLM_FORCE_RADIANS
|
||||
#include "OpenGL.h"
|
||||
#include <glm/glm.hpp>
|
||||
#include <glm/gtc/constants.hpp>
|
||||
#include <glm/gtc/matrix_transform.hpp>
|
||||
#include <glm/gtc/type_ptr.hpp>
|
||||
#include <glm/gtc/quaternion.hpp>
|
||||
#include <glm/gtx/quaternion.hpp>
|
||||
|
||||
#include "glerror.h"
|
||||
#include "Camera.h"
|
||||
#include "ShaderProgram.h"
|
||||
#include "Model.h"
|
||||
#include "Components/PointLight.h"
|
||||
|
||||
class Renderer
|
||||
{
|
||||
public:
|
||||
ShaderProgram m_ShaderProgram;
|
||||
|
||||
glm::mat4 viewMatrix;
|
||||
glm::mat4 projectionMatrix;
|
||||
|
||||
std::vector<Model*> ModelsToRender;
|
||||
int HEIGHT, WIDTH;
|
||||
|
||||
std::list<std::tuple<Model*, glm::mat4>> ModelsToRender;
|
||||
int Lights;
|
||||
std::vector<float> Light_position;
|
||||
std::vector<float> Light_specular;
|
||||
std::vector<float> Light_diffuse;
|
||||
std::vector<float> Light_constantAttenuation;
|
||||
std::vector<float> Light_linearAttenuation;
|
||||
std::vector<float> Light_quadraticAttenuation;
|
||||
std::vector<float> Light_spotExponent;
|
||||
std::list<std::tuple<glm::mat4, bool>> AABBsToRender;
|
||||
|
||||
Renderer();
|
||||
|
||||
@@ -35,17 +47,67 @@ public:
|
||||
void Draw(double dt);
|
||||
void DrawText();
|
||||
|
||||
void AddModelToDraw(Model*);
|
||||
void AddModelToDraw(std::shared_ptr<Model> model, glm::vec3 position, glm::quat orientation, glm::vec3 scale);
|
||||
void AddTextToDraw();
|
||||
void AddPointLightToDraw(
|
||||
glm::vec3 _position,
|
||||
glm::vec3 _specular,
|
||||
glm::vec3 _diffuse,
|
||||
float _constantAttenuation,
|
||||
float _linearAttenuation,
|
||||
float _quadraticAttenuation,
|
||||
float _spotExponent
|
||||
);
|
||||
void AddAABBToDraw(glm::vec3 origin, glm::vec3 volumeVector, bool colliding);
|
||||
|
||||
void LoadContent();
|
||||
|
||||
GLFWwindow* GetWindow() const { return m_Window; }
|
||||
std::shared_ptr<Camera> GetCamera() const { return m_Camera; }
|
||||
|
||||
bool DrawNormals() const { return m_DrawNormals; }
|
||||
void DrawNormals(bool val) { m_DrawNormals = val; }
|
||||
bool DrawWireframe() const { return m_DrawWireframe; }
|
||||
void DrawWireframe(bool val) { m_DrawWireframe = val; }
|
||||
bool DrawBounds() const { return m_DrawBounds; }
|
||||
void DrawBounds(bool val) { m_DrawBounds = val; }
|
||||
|
||||
private:
|
||||
GLFWwindow* m_Window;
|
||||
GLint m_glVersion[2];
|
||||
GLchar* m_glVendor;
|
||||
bool m_VSync;
|
||||
bool m_DrawNormals;
|
||||
bool m_DrawWireframe;
|
||||
bool m_DrawBounds;
|
||||
|
||||
int m_ShadowMapRes;
|
||||
glm::vec3 m_SunPosition;
|
||||
glm::vec3 m_SunTarget;
|
||||
glm::mat4 m_SunProjection;
|
||||
|
||||
GLuint m_DebugAABB;
|
||||
GLuint m_ScreenQuad;
|
||||
GLuint m_ShadowFrameBuffer;
|
||||
GLuint m_ShadowDepthTexture;
|
||||
|
||||
std::shared_ptr<Camera> m_Camera;
|
||||
|
||||
ShaderProgram m_ShaderProgram;
|
||||
ShaderProgram m_ShaderProgramNormals;
|
||||
ShaderProgram m_ShaderProgramShadows;
|
||||
ShaderProgram m_ShaderProgramShadowsDrawDepth;
|
||||
ShaderProgram m_ShaderProgramDebugAABB;
|
||||
|
||||
void ClearStuff();
|
||||
void DrawScene();
|
||||
void DrawModels(ShaderProgram &shader);
|
||||
void DrawShadowMap();
|
||||
void CreateShadowMap(int resolution);
|
||||
GLuint CreateQuad();
|
||||
void DrawDebugShadowMap();
|
||||
GLuint CreateAABB();
|
||||
|
||||
};
|
||||
|
||||
#endif // Renderer_h__
|
||||
@@ -84,20 +84,16 @@ bool Shader::IsCompiled() const
|
||||
return m_ShaderHandle != 0;
|
||||
}
|
||||
|
||||
ShaderProgram::ShaderProgram()
|
||||
{
|
||||
Initialize();
|
||||
}
|
||||
|
||||
ShaderProgram::~ShaderProgram()
|
||||
{
|
||||
Unbind();
|
||||
glDeleteProgram(m_ShaderProgramHandle);
|
||||
if (m_ShaderProgramHandle != 0) {
|
||||
glDeleteProgram(m_ShaderProgramHandle);
|
||||
}
|
||||
}
|
||||
|
||||
void ShaderProgram::AddShader(std::unique_ptr<Shader> shader)
|
||||
void ShaderProgram::AddShader(std::shared_ptr<Shader> shader)
|
||||
{
|
||||
m_Shaders.push_back(std::move(shader));
|
||||
m_Shaders.push_back(shader);
|
||||
}
|
||||
|
||||
void ShaderProgram::Compile()
|
||||
@@ -111,6 +107,11 @@ void ShaderProgram::Compile()
|
||||
|
||||
GLuint ShaderProgram::Link()
|
||||
{
|
||||
if (m_Shaders.size() == 0) {
|
||||
LOG_ERROR("Failed to link shader program: No shaders bound");
|
||||
return 0;
|
||||
}
|
||||
|
||||
LOG_INFO("Linking shader program");
|
||||
m_ShaderProgramHandle = glCreateProgram();
|
||||
for (auto &shader : m_Shaders) {
|
||||
@@ -119,15 +120,16 @@ GLuint ShaderProgram::Link()
|
||||
glLinkProgram(m_ShaderProgramHandle);
|
||||
if (GLERROR("glLinkProgram"))
|
||||
return 0;
|
||||
|
||||
for (auto &shader : m_Shaders) {
|
||||
shader.release();
|
||||
}
|
||||
m_Shaders.clear();
|
||||
|
||||
return m_ShaderProgramHandle;
|
||||
}
|
||||
|
||||
GLuint ShaderProgram::GetHandle()
|
||||
{
|
||||
return m_ShaderProgramHandle;
|
||||
}
|
||||
|
||||
void ShaderProgram::Bind()
|
||||
{
|
||||
if (m_ShaderProgramHandle == 0)
|
||||
@@ -139,9 +141,4 @@ void ShaderProgram::Bind()
|
||||
void ShaderProgram::Unbind()
|
||||
{
|
||||
glActiveShaderProgram(0, 0);
|
||||
}
|
||||
|
||||
void ShaderProgram::Initialize()
|
||||
{
|
||||
m_ShaderProgramHandle = 0;
|
||||
}
|
||||
}
|
||||
@@ -6,11 +6,7 @@
|
||||
#include <fstream>
|
||||
#include <vector>
|
||||
|
||||
#define _CRT_SECURE_NO_WARNINGS
|
||||
#include <GL/glew.h>
|
||||
#define GLFW_INCLUDE_GLU
|
||||
#include <GLFW/glfw3.h>
|
||||
#include <glext.h>
|
||||
#include "OpenGL.h"
|
||||
|
||||
#include "glerror.h"
|
||||
|
||||
@@ -68,23 +64,20 @@ public:
|
||||
class ShaderProgram
|
||||
{
|
||||
public:
|
||||
ShaderProgram();
|
||||
ShaderProgram()
|
||||
: m_ShaderProgramHandle(0) { }
|
||||
~ShaderProgram();
|
||||
|
||||
void AddShader(std::unique_ptr<Shader> shader);
|
||||
|
||||
void AddShader(std::shared_ptr<Shader> shader);
|
||||
void Compile();
|
||||
GLuint Link();
|
||||
|
||||
GLuint GetHandle();
|
||||
void Bind();
|
||||
|
||||
void Unbind();
|
||||
|
||||
private:
|
||||
GLuint m_ShaderProgramHandle;
|
||||
std::vector<std::unique_ptr<Shader>> m_Shaders;
|
||||
|
||||
void Initialize();
|
||||
std::vector<std::shared_ptr<Shader>> m_Shaders;
|
||||
};
|
||||
|
||||
#endif // ShaderProgram_h__
|
||||
@@ -0,0 +1,17 @@
|
||||
#version 430
|
||||
|
||||
uniform vec4 Color;
|
||||
|
||||
in VertexData {
|
||||
vec3 Position;
|
||||
vec3 Normal;
|
||||
vec2 TextureCoord;
|
||||
vec3 ShadowCoord;
|
||||
} Input;
|
||||
|
||||
out vec4 FragmentColor;
|
||||
|
||||
void main() {
|
||||
//FragmentColor = vec4(1.0 - gl_Color.r, 1.0 - gl_Color.g, 1.0 - gl_Color.b, 0.0);
|
||||
FragmentColor = Color;
|
||||
}
|
||||
@@ -1,18 +1,109 @@
|
||||
#version 440
|
||||
#version 430
|
||||
|
||||
uniform mat4 MVP;
|
||||
uniform sampler2D texture0;
|
||||
uniform mat4 model;
|
||||
uniform mat4 view;
|
||||
|
||||
layout(binding=0) uniform sampler2D texture0;
|
||||
layout(binding=1) uniform sampler2D shadowMap;
|
||||
|
||||
const int maxNumberOfLights = 82;
|
||||
uniform int numberOfLights;
|
||||
uniform vec3 position[maxNumberOfLights];
|
||||
uniform vec3 specular[maxNumberOfLights];
|
||||
uniform vec3 diffuse[maxNumberOfLights];
|
||||
uniform float constantAttenuation[maxNumberOfLights];
|
||||
uniform float linearAttenuation[maxNumberOfLights];
|
||||
uniform float quadraticAttenuation[maxNumberOfLights];
|
||||
uniform float spotExponent[maxNumberOfLights];
|
||||
|
||||
in VertexData {
|
||||
vec3 Position;
|
||||
vec3 Normal;
|
||||
vec2 TextureCoord;
|
||||
vec3 ShadowCoord;
|
||||
} Input;
|
||||
|
||||
out vec4 FragmentColor;
|
||||
vec3 scene_ambient = vec3(0.3);
|
||||
|
||||
out vec4 fragmentColor;
|
||||
|
||||
void main()
|
||||
{
|
||||
void main() {
|
||||
|
||||
// Texture
|
||||
vec4 texel = texture2D(texture0, Input.TextureCoord);
|
||||
FragmentColor = texel;
|
||||
//vec4 texel = (blend.x * texel0) + (blend.y * texel1) + (blend.z * texel2);
|
||||
|
||||
//
|
||||
// Phong shading
|
||||
//
|
||||
|
||||
// Ambient light
|
||||
vec3 La = scene_ambient; // Ambient light
|
||||
vec3 Ks = vec3(0.3, 0.3, 0.3); // Specular reflectance
|
||||
vec3 Kd = vec3(1.0, 1.0, 1.0); // Diffuse reflectance
|
||||
vec3 Ka = vec3(1.0, 1.0, 1.0); // Ambient reflectance
|
||||
vec3 Is;
|
||||
vec3 Id;
|
||||
|
||||
// Shadows
|
||||
//float cosTheta = clamp(dot(Input.Normal, vec3(0, 1, 0)), 0.0, 1.0);
|
||||
//float bias = 0.001 * tan(acos(cosTheta)); // cosTheta is dot( n,l ), clamped between 0 and 1
|
||||
//bias = clamp(bias, 0.0, 0.01);
|
||||
float visibility = 1.0;
|
||||
if (Input.ShadowCoord.x >= 0.0 && Input.ShadowCoord.x <= 1.0 && Input.ShadowCoord.y >= 0.0 && Input.ShadowCoord.y <= 1.0) {
|
||||
float bias = 0.0005;
|
||||
vec4 shadowMapValue = texture(shadowMap, Input.ShadowCoord.xy);
|
||||
if (shadowMapValue.z < clamp(Input.ShadowCoord.z - bias, 0, 1)) {
|
||||
visibility = 0.5;
|
||||
}
|
||||
}
|
||||
|
||||
vec3 totalLighting = La * Ka * visibility;
|
||||
|
||||
float attenuation;
|
||||
|
||||
for(int i = 0; i < numberOfLights && i < maxNumberOfLights; i++)
|
||||
{
|
||||
// Light
|
||||
//vec3 lightPosition = vec3(0, 0, 2);
|
||||
vec3 Ls = specular[i]; // Specular light
|
||||
vec3 Ld = diffuse[i]; // Diffuse light
|
||||
|
||||
vec3 lightPosView = vec3(view * vec4(position[i], 1.0));
|
||||
vec3 surfacePosition = vec3(model * vec4(Input.Position, 1.0));
|
||||
vec3 surfacePosView = vec3(view * vec4(surfacePosition, 1.0));
|
||||
vec3 surfaceToLight = normalize(lightPosView - surfacePosView);
|
||||
mat3 normalMatrix = transpose(inverse(mat3(view * model)));
|
||||
vec3 surfaceNormal = normalize(normalMatrix * Input.Normal);
|
||||
|
||||
float dist = length(position[i] - surfacePosition);
|
||||
|
||||
attenuation = 1.0 / (constantAttenuation[i]
|
||||
+ linearAttenuation[i] * dist
|
||||
+ quadraticAttenuation[i] * pow(dist, 2.0));
|
||||
//attenuation = attenuation * pow(clampedCosine, spotExponent[i]);
|
||||
|
||||
// Diffuse light
|
||||
float dotProd = dot(surfaceToLight, surfaceNormal);
|
||||
dotProd = max(dotProd, 0.0);
|
||||
|
||||
Id = Ld * Kd * abs(dotProd) * attenuation;
|
||||
|
||||
// Specular light
|
||||
vec3 reflection = reflect(-surfaceToLight, surfaceNormal);
|
||||
float dotSpecular = dot(reflection, normalize(-surfacePosView));
|
||||
dotSpecular = max(dotSpecular, 0.0);
|
||||
float specularFactor = pow(dotSpecular, 30.0); // Specular factor
|
||||
|
||||
Is = attenuation * Ls * Ks * specularFactor;
|
||||
|
||||
totalLighting = totalLighting + Id + Is;
|
||||
}
|
||||
|
||||
fragmentColor = vec4(totalLighting, 1.0) * texel;
|
||||
|
||||
|
||||
//fragmentColor = vec4(Id, 1.0) * texel;
|
||||
|
||||
//fragmentColor = texel;
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
#version 430
|
||||
|
||||
uniform mat4 MVP;
|
||||
|
||||
out vec4 FragmentColor;
|
||||
|
||||
void main() {
|
||||
FragmentColor = vec4(1.0, 1.0, 1.0, 1.0);
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
#version 430
|
||||
|
||||
uniform mat4 MVP;
|
||||
|
||||
layout(triangles) in;
|
||||
layout(line_strip, max_vertices = 6) out;
|
||||
|
||||
in VertexData {
|
||||
vec3 Position;
|
||||
vec3 Normal;
|
||||
vec2 TextureCoord;
|
||||
} Input[3];
|
||||
|
||||
out VertexData {
|
||||
vec3 Position;
|
||||
vec3 Normal;
|
||||
vec2 TextureCoord;
|
||||
} Output;
|
||||
|
||||
void main()
|
||||
{
|
||||
for (int i = 0; i < gl_in.length(); i++)
|
||||
{
|
||||
gl_Position = MVP * vec4(Input[i].Position, 1.0);
|
||||
EmitVertex();
|
||||
gl_Position = MVP * vec4(Input[i].Position + Input[i].Normal, 1.0);
|
||||
EmitVertex();
|
||||
EndPrimitive();
|
||||
|
||||
Output.Position = Input[i].Position;
|
||||
Output.Normal = Input[i].Normal;
|
||||
Output.TextureCoord = Input[i].TextureCoord;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
#version 430
|
||||
|
||||
uniform mat4 MVP;
|
||||
|
||||
layout(location = 0) out float FragmentDepth;
|
||||
|
||||
void main() {
|
||||
FragmentDepth = gl_FragCoord.z;
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
#version 430
|
||||
|
||||
uniform mat4 MVP;
|
||||
|
||||
layout(location = 0) in vec3 Position;
|
||||
layout(location = 1) in vec3 Normal;
|
||||
layout(location = 2) in vec2 TextureCoord;
|
||||
|
||||
out VertexData {
|
||||
vec3 Position;
|
||||
vec3 Normal;
|
||||
vec2 TextureCoord;
|
||||
} Output;
|
||||
|
||||
void main()
|
||||
{
|
||||
gl_Position = MVP * vec4(Position, 1.0);
|
||||
|
||||
Output.Position = Position;
|
||||
Output.Normal = Normal;
|
||||
Output.TextureCoord = TextureCoord;
|
||||
}
|
||||
@@ -1,6 +1,7 @@
|
||||
#version 440
|
||||
#version 430
|
||||
|
||||
uniform mat4 MVP;
|
||||
uniform mat4 DepthMVP;
|
||||
|
||||
layout(location = 0) in vec3 Position;
|
||||
layout(location = 1) in vec3 Normal;
|
||||
@@ -10,6 +11,7 @@ out VertexData {
|
||||
vec3 Position;
|
||||
vec3 Normal;
|
||||
vec2 TextureCoord;
|
||||
vec3 ShadowCoord;
|
||||
} Output;
|
||||
|
||||
void main()
|
||||
@@ -19,4 +21,5 @@ void main()
|
||||
Output.Position = Position;
|
||||
Output.Normal = Normal;
|
||||
Output.TextureCoord = TextureCoord;
|
||||
Output.ShadowCoord = vec3(DepthMVP * vec4(Position, 1.0));
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
#version 430
|
||||
|
||||
layout(binding = 0) uniform sampler2D DepthTexture;
|
||||
|
||||
in VertexData {
|
||||
vec3 Position;
|
||||
vec2 TextureCoord;
|
||||
} Input;
|
||||
|
||||
out vec4 FragmentColor;
|
||||
|
||||
float LinearizeDepth(float z)
|
||||
{
|
||||
float n = 0.1; // camera z near
|
||||
float f = 800.0; // camera z far
|
||||
return (2.0 * n) / (f + n - z * (f - n));
|
||||
}
|
||||
|
||||
void main() {
|
||||
float z = texture(DepthTexture, Input.TextureCoord).x;
|
||||
vec4 color = vec4(z, z, z, 0);
|
||||
|
||||
FragmentColor = color;
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
#version 430
|
||||
|
||||
layout(location = 0) in vec3 Position;
|
||||
layout(location = 2) in vec2 TextureCoord;
|
||||
|
||||
out VertexData {
|
||||
vec3 Position;
|
||||
vec2 TextureCoord;
|
||||
} Output;
|
||||
|
||||
void main()
|
||||
{
|
||||
gl_Position = vec4(Position, 1.0);
|
||||
|
||||
Output.Position = Position;
|
||||
Output.TextureCoord = TextureCoord;
|
||||
}
|
||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -19,7 +19,9 @@ public:
|
||||
virtual void UpdateEntity(double dt, EntityID entity, EntityID parent) { }
|
||||
|
||||
// Called when a component is created
|
||||
virtual void OnComponentCreated(std::string type, std:: shared_ptr<Component> 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:
|
||||
World* m_World;
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
|
||||
void Systems::CollisionSystem::UpdateEntity(double dt, EntityID entity, EntityID parent)
|
||||
{
|
||||
if (parent != 0)
|
||||
/*if (parent != 0)
|
||||
{
|
||||
auto transform = m_World->GetComponent<Components::Transform>(entity, "Transform");
|
||||
auto parentTransform = m_World->GetComponent<Components::Transform>(parent, "Transform");
|
||||
@@ -11,6 +11,120 @@ void Systems::CollisionSystem::UpdateEntity(double dt, EntityID entity, EntityID
|
||||
transform->Position[0] += parentTransform->Position[0];
|
||||
transform->Position[1] += parentTransform->Position[1];
|
||||
transform->Position[2] += parentTransform->Position[2];
|
||||
}*/
|
||||
|
||||
auto collisionComponent = m_World->GetComponent<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();
|
||||
|
||||
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);
|
||||
}
|
||||
LOG_INFO("Updating entity %i with parent %i", entity, parent);
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
@@ -3,8 +3,11 @@
|
||||
|
||||
#include "System.h"
|
||||
#include "logging.h"
|
||||
#include <glew-1.10.0/include/GL/glew.h>
|
||||
|
||||
#include "Components/Transform.h"
|
||||
#include "Components/Collision.h"
|
||||
#include "Components/Bounds.h"
|
||||
|
||||
namespace Systems
|
||||
{
|
||||
@@ -16,6 +19,8 @@ public:
|
||||
: System(world) { }
|
||||
|
||||
void UpdateEntity(double dt, EntityID entity, EntityID parent) override;
|
||||
void Intersects(EntityID, EntityID);
|
||||
void CreateBoundingBox(std::shared_ptr<Components::Bounds>);
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
@@ -23,6 +23,35 @@ void Systems::InputSystem::Update(double dt)
|
||||
m_CurrentMouseDeltaY = ypos - m_LastMouseY;
|
||||
m_LastMouseX = xpos;
|
||||
m_LastMouseY = ypos;
|
||||
|
||||
// Lock mouse while holding LMB
|
||||
if (m_CurrentMouseState[GLFW_MOUSE_BUTTON_LEFT]) {
|
||||
m_LastMouseX = m_Renderer->WIDTH / 2.f; // xpos;
|
||||
m_LastMouseY = m_Renderer->HEIGHT / 2.f; // ypos;
|
||||
glfwSetCursorPos(m_Renderer->GetWindow(), m_LastMouseX, m_LastMouseY);
|
||||
}
|
||||
// Hide/show cursor with LMB
|
||||
if (m_CurrentMouseState[GLFW_MOUSE_BUTTON_LEFT] && !m_LastMouseState[GLFW_MOUSE_BUTTON_LEFT]) {
|
||||
glfwSetInputMode(m_Renderer->GetWindow(), GLFW_CURSOR, GLFW_CURSOR_HIDDEN);
|
||||
}
|
||||
if (!m_CurrentMouseState[GLFW_MOUSE_BUTTON_LEFT] && m_LastMouseState[GLFW_MOUSE_BUTTON_LEFT]) {
|
||||
glfwSetInputMode(m_Renderer->GetWindow(), GLFW_CURSOR, GLFW_CURSOR_NORMAL);
|
||||
}
|
||||
|
||||
#ifdef DEBUG
|
||||
// Wireframe
|
||||
if (m_CurrentKeyState[GLFW_KEY_F1] && !m_LastKeyState[GLFW_KEY_F1]) {
|
||||
m_Renderer->DrawWireframe(!m_Renderer->DrawWireframe());
|
||||
}
|
||||
// Normals
|
||||
if (m_CurrentKeyState[GLFW_KEY_F2] && !m_LastKeyState[GLFW_KEY_F2]) {
|
||||
m_Renderer->DrawNormals(!m_Renderer->DrawNormals());
|
||||
}
|
||||
// Bounds
|
||||
if (m_CurrentKeyState[GLFW_KEY_F3] && !m_LastKeyState[GLFW_KEY_F3]) {
|
||||
m_Renderer->DrawBounds(!m_Renderer->DrawBounds());
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
void Systems::InputSystem::UpdateEntity(double dt, EntityID entity, EntityID parent)
|
||||
@@ -38,3 +67,6 @@ void Systems::InputSystem::UpdateEntity(double dt, EntityID entity, EntityID par
|
||||
input->dX = m_CurrentMouseDeltaX;
|
||||
input->dY = m_CurrentMouseDeltaY;
|
||||
}
|
||||
|
||||
std::array<int, GLFW_KEY_LAST+1> Systems::InputSystem::m_CurrentKeyState;
|
||||
std::array<int, GLFW_KEY_LAST+1> Systems::InputSystem::m_LastKeyState;
|
||||
|
||||
@@ -13,7 +13,7 @@ namespace Systems
|
||||
class InputSystem : public System
|
||||
{
|
||||
public:
|
||||
InputSystem(World* world, std::shared_ptr<Renderer> renderer)
|
||||
InputSystem(World* world, std::shared_ptr<Renderer> renderer)
|
||||
: System(world), m_Renderer(renderer) { }
|
||||
|
||||
void Update(double dt) override;
|
||||
@@ -21,13 +21,13 @@ public:
|
||||
|
||||
private:
|
||||
std::shared_ptr<Renderer> m_Renderer;
|
||||
|
||||
std::array<int, GLFW_KEY_LAST+1> m_CurrentKeyState;
|
||||
std::array<int, GLFW_KEY_LAST+1> m_LastKeyState;
|
||||
static std::array<int, GLFW_KEY_LAST+1> m_CurrentKeyState;
|
||||
static std::array<int, GLFW_KEY_LAST+1> m_LastKeyState;
|
||||
std::array<int, GLFW_MOUSE_BUTTON_LAST+1> m_CurrentMouseState;
|
||||
std::array<int, GLFW_MOUSE_BUTTON_LAST+1> m_LastMouseState;
|
||||
float m_CurrentMouseDeltaX, m_CurrentMouseDeltaY;
|
||||
float m_LastMouseX, m_LastMouseY;
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,138 @@
|
||||
#include "LevelGenerationSystem.h"
|
||||
|
||||
Systems::LevelGenerationSystem::LevelGenerationSystem( World* world )
|
||||
: System(world)
|
||||
{
|
||||
elapsedtime = 0;
|
||||
|
||||
velocity = 0;
|
||||
startx = 0;
|
||||
startyz = glm::vec2(0, -1000);
|
||||
}
|
||||
|
||||
void Systems::LevelGenerationSystem::SpawnObstacle()
|
||||
{
|
||||
typeRandom = 0 + (rand() % 10);
|
||||
|
||||
EntityID ent;
|
||||
|
||||
ent = m_World->CreateEntity();
|
||||
obstacles.push_back(ent);
|
||||
m_World->SetProperty(ent, "Name", std::string("Obstacle"));
|
||||
transform = m_World->AddComponent<Components::Transform>(ent, "Transform");
|
||||
bounds = m_World->AddComponent<Components::Bounds>(ent, "Bounds");
|
||||
collision = m_World->AddComponent<Components::Collision>(ent, "Collision");
|
||||
model = m_World->AddComponent<Components::Model>(ent, "Model");
|
||||
auto sound = m_World->AddComponent<Components::SoundEmitter>(ent, "SoundEmitter");
|
||||
|
||||
|
||||
positionRandom = -500 + startx + (rand() % 1000);
|
||||
transform->Position = glm::vec3(positionRandom, startyz);
|
||||
//transform->Velocity = glm::vec3(0.f, 10.f, 100.f);
|
||||
|
||||
sound->Loop = true;
|
||||
sound->Gain = 1.f;
|
||||
sound->ReferenceDistance = 15.f;
|
||||
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->Origin = glm::vec3(1,11,-1);
|
||||
model->ModelFile = "Models/obstacle_mountain_1.obj";
|
||||
}
|
||||
else if(typeRandom >= 2 && typeRandom < 5) // Single Mountain :D
|
||||
{
|
||||
float scale = (float)(rand() % 1000) / 200;
|
||||
transform->Scale = glm::vec3(scale);
|
||||
bounds->VolumeVector = glm::vec3(3.5f, 7.5f, 3.5f);
|
||||
bounds->Origin = glm::vec3(0,7.5f,0);
|
||||
model->ModelFile = "Models/obstacle_mountain_2.obj";
|
||||
}
|
||||
else if(typeRandom >= 5 && typeRandom < 8)
|
||||
{
|
||||
float scale = (float)(rand() % 1000) / 100;
|
||||
transform->Scale = glm::vec3(scale);
|
||||
bounds->VolumeVector = glm::vec3(1, 1, 1);
|
||||
bounds->Origin = glm::vec3(0,1,0);
|
||||
model->ModelFile = "Models/obstacle_cube_1.obj";
|
||||
}
|
||||
if(typeRandom >= 8 && typeRandom < 10)
|
||||
{
|
||||
float scale = (float)(rand() % 1000) / 100;
|
||||
bounds->VolumeVector = glm::vec3(4, 4, 4);
|
||||
bounds->Origin = glm::vec3(0,4,0);
|
||||
pointLight = m_World->AddComponent<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;
|
||||
|
||||
powerUp = m_World->AddComponent<Components::PowerUp>(ent, "PowerUp");
|
||||
powerUp->Speed = 10.f;
|
||||
|
||||
model->ModelFile = "Models/powerup.obj";
|
||||
}
|
||||
|
||||
|
||||
// Put it below ground level
|
||||
transform->Position.y -= bounds->VolumeVector.y * 2.f;
|
||||
|
||||
}
|
||||
|
||||
void Systems::LevelGenerationSystem::Update( double dt )
|
||||
{
|
||||
|
||||
elapsedtime += dt;
|
||||
|
||||
if(elapsedtime > 0.1){
|
||||
SpawnObstacle();
|
||||
elapsedtime = 0;
|
||||
}
|
||||
|
||||
std::list<EntityID> removethis;
|
||||
|
||||
for(auto ent : obstacles)
|
||||
{
|
||||
auto transform = m_World->GetComponent<Components::Transform>(ent, "Transform");
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
for(auto ent : removethis)
|
||||
{
|
||||
m_World->RemoveEntity(ent);
|
||||
obstacles.remove(ent);
|
||||
}
|
||||
removethis.clear();
|
||||
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,50 @@
|
||||
#ifndef LevelGenerationSystem_h__
|
||||
#define LevelGenerationSystem_h__
|
||||
|
||||
#include "System.h"
|
||||
#include "Systems/SoundSystem.h"
|
||||
#include "World.h"
|
||||
#include "Components/Transform.h"
|
||||
#include "Components/Bounds.h"
|
||||
#include "Components/Collision.h"
|
||||
#include "Components/Model.h"
|
||||
#include "Components/PointLight.h"
|
||||
#include "Components/SoundEmitter.h"
|
||||
#include "Components/PowerUp.h"
|
||||
|
||||
|
||||
namespace Systems
|
||||
{
|
||||
class LevelGenerationSystem : public System
|
||||
{
|
||||
public:
|
||||
LevelGenerationSystem(World* world);
|
||||
|
||||
|
||||
void SpawnObstacle();
|
||||
|
||||
void Update(double dt) override;
|
||||
void UpdateEntity(double dt, EntityID entity, EntityID parent) override;
|
||||
|
||||
private:
|
||||
int typeRandom;
|
||||
int positionRandom;
|
||||
glm::vec2 startyz;
|
||||
float startx;
|
||||
|
||||
double elapsedtime;
|
||||
|
||||
std::list<EntityID> obstacles;
|
||||
float velocity;
|
||||
|
||||
std::shared_ptr<Components::Transform> transform;
|
||||
std::shared_ptr<Components::Bounds> bounds;
|
||||
std::shared_ptr<Components::Collision> collision;
|
||||
std::shared_ptr<Components::Model> model;
|
||||
std::shared_ptr<Components::PointLight> pointLight;
|
||||
std::shared_ptr<Components::PowerUp> powerUp;
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
#endif // LevelGenerationSystem_h__
|
||||
@@ -0,0 +1,126 @@
|
||||
#include "PlayerSystem.h"
|
||||
#include "World.h"
|
||||
|
||||
Systems::PlayerSystem::PlayerSystem( World* world ) : System(world)
|
||||
{
|
||||
m_PlayerSpeed = 20;
|
||||
m_PlayerOriginalBounds = glm::vec3(0);
|
||||
}
|
||||
|
||||
void Systems::PlayerSystem::Update(double dt)
|
||||
{
|
||||
}
|
||||
|
||||
void Systems::PlayerSystem::UpdateEntity(double dt, EntityID entity, EntityID parent)
|
||||
{
|
||||
auto transform = m_World->GetComponent<Components::Transform>(entity, "Transform");
|
||||
if (transform == nullptr)
|
||||
return;
|
||||
auto input = m_World->GetComponent<Components::Input>(entity, "Input");
|
||||
if (input == nullptr)
|
||||
return;
|
||||
|
||||
auto name = m_World->GetProperty<std::string>(entity, "Name");
|
||||
if (name == "Camera") {
|
||||
glm::vec3 Camera_Right = glm::vec3(glm::vec4(1, 0, 0, 0) * transform->Orientation);
|
||||
glm::vec3 Camera_Forward = glm::vec3(glm::vec4(0, 0, 1, 0) * transform->Orientation);
|
||||
|
||||
float speed = m_PlayerSpeed;
|
||||
if(input->KeyState[GLFW_KEY_LEFT_SHIFT]) {
|
||||
speed *= 4.0f;
|
||||
}
|
||||
if(input->KeyState[GLFW_KEY_LEFT_ALT]) {
|
||||
speed /= 4.0f;
|
||||
}
|
||||
if(input->KeyState[GLFW_KEY_A] || input->KeyState[GLFW_KEY_LEFT]) {
|
||||
transform->Position -= Camera_Right * (float)dt * speed;
|
||||
}
|
||||
else if(input->KeyState[GLFW_KEY_D] || input->KeyState[GLFW_KEY_RIGHT]) {
|
||||
transform->Position += Camera_Right * (float)dt * speed;
|
||||
}
|
||||
if(input->KeyState[GLFW_KEY_W]) {
|
||||
transform->Position -= Camera_Forward * (float)dt * speed;
|
||||
}
|
||||
if(input->KeyState[GLFW_KEY_S]) {
|
||||
transform->Position += Camera_Forward * (float)dt * speed;
|
||||
}
|
||||
if(input->KeyState[GLFW_KEY_SPACE]) {
|
||||
transform->Position += glm::vec3(0, 1, 0) * (float)dt * speed;
|
||||
}
|
||||
if(input->KeyState[GLFW_KEY_LEFT_CONTROL]) {
|
||||
transform->Position -= glm::vec3(0, 1, 0) * (float)dt * speed;
|
||||
}
|
||||
if (input->MouseState[GLFW_MOUSE_BUTTON_LEFT]) {
|
||||
// TOUCHING THIS CODE MIGHT COUSE THE UNIVERSE TO IMPLODE, ALSO DRAGONS
|
||||
//---------------------------------------------------------------------
|
||||
transform->Orientation = glm::angleAxis<float>(input->dY/300.f,glm::vec3(1,0,0)) * transform->Orientation;
|
||||
|
||||
transform->Orientation = transform->Orientation * glm::angleAxis<float>(input->dX/300.f,glm::vec3(0,1,0));
|
||||
//---------------------------------------------------------------------
|
||||
// TOUCHING THIS CODE MIGHT COUSE THE UNIVERSE TO IMPLODE, ALSO DRAGONS
|
||||
}
|
||||
}
|
||||
|
||||
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_Forward = glm::vec3(glm::vec4(0, 0, 1, 0));
|
||||
|
||||
float TurnSpeed = 1.0f;
|
||||
glm::vec3 Euler = glm::eulerAngles(transform->Orientation);
|
||||
|
||||
if(input->KeyState[GLFW_KEY_LEFT]) {
|
||||
transform->Position -= Ship_Right * (float)dt * (m_PlayerSpeed + Euler.z);
|
||||
|
||||
if(Euler.z < 10.f)
|
||||
{
|
||||
transform->Orientation = transform->Orientation * glm::angleAxis<float>((float)dt * TurnSpeed,glm::vec3(0,0,1));
|
||||
}
|
||||
else if(Euler.z < 20.f)
|
||||
{
|
||||
transform->Orientation = transform->Orientation * glm::angleAxis<float>((float)dt * TurnSpeed/2,glm::vec3(0,0,1));
|
||||
}
|
||||
else if (Euler.z < 25.f)
|
||||
{
|
||||
transform->Orientation = transform->Orientation * glm::angleAxis<float>((float)dt * TurnSpeed/4,glm::vec3(0,0,1));
|
||||
}
|
||||
}
|
||||
else if(input->KeyState[GLFW_KEY_RIGHT]) {
|
||||
transform->Position += Ship_Right * (float)dt * (m_PlayerSpeed - Euler.z);
|
||||
|
||||
if(Euler.z > -10.f)
|
||||
{
|
||||
transform->Orientation = transform->Orientation * glm::angleAxis<float>((float)dt * TurnSpeed,glm::vec3(0,0,-1));
|
||||
}
|
||||
else if(Euler.z > -20.f)
|
||||
{
|
||||
transform->Orientation = transform->Orientation * glm::angleAxis<float>((float)dt * TurnSpeed/2,glm::vec3(0,0,-1));
|
||||
}
|
||||
else if (Euler.z > -25.f)
|
||||
{
|
||||
transform->Orientation = transform->Orientation * glm::angleAxis<float>((float)dt * TurnSpeed/4,glm::vec3(0,0,-1));
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if(Euler.z < 1.5f && Euler.z > -1.5f)
|
||||
transform->Orientation = glm::angleAxis<float>(0,glm::vec3(0,0,1));
|
||||
else if(Euler.z < 0.f)
|
||||
transform->Orientation = transform->Orientation * glm::angleAxis<float>((float)dt,glm::vec3(0,0,1));
|
||||
else if(Euler.z > 0.f)
|
||||
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));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,33 @@
|
||||
#ifndef PlayerSystem_h__
|
||||
#define PlayerSystem_h__
|
||||
|
||||
#include <array>
|
||||
|
||||
#include "System.h"
|
||||
#include "Components/Transform.h"
|
||||
#include "Components/Input.h"
|
||||
#include "Components/Collision.h"
|
||||
#include "Components/Bounds.h"
|
||||
#include "logging.h"
|
||||
|
||||
|
||||
|
||||
namespace Systems
|
||||
{
|
||||
|
||||
class PlayerSystem : public System
|
||||
{
|
||||
public:
|
||||
PlayerSystem(World* world);
|
||||
|
||||
void Update(double dt) override;
|
||||
void UpdateEntity(double dt, EntityID entity, EntityID parent) override;
|
||||
|
||||
private:
|
||||
float m_PlayerSpeed;
|
||||
glm::vec3 m_PlayerOriginalBounds;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif // InputSystem_h__
|
||||
|
||||
@@ -0,0 +1,68 @@
|
||||
#include "RenderSystem.h"
|
||||
#include "World.h"
|
||||
|
||||
void Systems::RenderSystem::OnComponentCreated( std::string type, std:: shared_ptr<Component> component )
|
||||
{
|
||||
if(type == "Model")
|
||||
{
|
||||
auto modelComponent = std::static_pointer_cast<Components::Model>(component);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
void Systems::RenderSystem::UpdateEntity( double dt, EntityID entity, EntityID parent )
|
||||
{
|
||||
auto transformComponent = m_World->GetComponent<Components::Transform>(entity, "Transform");
|
||||
if (transformComponent == nullptr)
|
||||
return;
|
||||
|
||||
// Draw models
|
||||
auto modelComponent = m_World->GetComponent<Components::Model>(entity, "Model");
|
||||
if (modelComponent != nullptr)
|
||||
{
|
||||
if (m_CachedModels.find(modelComponent->ModelFile) == m_CachedModels.end()){
|
||||
m_CachedModels[modelComponent->ModelFile] = std::make_shared<Model>(OBJ(modelComponent->ModelFile));
|
||||
}
|
||||
|
||||
auto model = m_CachedModels[modelComponent->ModelFile];
|
||||
m_Renderer->AddModelToDraw(model, transformComponent->Position, transformComponent->Orientation, transformComponent->Scale);
|
||||
}
|
||||
|
||||
// Debug draw bounds
|
||||
#ifdef DEBUG
|
||||
auto collision = m_World->GetComponent<Components::Collision>(entity, "Collision");
|
||||
auto bounds = m_World->GetComponent<Components::Bounds>(entity, "Bounds");
|
||||
if (bounds != nullptr) {
|
||||
glm::vec3 origin = transformComponent->Position + (transformComponent->Scale * bounds->Origin);
|
||||
glm::vec3 volumeVector = transformComponent->Scale * bounds->VolumeVector;
|
||||
m_Renderer->AddAABBToDraw(origin, volumeVector, (collision != nullptr && collision->CollidingEntities.size() > 0));
|
||||
}
|
||||
#endif
|
||||
|
||||
auto pointLightComponent = m_World->GetComponent<Components::PointLight>(entity, "PointLight");
|
||||
if (pointLightComponent != nullptr)
|
||||
{
|
||||
m_Renderer->AddPointLightToDraw(
|
||||
transformComponent->Position,
|
||||
pointLightComponent->Specular,
|
||||
pointLightComponent->Diffuse,
|
||||
pointLightComponent->constantAttenuation,
|
||||
pointLightComponent->linearAttenuation,
|
||||
pointLightComponent->quadraticAttenuation,
|
||||
pointLightComponent->spotExponent);
|
||||
}
|
||||
auto cameraComponent = m_World->GetComponent<Components::Camera>(entity, "Camera");
|
||||
if (cameraComponent != nullptr)
|
||||
{
|
||||
m_Renderer->GetCamera()->Position(transformComponent->Position);
|
||||
m_Renderer->GetCamera()->Orientation(transformComponent->Orientation);
|
||||
|
||||
m_Renderer->GetCamera()->FOV(cameraComponent->FOV);
|
||||
m_Renderer->GetCamera()->NearClip(cameraComponent->NearClip);
|
||||
m_Renderer->GetCamera()->FarClip(cameraComponent->FarClip);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,41 @@
|
||||
#ifndef RenderSystem_h__
|
||||
#define RenderSystem_h__
|
||||
|
||||
#include <unordered_map>
|
||||
|
||||
#include "System.h"
|
||||
#include "Model.h"
|
||||
#include "Texture.h"
|
||||
#include "Components/Model.h"
|
||||
#include "Components/Transform.h"
|
||||
#include "Components/Camera.h"
|
||||
#include "Components/Bounds.h"
|
||||
#include "Components/Collision.h"
|
||||
#include "Renderer.h"
|
||||
|
||||
namespace Systems
|
||||
{
|
||||
|
||||
class RenderSystem : public System
|
||||
{
|
||||
public:
|
||||
RenderSystem(World* world, std::shared_ptr<Renderer> renderer)
|
||||
: System(world), m_Renderer(renderer){ }
|
||||
|
||||
std::unordered_map<std::string, std::shared_ptr<Model>> m_CachedModels;
|
||||
|
||||
void OnComponentCreated(std::string type, std:: shared_ptr<Component> component) override;
|
||||
void UpdateEntity(double dt, EntityID entity, EntityID parent) override;
|
||||
|
||||
private:
|
||||
std::shared_ptr<Renderer> m_Renderer;
|
||||
|
||||
};
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
#endif //RenderSystem_h__
|
||||
@@ -0,0 +1,45 @@
|
||||
#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;
|
||||
void OnComponentRemoved(std::string type, Component* component) override;
|
||||
void PlaySound(std::shared_ptr<Components::SoundEmitter> emitter, std::string fileName);
|
||||
|
||||
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__
|
||||
|
||||
|
||||
@@ -0,0 +1,189 @@
|
||||
#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 fileName)
|
||||
{
|
||||
if (m_Sources.find(emitter.get()) == m_Sources.end())
|
||||
return;
|
||||
|
||||
ALuint buffer = LoadFile(fileName);
|
||||
ALuint source = m_Sources[emitter.get()];
|
||||
alSourcei(source, AL_BUFFER, buffer);
|
||||
alSourcePlay(m_Sources[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 fileName)
|
||||
{
|
||||
if (m_BufferCache.find(fileName) != m_BufferCache.end())
|
||||
return m_BufferCache[fileName];
|
||||
|
||||
FILE *fp = NULL;
|
||||
fp = fopen(fileName.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[fileName] = buffer;
|
||||
return buffer;
|
||||
}
|
||||
|
||||
ALuint Systems::SoundSystem::CreateSource()
|
||||
{
|
||||
ALuint source;
|
||||
alGenSources((ALuint)1, &source);
|
||||
|
||||
return source;
|
||||
}
|
||||
@@ -1,14 +1,14 @@
|
||||
#include "Texture.h"
|
||||
|
||||
Texture::Texture( const char* path )
|
||||
Texture::Texture(std::string path)
|
||||
{
|
||||
Load(path);
|
||||
}
|
||||
|
||||
|
||||
void Texture::Load( const char* path )
|
||||
void Texture::Load(std::string path)
|
||||
{
|
||||
texture = SOIL_load_OGL_texture(path, 0, 0, SOIL_FLAG_INVERT_Y);
|
||||
texture = SOIL_load_OGL_texture(path.c_str(), 0, 0, SOIL_FLAG_INVERT_Y);
|
||||
}
|
||||
|
||||
void Texture::Bind()
|
||||
|
||||
@@ -1,22 +1,21 @@
|
||||
#ifndef Texture_h__
|
||||
#define Texture_h__
|
||||
|
||||
#include <GL/glew.h>
|
||||
#define GLFW_INCLUDE_GLU
|
||||
#include <GLFW/glfw3.h>
|
||||
#include <glext.h>
|
||||
#include <string>
|
||||
|
||||
#include "OpenGL.h"
|
||||
#include <SOIL.h>
|
||||
|
||||
class Texture
|
||||
{
|
||||
public:
|
||||
Texture(const char* path);
|
||||
Texture(std::string path);
|
||||
|
||||
~Texture();
|
||||
|
||||
GLuint texture;
|
||||
|
||||
void Load(const char* path);
|
||||
void Load(std::string path);
|
||||
void Bind();
|
||||
};
|
||||
|
||||
|
||||
@@ -61,6 +61,19 @@ bool World::ValidEntity(EntityID entity)
|
||||
void World::RemoveEntity(EntityID entity)
|
||||
{
|
||||
m_EntityParents.erase(entity);
|
||||
// Remove components
|
||||
for (auto pair : m_EntityComponents[entity]) {
|
||||
auto type = pair.first;
|
||||
auto component = pair.second;
|
||||
// Trigger events
|
||||
for (auto pair : m_Systems) {
|
||||
auto system = pair.second;
|
||||
system->OnComponentRemoved(type, component.get());
|
||||
}
|
||||
m_ComponentsOfType[type].remove(component);
|
||||
}
|
||||
m_EntityComponents.erase(entity);
|
||||
|
||||
RecycleEntityID(entity);
|
||||
}
|
||||
|
||||
|
||||
+28
-5
@@ -2,9 +2,13 @@
|
||||
#define World_h__
|
||||
|
||||
#include <stack>
|
||||
#include <map>
|
||||
#include <unordered_map>
|
||||
#include <vector>
|
||||
#include <string>
|
||||
#include <queue>
|
||||
|
||||
#include <boost/any.hpp>
|
||||
|
||||
#include "logging.h"
|
||||
|
||||
@@ -36,11 +40,27 @@ public:
|
||||
|
||||
EntityID GetEntityParent(EntityID entity);
|
||||
|
||||
template <class T>
|
||||
T GetProperty(EntityID entity, std::string property)
|
||||
{
|
||||
if(m_EntityProperties.find(entity) == m_EntityProperties.end())
|
||||
return T();
|
||||
if(m_EntityProperties[entity].find(property) == m_EntityProperties[entity].end())
|
||||
return T();
|
||||
|
||||
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);
|
||||
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);*/
|
||||
|
||||
@@ -48,6 +68,8 @@ public:
|
||||
// Recursively update through the scene graph
|
||||
void RecursiveUpdate(std::shared_ptr<System> system, double dt, EntityID parentEntity);
|
||||
|
||||
std::unordered_map<EntityID, EntityID>* GetEntities() { return &m_EntityParents; }
|
||||
|
||||
protected:
|
||||
SystemFactory m_SystemFactory;
|
||||
ComponentFactory m_ComponentFactory;
|
||||
@@ -57,9 +79,10 @@ protected:
|
||||
EntityID m_LastEntityID;
|
||||
std::stack<EntityID> m_RecycledEntityIDs;
|
||||
// A bottom to top tree. A map of child entities to parent entities.
|
||||
std::unordered_map<EntityID, EntityID> m_EntityParents;
|
||||
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<std::string, std::list<std::shared_ptr<Component>>> m_ComponentsOfType;
|
||||
std::unordered_map<EntityID, std::map<std::string, std::shared_ptr<Component>>> m_EntityComponents;
|
||||
|
||||
EntityID GenerateEntityID();
|
||||
@@ -94,9 +117,9 @@ std::shared_ptr<T> World::AddComponent(EntityID entity, std::string componentTyp
|
||||
|
||||
|
||||
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__
|
||||
@@ -1,8 +1,6 @@
|
||||
#ifndef _GLERROR_H
|
||||
#define _GLERROR_H
|
||||
|
||||
#define GLFW_INCLUDE_GLU
|
||||
#include <GLFW\glfw3.h>
|
||||
#include <iostream>
|
||||
|
||||
#include "logging.h"
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
#define DEBUG_H
|
||||
|
||||
#ifdef _WIN32
|
||||
#define _CRT_SECURE_NO_WARNINGS
|
||||
// http://stackoverflow.com/a/2282433
|
||||
#define __func__ __FUNCTION__
|
||||
// http://stackoverflow.com/a/8488201
|
||||
@@ -46,10 +47,13 @@ static void _LOG(_LOG_LEVEL logLevel, char* file, char* func, unsigned int line,
|
||||
if (logLevel > LOG_LEVEL)
|
||||
return;
|
||||
|
||||
char message[512];
|
||||
va_list args;
|
||||
va_start(args, format);
|
||||
vsnprintf_s(message, 512, format, args);
|
||||
char* message = nullptr;
|
||||
size_t size = vsnprintf(message, 0, format, args);
|
||||
message = new char[size+1];
|
||||
message[size] = '\0';
|
||||
vsnprintf(message, size, format, args);
|
||||
va_end(args);
|
||||
|
||||
if (logLevel == LOG_LEVEL_ERROR)
|
||||
@@ -61,6 +65,8 @@ static void _LOG(_LOG_LEVEL logLevel, char* file, char* func, unsigned int line,
|
||||
{
|
||||
std::cout << _LOG_LEVEL_PREFIX[logLevel] << message << std::endl;
|
||||
}
|
||||
|
||||
delete[] message;
|
||||
}
|
||||
|
||||
#define LOG(logLevel, format, ...) \
|
||||
|
||||
@@ -0,0 +1,10 @@
|
||||
#include "Engine.h"
|
||||
|
||||
int main(int argc, char* argv[])
|
||||
{
|
||||
Engine engine(argc, argv);
|
||||
while (engine.Running())
|
||||
engine.Tick();
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
Reference in New Issue
Block a user