Children transforms relative to parents using TransformSystem::AbsolutePosition and TransformSystem::AbsoluteOrientation
This commit is contained in:
@@ -93,6 +93,7 @@ void Systems::LevelGenerationSystem::Update( double dt )
|
||||
for(auto ent : obstacles)
|
||||
{
|
||||
auto transform = m_World->GetComponent<Components::Transform>(ent, "Transform");
|
||||
auto model = m_World->GetComponent<Components::Model>(ent, "Model");
|
||||
|
||||
transform->Velocity.z = velocity;
|
||||
transform->Position += transform->Velocity * (float)dt;
|
||||
@@ -103,7 +104,12 @@ void Systems::LevelGenerationSystem::Update( double dt )
|
||||
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);
|
||||
}
|
||||
|
||||
@@ -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<Components::Collision>(entity, "Collision");
|
||||
auto bounds = m_World->GetComponent<Components::Bounds>(entity, "Bounds");
|
||||
if (bounds != nullptr) {
|
||||
glm::vec3 origin = transformComponent->Position + (transformComponent->Scale * bounds->Origin);
|
||||
glm::vec3 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<Components::PointLight>(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<Components::Camera>(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<Systems::TransformSystem>("TransformSystem");
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
#include <unordered_map>
|
||||
|
||||
#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> renderer)
|
||||
: System(world), m_Renderer(renderer){ }
|
||||
|
||||
void Initialize() override;
|
||||
|
||||
std::unordered_map<std::string, std::shared_ptr<Model>> m_CachedModels;
|
||||
|
||||
void OnComponentCreated(std::string type, std:: shared_ptr<Component> component) override;
|
||||
@@ -29,7 +32,7 @@ namespace Systems
|
||||
|
||||
private:
|
||||
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__
|
||||
Reference in New Issue
Block a user