A game about forced loneliness, made by TACStudios
1using System; 2using UnityEngine; 3using Unity.Mathematics; 4 5namespace UnityEngine.Rendering 6{ 7 [Serializable] 8 internal partial struct AABB 9 { 10 public float3 center; 11 public float3 extents; // half the size, must be 0 or greater 12 13 public float3 min { get { return center - extents; } } 14 public float3 max { get { return center + extents; } } 15 16 /// <summary>Returns a string representation of the AABB.</summary> 17 public override string ToString() 18 { 19 return $"AABB(Center:{center}, Extents:{extents}"; 20 } 21 22 static float3 RotateExtents(float3 extents, float3 m0, float3 m1, float3 m2) 23 { 24 return math.abs(m0 * extents.x) + math.abs(m1 * extents.y) + math.abs(m2 * extents.z); 25 } 26 27 public static AABB Transform(float4x4 transform, AABB localBounds) 28 { 29 AABB transformed; 30 transformed.extents = RotateExtents(localBounds.extents, transform.c0.xyz, transform.c1.xyz, transform.c2.xyz); 31 transformed.center = math.transform(transform, localBounds.center); 32 return transformed; 33 } 34 } 35 36 internal static class AABBExtensions 37 { 38 public static AABB ToAABB(this Bounds bounds) 39 { 40 return new AABB { center = bounds.center, extents = bounds.extents }; 41 } 42 43 public static Bounds ToBounds(this AABB aabb) 44 { 45 return new Bounds { center = aabb.center, extents = aabb.extents }; 46 } 47 } 48}