Merge branch 'master' of github.com:sippeangelo/Escape-the-Dawn
Conflicts: Escape-the-Dawn/Systems/LevelGenerationSystem.cpp Escape-the-Dawn/Systems/PlayerSystem.cpp
This commit is contained in:
@@ -10,7 +10,10 @@ namespace Components
|
|||||||
|
|
||||||
struct Collision : Component
|
struct Collision : Component
|
||||||
{
|
{
|
||||||
|
Collision() : Phantom(false), Interested(false) { }
|
||||||
|
|
||||||
bool Phantom;
|
bool Phantom;
|
||||||
|
bool Interested;
|
||||||
std::vector<EntityID> CollidingEntities;
|
std::vector<EntityID> CollidingEntities;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -11,7 +11,7 @@ namespace Components
|
|||||||
struct SoundEmitter : Component
|
struct SoundEmitter : Component
|
||||||
{
|
{
|
||||||
float Gain;
|
float Gain;
|
||||||
float MaxDistance;
|
//float MaxDistance;
|
||||||
float ReferenceDistance;
|
float ReferenceDistance;
|
||||||
float Pitch;
|
float Pitch;
|
||||||
bool Loop;
|
bool Loop;
|
||||||
|
|||||||
@@ -82,12 +82,12 @@
|
|||||||
<Optimization>MaxSpeed</Optimization>
|
<Optimization>MaxSpeed</Optimization>
|
||||||
<FunctionLevelLinking>true</FunctionLevelLinking>
|
<FunctionLevelLinking>true</FunctionLevelLinking>
|
||||||
<IntrinsicFunctions>true</IntrinsicFunctions>
|
<IntrinsicFunctions>true</IntrinsicFunctions>
|
||||||
<PreprocessorDefinitions>GLEW_STATIC;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
<PreprocessorDefinitions>GLEW_STATIC;DEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||||
<PrecompiledHeader>NotUsing</PrecompiledHeader>
|
<PrecompiledHeader>NotUsing</PrecompiledHeader>
|
||||||
<DebugInformationFormat>None</DebugInformationFormat>
|
<DebugInformationFormat>ProgramDatabase</DebugInformationFormat>
|
||||||
|
<MinimalRebuild>true</MinimalRebuild>
|
||||||
</ClCompile>
|
</ClCompile>
|
||||||
<Link>
|
<Link>
|
||||||
<GenerateDebugInformation>false</GenerateDebugInformation>
|
|
||||||
<EnableCOMDATFolding>true</EnableCOMDATFolding>
|
<EnableCOMDATFolding>true</EnableCOMDATFolding>
|
||||||
<OptimizeReferences>true</OptimizeReferences>
|
<OptimizeReferences>true</OptimizeReferences>
|
||||||
<AdditionalDependencies>OpenAL32.lib;opengl32.lib;glu32.lib;SOIL.lib;glew32s.lib;glfw3.lib;%(AdditionalDependencies)</AdditionalDependencies>
|
<AdditionalDependencies>OpenAL32.lib;opengl32.lib;glu32.lib;SOIL.lib;glew32s.lib;glfw3.lib;%(AdditionalDependencies)</AdditionalDependencies>
|
||||||
|
|||||||
@@ -21,31 +21,16 @@ void GameWorld::Initialize()
|
|||||||
std::shared_ptr<Components::Collision> collision;
|
std::shared_ptr<Components::Collision> collision;
|
||||||
EntityID ent;
|
EntityID ent;
|
||||||
|
|
||||||
// Camera
|
|
||||||
entcamera = CreateEntity();
|
|
||||||
SetProperty(entcamera, "Name", std::string("Camera"));
|
|
||||||
transform = AddComponent<Components::Transform>(entcamera, "Transform");
|
|
||||||
AddComponent<Components::Input>(entcamera, "Input");
|
|
||||||
transform->Position = glm::vec3(0.f, 10.f, 14.f);
|
|
||||||
camera = AddComponent<Components::Camera>(entcamera, "Camera");
|
|
||||||
camera->FOV = 45.f;
|
|
||||||
camera->FarClip = 1000.f;
|
|
||||||
camera->NearClip = 0.01f;
|
|
||||||
transform->Orientation = glm::angleAxis<float>(glm::radians(15.0f),glm::vec3(1,0,0));
|
|
||||||
collision = AddComponent<Components::Collision>(entcamera, "Collision");
|
|
||||||
collision->Phantom = false;
|
|
||||||
bounds = AddComponent<Components::Bounds>(entcamera, "Bounds");
|
|
||||||
bounds->VolumeVector = glm::vec3(0.1f,0.1f,0.1f);
|
|
||||||
|
|
||||||
// Fucking lights
|
// Fucking lights
|
||||||
ent = CreateEntity();
|
ent = CreateEntity();
|
||||||
transform = AddComponent<Components::Transform>(ent, "Transform");
|
transform = AddComponent<Components::Transform>(ent, "Transform");
|
||||||
transform->Position = glm::vec3(0.f, 4.f, 0.f);
|
transform->Position = glm::vec3(0.f, 7.f, 0.f);
|
||||||
transform->Position = glm::vec3(10.f, 2.f, 5.f);
|
|
||||||
pointLight = AddComponent<Components::PointLight>(ent, "PointLight");
|
pointLight = AddComponent<Components::PointLight>(ent, "PointLight");
|
||||||
pointLight->Specular = glm::vec3(1.0, 1.0, 1.0);
|
pointLight->Specular = glm::vec3(1.0, 1.0, 1.0);
|
||||||
pointLight->Diffuse = glm::vec3(1.0, 1.0, 1.0);
|
pointLight->Diffuse = glm::vec3(0.0, 0.0, 5.0);
|
||||||
pointLight->Diffuse = glm::vec3(1.0, 1.0, 5.0);
|
|
||||||
pointLight->constantAttenuation = 0.f;
|
pointLight->constantAttenuation = 0.f;
|
||||||
pointLight->linearAttenuation = 1.f;
|
pointLight->linearAttenuation = 1.f;
|
||||||
pointLight->quadraticAttenuation = 0.f;
|
pointLight->quadraticAttenuation = 0.f;
|
||||||
@@ -54,13 +39,10 @@ void GameWorld::Initialize()
|
|||||||
model->ModelFile = "Models/sphere.obj";
|
model->ModelFile = "Models/sphere.obj";
|
||||||
ent = CreateEntity();
|
ent = CreateEntity();
|
||||||
transform = AddComponent<Components::Transform>(ent, "Transform");
|
transform = AddComponent<Components::Transform>(ent, "Transform");
|
||||||
transform->Position = glm::vec3(10.f, 4.f, 0.f);
|
transform->Position = glm::vec3(10.f, 7.f, 0.f);
|
||||||
transform->Position = glm::vec3(0.f, 2.f, 5.f);
|
|
||||||
pointLight = AddComponent<Components::PointLight>(ent, "PointLight");
|
pointLight = AddComponent<Components::PointLight>(ent, "PointLight");
|
||||||
pointLight->Specular = glm::vec3(1.0, 1.0, 1.0);
|
pointLight->Specular = glm::vec3(1.0, 1.0, 1.0);
|
||||||
pointLight->Diffuse = glm::vec3(1.0, 1.0, 1.0);
|
pointLight->Diffuse = glm::vec3(0.0, 5.0, 0.0);
|
||||||
pointLight->Specular = glm::vec3(3.0, 3.0, 3.0);
|
|
||||||
pointLight->Diffuse = glm::vec3(3.0, 0.0, 0.0);
|
|
||||||
pointLight->constantAttenuation = 0.f;
|
pointLight->constantAttenuation = 0.f;
|
||||||
pointLight->linearAttenuation = 1.f;
|
pointLight->linearAttenuation = 1.f;
|
||||||
pointLight->quadraticAttenuation = 0.f;
|
pointLight->quadraticAttenuation = 0.f;
|
||||||
@@ -69,12 +51,10 @@ void GameWorld::Initialize()
|
|||||||
model->ModelFile = "Models/sphere.obj";
|
model->ModelFile = "Models/sphere.obj";
|
||||||
ent = CreateEntity();
|
ent = CreateEntity();
|
||||||
transform = AddComponent<Components::Transform>(ent, "Transform");
|
transform = AddComponent<Components::Transform>(ent, "Transform");
|
||||||
transform->Position = glm::vec3(0.f, -4.f, 0.f);
|
transform->Position = glm::vec3(-10.f, 7.f, 0.f);
|
||||||
transform->Position = glm::vec3(-10.f, 2.f, 5.f);
|
|
||||||
pointLight = AddComponent<Components::PointLight>(ent, "PointLight");
|
pointLight = AddComponent<Components::PointLight>(ent, "PointLight");
|
||||||
pointLight->Specular = glm::vec3(1.0, 1.0, 1.0);
|
pointLight->Specular = glm::vec3(1.0, 1.0, 1.0);
|
||||||
pointLight->Diffuse = glm::vec3(1.0, 1.0, 1.0);
|
pointLight->Diffuse = glm::vec3(5.0, 0.0, 0.0);
|
||||||
pointLight->Diffuse = glm::vec3(0.0, 3.0, 0.0);
|
|
||||||
pointLight->constantAttenuation = 0.f;
|
pointLight->constantAttenuation = 0.f;
|
||||||
pointLight->linearAttenuation = 1.f;
|
pointLight->linearAttenuation = 1.f;
|
||||||
pointLight->quadraticAttenuation = 0.f;
|
pointLight->quadraticAttenuation = 0.f;
|
||||||
@@ -93,18 +73,42 @@ void GameWorld::Initialize()
|
|||||||
m_Player = CreateEntity();
|
m_Player = CreateEntity();
|
||||||
SetProperty(m_Player, "Name", std::string("PlayerShip"));
|
SetProperty(m_Player, "Name", std::string("PlayerShip"));
|
||||||
transform = AddComponent<Components::Transform>(m_Player, "Transform");
|
transform = AddComponent<Components::Transform>(m_Player, "Transform");
|
||||||
transform->Position = glm::vec3(0.f, 4.f, -5.f);
|
transform->Position = glm::vec3(0.f, 2.f, -5.f);
|
||||||
transform->Scale = glm::vec3(1.0f);
|
transform->Scale = glm::vec3(1.0f);
|
||||||
model = AddComponent<Components::Model>(m_Player, "Model");
|
model = AddComponent<Components::Model>(m_Player, "Model");
|
||||||
model->ModelFile = "Models/ship.obj";
|
model->ModelFile = "Models/ship.obj";
|
||||||
|
pointLight = AddComponent<Components::PointLight>(m_Player, "PointLight");
|
||||||
|
pointLight->Specular = glm::vec3(1.0, 1.0, 1.0);
|
||||||
|
pointLight->Diffuse = glm::vec3(0.4, 0.4, 1.0);
|
||||||
|
pointLight->constantAttenuation = 0.f;
|
||||||
|
pointLight->linearAttenuation = 1.f;
|
||||||
|
pointLight->quadraticAttenuation = 0.f;
|
||||||
|
pointLight->spotExponent = 0.0f;
|
||||||
AddComponent<Components::Input>(m_Player, "Input");
|
AddComponent<Components::Input>(m_Player, "Input");
|
||||||
collision = AddComponent<Components::Collision>(m_Player, "Collision");
|
collision = AddComponent<Components::Collision>(m_Player, "Collision");
|
||||||
collision->Phantom = false;
|
collision->Phantom = false;
|
||||||
|
collision->Interested = true;
|
||||||
bounds = AddComponent<Components::Bounds>(m_Player, "Bounds");
|
bounds = AddComponent<Components::Bounds>(m_Player, "Bounds");
|
||||||
bounds->Origin = glm::vec3(transform->Position.x, transform->Position.y - 4, transform->Position.z + 3);
|
bounds->Origin = glm::vec3(0, 0, 2.f);
|
||||||
bounds->VolumeVector = glm::vec3(4.f,0.7f,4);
|
bounds->VolumeVector = glm::vec3(4.f, 0.7f, 1);
|
||||||
|
|
||||||
ent = CreateEntity();
|
|
||||||
|
// Camera
|
||||||
|
entcamera = CreateEntity(m_Player);
|
||||||
|
SetProperty(entcamera, "Name", std::string("Camera"));
|
||||||
|
transform = AddComponent<Components::Transform>(entcamera, "Transform");
|
||||||
|
AddComponent<Components::Input>(entcamera, "Input");
|
||||||
|
transform->Position = glm::vec3(0.f, 10.f, 14.f);
|
||||||
|
camera = AddComponent<Components::Camera>(entcamera, "Camera");
|
||||||
|
camera->FOV = 45.f;
|
||||||
|
camera->FarClip = 1000.f;
|
||||||
|
camera->NearClip = 0.01f;
|
||||||
|
transform->Orientation = glm::angleAxis<float>(glm::radians(15.0f),glm::vec3(1,0,0));
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/*ent = CreateEntity();
|
||||||
transform = AddComponent<Components::Transform>(ent, "Transform");
|
transform = AddComponent<Components::Transform>(ent, "Transform");
|
||||||
transform->Position = glm::vec3(10.f, 4.f, 0.f);
|
transform->Position = glm::vec3(10.f, 4.f, 0.f);
|
||||||
model = AddComponent<Components::Model>(ent, "Model");
|
model = AddComponent<Components::Model>(ent, "Model");
|
||||||
@@ -113,7 +117,7 @@ void GameWorld::Initialize()
|
|||||||
collision->Phantom = false;
|
collision->Phantom = false;
|
||||||
bounds = AddComponent<Components::Bounds>(player2, "Bounds");
|
bounds = AddComponent<Components::Bounds>(player2, "Bounds");
|
||||||
bounds->Origin = transform->Position;
|
bounds->Origin = transform->Position;
|
||||||
bounds->VolumeVector = glm::vec3(2.f,2.f,2.f);
|
bounds->VolumeVector = glm::vec3(2.f,2.f,2.f);*/
|
||||||
}
|
}
|
||||||
|
|
||||||
void GameWorld::Update(double dt)
|
void GameWorld::Update(double dt)
|
||||||
|
|||||||
@@ -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 |
@@ -3,12 +3,21 @@
|
|||||||
Renderer::Renderer()
|
Renderer::Renderer()
|
||||||
{
|
{
|
||||||
m_VSync = false;
|
m_VSync = false;
|
||||||
|
#ifdef DEBUG
|
||||||
m_DrawNormals = false;
|
m_DrawNormals = false;
|
||||||
m_DrawWireframe = false;
|
m_DrawWireframe = false;
|
||||||
|
m_DrawBounds = true;
|
||||||
|
#else
|
||||||
|
m_DrawNormals = false;
|
||||||
|
m_DrawWireframe = false;
|
||||||
|
m_DrawBounds = false;
|
||||||
|
#endif
|
||||||
|
|
||||||
m_SunPosition = glm::vec3(0, 10, 10);
|
m_ShadowMapRes = 2048*2;
|
||||||
|
m_SunPosition = glm::vec3(0, 0.3f, 10);
|
||||||
m_SunTarget = glm::vec3(0, 0, 0);
|
m_SunTarget = glm::vec3(0, 0, 0);
|
||||||
m_SunProjection = glm::ortho<float>(-20, 20, -20, 20, -10, 20);
|
m_SunProjection = glm::ortho<float>(-200, 200, -10, 100, -800, 400);
|
||||||
|
Lights = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Renderer::Initialize()
|
void Renderer::Initialize()
|
||||||
@@ -92,7 +101,7 @@ void Renderer::LoadContent()
|
|||||||
|
|
||||||
m_DebugAABB = CreateAABB();
|
m_DebugAABB = CreateAABB();
|
||||||
m_ScreenQuad = CreateQuad();
|
m_ScreenQuad = CreateQuad();
|
||||||
CreateShadowMap(2048*2);
|
CreateShadowMap(m_ShadowMapRes);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Renderer::CreateShadowMap(int resolution)
|
void Renderer::CreateShadowMap(int resolution)
|
||||||
@@ -128,31 +137,33 @@ void Renderer::Draw(double dt)
|
|||||||
DrawScene();
|
DrawScene();
|
||||||
|
|
||||||
#ifdef DEBUG
|
#ifdef DEBUG
|
||||||
glEnable(GL_BLEND);
|
// Draw bounding boxes
|
||||||
glBlendFunc(GL_ONE_MINUS_DST_COLOR, GL_ZERO);
|
if (m_DrawBounds) {
|
||||||
m_ShaderProgramDebugAABB.Bind();
|
glEnable(GL_BLEND);
|
||||||
for (auto tuple : AABBsToRender) {
|
glBlendFunc(GL_ONE_MINUS_DST_COLOR, GL_ZERO);
|
||||||
glm::mat4 modelMatrix;
|
m_ShaderProgramDebugAABB.Bind();
|
||||||
bool colliding;
|
for (auto tuple : AABBsToRender) {
|
||||||
std::tie(modelMatrix, colliding) = tuple;
|
glm::mat4 modelMatrix;
|
||||||
// Model matrix
|
bool colliding;
|
||||||
glm::mat4 cameraMatrix = m_Camera->ProjectionMatrix() * m_Camera->ViewMatrix();
|
std::tie(modelMatrix, colliding) = tuple;
|
||||||
glm::mat4 MVP = cameraMatrix * modelMatrix;
|
// Model matrix
|
||||||
glUniformMatrix4fv(glGetUniformLocation(m_ShaderProgramDebugAABB.GetHandle(), "MVP"), 1, GL_FALSE, glm::value_ptr(MVP));
|
glm::mat4 cameraMatrix = m_Camera->ProjectionMatrix() * m_Camera->ViewMatrix();
|
||||||
// Color
|
glm::mat4 MVP = cameraMatrix * modelMatrix;
|
||||||
glm::vec4 color(1.f, 1.f, 1.f, 0.f);
|
glUniformMatrix4fv(glGetUniformLocation(m_ShaderProgramDebugAABB.GetHandle(), "MVP"), 1, GL_FALSE, glm::value_ptr(MVP));
|
||||||
if (colliding)
|
// Color
|
||||||
color = glm::vec4(1.f, 0.f, 0.f, 0.f);
|
glm::vec4 color(1.f, 1.f, 1.f, 0.f);
|
||||||
glUniform4fv(glGetUniformLocation(m_ShaderProgramDebugAABB.GetHandle(), "Color"), 1, glm::value_ptr(color));
|
if (colliding)
|
||||||
glBindVertexArray(m_DebugAABB);
|
color = glm::vec4(1.f, 0.f, 0.f, 0.f);
|
||||||
glDrawArrays(GL_LINES, 0, 24);
|
glUniform4fv(glGetUniformLocation(m_ShaderProgramDebugAABB.GetHandle(), "Color"), 1, glm::value_ptr(color));
|
||||||
|
glBindVertexArray(m_DebugAABB);
|
||||||
|
glDrawArrays(GL_LINES, 0, 24);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
AABBsToRender.clear();
|
|
||||||
|
//DrawDebugShadowMap();
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
DrawDebugShadowMap();
|
ClearStuff();
|
||||||
|
|
||||||
ModelsToRender.clear();
|
|
||||||
glfwSwapBuffers(m_Window);
|
glfwSwapBuffers(m_Window);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -173,33 +184,51 @@ void Renderer::DrawScene()
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
// Draw models
|
// Draw models
|
||||||
glm::mat4 depthViewMatrix = glm::lookAt(m_SunPosition, m_SunTarget, glm::vec3(0, 1, 0));
|
glm::mat4 depthViewMatrix = glm::lookAt(m_SunPosition, m_SunTarget, glm::vec3(0, 1, 0)) * glm::translate(-m_Camera->Position() * glm::vec3(1, 0, 0));
|
||||||
glm::mat4 depthCamera = m_SunProjection * depthViewMatrix;
|
glm::mat4 depthCamera = m_SunProjection * depthViewMatrix;
|
||||||
glm::mat4 depthMVP = depthCamera;
|
|
||||||
glm::mat4 biasMatrix(
|
glm::mat4 biasMatrix(
|
||||||
0.5, 0.0, 0.0, 0.0,
|
0.5, 0.0, 0.0, 0.0,
|
||||||
0.0, 0.5, 0.0, 0.0,
|
0.0, 0.5, 0.0, 0.0,
|
||||||
0.0, 0.0, 0.5, 0.0,
|
0.0, 0.0, 0.5, 0.0,
|
||||||
0.5, 0.5, 0.5, 1.0
|
0.5, 0.5, 0.5, 1.0
|
||||||
);
|
);
|
||||||
glm::mat4 depthBiasMVP = biasMatrix * depthMVP;
|
|
||||||
|
|
||||||
m_ShaderProgram.Bind();
|
m_ShaderProgram.Bind();
|
||||||
glUniformMatrix4fv(glGetUniformLocation(m_ShaderProgram.GetHandle(), "DepthMVP"), 1, GL_FALSE, glm::value_ptr(depthBiasMVP));
|
glUniform1i(glGetUniformLocation(m_ShaderProgram.GetHandle(), "numberOfLights"), Lights);
|
||||||
glUniform3fv(glGetUniformLocation(m_ShaderProgram.GetHandle(), "position"), 3, Light_position.data());
|
glUniform3fv(glGetUniformLocation(m_ShaderProgram.GetHandle(), "position"), Lights, Light_position.data());
|
||||||
glUniform3fv(glGetUniformLocation(m_ShaderProgram.GetHandle(), "specular"), 3, Light_specular.data());
|
glUniform3fv(glGetUniformLocation(m_ShaderProgram.GetHandle(), "specular"), Lights, Light_specular.data());
|
||||||
glUniform3fv(glGetUniformLocation(m_ShaderProgram.GetHandle(), "diffuse"), 3, Light_diffuse.data());
|
glUniform3fv(glGetUniformLocation(m_ShaderProgram.GetHandle(), "diffuse"), Lights, Light_diffuse.data());
|
||||||
glUniform1fv(glGetUniformLocation(m_ShaderProgram.GetHandle(), "constantAttenuation"), 3, Light_constantAttenuation.data());
|
glUniform1fv(glGetUniformLocation(m_ShaderProgram.GetHandle(), "constantAttenuation"), Lights, Light_constantAttenuation.data());
|
||||||
glUniform1fv(glGetUniformLocation(m_ShaderProgram.GetHandle(), "linearAttenuation"), 3, Light_linearAttenuation.data());
|
glUniform1fv(glGetUniformLocation(m_ShaderProgram.GetHandle(), "linearAttenuation"), Lights, Light_linearAttenuation.data());
|
||||||
glUniform1fv(glGetUniformLocation(m_ShaderProgram.GetHandle(), "quadraticAttenuation"), 3, Light_quadraticAttenuation.data());
|
glUniform1fv(glGetUniformLocation(m_ShaderProgram.GetHandle(), "quadraticAttenuation"), Lights, Light_quadraticAttenuation.data());
|
||||||
glUniform1fv(glGetUniformLocation(m_ShaderProgram.GetHandle(), "spotExponent"), 3, Light_spotExponent.data());
|
glUniform1fv(glGetUniformLocation(m_ShaderProgram.GetHandle(), "spotExponent"), Lights, Light_spotExponent.data());
|
||||||
if (m_DrawWireframe) {
|
if (m_DrawWireframe) {
|
||||||
glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
|
glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
|
||||||
}
|
}
|
||||||
glActiveTexture(GL_TEXTURE1);
|
glActiveTexture(GL_TEXTURE1);
|
||||||
glBindTexture(GL_TEXTURE_2D, m_ShadowDepthTexture);
|
glBindTexture(GL_TEXTURE_2D, m_ShadowDepthTexture);
|
||||||
DrawModels(m_ShaderProgram);
|
//DrawModels(m_ShaderProgram);
|
||||||
|
glm::mat4 cameraMatrix = m_Camera->ProjectionMatrix() * m_Camera->ViewMatrix();
|
||||||
|
glm::mat4 MVP;
|
||||||
|
for (auto tuple : ModelsToRender)
|
||||||
|
{
|
||||||
|
Model* model;
|
||||||
|
glm::mat4 modelMatrix;
|
||||||
|
std::tie(model, modelMatrix) = tuple;
|
||||||
|
MVP = cameraMatrix * modelMatrix;
|
||||||
|
glm::mat4 depthMVP = biasMatrix * depthCamera * modelMatrix;
|
||||||
|
glUniformMatrix4fv(glGetUniformLocation(m_ShaderProgram.GetHandle(), "MVP"), 1, GL_FALSE, glm::value_ptr(MVP));
|
||||||
|
glUniformMatrix4fv(glGetUniformLocation(m_ShaderProgram.GetHandle(), "DepthMVP"), 1, GL_FALSE, glm::value_ptr(depthMVP));
|
||||||
|
glUniformMatrix4fv(glGetUniformLocation(m_ShaderProgram.GetHandle(), "model"), 1, GL_FALSE, glm::value_ptr(modelMatrix));
|
||||||
|
glUniformMatrix4fv(glGetUniformLocation(m_ShaderProgram.GetHandle(), "view"), 1, GL_FALSE, glm::value_ptr(m_Camera->ViewMatrix()));
|
||||||
|
glBindVertexArray(model->VAO);
|
||||||
|
for (auto texGroup : model->TextureGroups) {
|
||||||
|
glActiveTexture(GL_TEXTURE0);
|
||||||
|
glBindTexture(GL_TEXTURE_2D, texGroup.Texture->texture);
|
||||||
|
glDrawArrays(GL_TRIANGLES, texGroup.StartIndex, texGroup.EndIndex - texGroup.StartIndex + 1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#ifdef DEBUG
|
#ifdef DEBUG
|
||||||
// Debug draw model normals
|
// Debug draw model normals
|
||||||
if (m_DrawNormals) {
|
if (m_DrawNormals) {
|
||||||
@@ -217,12 +246,13 @@ void Renderer::DrawShadowMap()
|
|||||||
glCullFace(GL_BACK);
|
glCullFace(GL_BACK);
|
||||||
|
|
||||||
glBindFramebuffer(GL_FRAMEBUFFER, m_ShadowFrameBuffer);
|
glBindFramebuffer(GL_FRAMEBUFFER, m_ShadowFrameBuffer);
|
||||||
glViewport(0, 0, 2048*2, 2048*2);
|
glViewport(0, 0, m_ShadowMapRes, m_ShadowMapRes);
|
||||||
|
|
||||||
glClear(GL_DEPTH_BUFFER_BIT);
|
glClear(GL_DEPTH_BUFFER_BIT);
|
||||||
//glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
|
//glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
|
||||||
|
|
||||||
glm::mat4 depthViewMatrix = glm::lookAt(m_SunPosition, m_SunTarget, glm::vec3(0, 1, 0));
|
glm::mat4 depthViewMatrix = glm::lookAt(m_SunPosition, m_SunTarget, glm::vec3(0, 1, 0)) * glm::translate(-m_Camera->Position() * glm::vec3(1, 0, 0));
|
||||||
|
// glm::mat4 depthViewMatrix = glm::lookAt(m_SunPosition, m_SunTarget, glm::vec3(0, 1, 0));
|
||||||
glm::mat4 depthCamera = m_SunProjection * depthViewMatrix;
|
glm::mat4 depthCamera = m_SunProjection * depthViewMatrix;
|
||||||
|
|
||||||
//glm::mat4 cameraMatrix = depthProjectionMatrix * m_Camera->ViewMatrix();
|
//glm::mat4 cameraMatrix = depthProjectionMatrix * m_Camera->ViewMatrix();
|
||||||
@@ -231,12 +261,13 @@ void Renderer::DrawShadowMap()
|
|||||||
|
|
||||||
m_ShaderProgramShadows.Bind();
|
m_ShaderProgramShadows.Bind();
|
||||||
glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
|
glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
|
||||||
for (int i = 0; i < ModelsToRender.size(); i++)
|
for (auto tuple : ModelsToRender)
|
||||||
{
|
{
|
||||||
ModelData* modelData = ModelsToRender.at(i);
|
Model* model;
|
||||||
auto model = modelData->model;
|
glm::mat4 modelMatrix;
|
||||||
|
std::tie(model, modelMatrix) = tuple;
|
||||||
|
|
||||||
MVP = depthCamera * modelData->ModelMatrix;
|
MVP = depthCamera * modelMatrix;
|
||||||
glUniformMatrix4fv(glGetUniformLocation(m_ShaderProgramShadows.GetHandle(), "MVP"), 1, GL_FALSE, glm::value_ptr(MVP));
|
glUniformMatrix4fv(glGetUniformLocation(m_ShaderProgramShadows.GetHandle(), "MVP"), 1, GL_FALSE, glm::value_ptr(MVP));
|
||||||
|
|
||||||
glBindVertexArray(model->VAO);
|
glBindVertexArray(model->VAO);
|
||||||
@@ -266,14 +297,15 @@ void Renderer::DrawModels(ShaderProgram &shader)
|
|||||||
glm::mat4 cameraMatrix = m_Camera->ProjectionMatrix() * m_Camera->ViewMatrix();
|
glm::mat4 cameraMatrix = m_Camera->ProjectionMatrix() * m_Camera->ViewMatrix();
|
||||||
|
|
||||||
glm::mat4 MVP;
|
glm::mat4 MVP;
|
||||||
for (int i = 0; i < ModelsToRender.size(); i++)
|
for (auto tuple : ModelsToRender)
|
||||||
{
|
{
|
||||||
ModelData* modelData = ModelsToRender.at(i);
|
Model* model;
|
||||||
auto model = modelData->model;
|
glm::mat4 modelMatrix;
|
||||||
|
std::tie(model, modelMatrix) = tuple;
|
||||||
|
|
||||||
MVP = cameraMatrix * modelData->ModelMatrix;
|
MVP = cameraMatrix * modelMatrix;
|
||||||
glUniformMatrix4fv(glGetUniformLocation(shader.GetHandle(), "MVP"), 1, GL_FALSE, glm::value_ptr(MVP));
|
glUniformMatrix4fv(glGetUniformLocation(shader.GetHandle(), "MVP"), 1, GL_FALSE, glm::value_ptr(MVP));
|
||||||
glUniformMatrix4fv(glGetUniformLocation(shader.GetHandle(), "model"), 1, GL_FALSE, glm::value_ptr(modelData->ModelMatrix));
|
glUniformMatrix4fv(glGetUniformLocation(shader.GetHandle(), "model"), 1, GL_FALSE, glm::value_ptr(modelMatrix));
|
||||||
glUniformMatrix4fv(glGetUniformLocation(shader.GetHandle(), "view"), 1, GL_FALSE, glm::value_ptr(m_Camera->ViewMatrix()));
|
glUniformMatrix4fv(glGetUniformLocation(shader.GetHandle(), "view"), 1, GL_FALSE, glm::value_ptr(m_Camera->ViewMatrix()));
|
||||||
glBindVertexArray(model->VAO);
|
glBindVertexArray(model->VAO);
|
||||||
for (auto texGroup : model->TextureGroups) {
|
for (auto texGroup : model->TextureGroups) {
|
||||||
@@ -296,9 +328,9 @@ void Renderer::AddTextToDraw()
|
|||||||
|
|
||||||
void Renderer::AddModelToDraw(std::shared_ptr<Model> model, glm::vec3 position, glm::quat orientation, glm::vec3 scale)
|
void Renderer::AddModelToDraw(std::shared_ptr<Model> model, glm::vec3 position, glm::quat orientation, glm::vec3 scale)
|
||||||
{
|
{
|
||||||
glm::mat4 ModelMatrix = glm::translate(glm::mat4(), position) * glm::toMat4(orientation) * glm::scale(scale);
|
glm::mat4 modelMatrix = glm::translate(glm::mat4(), position) * glm::toMat4(orientation) * glm::scale(scale);
|
||||||
// You can now use ModelMatrix to build the MVP matrix
|
// You can now use ModelMatrix to build the MVP matrix
|
||||||
ModelsToRender.push_back(new ModelData(model, ModelMatrix));
|
ModelsToRender.push_back(std::make_tuple(model.get(), modelMatrix));
|
||||||
}
|
}
|
||||||
|
|
||||||
void Renderer::AddPointLightToDraw(
|
void Renderer::AddPointLightToDraw(
|
||||||
@@ -324,7 +356,7 @@ void Renderer::AddPointLightToDraw(
|
|||||||
Light_linearAttenuation.push_back(_linearAttenuation);
|
Light_linearAttenuation.push_back(_linearAttenuation);
|
||||||
Light_quadraticAttenuation.push_back(_quadraticAttenuation);
|
Light_quadraticAttenuation.push_back(_quadraticAttenuation);
|
||||||
Light_spotExponent.push_back(_spotExponent);
|
Light_spotExponent.push_back(_spotExponent);
|
||||||
|
Lights = Light_constantAttenuation.size();
|
||||||
}
|
}
|
||||||
|
|
||||||
void Renderer::AddAABBToDraw(glm::vec3 origin, glm::vec3 volumeVector, bool colliding)
|
void Renderer::AddAABBToDraw(glm::vec3 origin, glm::vec3 volumeVector, bool colliding)
|
||||||
@@ -426,3 +458,16 @@ GLuint Renderer::CreateAABB()
|
|||||||
|
|
||||||
return vao;
|
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();
|
||||||
|
}
|
||||||
@@ -30,15 +30,8 @@ public:
|
|||||||
|
|
||||||
int HEIGHT, WIDTH;
|
int HEIGHT, WIDTH;
|
||||||
|
|
||||||
struct ModelData
|
std::list<std::tuple<Model*, glm::mat4>> ModelsToRender;
|
||||||
{
|
int Lights;
|
||||||
std::shared_ptr<Model> model;
|
|
||||||
glm::mat4 ModelMatrix;
|
|
||||||
ModelData(std::shared_ptr<Model> _model, glm::mat4 _modelMatrix)
|
|
||||||
: model(_model), ModelMatrix(_modelMatrix) {}
|
|
||||||
};
|
|
||||||
|
|
||||||
std::vector<ModelData*> ModelsToRender;
|
|
||||||
std::vector<float> Light_position;
|
std::vector<float> Light_position;
|
||||||
std::vector<float> Light_specular;
|
std::vector<float> Light_specular;
|
||||||
std::vector<float> Light_diffuse;
|
std::vector<float> Light_diffuse;
|
||||||
@@ -46,7 +39,7 @@ public:
|
|||||||
std::vector<float> Light_linearAttenuation;
|
std::vector<float> Light_linearAttenuation;
|
||||||
std::vector<float> Light_quadraticAttenuation;
|
std::vector<float> Light_quadraticAttenuation;
|
||||||
std::vector<float> Light_spotExponent;
|
std::vector<float> Light_spotExponent;
|
||||||
std::vector<std::tuple<glm::mat4, bool>> AABBsToRender;
|
std::list<std::tuple<glm::mat4, bool>> AABBsToRender;
|
||||||
|
|
||||||
Renderer();
|
Renderer();
|
||||||
|
|
||||||
@@ -76,6 +69,8 @@ public:
|
|||||||
void DrawNormals(bool val) { m_DrawNormals = val; }
|
void DrawNormals(bool val) { m_DrawNormals = val; }
|
||||||
bool DrawWireframe() const { return m_DrawWireframe; }
|
bool DrawWireframe() const { return m_DrawWireframe; }
|
||||||
void DrawWireframe(bool val) { m_DrawWireframe = val; }
|
void DrawWireframe(bool val) { m_DrawWireframe = val; }
|
||||||
|
bool DrawBounds() const { return m_DrawBounds; }
|
||||||
|
void DrawBounds(bool val) { m_DrawBounds = val; }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
GLFWwindow* m_Window;
|
GLFWwindow* m_Window;
|
||||||
@@ -84,7 +79,9 @@ private:
|
|||||||
bool m_VSync;
|
bool m_VSync;
|
||||||
bool m_DrawNormals;
|
bool m_DrawNormals;
|
||||||
bool m_DrawWireframe;
|
bool m_DrawWireframe;
|
||||||
|
bool m_DrawBounds;
|
||||||
|
|
||||||
|
int m_ShadowMapRes;
|
||||||
glm::vec3 m_SunPosition;
|
glm::vec3 m_SunPosition;
|
||||||
glm::vec3 m_SunTarget;
|
glm::vec3 m_SunTarget;
|
||||||
glm::mat4 m_SunProjection;
|
glm::mat4 m_SunProjection;
|
||||||
@@ -101,7 +98,8 @@ private:
|
|||||||
ShaderProgram m_ShaderProgramShadows;
|
ShaderProgram m_ShaderProgramShadows;
|
||||||
ShaderProgram m_ShaderProgramShadowsDrawDepth;
|
ShaderProgram m_ShaderProgramShadowsDrawDepth;
|
||||||
ShaderProgram m_ShaderProgramDebugAABB;
|
ShaderProgram m_ShaderProgramDebugAABB;
|
||||||
|
|
||||||
|
void ClearStuff();
|
||||||
void DrawScene();
|
void DrawScene();
|
||||||
void DrawModels(ShaderProgram &shader);
|
void DrawModels(ShaderProgram &shader);
|
||||||
void DrawShadowMap();
|
void DrawShadowMap();
|
||||||
|
|||||||
@@ -6,15 +6,15 @@ uniform mat4 view;
|
|||||||
layout(binding=0) uniform sampler2D texture0;
|
layout(binding=0) uniform sampler2D texture0;
|
||||||
layout(binding=1) uniform sampler2D shadowMap;
|
layout(binding=1) uniform sampler2D shadowMap;
|
||||||
|
|
||||||
const int numberOfLights = 3;
|
const int maxNumberOfLights = 82;
|
||||||
|
uniform int numberOfLights;
|
||||||
uniform vec3 position[numberOfLights];
|
uniform vec3 position[maxNumberOfLights];
|
||||||
uniform vec3 specular[numberOfLights];
|
uniform vec3 specular[maxNumberOfLights];
|
||||||
uniform vec3 diffuse[numberOfLights];
|
uniform vec3 diffuse[maxNumberOfLights];
|
||||||
uniform float constantAttenuation[numberOfLights];
|
uniform float constantAttenuation[maxNumberOfLights];
|
||||||
uniform float linearAttenuation[numberOfLights];
|
uniform float linearAttenuation[maxNumberOfLights];
|
||||||
uniform float quadraticAttenuation[numberOfLights];
|
uniform float quadraticAttenuation[maxNumberOfLights];
|
||||||
uniform float spotExponent[numberOfLights];
|
uniform float spotExponent[maxNumberOfLights];
|
||||||
|
|
||||||
in VertexData {
|
in VertexData {
|
||||||
vec3 Position;
|
vec3 Position;
|
||||||
@@ -23,7 +23,7 @@ in VertexData {
|
|||||||
vec3 ShadowCoord;
|
vec3 ShadowCoord;
|
||||||
} Input;
|
} Input;
|
||||||
|
|
||||||
vec3 scene_ambient = vec3(0.2);
|
vec3 scene_ambient = vec3(0.3);
|
||||||
|
|
||||||
out vec4 fragmentColor;
|
out vec4 fragmentColor;
|
||||||
|
|
||||||
@@ -49,18 +49,20 @@ void main() {
|
|||||||
//float cosTheta = clamp(dot(Input.Normal, vec3(0, 1, 0)), 0.0, 1.0);
|
//float cosTheta = clamp(dot(Input.Normal, vec3(0, 1, 0)), 0.0, 1.0);
|
||||||
//float bias = 0.001 * tan(acos(cosTheta)); // cosTheta is dot( n,l ), clamped between 0 and 1
|
//float bias = 0.001 * tan(acos(cosTheta)); // cosTheta is dot( n,l ), clamped between 0 and 1
|
||||||
//bias = clamp(bias, 0.0, 0.01);
|
//bias = clamp(bias, 0.0, 0.01);
|
||||||
float bias = 0.003;
|
|
||||||
float visibility = 1.0;
|
float visibility = 1.0;
|
||||||
vec4 shadowMapValue = texture(shadowMap, Input.ShadowCoord.xy);
|
if (Input.ShadowCoord.x >= 0.0 && Input.ShadowCoord.x <= 1.0 && Input.ShadowCoord.y >= 0.0 && Input.ShadowCoord.y <= 1.0) {
|
||||||
if (shadowMapValue.z < Input.ShadowCoord.z - bias) {
|
float bias = 0.003;
|
||||||
visibility = 0.5;
|
vec4 shadowMapValue = texture(shadowMap, Input.ShadowCoord.xy);
|
||||||
|
if (shadowMapValue.z < Input.ShadowCoord.z - bias) {
|
||||||
|
visibility = 0.5;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
vec3 totalLighting = La * Ka * visibility;
|
vec3 totalLighting = La * Ka * visibility;
|
||||||
|
|
||||||
float attenuation;
|
float attenuation;
|
||||||
|
|
||||||
for(int i = 0; i < numberOfLights; i++)
|
for(int i = 0; i < numberOfLights && i < maxNumberOfLights; i++)
|
||||||
{
|
{
|
||||||
// Light
|
// Light
|
||||||
//vec3 lightPosition = vec3(0, 0, 2);
|
//vec3 lightPosition = vec3(0, 0, 2);
|
||||||
|
|||||||
@@ -12,7 +12,7 @@ out vec4 FragmentColor;
|
|||||||
float LinearizeDepth(float z)
|
float LinearizeDepth(float z)
|
||||||
{
|
{
|
||||||
float n = 0.1; // camera z near
|
float n = 0.1; // camera z near
|
||||||
float f = 10.0; // camera z far
|
float f = 800.0; // camera z far
|
||||||
return (2.0 * n) / (f + n - z * (f - n));
|
return (2.0 * n) / (f + n - z * (f - n));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Binary file not shown.
Binary file not shown.
@@ -19,7 +19,9 @@ public:
|
|||||||
virtual void UpdateEntity(double dt, EntityID entity, EntityID parent) { }
|
virtual void UpdateEntity(double dt, EntityID entity, EntityID parent) { }
|
||||||
|
|
||||||
// Called when a component is created
|
// Called when a component is created
|
||||||
virtual void OnComponentCreated(std::string type, std:: shared_ptr<Component> component) { }
|
virtual void OnComponentCreated(std::string type, std::shared_ptr<Component> component) { }
|
||||||
|
// Called when a component is removed
|
||||||
|
virtual void OnComponentRemoved(std::string type, Component* component) { }
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
World* m_World;
|
World* m_World;
|
||||||
|
|||||||
@@ -20,6 +20,10 @@ void Systems::CollisionSystem::UpdateEntity(double dt, EntityID entity, EntityID
|
|||||||
// Clear old collisions
|
// Clear old collisions
|
||||||
collisionComponent->CollidingEntities.clear();
|
collisionComponent->CollidingEntities.clear();
|
||||||
|
|
||||||
|
// Quit out if we're not interested in collision events
|
||||||
|
if (!collisionComponent->Interested)
|
||||||
|
return;
|
||||||
|
|
||||||
auto entities = m_World->GetEntities();
|
auto entities = m_World->GetEntities();
|
||||||
|
|
||||||
for (auto pair : *entities) {
|
for (auto pair : *entities) {
|
||||||
@@ -43,7 +47,8 @@ void Systems::CollisionSystem::UpdateEntity(double dt, EntityID entity, EntityID
|
|||||||
|
|
||||||
//pair.first, pair.second;
|
//pair.first, pair.second;
|
||||||
if(entity == entity2)
|
if(entity == entity2)
|
||||||
break;
|
continue;
|
||||||
|
|
||||||
Intersects(entity, entity2);
|
Intersects(entity, entity2);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -47,6 +47,10 @@ void Systems::InputSystem::Update(double dt)
|
|||||||
if (m_CurrentKeyState[GLFW_KEY_F2] && !m_LastKeyState[GLFW_KEY_F2]) {
|
if (m_CurrentKeyState[GLFW_KEY_F2] && !m_LastKeyState[GLFW_KEY_F2]) {
|
||||||
m_Renderer->DrawNormals(!m_Renderer->DrawNormals());
|
m_Renderer->DrawNormals(!m_Renderer->DrawNormals());
|
||||||
}
|
}
|
||||||
|
// Bounds
|
||||||
|
if (m_CurrentKeyState[GLFW_KEY_F3] && !m_LastKeyState[GLFW_KEY_F3]) {
|
||||||
|
m_Renderer->DrawBounds(!m_Renderer->DrawBounds());
|
||||||
|
}
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -5,14 +5,14 @@ Systems::LevelGenerationSystem::LevelGenerationSystem( World* world )
|
|||||||
{
|
{
|
||||||
elapsedtime = 0;
|
elapsedtime = 0;
|
||||||
|
|
||||||
|
velocity = 0;
|
||||||
startx = 0;
|
startx = 0;
|
||||||
startyz = glm::vec2(0, -1000);
|
startyz = glm::vec2(0, -1000);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Systems::LevelGenerationSystem::SpawnObstacle()
|
void Systems::LevelGenerationSystem::SpawnObstacle()
|
||||||
{
|
{
|
||||||
typeRandom = 0 + (rand() % 3);
|
typeRandom = 0 + (rand() % 10);
|
||||||
|
|
||||||
EntityID ent;
|
EntityID ent;
|
||||||
|
|
||||||
@@ -23,45 +23,64 @@ void Systems::LevelGenerationSystem::SpawnObstacle()
|
|||||||
bounds = m_World->AddComponent<Components::Bounds>(ent, "Bounds");
|
bounds = m_World->AddComponent<Components::Bounds>(ent, "Bounds");
|
||||||
collision = m_World->AddComponent<Components::Collision>(ent, "Collision");
|
collision = m_World->AddComponent<Components::Collision>(ent, "Collision");
|
||||||
model = m_World->AddComponent<Components::Model>(ent, "Model");
|
model = m_World->AddComponent<Components::Model>(ent, "Model");
|
||||||
|
auto sound = m_World->AddComponent<Components::SoundEmitter>(ent, "SoundEmitter");
|
||||||
|
|
||||||
|
|
||||||
positionRandom = -500 + startx + (rand() % 1000);
|
positionRandom = -500 + startx + (rand() % 1000);
|
||||||
|
transform->Position = glm::vec3(positionRandom, startyz);
|
||||||
|
//transform->Velocity = glm::vec3(0.f, 10.f, 100.f);
|
||||||
|
|
||||||
switch (typeRandom)
|
sound->Loop = true;
|
||||||
{
|
sound->Gain = 1.f;
|
||||||
case 0: // Mountain stuff :D
|
sound->ReferenceDistance = 15.f;
|
||||||
|
m_World->GetSystem<Systems::SoundSystem>("SoundSystem")->PlaySound(sound, "Sounds/hum.wav");
|
||||||
|
|
||||||
|
if(typeRandom >= 0 && typeRandom < 2) // Mountain stuff :D
|
||||||
{
|
{
|
||||||
transform->Position = glm::vec3( positionRandom, startyz); // fix position
|
|
||||||
float scale = (float)(rand() % 1000) / 250;
|
float scale = (float)(rand() % 1000) / 250;
|
||||||
transform->Scale = glm::vec3(scale);
|
transform->Scale = glm::vec3(scale);
|
||||||
bounds->VolumeVector = glm::vec3(9, 12, 7);
|
bounds->VolumeVector = glm::vec3(9, 12, 7);
|
||||||
bounds->Origin = glm::vec3(1,11,-1);
|
bounds->Origin = glm::vec3(1,11,-1);
|
||||||
model->ModelFile = "Models/obstacle_mountain_1.obj";
|
model->ModelFile = "Models/obstacle_mountain_1.obj";
|
||||||
}
|
}
|
||||||
break;
|
else if(typeRandom >= 2 && typeRandom < 5) // Single Mountain :D
|
||||||
case 1: // Single Mountain :D
|
|
||||||
{
|
{
|
||||||
transform->Position = glm::vec3( positionRandom, startyz); // fix position
|
|
||||||
float scale = (float)(rand() % 1000) / 200;
|
float scale = (float)(rand() % 1000) / 200;
|
||||||
transform->Scale = glm::vec3(scale);
|
transform->Scale = glm::vec3(scale);
|
||||||
bounds->VolumeVector = glm::vec3(3.5f, 7.5f, 3.5f);
|
bounds->VolumeVector = glm::vec3(3.5f, 7.5f, 3.5f);
|
||||||
bounds->Origin = glm::vec3(0,7.5f,0);
|
bounds->Origin = glm::vec3(0,7.5f,0);
|
||||||
model->ModelFile = "Models/obstacle_mountain_2.obj";
|
model->ModelFile = "Models/obstacle_mountain_2.obj";
|
||||||
}
|
}
|
||||||
break;
|
else if(typeRandom >= 5 && typeRandom < 8)
|
||||||
case 2:
|
|
||||||
{
|
{
|
||||||
transform->Position = glm::vec3( positionRandom, startyz); // fix position
|
|
||||||
float scale = (float)(rand() % 1000) / 100;
|
float scale = (float)(rand() % 1000) / 100;
|
||||||
transform->Scale = glm::vec3(scale);
|
transform->Scale = glm::vec3(scale);
|
||||||
bounds->VolumeVector = glm::vec3(1, 1, 1);
|
bounds->VolumeVector = glm::vec3(1, 1, 1);
|
||||||
bounds->Origin = glm::vec3(0,1,0);
|
bounds->Origin = glm::vec3(0,1,0);
|
||||||
model->ModelFile = "Models/obstacle_cube_1.obj";
|
model->ModelFile = "Models/obstacle_cube_1.obj";
|
||||||
}
|
}
|
||||||
break;
|
if(typeRandom >= 8 && typeRandom < 10)
|
||||||
default:
|
{
|
||||||
|
float scale = (float)(rand() % 1000) / 100;
|
||||||
|
bounds->VolumeVector = glm::vec3(4, 4, 4);
|
||||||
|
bounds->Origin = glm::vec3(0,4,0);
|
||||||
|
pointLight = m_World->AddComponent<Components::PointLight>(ent, "PointLight");
|
||||||
|
pointLight->Specular = glm::vec3(1.0, 1.0, 1.0);
|
||||||
|
pointLight->Diffuse = glm::vec3(0.3, 1.0, 0.3);
|
||||||
|
pointLight->constantAttenuation = 0.f;
|
||||||
|
pointLight->linearAttenuation = 1.f;
|
||||||
|
pointLight->quadraticAttenuation = 0.f;
|
||||||
|
pointLight->spotExponent = 0.0f;
|
||||||
|
|
||||||
break;
|
powerUp = m_World->AddComponent<Components::PowerUp>(ent, "PowerUp");
|
||||||
}
|
powerUp->Speed = 10.f;
|
||||||
|
|
||||||
|
model->ModelFile = "Models/powerup.obj";
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// Put it below ground level
|
||||||
|
transform->Position.y -= bounds->VolumeVector.y * 2.f;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -75,14 +94,22 @@ void Systems::LevelGenerationSystem::Update( double dt )
|
|||||||
elapsedtime = 0;
|
elapsedtime = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::vector<EntityID> removethis;
|
std::list<EntityID> removethis;
|
||||||
|
|
||||||
for(auto ent : obstacles)
|
for(auto ent : obstacles)
|
||||||
{
|
{
|
||||||
auto transformComponent = m_World->GetComponent<Components::Transform>(ent, "Transform");
|
auto transform = m_World->GetComponent<Components::Transform>(ent, "Transform");
|
||||||
transformComponent->Position.z += 100.f * dt;
|
|
||||||
|
|
||||||
if(transformComponent->Position.z > 100)
|
transform->Velocity.z = -velocity;
|
||||||
|
transform->Position += transform->Velocity * (float)dt;
|
||||||
|
|
||||||
|
// Stop raising obstacles when they reach ground level
|
||||||
|
if (transform->Velocity.y > 0 && transform->Position.y >= 0) {
|
||||||
|
transform->Position.y = 0;
|
||||||
|
transform->Velocity.y = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(transform->Position.z > 800)
|
||||||
{
|
{
|
||||||
removethis.push_back(ent);
|
removethis.push_back(ent);
|
||||||
}
|
}
|
||||||
@@ -104,6 +131,7 @@ void Systems::LevelGenerationSystem::UpdateEntity( double dt, EntityID entity, E
|
|||||||
auto transformComponent = m_World->GetComponent<Components::Transform>(entity, "Transform");
|
auto transformComponent = m_World->GetComponent<Components::Transform>(entity, "Transform");
|
||||||
startyz = glm::vec2(0, transformComponent->Position.z - 1000);
|
startyz = glm::vec2(0, transformComponent->Position.z - 1000);
|
||||||
startx = transformComponent->Position.x;
|
startx = transformComponent->Position.x;
|
||||||
|
velocity = transformComponent->Velocity.z;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -2,11 +2,16 @@
|
|||||||
#define LevelGenerationSystem_h__
|
#define LevelGenerationSystem_h__
|
||||||
|
|
||||||
#include "System.h"
|
#include "System.h"
|
||||||
|
#include "Systems/SoundSystem.h"
|
||||||
#include "World.h"
|
#include "World.h"
|
||||||
#include "Components/Transform.h"
|
#include "Components/Transform.h"
|
||||||
#include "Components/Bounds.h"
|
#include "Components/Bounds.h"
|
||||||
#include "Components/Collision.h"
|
#include "Components/Collision.h"
|
||||||
#include "Components/Model.h"
|
#include "Components/Model.h"
|
||||||
|
#include "Components/PointLight.h"
|
||||||
|
#include "Components/SoundEmitter.h"
|
||||||
|
#include "Components/PowerUp.h"
|
||||||
|
|
||||||
|
|
||||||
namespace Systems
|
namespace Systems
|
||||||
{
|
{
|
||||||
@@ -30,12 +35,14 @@ namespace Systems
|
|||||||
double elapsedtime;
|
double elapsedtime;
|
||||||
|
|
||||||
std::list<EntityID> obstacles;
|
std::list<EntityID> obstacles;
|
||||||
|
float velocity;
|
||||||
|
|
||||||
std::shared_ptr<Components::Transform> transform;
|
std::shared_ptr<Components::Transform> transform;
|
||||||
std::shared_ptr<Components::Bounds> bounds;
|
std::shared_ptr<Components::Bounds> bounds;
|
||||||
std::shared_ptr<Components::Collision> collision;
|
std::shared_ptr<Components::Collision> collision;
|
||||||
std::shared_ptr<Components::Model> model;
|
std::shared_ptr<Components::Model> model;
|
||||||
|
std::shared_ptr<Components::PointLight> pointLight;
|
||||||
|
std::shared_ptr<Components::PowerUp> powerUp;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -3,6 +3,8 @@
|
|||||||
|
|
||||||
Systems::PlayerSystem::PlayerSystem( World* world ) : System(world)
|
Systems::PlayerSystem::PlayerSystem( World* world ) : System(world)
|
||||||
{
|
{
|
||||||
|
m_PlayerSpeed = 20;
|
||||||
|
m_PlayerOriginalBounds = glm::vec3(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Systems::PlayerSystem::Update(double dt)
|
void Systems::PlayerSystem::Update(double dt)
|
||||||
@@ -18,14 +20,12 @@ void Systems::PlayerSystem::UpdateEntity(double dt, EntityID entity, EntityID pa
|
|||||||
if (input == nullptr)
|
if (input == nullptr)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
float speed = 50.0f;
|
|
||||||
|
|
||||||
auto name = m_World->GetProperty<std::string>(entity, "Name");
|
auto name = m_World->GetProperty<std::string>(entity, "Name");
|
||||||
if (name == "Camera") {
|
if (name == "Camera") {
|
||||||
|
|
||||||
glm::vec3 Camera_Right = glm::vec3(glm::vec4(1, 0, 0, 0) * transform->Orientation);
|
glm::vec3 Camera_Right = glm::vec3(glm::vec4(1, 0, 0, 0) * transform->Orientation);
|
||||||
glm::vec3 Camera_Forward = glm::vec3(glm::vec4(0, 0, 1, 0) * transform->Orientation);
|
glm::vec3 Camera_Forward = glm::vec3(glm::vec4(0, 0, 1, 0) * transform->Orientation);
|
||||||
|
|
||||||
|
float speed = m_PlayerSpeed;
|
||||||
if(input->KeyState[GLFW_KEY_LEFT_SHIFT]) {
|
if(input->KeyState[GLFW_KEY_LEFT_SHIFT]) {
|
||||||
speed *= 4.0f;
|
speed *= 4.0f;
|
||||||
}
|
}
|
||||||
@@ -59,19 +59,15 @@ void Systems::PlayerSystem::UpdateEntity(double dt, EntityID entity, EntityID pa
|
|||||||
//---------------------------------------------------------------------
|
//---------------------------------------------------------------------
|
||||||
// TOUCHING THIS CODE MIGHT COUSE THE UNIVERSE TO IMPLODE, ALSO DRAGONS
|
// TOUCHING THIS CODE MIGHT COUSE THE UNIVERSE TO IMPLODE, ALSO DRAGONS
|
||||||
}
|
}
|
||||||
|
|
||||||
auto collision = m_World->GetComponent<Components::Collision>(entity, "Collision");
|
|
||||||
if(collision->CollidingEntities.size() > 0) {
|
|
||||||
// DO STUFF
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
name = m_World->GetProperty<std::string>(entity, "Name");
|
|
||||||
if (name == "PlayerShip")
|
if (name == "PlayerShip")
|
||||||
{
|
{
|
||||||
|
auto bounds = m_World->GetComponent<Components::Bounds>(entity, "Bounds");
|
||||||
|
if (bounds && m_PlayerOriginalBounds == glm::vec3(0)) {
|
||||||
|
m_PlayerOriginalBounds = bounds->VolumeVector;
|
||||||
|
}
|
||||||
|
|
||||||
glm::vec3 Ship_Right = glm::vec3(glm::vec4(1, 0, 0, 0));
|
glm::vec3 Ship_Right = glm::vec3(glm::vec4(1, 0, 0, 0));
|
||||||
glm::vec3 Ship_Forward = glm::vec3(glm::vec4(0, 0, 1, 0));
|
glm::vec3 Ship_Forward = glm::vec3(glm::vec4(0, 0, 1, 0));
|
||||||
|
|
||||||
@@ -79,7 +75,7 @@ void Systems::PlayerSystem::UpdateEntity(double dt, EntityID entity, EntityID pa
|
|||||||
glm::vec3 Euler = glm::eulerAngles(transform->Orientation);
|
glm::vec3 Euler = glm::eulerAngles(transform->Orientation);
|
||||||
|
|
||||||
if(input->KeyState[GLFW_KEY_LEFT]) {
|
if(input->KeyState[GLFW_KEY_LEFT]) {
|
||||||
transform->Position -= Ship_Right * (float)dt * speed;
|
transform->Position -= Ship_Right * (float)dt * m_PlayerSpeed;
|
||||||
|
|
||||||
if(Euler.z < 10.f)
|
if(Euler.z < 10.f)
|
||||||
{
|
{
|
||||||
@@ -95,7 +91,7 @@ void Systems::PlayerSystem::UpdateEntity(double dt, EntityID entity, EntityID pa
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if(input->KeyState[GLFW_KEY_RIGHT]) {
|
else if(input->KeyState[GLFW_KEY_RIGHT]) {
|
||||||
transform->Position += Ship_Right * (float)dt * speed;
|
transform->Position += Ship_Right * (float)dt * m_PlayerSpeed;
|
||||||
|
|
||||||
if(Euler.z > -10.f)
|
if(Euler.z > -10.f)
|
||||||
{
|
{
|
||||||
@@ -119,6 +115,12 @@ void Systems::PlayerSystem::UpdateEntity(double dt, EntityID entity, EntityID pa
|
|||||||
else if(Euler.z > 0.f)
|
else if(Euler.z > 0.f)
|
||||||
transform->Orientation = transform->Orientation * glm::angleAxis<float>((float)dt,glm::vec3(0,0,-1));
|
transform->Orientation = transform->Orientation * glm::angleAxis<float>((float)dt,glm::vec3(0,0,-1));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Update player bounds based on rotation
|
||||||
|
if (bounds) {
|
||||||
|
Euler = glm::eulerAngles(transform->Orientation);
|
||||||
|
bounds->VolumeVector.x = m_PlayerOriginalBounds.x * glm::cos(glm::radians(Euler.z));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -7,6 +7,7 @@
|
|||||||
#include "Components/Transform.h"
|
#include "Components/Transform.h"
|
||||||
#include "Components/Input.h"
|
#include "Components/Input.h"
|
||||||
#include "Components/Collision.h"
|
#include "Components/Collision.h"
|
||||||
|
#include "Components/Bounds.h"
|
||||||
#include "logging.h"
|
#include "logging.h"
|
||||||
|
|
||||||
|
|
||||||
@@ -23,7 +24,8 @@ namespace Systems
|
|||||||
void UpdateEntity(double dt, EntityID entity, EntityID parent) override;
|
void UpdateEntity(double dt, EntityID entity, EntityID parent) override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
float m_PlayerSpeed;
|
||||||
|
glm::vec3 m_PlayerOriginalBounds;
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -20,6 +20,7 @@ public:
|
|||||||
void Update(double dt) override;
|
void Update(double dt) override;
|
||||||
void UpdateEntity(double dt, EntityID entity, EntityID parent) override;
|
void UpdateEntity(double dt, EntityID entity, EntityID parent) override;
|
||||||
void OnComponentCreated(std::string type, std::shared_ptr<Component> component) override;
|
void OnComponentCreated(std::string type, std::shared_ptr<Component> component) override;
|
||||||
|
void OnComponentRemoved(std::string type, Component* component) override;
|
||||||
void PlaySound(std::shared_ptr<Components::SoundEmitter> emitter, std::string fileName);
|
void PlaySound(std::shared_ptr<Components::SoundEmitter> emitter, std::string fileName);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
@@ -35,7 +36,7 @@ private:
|
|||||||
unsigned long dataSize;
|
unsigned long dataSize;
|
||||||
|
|
||||||
|
|
||||||
std::map<Component*, ALuint> m_Source;
|
std::map<Component*, ALuint> m_Sources;
|
||||||
std::map<std::string, ALuint> m_BufferCache; // string = fileName
|
std::map<std::string, ALuint> m_BufferCache; // string = fileName
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -18,6 +18,9 @@ Systems::SoundSystem::SoundSystem(World* world)
|
|||||||
}
|
}
|
||||||
|
|
||||||
alGetError();
|
alGetError();
|
||||||
|
|
||||||
|
alSpeedOfSound(340.29f); // Speed of sound
|
||||||
|
alDistanceModel(AL_INVERSE_DISTANCE);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Systems::SoundSystem::Update(double dt)
|
void Systems::SoundSystem::Update(double dt)
|
||||||
@@ -54,10 +57,10 @@ void Systems::SoundSystem::UpdateEntity(double dt, EntityID entity, EntityID par
|
|||||||
auto soundEmitter = m_World->GetComponent<Components::SoundEmitter>(entity, "SoundEmitter");
|
auto soundEmitter = m_World->GetComponent<Components::SoundEmitter>(entity, "SoundEmitter");
|
||||||
if(soundEmitter != nullptr)
|
if(soundEmitter != nullptr)
|
||||||
{
|
{
|
||||||
ALuint source = m_Source[soundEmitter.get()];
|
ALuint source = m_Sources[soundEmitter];
|
||||||
alSourcei(source, AL_GAIN, soundEmitter->Gain);
|
alSourcef(source, AL_GAIN, soundEmitter->Gain);
|
||||||
alSourcei(source, AL_MAX_DISTANCE, soundEmitter->MaxDistance);
|
//alSourcef(source, AL_MAX_DISTANCE, soundEmitter->MaxDistance);
|
||||||
alSourcei(source, AL_REFERENCE_DISTANCE, soundEmitter->ReferenceDistance);
|
alSourcef(source, AL_REFERENCE_DISTANCE, soundEmitter->ReferenceDistance);
|
||||||
alSourcef(source, AL_PITCH, soundEmitter->Pitch);
|
alSourcef(source, AL_PITCH, soundEmitter->Pitch);
|
||||||
alSourcei(source, AL_LOOPING, soundEmitter->Loop);
|
alSourcei(source, AL_LOOPING, soundEmitter->Loop);
|
||||||
|
|
||||||
@@ -74,17 +77,30 @@ void Systems::SoundSystem::UpdateEntity(double dt, EntityID entity, EntityID par
|
|||||||
|
|
||||||
void Systems::SoundSystem::PlaySound(std::shared_ptr<Components::SoundEmitter> emitter, std::string fileName)
|
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 buffer = LoadFile(fileName);
|
||||||
ALuint source = m_Source[emitter.get()];
|
ALuint source = m_Sources[emitter.get()];
|
||||||
alSourcei(source, AL_BUFFER, buffer);
|
alSourcei(source, AL_BUFFER, buffer);
|
||||||
alSourcePlay(m_Source[emitter.get()]);
|
alSourcePlay(m_Sources[emitter.get()]);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Systems::SoundSystem::OnComponentCreated(std::string type, std::shared_ptr<Component> component)
|
void Systems::SoundSystem::OnComponentCreated(std::string type, std::shared_ptr<Component> component)
|
||||||
{
|
{
|
||||||
if(type == "SoundEmitter") {
|
if(type == "SoundEmitter") {
|
||||||
ALuint source = CreateSource();
|
ALuint source = CreateSource();
|
||||||
m_Source[component.get()] = source;
|
m_Sources[component.get()] = source;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void Systems::SoundSystem::OnComponentRemoved(std::string type, Component* component)
|
||||||
|
{
|
||||||
|
if(type == "SoundEmitter") {
|
||||||
|
if (m_Sources.find(component) != m_Sources.end()) {
|
||||||
|
ALuint source = m_Sources[component];
|
||||||
|
alDeleteSources(1, &source);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -61,12 +61,19 @@ bool World::ValidEntity(EntityID entity)
|
|||||||
void World::RemoveEntity(EntityID entity)
|
void World::RemoveEntity(EntityID entity)
|
||||||
{
|
{
|
||||||
m_EntityParents.erase(entity);
|
m_EntityParents.erase(entity);
|
||||||
m_EntityComponents.erase(entity);
|
// Remove components
|
||||||
for (auto pair : m_EntityComponents[entity]) {
|
for (auto pair : m_EntityComponents[entity]) {
|
||||||
auto type = pair.first;
|
auto type = pair.first;
|
||||||
auto component = pair.second;
|
auto component = pair.second;
|
||||||
|
// Trigger events
|
||||||
|
for (auto pair : m_Systems) {
|
||||||
|
auto system = pair.second;
|
||||||
|
system->OnComponentRemoved(type, component.get());
|
||||||
|
}
|
||||||
m_ComponentsOfType[type].remove(component);
|
m_ComponentsOfType[type].remove(component);
|
||||||
}
|
}
|
||||||
|
m_EntityComponents.erase(entity);
|
||||||
|
|
||||||
RecycleEntityID(entity);
|
RecycleEntityID(entity);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -60,7 +60,7 @@ public:
|
|||||||
std::shared_ptr<T> AddComponent(EntityID entity, std::string componentType);
|
std::shared_ptr<T> AddComponent(EntityID entity, std::string componentType);
|
||||||
std::shared_ptr<Component> AddComponent(EntityID entity, std::string componentType);
|
std::shared_ptr<Component> AddComponent(EntityID entity, std::string componentType);
|
||||||
template <class T>
|
template <class T>
|
||||||
std::shared_ptr<T> GetComponent(EntityID entity, std::string componentType);
|
T* GetComponent(EntityID entity, std::string componentType);
|
||||||
|
|
||||||
/*std::vector<EntityID> GetEntityChildren(EntityID entity);*/
|
/*std::vector<EntityID> GetEntityChildren(EntityID entity);*/
|
||||||
|
|
||||||
@@ -117,9 +117,9 @@ std::shared_ptr<T> World::AddComponent(EntityID entity, std::string componentTyp
|
|||||||
|
|
||||||
|
|
||||||
template <class T>
|
template <class T>
|
||||||
std::shared_ptr<T> World::GetComponent(EntityID entity, std::string componentType)
|
T* World::GetComponent(EntityID entity, std::string componentType)
|
||||||
{
|
{
|
||||||
return std::static_pointer_cast<T>(m_EntityComponents[entity][componentType]);
|
return (T*)m_EntityComponents[entity][componentType].get();
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif // World_h__
|
#endif // World_h__
|
||||||
Reference in New Issue
Block a user