ecs and tranforms
added the moonworks ecs library. testing it by setting up a transform and parent system.
This commit is contained in:
		
							
								
								
									
										25
									
								
								Nerfed.Runtime/Util/Transform.cs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										25
									
								
								Nerfed.Runtime/Util/Transform.cs
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,25 @@
 | 
			
		||||
using Nerfed.Runtime.Components;
 | 
			
		||||
using System.Numerics;
 | 
			
		||||
 | 
			
		||||
namespace Nerfed.Runtime.Util
 | 
			
		||||
{
 | 
			
		||||
    // https://github.com/needle-mirror/com.unity.entities/blob/master/Unity.Transforms/TransformHelpers.cs
 | 
			
		||||
    internal static class Transform
 | 
			
		||||
    {
 | 
			
		||||
        public static Vector3 Forward(in this Matrix4x4 matrix) => new Vector3(matrix.M31, matrix.M32, matrix.M33);
 | 
			
		||||
        public static Vector3 Back(in this Matrix4x4 matrix) => -matrix.Forward();
 | 
			
		||||
        public static Vector3 Up(in this Matrix4x4 matrix) => new Vector3(matrix.M21, matrix.M22, matrix.M23);
 | 
			
		||||
        public static Vector3 Down(in this Matrix4x4 matrix) => -matrix.Up();
 | 
			
		||||
        public static Vector3 Right(in this Matrix4x4 matrix) => new Vector3(matrix.M11, matrix.M12, matrix.M13);
 | 
			
		||||
        public static Vector3 Left(in this Matrix4x4 matrix) => -matrix.Right();
 | 
			
		||||
        //public static Vector3 Translation(in this Matrix4x4 matrix) => new Vector3();
 | 
			
		||||
        //public static Quaternion Rotation(in this Matrix4x4 matrix) => new Quaternion();
 | 
			
		||||
 | 
			
		||||
        public static Matrix4x4 TRS(in this LocalTransform localTransform)
 | 
			
		||||
        {
 | 
			
		||||
            return Matrix4x4.CreateScale(localTransform.scale) *
 | 
			
		||||
                Matrix4x4.CreateFromQuaternion(localTransform.rotation) *
 | 
			
		||||
                Matrix4x4.CreateTranslation(localTransform.position);
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
		Reference in New Issue
	
	Block a user