Children transforms relative to parents using TransformSystem::AbsolutePosition and TransformSystem::AbsoluteOrientation
This commit is contained in:
@@ -11,8 +11,10 @@ namespace Components
|
|||||||
|
|
||||||
struct Model : Component
|
struct Model : Component
|
||||||
{
|
{
|
||||||
const char* ModelFile;
|
Model() : Visible(true) { }
|
||||||
|
std::string ModelFile;
|
||||||
Color Color;
|
Color Color;
|
||||||
|
bool Visible;
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -110,6 +110,7 @@
|
|||||||
<ClCompile Include="Renderer.cpp" />
|
<ClCompile Include="Renderer.cpp" />
|
||||||
<ClCompile Include="ShaderProgram.cpp" />
|
<ClCompile Include="ShaderProgram.cpp" />
|
||||||
<ClCompile Include="Systems\CollisionSystem.cpp" />
|
<ClCompile Include="Systems\CollisionSystem.cpp" />
|
||||||
|
<ClCompile Include="Systems\TransformSystem.cpp" />
|
||||||
<ClCompile Include="Texture.cpp" />
|
<ClCompile Include="Texture.cpp" />
|
||||||
<ClCompile Include="TextFrame.cpp" />
|
<ClCompile Include="TextFrame.cpp" />
|
||||||
<ClCompile Include="World.cpp" />
|
<ClCompile Include="World.cpp" />
|
||||||
@@ -161,6 +162,7 @@
|
|||||||
<ClInclude Include="Systems\PlayerSystem.h" />
|
<ClInclude Include="Systems\PlayerSystem.h" />
|
||||||
<ClInclude Include="Systems\RenderSystem.h" />
|
<ClInclude Include="Systems\RenderSystem.h" />
|
||||||
<ClInclude Include="Systems\SoundSystem.h" />
|
<ClInclude Include="Systems\SoundSystem.h" />
|
||||||
|
<ClInclude Include="Systems\TransformSystem.h" />
|
||||||
<ClInclude Include="Texture.h" />
|
<ClInclude Include="Texture.h" />
|
||||||
<ClInclude Include="TextFrame.h" />
|
<ClInclude Include="TextFrame.h" />
|
||||||
<ClInclude Include="World.h" />
|
<ClInclude Include="World.h" />
|
||||||
|
|||||||
@@ -47,6 +47,9 @@
|
|||||||
<ClCompile Include="OBJ.cpp" />
|
<ClCompile Include="OBJ.cpp" />
|
||||||
<ClCompile Include="main.cpp" />
|
<ClCompile Include="main.cpp" />
|
||||||
<ClCompile Include="GameWorld.cpp" />
|
<ClCompile Include="GameWorld.cpp" />
|
||||||
|
<ClCompile Include="Systems\TransformSystem.cpp">
|
||||||
|
<Filter>Systems</Filter>
|
||||||
|
</ClCompile>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ClInclude Include="Component.h" />
|
<ClInclude Include="Component.h" />
|
||||||
@@ -148,6 +151,9 @@
|
|||||||
<ClInclude Include="Camera.h" />
|
<ClInclude Include="Camera.h" />
|
||||||
<ClInclude Include="OBJ.h" />
|
<ClInclude Include="OBJ.h" />
|
||||||
<ClInclude Include="OpenGL.h" />
|
<ClInclude Include="OpenGL.h" />
|
||||||
|
<ClInclude Include="Systems\TransformSystem.h">
|
||||||
|
<Filter>Systems</Filter>
|
||||||
|
</ClInclude>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<None Include="Shaders\Fragment.glsl">
|
<None Include="Shaders\Fragment.glsl">
|
||||||
|
|||||||
@@ -5,14 +5,6 @@ void GameWorld::Initialize()
|
|||||||
{
|
{
|
||||||
World::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::Transform> transform;
|
||||||
std::shared_ptr<Components::Model> model;
|
std::shared_ptr<Components::Model> model;
|
||||||
std::shared_ptr<Components::PointLight> pointLight;
|
std::shared_ptr<Components::PointLight> pointLight;
|
||||||
@@ -21,11 +13,8 @@ void GameWorld::Initialize()
|
|||||||
std::shared_ptr<Components::Collision> collision;
|
std::shared_ptr<Components::Collision> collision;
|
||||||
EntityID ent;
|
EntityID ent;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// 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, 7.f, 0.f);
|
transform->Position = glm::vec3(0.f, 7.f, 0.f);
|
||||||
pointLight = AddComponent<Components::PointLight>(ent, "PointLight");
|
pointLight = AddComponent<Components::PointLight>(ent, "PointLight");
|
||||||
@@ -60,7 +49,7 @@ void GameWorld::Initialize()
|
|||||||
pointLight->quadraticAttenuation = 0.f;
|
pointLight->quadraticAttenuation = 0.f;
|
||||||
pointLight->spotExponent = 0.0f;
|
pointLight->spotExponent = 0.0f;
|
||||||
model = AddComponent<Components::Model>(ent, "Model");
|
model = AddComponent<Components::Model>(ent, "Model");
|
||||||
model->ModelFile = "Models/sphere.obj";
|
model->ModelFile = "Models/sphere.obj";*/
|
||||||
|
|
||||||
//ground
|
//ground
|
||||||
ent = CreateEntity();
|
ent = CreateEntity();
|
||||||
@@ -91,13 +80,6 @@ void GameWorld::Initialize()
|
|||||||
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;
|
||||||
@@ -105,12 +87,43 @@ void GameWorld::Initialize()
|
|||||||
bounds = AddComponent<Components::Bounds>(m_Player, "Bounds");
|
bounds = AddComponent<Components::Bounds>(m_Player, "Bounds");
|
||||||
bounds->Origin = glm::vec3(0, 0, 2.f);
|
bounds->Origin = glm::vec3(0, 0, 2.f);
|
||||||
bounds->VolumeVector = glm::vec3(4.f, 0.7f, 1);
|
bounds->VolumeVector = glm::vec3(4.f, 0.7f, 1);
|
||||||
|
// Player light
|
||||||
|
auto playerLight = CreateEntity(m_Player);
|
||||||
|
transform = AddComponent<Components::Transform>(playerLight, "Transform");
|
||||||
|
transform->Position = glm::vec3(1.5f, 0.25f, 2.5f);
|
||||||
|
pointLight = AddComponent<Components::PointLight>(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<Components::Bounds>(playerLight, "Bounds");
|
||||||
|
bounds->VolumeVector = glm::vec3(0.5f);
|
||||||
|
playerLight = CreateEntity(m_Player);
|
||||||
|
transform = AddComponent<Components::Transform>(playerLight, "Transform");
|
||||||
|
transform->Position = glm::vec3(-1.5f, 0.25f, 2.5f);
|
||||||
|
pointLight = AddComponent<Components::PointLight>(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<Components::Bounds>(playerLight, "Bounds");
|
||||||
|
bounds->VolumeVector = glm::vec3(0.5f);
|
||||||
|
playerLight = CreateEntity(m_Player);
|
||||||
|
transform = AddComponent<Components::Transform>(playerLight, "Transform");
|
||||||
|
transform->Position = glm::vec3(0.0f, 2.0f, 2.5f);
|
||||||
|
pointLight = AddComponent<Components::PointLight>(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<Components::Bounds>(playerLight, "Bounds");
|
||||||
|
bounds->VolumeVector = glm::vec3(0.5f);
|
||||||
|
|
||||||
/*ent = CreateEntity();
|
/*ent = CreateEntity();
|
||||||
transform = AddComponent<Components::Transform>(ent, "Transform");
|
transform = AddComponent<Components::Transform>(ent, "Transform");
|
||||||
@@ -155,5 +168,18 @@ void GameWorld::RegisterSystems()
|
|||||||
//m_SystemFactory.Register("ParticleSystem", [this]() { return new Systems::ParticleSystem(this); });
|
//m_SystemFactory.Register("ParticleSystem", [this]() { return new Systems::ParticleSystem(this); });
|
||||||
m_SystemFactory.Register("PlayerSystem", [this]() { return new Systems::PlayerSystem(this); });
|
m_SystemFactory.Register("PlayerSystem", [this]() { return new Systems::PlayerSystem(this); });
|
||||||
m_SystemFactory.Register("SoundSystem", [this]() { return new Systems::SoundSystem(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); });
|
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");
|
||||||
|
}
|
||||||
@@ -4,6 +4,7 @@
|
|||||||
#include "World.h"
|
#include "World.h"
|
||||||
#include "Renderer.h"
|
#include "Renderer.h"
|
||||||
|
|
||||||
|
#include "Systems/TransformSystem.h"
|
||||||
#include "Systems/CollisionSystem.h"
|
#include "Systems/CollisionSystem.h"
|
||||||
#include "Systems/InputSystem.h"
|
#include "Systems/InputSystem.h"
|
||||||
#include "Systems/LevelGenerationSystem.h"
|
#include "Systems/LevelGenerationSystem.h"
|
||||||
@@ -36,9 +37,10 @@ public:
|
|||||||
void Initialize();
|
void Initialize();
|
||||||
|
|
||||||
void RegisterSystems() override;
|
void RegisterSystems() override;
|
||||||
|
void AddSystems() override;
|
||||||
void RegisterComponents() override;
|
void RegisterComponents() override;
|
||||||
|
|
||||||
void Update(double dt) ;
|
void Update(double dt);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::shared_ptr<Renderer> m_Renderer;
|
std::shared_ptr<Renderer> m_Renderer;
|
||||||
|
|||||||
@@ -14,7 +14,7 @@ Renderer::Renderer()
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
m_ShadowMapRes = 2048*2;
|
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_SunTarget = glm::vec3(0, 0, 0);
|
||||||
m_SunProjection = glm::ortho<float>(-200, 200, -10, 100, -800, 800);
|
m_SunProjection = glm::ortho<float>(-200, 200, -10, 100, -800, 800);
|
||||||
Lights = 0;
|
Lights = 0;
|
||||||
@@ -216,7 +216,11 @@ void Renderer::DrawScene()
|
|||||||
{
|
{
|
||||||
Model* model;
|
Model* model;
|
||||||
glm::mat4 modelMatrix;
|
glm::mat4 modelMatrix;
|
||||||
std::tie(model, modelMatrix) = tuple;
|
bool visible;
|
||||||
|
std::tie(model, modelMatrix, visible) = tuple;
|
||||||
|
if (!visible)
|
||||||
|
continue;
|
||||||
|
|
||||||
MVP = cameraMatrix * modelMatrix;
|
MVP = cameraMatrix * modelMatrix;
|
||||||
depthMVP = depthCameraMatrix * modelMatrix;
|
depthMVP = depthCameraMatrix * modelMatrix;
|
||||||
glUniformMatrix4fv(glGetUniformLocation(m_ShaderProgram.GetHandle(), "MVP"), 1, GL_FALSE, glm::value_ptr(MVP));
|
glUniformMatrix4fv(glGetUniformLocation(m_ShaderProgram.GetHandle(), "MVP"), 1, GL_FALSE, glm::value_ptr(MVP));
|
||||||
@@ -267,7 +271,8 @@ void Renderer::DrawShadowMap()
|
|||||||
{
|
{
|
||||||
Model* model;
|
Model* model;
|
||||||
glm::mat4 modelMatrix;
|
glm::mat4 modelMatrix;
|
||||||
std::tie(model, modelMatrix) = tuple;
|
bool visible;
|
||||||
|
std::tie(model, modelMatrix, visible) = tuple;
|
||||||
|
|
||||||
MVP = depthCamera * 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));
|
||||||
@@ -296,26 +301,26 @@ void Renderer::DrawDebugShadowMap()
|
|||||||
|
|
||||||
void Renderer::DrawModels(ShaderProgram &shader)
|
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 (auto tuple : ModelsToRender)
|
for (auto tuple : ModelsToRender)
|
||||||
{
|
{
|
||||||
Model* model;
|
Model* model;
|
||||||
glm::mat4 modelMatrix;
|
glm::mat4 modelMatrix;
|
||||||
std::tie(model, modelMatrix) = tuple;
|
std::tie(model, modelMatrix) = tuple;
|
||||||
|
|
||||||
MVP = cameraMatrix * 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(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) {
|
||||||
glActiveTexture(GL_TEXTURE0);
|
glActiveTexture(GL_TEXTURE0);
|
||||||
glBindTexture(GL_TEXTURE_2D, texGroup.Texture->texture);
|
glBindTexture(GL_TEXTURE_2D, texGroup.Texture->texture);
|
||||||
glDrawArrays(GL_TRIANGLES, texGroup.StartIndex, texGroup.EndIndex - texGroup.StartIndex + 1);
|
glDrawArrays(GL_TRIANGLES, texGroup.StartIndex, texGroup.EndIndex - texGroup.StartIndex + 1);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
}*/
|
||||||
}
|
}
|
||||||
|
|
||||||
void Renderer::DrawText()
|
void Renderer::DrawText()
|
||||||
@@ -328,11 +333,11 @@ void Renderer::AddTextToDraw()
|
|||||||
//Add to draw shit vector
|
//Add to draw shit vector
|
||||||
}
|
}
|
||||||
|
|
||||||
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, bool visible)
|
||||||
{
|
{
|
||||||
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(std::make_tuple(model.get(), modelMatrix));
|
ModelsToRender.push_back(std::make_tuple(model.get(), modelMatrix, visible));
|
||||||
}
|
}
|
||||||
|
|
||||||
void Renderer::AddPointLightToDraw(
|
void Renderer::AddPointLightToDraw(
|
||||||
|
|||||||
@@ -30,7 +30,7 @@ public:
|
|||||||
|
|
||||||
int HEIGHT, WIDTH;
|
int HEIGHT, WIDTH;
|
||||||
|
|
||||||
std::list<std::tuple<Model*, glm::mat4>> ModelsToRender;
|
std::list<std::tuple<Model*, glm::mat4, bool>> ModelsToRender;
|
||||||
int Lights;
|
int Lights;
|
||||||
std::vector<float> Light_position;
|
std::vector<float> Light_position;
|
||||||
std::vector<float> Light_specular;
|
std::vector<float> Light_specular;
|
||||||
@@ -47,7 +47,7 @@ public:
|
|||||||
void Draw(double dt);
|
void Draw(double dt);
|
||||||
void DrawText();
|
void DrawText();
|
||||||
|
|
||||||
void AddModelToDraw(std::shared_ptr<Model> model, glm::vec3 position, glm::quat orientation, glm::vec3 scale);
|
void AddModelToDraw(std::shared_ptr<Model> model, glm::vec3 position, glm::quat orientation, glm::vec3 scale, bool visible);
|
||||||
void AddTextToDraw();
|
void AddTextToDraw();
|
||||||
void AddPointLightToDraw(
|
void AddPointLightToDraw(
|
||||||
glm::vec3 _position,
|
glm::vec3 _position,
|
||||||
|
|||||||
@@ -13,6 +13,8 @@ public:
|
|||||||
System(World* world) : m_World(world) { }
|
System(World* world) : m_World(world) { }
|
||||||
virtual ~System() { }
|
virtual ~System() { }
|
||||||
|
|
||||||
|
virtual void Initialize() { }
|
||||||
|
|
||||||
// Called once per system every tick
|
// Called once per system every tick
|
||||||
virtual void Update(double dt) { }
|
virtual void Update(double dt) { }
|
||||||
// Called once for every entity in the world every tick
|
// Called once for every entity in the world every tick
|
||||||
|
|||||||
@@ -93,6 +93,7 @@ void Systems::LevelGenerationSystem::Update( double dt )
|
|||||||
for(auto ent : obstacles)
|
for(auto ent : obstacles)
|
||||||
{
|
{
|
||||||
auto transform = m_World->GetComponent<Components::Transform>(ent, "Transform");
|
auto transform = m_World->GetComponent<Components::Transform>(ent, "Transform");
|
||||||
|
auto model = m_World->GetComponent<Components::Model>(ent, "Model");
|
||||||
|
|
||||||
transform->Velocity.z = velocity;
|
transform->Velocity.z = velocity;
|
||||||
transform->Position += transform->Velocity * (float)dt;
|
transform->Position += transform->Velocity * (float)dt;
|
||||||
@@ -103,7 +104,12 @@ void Systems::LevelGenerationSystem::Update( double dt )
|
|||||||
transform->Velocity.y = 0;
|
transform->Velocity.y = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(transform->Position.z > 800)
|
if (transform->Position.z > 10 && model->Visible)
|
||||||
|
{
|
||||||
|
model->Visible = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(transform->Position.z > 2000)
|
||||||
{
|
{
|
||||||
removethis.push_back(ent);
|
removethis.push_back(ent);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -25,7 +25,9 @@ void Systems::RenderSystem::UpdateEntity( double dt, EntityID entity, EntityID p
|
|||||||
}
|
}
|
||||||
|
|
||||||
auto model = m_CachedModels[modelComponent->ModelFile];
|
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
|
// Debug draw bounds
|
||||||
@@ -33,7 +35,7 @@ void Systems::RenderSystem::UpdateEntity( double dt, EntityID entity, EntityID p
|
|||||||
auto collision = m_World->GetComponent<Components::Collision>(entity, "Collision");
|
auto collision = m_World->GetComponent<Components::Collision>(entity, "Collision");
|
||||||
auto bounds = m_World->GetComponent<Components::Bounds>(entity, "Bounds");
|
auto bounds = m_World->GetComponent<Components::Bounds>(entity, "Bounds");
|
||||||
if (bounds != nullptr) {
|
if (bounds != nullptr) {
|
||||||
glm::vec3 origin = transformComponent->Position + (transformComponent->Scale * bounds->Origin);
|
glm::vec3 origin = m_TransformSystem->AbsolutePosition(entity) + (transformComponent->Scale * bounds->Origin);
|
||||||
glm::vec3 volumeVector = transformComponent->Scale * bounds->VolumeVector;
|
glm::vec3 volumeVector = transformComponent->Scale * bounds->VolumeVector;
|
||||||
m_Renderer->AddAABBToDraw(origin, volumeVector, (collision != nullptr && collision->CollidingEntities.size() > 0));
|
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<Components::PointLight>(entity, "PointLight");
|
auto pointLightComponent = m_World->GetComponent<Components::PointLight>(entity, "PointLight");
|
||||||
if (pointLightComponent != nullptr)
|
if (pointLightComponent != nullptr)
|
||||||
{
|
{
|
||||||
|
glm::vec3 position = m_TransformSystem->AbsolutePosition(entity);
|
||||||
m_Renderer->AddPointLightToDraw(
|
m_Renderer->AddPointLightToDraw(
|
||||||
transformComponent->Position,
|
position,
|
||||||
pointLightComponent->Specular,
|
pointLightComponent->Specular,
|
||||||
pointLightComponent->Diffuse,
|
pointLightComponent->Diffuse,
|
||||||
pointLightComponent->constantAttenuation,
|
pointLightComponent->constantAttenuation,
|
||||||
@@ -51,6 +54,7 @@ void Systems::RenderSystem::UpdateEntity( double dt, EntityID entity, EntityID p
|
|||||||
pointLightComponent->quadraticAttenuation,
|
pointLightComponent->quadraticAttenuation,
|
||||||
pointLightComponent->spotExponent);
|
pointLightComponent->spotExponent);
|
||||||
}
|
}
|
||||||
|
|
||||||
auto cameraComponent = m_World->GetComponent<Components::Camera>(entity, "Camera");
|
auto cameraComponent = m_World->GetComponent<Components::Camera>(entity, "Camera");
|
||||||
if (cameraComponent != nullptr)
|
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<Systems::TransformSystem>("TransformSystem");
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -4,6 +4,7 @@
|
|||||||
#include <unordered_map>
|
#include <unordered_map>
|
||||||
|
|
||||||
#include "System.h"
|
#include "System.h"
|
||||||
|
#include "Systems/TransformSystem.h"
|
||||||
#include "Model.h"
|
#include "Model.h"
|
||||||
#include "Texture.h"
|
#include "Texture.h"
|
||||||
#include "Components/Model.h"
|
#include "Components/Model.h"
|
||||||
@@ -22,6 +23,8 @@ namespace Systems
|
|||||||
RenderSystem(World* world, std::shared_ptr<Renderer> renderer)
|
RenderSystem(World* world, std::shared_ptr<Renderer> renderer)
|
||||||
: System(world), m_Renderer(renderer){ }
|
: System(world), m_Renderer(renderer){ }
|
||||||
|
|
||||||
|
void Initialize() override;
|
||||||
|
|
||||||
std::unordered_map<std::string, std::shared_ptr<Model>> m_CachedModels;
|
std::unordered_map<std::string, std::shared_ptr<Model>> m_CachedModels;
|
||||||
|
|
||||||
void OnComponentCreated(std::string type, std:: shared_ptr<Component> component) override;
|
void OnComponentCreated(std::string type, std:: shared_ptr<Component> component) override;
|
||||||
@@ -29,7 +32,7 @@ namespace Systems
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
std::shared_ptr<Renderer> m_Renderer;
|
std::shared_ptr<Renderer> m_Renderer;
|
||||||
|
std::shared_ptr<Systems::TransformSystem> m_TransformSystem;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -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<Components::Transform>(entity, "Transform");
|
||||||
|
// auto parentTransform = m_World->GetComponent<Components::Transform>(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<Components::Transform>(entity, "Transform");
|
||||||
|
//absPosition += transform->Position;
|
||||||
|
entity = m_World->GetEntityParent(entity);
|
||||||
|
auto transform2 = m_World->GetComponent<Components::Transform>(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<Components::Transform>(entity, "Transform");
|
||||||
|
absOrientation *= transform->Orientation;
|
||||||
|
entity = m_World->GetEntityParent(entity);
|
||||||
|
} while (entity != 0);
|
||||||
|
|
||||||
|
return absOrientation;
|
||||||
|
}
|
||||||
@@ -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__
|
||||||
@@ -107,19 +107,14 @@ World::World()
|
|||||||
void World::Initialize()
|
void World::Initialize()
|
||||||
{
|
{
|
||||||
RegisterSystems();
|
RegisterSystems();
|
||||||
|
AddSystems();
|
||||||
|
for (auto system : m_Systems) {
|
||||||
|
system.second->Initialize();
|
||||||
|
}
|
||||||
|
|
||||||
RegisterComponents();
|
RegisterComponents();
|
||||||
}
|
}
|
||||||
|
|
||||||
void World::RegisterSystems()
|
|
||||||
{
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
void World::RegisterComponents()
|
|
||||||
{
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
std::shared_ptr<Component> World::AddComponent(EntityID entity, std::string componentType)
|
std::shared_ptr<Component> World::AddComponent(EntityID entity, std::string componentType)
|
||||||
{
|
{
|
||||||
return AddComponent<Component>(entity, componentType);
|
return AddComponent<Component>(entity, componentType);
|
||||||
|
|||||||
@@ -25,8 +25,10 @@ public:
|
|||||||
|
|
||||||
virtual void Initialize();
|
virtual void Initialize();
|
||||||
|
|
||||||
virtual void RegisterComponents();
|
virtual void RegisterSystems() = 0;
|
||||||
virtual void RegisterSystems();
|
virtual void AddSystems() = 0;
|
||||||
|
virtual void RegisterComponents() = 0;
|
||||||
|
|
||||||
|
|
||||||
void AddSystem(std::string systemType);
|
void AddSystem(std::string systemType);
|
||||||
template <class T>
|
template <class T>
|
||||||
|
|||||||
Reference in New Issue
Block a user