From: Shawdooow Date: Fri, 19 Nov 2021 21:06:13 +0000 (-0500) Subject: quat and vec4 use unsafe now X-Git-Tag: v0.2.4-beta~24 X-Git-Url: https://git.osiis.dedyn.io/?a=commitdiff_plain;h=4be0c0d73c284592206c785cdb11a283fef90c17;p=jp%2Fvke.net.git quat and vec4 use unsafe now --- diff --git a/vke/src/Utils.cs b/vke/src/Utils.cs index 6eee9de..cce3964 100644 --- a/vke/src/Utils.cs +++ b/vke/src/Utils.cs @@ -74,32 +74,18 @@ namespace Vulkan { /// Populate a Vector4 with values from a float array /// public static void FromFloatArray (ref Vector4 v, float[] floats) { - if (floats.Length > 0) - v.X = floats[0]; - if (floats.Length > 1) - v.Y = floats[1]; - if (floats.Length > 2) - v.Z = floats[2]; - if (floats.Length > 3) - v.W = floats[3]; - } + v = Unsafe.As(ref floats)[0]; + } /// /// Populate a Quaternion with values from a float array /// - public static void FromFloatArray (ref Quaternion v, float[] floats) { - if (floats.Length > 0) - v.X = floats[0]; - if (floats.Length > 1) - v.Y = floats[1]; - if (floats.Length > 2) - v.Z = floats[2]; - if (floats.Length > 3) - v.W = floats[3]; + public static void FromFloatArray (ref Quaternion q, float[] floats) { + q = Unsafe.As(ref floats)[0]; } /// /// Populate a Vector2 with values from a byte array starting at offset /// - public static void FromByteArray (ref Vector2 v, byte[] byteArray, int offset) { + public static void FromByteArray (ref Vector2 v, byte[] byteArray, int offset, int length = 8) { v.X = BitConverter.ToSingle (byteArray, offset); v.Y = BitConverter.ToSingle (byteArray, offset + 4); } @@ -139,7 +125,7 @@ namespace Vulkan { return new Vector3 (v4.X, v4.Y, v4.Z); } public static Vector3 ToVector3 (this Vector4 v) { - return new Vector3 (v.X, v.Y, v.Z); + return Unsafe.As(ref v); } #endregion