diff --git a/Escape-the-Dawn/Camera.cpp b/Escape-the-Dawn/Camera.cpp
index 542864d..316a9a0 100644
--- a/Escape-the-Dawn/Camera.cpp
+++ b/Escape-the-Dawn/Camera.cpp
@@ -78,3 +78,21 @@ void Camera::UpdateViewMatrix()
{
m_ViewMatrix = glm::translate(glm::toMat4(m_Orientation), -m_Position);
}
+
+void Camera::FOV(float val)
+{
+ m_FOV = val;
+ UpdateProjectionMatrix();
+}
+
+void Camera::NearClip(float val)
+{
+ m_NearClip = val;
+ UpdateProjectionMatrix();
+}
+
+void Camera::FarClip(float val)
+{
+ m_FarClip = val;
+ UpdateProjectionMatrix();
+}
diff --git a/Escape-the-Dawn/Components/Model.h b/Escape-the-Dawn/Components/Model.h
index 11297da..dc58640 100644
--- a/Escape-the-Dawn/Components/Model.h
+++ b/Escape-the-Dawn/Components/Model.h
@@ -11,8 +11,10 @@ namespace Components
struct Model : Component
{
- const char* ModelFile;
+ Model() : Visible(true) { }
+ std::string ModelFile;
Color Color;
+ bool Visible;
};
}
diff --git a/Escape-the-Dawn/Escape-the-Dawn.vcxproj b/Escape-the-Dawn/Escape-the-Dawn.vcxproj
index 7f9c2d5..d8c44c3 100644
--- a/Escape-the-Dawn/Escape-the-Dawn.vcxproj
+++ b/Escape-the-Dawn/Escape-the-Dawn.vcxproj
@@ -110,6 +110,7 @@
+
@@ -161,6 +162,7 @@
+
diff --git a/Escape-the-Dawn/Escape-the-Dawn.vcxproj.filters b/Escape-the-Dawn/Escape-the-Dawn.vcxproj.filters
index 7740421..06f96a7 100644
--- a/Escape-the-Dawn/Escape-the-Dawn.vcxproj.filters
+++ b/Escape-the-Dawn/Escape-the-Dawn.vcxproj.filters
@@ -47,6 +47,9 @@
+
+ Systems
+
@@ -148,6 +151,9 @@
+
+ Systems
+
diff --git a/Escape-the-Dawn/GameWorld.cpp b/Escape-the-Dawn/GameWorld.cpp
index 3697aa8..10657cd 100644
--- a/Escape-the-Dawn/GameWorld.cpp
+++ b/Escape-the-Dawn/GameWorld.cpp
@@ -5,14 +5,6 @@ void GameWorld::Initialize()
{
World::Initialize();
- AddSystem("LevelGenerationSystem");
- AddSystem("InputSystem");
- AddSystem("CollisionSystem");
- //AddSystem("ParticleSystem");
- AddSystem("PlayerSystem");
- AddSystem("SoundSystem");
- AddSystem("RenderSystem");
-
std::shared_ptr transform;
std::shared_ptr model;
std::shared_ptr pointLight;
@@ -21,11 +13,8 @@ void GameWorld::Initialize()
std::shared_ptr collision;
EntityID ent;
-
-
-
// Fucking lights
- ent = CreateEntity();
+ /*ent = CreateEntity();
transform = AddComponent(ent, "Transform");
transform->Position = glm::vec3(0.f, 7.f, 0.f);
pointLight = AddComponent(ent, "PointLight");
@@ -60,7 +49,7 @@ void GameWorld::Initialize()
pointLight->quadraticAttenuation = 0.f;
pointLight->spotExponent = 0.0f;
model = AddComponent(ent, "Model");
- model->ModelFile = "Models/sphere.obj";
+ model->ModelFile = "Models/sphere.obj";*/
//ground
ent = CreateEntity();
@@ -91,13 +80,6 @@ void GameWorld::Initialize()
transform->Scale = glm::vec3(1.0f);
model = AddComponent(m_Player, "Model");
model->ModelFile = "Models/ship.obj";
- pointLight = AddComponent(m_Player, "PointLight");
- pointLight->Specular = glm::vec3(1.0, 1.0, 1.0);
- pointLight->Diffuse = glm::vec3(0.4, 0.4, 1.0);
- pointLight->constantAttenuation = 0.f;
- pointLight->linearAttenuation = 1.f;
- pointLight->quadraticAttenuation = 0.f;
- pointLight->spotExponent = 0.0f;
AddComponent(m_Player, "Input");
collision = AddComponent(m_Player, "Collision");
collision->Phantom = false;
@@ -105,12 +87,43 @@ void GameWorld::Initialize()
bounds = AddComponent(m_Player, "Bounds");
bounds->Origin = glm::vec3(0, 0, 2.f);
bounds->VolumeVector = glm::vec3(4.f, 0.7f, 1);
-
-
-
-
-
-
+ // Player light
+ auto playerLight = CreateEntity(m_Player);
+ transform = AddComponent(playerLight, "Transform");
+ transform->Position = glm::vec3(1.5f, 0.25f, 2.5f);
+ pointLight = AddComponent(playerLight, "PointLight");
+ pointLight->Specular = glm::vec3(0.1f, 0.1f, 0.1f);
+ pointLight->Diffuse = glm::vec3(0.45f, 0.65f, 1.f);
+ pointLight->constantAttenuation = 0.f;
+ pointLight->linearAttenuation = 0.9f;
+ pointLight->quadraticAttenuation = 0.f;
+ pointLight->spotExponent = 0.0f;
+ bounds = AddComponent(playerLight, "Bounds");
+ bounds->VolumeVector = glm::vec3(0.5f);
+ playerLight = CreateEntity(m_Player);
+ transform = AddComponent(playerLight, "Transform");
+ transform->Position = glm::vec3(-1.5f, 0.25f, 2.5f);
+ pointLight = AddComponent(playerLight, "PointLight");
+ pointLight->Specular = glm::vec3(0.1f, 0.1f, 0.1f);
+ pointLight->Diffuse = glm::vec3(0.45f, 0.65f, 1.f);
+ pointLight->constantAttenuation = 0.f;
+ pointLight->linearAttenuation = 0.9f;
+ pointLight->quadraticAttenuation = 0.f;
+ pointLight->spotExponent = 0.0f;
+ bounds = AddComponent(playerLight, "Bounds");
+ bounds->VolumeVector = glm::vec3(0.5f);
+ playerLight = CreateEntity(m_Player);
+ transform = AddComponent(playerLight, "Transform");
+ transform->Position = glm::vec3(0.0f, 2.0f, 2.5f);
+ pointLight = AddComponent(playerLight, "PointLight");
+ pointLight->Specular = glm::vec3(0.1f, 0.1f, 0.1f);
+ pointLight->Diffuse = glm::vec3(0.45f, 0.65f, 1.f);
+ pointLight->constantAttenuation = 0.f;
+ pointLight->linearAttenuation = 1.0f;
+ pointLight->quadraticAttenuation = 0.f;
+ pointLight->spotExponent = 0.0f;
+ bounds = AddComponent(playerLight, "Bounds");
+ bounds->VolumeVector = glm::vec3(0.5f);
/*ent = CreateEntity();
transform = AddComponent(ent, "Transform");
@@ -155,5 +168,18 @@ void GameWorld::RegisterSystems()
//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("TransformSystem", [this]() { return new Systems::TransformSystem(this); });
m_SystemFactory.Register("RenderSystem", [this]() { return new Systems::RenderSystem(this, m_Renderer); });
+}
+
+void GameWorld::AddSystems()
+{
+ AddSystem("TransformSystem");
+ AddSystem("LevelGenerationSystem");
+ AddSystem("InputSystem");
+ AddSystem("CollisionSystem");
+ //AddSystem("ParticleSystem");
+ AddSystem("PlayerSystem");
+ AddSystem("SoundSystem");
+ AddSystem("RenderSystem");
}
\ No newline at end of file
diff --git a/Escape-the-Dawn/GameWorld.h b/Escape-the-Dawn/GameWorld.h
index d2ac780..a192608 100644
--- a/Escape-the-Dawn/GameWorld.h
+++ b/Escape-the-Dawn/GameWorld.h
@@ -4,6 +4,7 @@
#include "World.h"
#include "Renderer.h"
+#include "Systems/TransformSystem.h"
#include "Systems/CollisionSystem.h"
#include "Systems/InputSystem.h"
#include "Systems/LevelGenerationSystem.h"
@@ -36,9 +37,10 @@ public:
void Initialize();
void RegisterSystems() override;
+ void AddSystems() override;
void RegisterComponents() override;
- void Update(double dt) ;
+ void Update(double dt);
private:
std::shared_ptr m_Renderer;
diff --git a/Escape-the-Dawn/Renderer.cpp b/Escape-the-Dawn/Renderer.cpp
index 87a7e79..b2e985f 100644
--- a/Escape-the-Dawn/Renderer.cpp
+++ b/Escape-the-Dawn/Renderer.cpp
@@ -14,7 +14,7 @@ Renderer::Renderer()
#endif
m_ShadowMapRes = 2048*2;
- m_SunPosition = glm::vec3(0, 0.3f, 10);
+ m_SunPosition = glm::vec3(0, 1.5f, 10);
m_SunTarget = glm::vec3(0, 0, 0);
m_SunProjection = glm::ortho(-200, 200, -10, 100, -800, 800);
Lights = 0;
@@ -216,7 +216,11 @@ void Renderer::DrawScene()
{
Model* model;
glm::mat4 modelMatrix;
- std::tie(model, modelMatrix) = tuple;
+ bool visible;
+ std::tie(model, modelMatrix, visible) = tuple;
+ if (!visible)
+ continue;
+
MVP = cameraMatrix * modelMatrix;
depthMVP = depthCameraMatrix * modelMatrix;
glUniformMatrix4fv(glGetUniformLocation(m_ShaderProgram.GetHandle(), "MVP"), 1, GL_FALSE, glm::value_ptr(MVP));
@@ -267,7 +271,8 @@ void Renderer::DrawShadowMap()
{
Model* model;
glm::mat4 modelMatrix;
- std::tie(model, modelMatrix) = tuple;
+ bool visible;
+ std::tie(model, modelMatrix, visible) = tuple;
MVP = depthCamera * modelMatrix;
glUniformMatrix4fv(glGetUniformLocation(m_ShaderProgramShadows.GetHandle(), "MVP"), 1, GL_FALSE, glm::value_ptr(MVP));
@@ -296,26 +301,26 @@ void Renderer::DrawDebugShadowMap()
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;
for (auto tuple : ModelsToRender)
{
- Model* model;
- glm::mat4 modelMatrix;
- std::tie(model, modelMatrix) = tuple;
+ 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);
- }
+ 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()
@@ -328,11 +333,11 @@ void Renderer::AddTextToDraw()
//Add to draw shit vector
}
-void Renderer::AddModelToDraw(std::shared_ptr model, glm::vec3 position, glm::quat orientation, glm::vec3 scale)
+void Renderer::AddModelToDraw(std::shared_ptr model, glm::vec3 position, glm::quat orientation, glm::vec3 scale, bool visible)
{
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));
+ ModelsToRender.push_back(std::make_tuple(model.get(), modelMatrix, visible));
}
void Renderer::AddPointLightToDraw(
diff --git a/Escape-the-Dawn/Renderer.h b/Escape-the-Dawn/Renderer.h
index 2c4c492..5c35b4f 100644
--- a/Escape-the-Dawn/Renderer.h
+++ b/Escape-the-Dawn/Renderer.h
@@ -30,7 +30,7 @@ public:
int HEIGHT, WIDTH;
- std::list> ModelsToRender;
+ std::list> ModelsToRender;
int Lights;
std::vector Light_position;
std::vector Light_specular;
@@ -47,7 +47,7 @@ public:
void Draw(double dt);
void DrawText();
- void AddModelToDraw(std::shared_ptr model, glm::vec3 position, glm::quat orientation, glm::vec3 scale);
+ void AddModelToDraw(std::shared_ptr model, glm::vec3 position, glm::quat orientation, glm::vec3 scale, bool visible);
void AddTextToDraw();
void AddPointLightToDraw(
glm::vec3 _position,
diff --git a/Escape-the-Dawn/System.h b/Escape-the-Dawn/System.h
index f62eda9..cbe9cb8 100644
--- a/Escape-the-Dawn/System.h
+++ b/Escape-the-Dawn/System.h
@@ -13,6 +13,8 @@ public:
System(World* world) : m_World(world) { }
virtual ~System() { }
+ virtual void Initialize() { }
+
// Called once per system every tick
virtual void Update(double dt) { }
// Called once for every entity in the world every tick
diff --git a/Escape-the-Dawn/Systems/LevelGenerationSystem.cpp b/Escape-the-Dawn/Systems/LevelGenerationSystem.cpp
index b197318..31e31da 100644
--- a/Escape-the-Dawn/Systems/LevelGenerationSystem.cpp
+++ b/Escape-the-Dawn/Systems/LevelGenerationSystem.cpp
@@ -91,10 +91,8 @@ void Systems::LevelGenerationSystem::Update( double dt )
elapsedtime = 0;
}
-
-
}
void Systems::LevelGenerationSystem::UpdateEntity( double dt, EntityID entity, EntityID parent )
@@ -112,9 +110,15 @@ void Systems::LevelGenerationSystem::UpdateEntity( double dt, EntityID entity, E
transform->Velocity.y = 0;
}
- if(transform->Position.z > 800)
+ auto model = m_World->GetComponent(entity, "Model");
+ if (transform->Position.z > 10 && model->Visible)
+ {
+ model->Visible = false;
+ }
+
+ if(transform->Position.z > 800) {
m_World->RemoveEntity(entity);
-
+ }
}
if( m_World->GetProperty(entity, "Name") == "Player")
diff --git a/Escape-the-Dawn/Systems/RenderSystem.cpp b/Escape-the-Dawn/Systems/RenderSystem.cpp
index 3165a0f..67827bd 100644
--- a/Escape-the-Dawn/Systems/RenderSystem.cpp
+++ b/Escape-the-Dawn/Systems/RenderSystem.cpp
@@ -25,7 +25,9 @@ void Systems::RenderSystem::UpdateEntity( double dt, EntityID entity, EntityID p
}
auto model = m_CachedModels[modelComponent->ModelFile];
- m_Renderer->AddModelToDraw(model, transformComponent->Position, transformComponent->Orientation, transformComponent->Scale);
+ glm::vec3 position = m_TransformSystem->AbsolutePosition(entity);
+ glm::quat orientation = m_TransformSystem->AbsoluteOrientation(entity);
+ m_Renderer->AddModelToDraw(model, position, orientation, transformComponent->Scale, modelComponent->Visible);
}
// Debug draw bounds
@@ -33,7 +35,7 @@ void Systems::RenderSystem::UpdateEntity( double dt, EntityID entity, EntityID p
auto collision = m_World->GetComponent(entity, "Collision");
auto bounds = m_World->GetComponent(entity, "Bounds");
if (bounds != nullptr) {
- glm::vec3 origin = transformComponent->Position + (transformComponent->Scale * bounds->Origin);
+ glm::vec3 origin = m_TransformSystem->AbsolutePosition(entity) + (transformComponent->Scale * bounds->Origin);
glm::vec3 volumeVector = transformComponent->Scale * bounds->VolumeVector;
m_Renderer->AddAABBToDraw(origin, volumeVector, (collision != nullptr && collision->CollidingEntities.size() > 0));
}
@@ -42,8 +44,9 @@ void Systems::RenderSystem::UpdateEntity( double dt, EntityID entity, EntityID p
auto pointLightComponent = m_World->GetComponent(entity, "PointLight");
if (pointLightComponent != nullptr)
{
+ glm::vec3 position = m_TransformSystem->AbsolutePosition(entity);
m_Renderer->AddPointLightToDraw(
- transformComponent->Position,
+ position,
pointLightComponent->Specular,
pointLightComponent->Diffuse,
pointLightComponent->constantAttenuation,
@@ -51,6 +54,7 @@ void Systems::RenderSystem::UpdateEntity( double dt, EntityID entity, EntityID p
pointLightComponent->quadraticAttenuation,
pointLightComponent->spotExponent);
}
+
auto cameraComponent = m_World->GetComponent(entity, "Camera");
if (cameraComponent != nullptr)
{
@@ -63,6 +67,12 @@ void Systems::RenderSystem::UpdateEntity( double dt, EntityID entity, EntityID p
}
}
+void Systems::RenderSystem::Initialize()
+{
+ m_TransformSystem = m_World->GetSystem("TransformSystem");
+}
+
+
diff --git a/Escape-the-Dawn/Systems/RenderSystem.h b/Escape-the-Dawn/Systems/RenderSystem.h
index d2a182f..f9e5ee6 100644
--- a/Escape-the-Dawn/Systems/RenderSystem.h
+++ b/Escape-the-Dawn/Systems/RenderSystem.h
@@ -4,6 +4,7 @@
#include
#include "System.h"
+#include "Systems/TransformSystem.h"
#include "Model.h"
#include "Texture.h"
#include "Components/Model.h"
@@ -22,6 +23,8 @@ namespace Systems
RenderSystem(World* world, std::shared_ptr renderer)
: System(world), m_Renderer(renderer){ }
+ void Initialize() override;
+
std::unordered_map> m_CachedModels;
void OnComponentCreated(std::string type, std:: shared_ptr component) override;
@@ -29,7 +32,7 @@ namespace Systems
private:
std::shared_ptr m_Renderer;
-
+ std::shared_ptr m_TransformSystem;
};
diff --git a/Escape-the-Dawn/Systems/TransformSystem.cpp b/Escape-the-Dawn/Systems/TransformSystem.cpp
new file mode 100644
index 0000000..9cd65fa
--- /dev/null
+++ b/Escape-the-Dawn/Systems/TransformSystem.cpp
@@ -0,0 +1,47 @@
+#include "TransformSystem.h"
+#include "World.h"
+
+//void Systems::TransformSystem::UpdateEntity(double dt, EntityID entity, EntityID parent)
+//{
+// if (parent == 0)
+// return;
+//
+// auto transform = m_World->GetComponent(entity, "Transform");
+// auto parentTransform = m_World->GetComponent(parent, "Transform");
+//
+// transform->Position = parentTransform->Position + transform->RelativePosition;
+//}
+
+glm::vec3 Systems::TransformSystem::AbsolutePosition(EntityID entity)
+{
+ glm::vec3 absPosition;
+ glm::quat accumulativeOrientation;
+
+ do
+ {
+ auto transform = m_World->GetComponent(entity, "Transform");
+ //absPosition += transform->Position;
+ entity = m_World->GetEntityParent(entity);
+ auto transform2 = m_World->GetComponent(entity, "Transform");
+ if (entity != 0)
+ absPosition += transform2->Orientation * transform->Position;
+ else
+ absPosition += transform->Position;
+ } while (entity != 0);
+
+ return absPosition * accumulativeOrientation;
+}
+
+glm::quat Systems::TransformSystem::AbsoluteOrientation(EntityID entity)
+{
+ glm::quat absOrientation;
+
+ do
+ {
+ auto transform = m_World->GetComponent(entity, "Transform");
+ absOrientation *= transform->Orientation;
+ entity = m_World->GetEntityParent(entity);
+ } while (entity != 0);
+
+ return absOrientation;
+}
\ No newline at end of file
diff --git a/Escape-the-Dawn/Systems/TransformSystem.h b/Escape-the-Dawn/Systems/TransformSystem.h
new file mode 100644
index 0000000..b0cc2fa
--- /dev/null
+++ b/Escape-the-Dawn/Systems/TransformSystem.h
@@ -0,0 +1,25 @@
+#ifndef TransformSystem_h__
+#define TransformSystem_h__
+
+#include "System.h"
+#include "Components/Transform.h"
+
+namespace Systems
+{
+
+ class TransformSystem : public System
+ {
+ public:
+ TransformSystem(World* world)
+ : System(world) { }
+
+ //void Update(double dt) override;
+ //void UpdateEntity(double dt, EntityID entity, EntityID parent) override;
+
+ glm::vec3 AbsolutePosition(EntityID entity);
+ glm::quat AbsoluteOrientation(EntityID entity);
+ };
+
+}
+
+#endif // TransformSystem_h__
diff --git a/Escape-the-Dawn/World.cpp b/Escape-the-Dawn/World.cpp
index 1e24e82..15bbe40 100644
--- a/Escape-the-Dawn/World.cpp
+++ b/Escape-the-Dawn/World.cpp
@@ -107,19 +107,14 @@ World::World()
void World::Initialize()
{
RegisterSystems();
+ AddSystems();
+ for (auto system : m_Systems) {
+ system.second->Initialize();
+ }
+
RegisterComponents();
}
-void World::RegisterSystems()
-{
-
-}
-
-void World::RegisterComponents()
-{
-
-}
-
std::shared_ptr World::AddComponent(EntityID entity, std::string componentType)
{
return AddComponent(entity, componentType);
diff --git a/Escape-the-Dawn/World.h b/Escape-the-Dawn/World.h
index 18a0fce..b481397 100644
--- a/Escape-the-Dawn/World.h
+++ b/Escape-the-Dawn/World.h
@@ -25,8 +25,10 @@ public:
virtual void Initialize();
- virtual void RegisterComponents();
- virtual void RegisterSystems();
+ virtual void RegisterSystems() = 0;
+ virtual void AddSystems() = 0;
+ virtual void RegisterComponents() = 0;
+
void AddSystem(std::string systemType);
template