ScriptCore: Added Transform.WorldTransform

This commit is contained in:
Simon Lübeß
2024-02-19 21:39:07 +01:00
parent 1ca9746921
commit 0a822dcd79
3 changed files with 56 additions and 0 deletions
+37
View File
@@ -507,6 +507,43 @@ static class ScriptGlue
// TODO: we need to handle repositioning of colliders that are children of the entity with rigidbody...
}
[RegisterCall("ScriptGlue::Transform_GetWorldTranslation")]
static void Transform_GetWorldTranslation(UUID entityId, out float3 translationWorld)
{
Entity entity = GetEntitySafe(entityId);
TransformComponent* transform = entity.Transform;
translationWorld = transform.WorldTransform.Translation; //(float4(entity.Transform.Position, 1.0f) * entity.Transform.WorldTransform).XYZ;
}
[RegisterCall("ScriptGlue::Transform_SetWorldTranslation")]
static void Transform_SetWorldTranslation(UUID entityId, in float3 translation)
{
Log.ClientLogger.Warning("Transform_SetWorldTranslation is not implemented!");
// Entity entity = GetEntitySafe(entityId);
// entity.Transform.Position = translation;
// // if necessary reposition Rigidbody2D
// if (entity.TryGetComponent<Rigidbody2DComponent>(let rigidbody2D))
// {
// rigidbody2D.SetPosition(translation.XY);
// }
// TODO: we need to handle repositioning of colliders that are children of the entity with rigidbody...
}
[RegisterCall("ScriptGlue::Transform_TransformPointToWorld")]
static void Transform_TransformPointToWorld(UUID entityId, float3 point, out float3 pointWorld)
{
Entity entity = GetEntitySafe(entityId);
float3 localPoint = entity.Transform.Position;
pointWorld = (float4(localPoint, 1.0f) * entity.Transform.WorldTransform).XYZ;
}
[RegisterCall("ScriptGlue::Transform_GetRotation")]
static void Transform_GetRotation(UUID entityId, out Quaternion rotation)
{
+13
View File
@@ -37,6 +37,19 @@ public class Transform : Component
set => ScriptGlue.Transform_SetTranslation(Entity.UUID, in value);
}
/// <summary>
/// Gets or sets the translation (position) of the entity in global space.
/// </summary>
public float3 WorldTranslation
{
get
{
ScriptGlue.Transform_GetWorldTranslation(Entity.UUID, out float3 translation);
return translation;
}
set => ScriptGlue.Transform_SetWorldTranslation(Entity.UUID, in value);
}
/// <summary>
/// Gets or sets the rotation of the entity.
/// </summary>
+6
View File
@@ -81,6 +81,12 @@ internal static class ScriptGlue
[MethodImpl(MethodImplOptions.InternalCall)]
internal static extern void Transform_SetTranslation(UUID entityId, in float3 translation);
[MethodImpl(MethodImplOptions.InternalCall)]
internal static extern void Transform_GetWorldTranslation(UUID entityId, out float3 translation);
[MethodImpl(MethodImplOptions.InternalCall)]
internal static extern void Transform_SetWorldTranslation(UUID entityId, in float3 translation);
[MethodImpl(MethodImplOptions.InternalCall)]
internal static extern void Transform_GetRotation(UUID entityId, out Quaternion rotation);