Renderables now use TransformComponent's matrix

This commit is contained in:
Kah Wei 2022-09-23 16:41:44 +08:00
parent 04cdb25ddd
commit 77cccd63be
4 changed files with 24 additions and 12 deletions

View File

@ -45,11 +45,7 @@ namespace Sandbox
renderable.Mesh = CUBE_MESH;
renderable.SetMaterial(matInst);
// Create transform
auto& transform = *SHADE::SHComponentManager::GetComponent_s<SHADE::SHTransformComponent>(testObj);
transform.SetLocalPosition(SHVec3{ 0.0f, 0.0f, 2.0f });
renderable.TransformMatrix = SHMatrix::Translate(0.0f, 0.0f, 2.0f);
SHADE::SHScriptEngine* scriptEngine = static_cast<SHADE::SHScriptEngine*>(SHADE::SHSystemManager::GetSystem<SHADE::SHScriptEngine>());
scriptEngine->AddScript(*SHADE::SHEntityManager::GetEntityByID(testObj), "TestScript");
}
@ -58,11 +54,9 @@ namespace Sandbox
{
static float rotation = 0.0f;
auto& renderable = *SHADE::SHComponentManager::GetComponent_s<SHADE::SHRenderable>(testObj);
SHTransform tf;
tf.rotation = SHVec3(rotation, 0.0f, 0.0f);
renderable.TransformMatrix = tf.ComputeTRS();
auto& transform = *SHADE::SHComponentManager::GetComponent_s<SHADE::SHTransformComponent>(testObj);
transform.SetLocalRotation(rotation, 0.0f, 0.0f);
rotation += dt * 10.0f;
// Destroy entity if space is pressed

View File

@ -22,6 +22,8 @@ of DigiPen Institute of Technology is prohibited.
#include "Graphics/Pipeline/SHVkPipeline.h"
#include "Graphics/MiddleEnd/Interface/SHGraphicsConstants.h"
#include "Graphics/MiddleEnd/Interface/SHMaterialInstance.h"
#include "ECS_Base/Managers/SHComponentManager.h"
#include "Math/Transform/SHTransformComponent.h"
namespace SHADE
{
@ -115,7 +117,16 @@ namespace SHADE
for (const SHRenderable* renderable : subBatch.Renderables)
{
// Transform
transformData.emplace_back(renderable->TransformMatrix);
auto transform = SHComponentManager::GetComponent_s<SHTransformComponent>(renderable->GetEID());
if (!transform)
{
SHLOG_WARNING("[SHBatch] Entity contianing a SHRenderable with no SHTransformComponent found!");
transformData.emplace_back();
}
else
{
transformData.emplace_back(transform->GetTRS());
}
}
// Transfer to GPU
@ -190,7 +201,16 @@ namespace SHADE
for (const SHRenderable* renderable : subBatch.Renderables)
{
// Transform
transformData.emplace_back(renderable->TransformMatrix);
auto transform = SHComponentManager::GetComponent_s<SHTransformComponent>(renderable->GetEID());
if (!transform)
{
SHLOG_WARNING("[SHBatch] Entity contianing a SHRenderable with no SHTransformComponent found!");
transformData.emplace_back();
}
else
{
transformData.emplace_back(transform->GetTRS());
}
// Material Properties
if (!EMPTY_MAT_PROPS)
{

View File

@ -92,5 +92,4 @@ namespace SHADE
materialChanged = false;
oldMaterial = {};
}
}

View File

@ -66,7 +66,6 @@ namespace SHADE
/* Data Members */
/*-------------------------------------------------------------------------------*/
Handle<SHMesh> Mesh;
SHMatrix TransformMatrix; // TODO: Replace with Transform component
private:
/*-------------------------------------------------------------------------------*/