Naming, comments and local to world update

This commit is contained in:
max
2024-10-13 01:05:46 +02:00
parent 30deeca452
commit b3adef3a40
3 changed files with 48 additions and 6 deletions

View File

@ -3,13 +3,21 @@ using Nerfed.Runtime.Components;
using Nerfed.Runtime.Util;
using System.Numerics;
// TODO:
// Explore if having a WorldTransform and LocalTransfom component each holding position, rotation, scale values and the matricies is useful.
// Often you need to either get or set these values.
// If so, we probably need a utility funciton to do so. Since changing these values means that we need to update all the related data + children as well.
// TODO:
// When modifying transform all the children need to be updated as well.
namespace Nerfed.Runtime.Systems
{
public class TransformSystem : MoonTools.ECS.System
public class LocalToWorldSystem : MoonTools.ECS.System
{
private readonly Filter rootEntitiesFilter;
public TransformSystem(World world) : base(world)
public LocalToWorldSystem(World world) : base(world)
{
rootEntitiesFilter = FilterBuilder.Include<LocalTransform>().Exclude<Parent>().Build();
}
@ -27,8 +35,8 @@ namespace Nerfed.Runtime.Systems
private void UpdateWorldTransform(in Entity entity, in Matrix4x4 parentLocalToWorld)
{
// TODO: Only update dirty transforms.
// Maybe store the local transform matrix.
// If something is dirty all the children need to update their localToWorld matrix.
// If a parent is dirty all the children need to update their localToWorld matrix.
// How do we check if something is dirty? How do we know if a LocalTransform has been changed?
LocalTransform localTransform = Get<LocalTransform>(entity);
Matrix4x4 localToWorldMatrix = Matrix4x4.Multiply(parentLocalToWorld, localTransform.TRS());