ScriptCore: matrix generator

This commit is contained in:
Simon Lübeß
2024-03-02 13:54:34 +01:00
parent 0a8d83ffb6
commit caaa7646ef
17 changed files with 1529 additions and 42 deletions
+44
View File
@@ -0,0 +1,44 @@
using System;
using GlitchyEngine.Math;
using GlitchyEngine.Math.Attributes;
namespace GlitchyEngine.Math;
/// <summary>
/// Represents a vector with two boolean values.
/// </summary>
[Vector(typeof(bool), 2, "bool")]
[VectorLogic]
public partial struct bool2
{
public static bool2 operator !(bool2 value)
{
return new bool2(!value.X, !value.Y);
}
}
/// <summary>
/// Represents a vector with three boolean values.
/// </summary>
[Vector(typeof(bool), 3, "bool")]
[VectorLogic]
public partial struct bool3
{
public static bool3 operator !(bool3 value)
{
return new bool3(!value.X, !value.Y, !value.Z);
}
}
/// <summary>
/// Represents a vector with four boolean values.
/// </summary>
[Vector(typeof(bool), 4, "bool")]
[VectorLogic]
public partial struct bool4
{
public static bool4 operator !(bool4 value)
{
return new bool4(!value.X, !value.Y, !value.Z, !value.W);
}
}
+38
View File
@@ -0,0 +1,38 @@
using System;
using GlitchyEngine.Math;
using GlitchyEngine.Math.Attributes;
namespace GlitchyEngine.Math;
/// <summary>
/// Represents a vector with two double-precision floating-point values.
/// </summary>
[Vector(typeof(double), 2, "double")]
[VectorMath]
[ComparableVector]
[VectorCast(typeof(float2), true)]
public partial struct double2
{
}
/// <summary>
/// Represents a vector with three double-precision floating-point values.
/// </summary>
[Vector(typeof(double), 3, "double")]
[VectorMath]
[ComparableVector]
[VectorCast(typeof(float3), true)]
public partial struct double3
{
}
/// <summary>
/// Represents a vector with four double-precision floating-point values.
/// </summary>
[Vector(typeof(double), 4, "double")]
[VectorMath]
[ComparableVector]
[VectorCast(typeof(float4), true)]
public partial struct double4
{
}
+142
View File
@@ -0,0 +1,142 @@
using System;
using System.Collections.Generic;
using System.Numerics;
using System.Runtime.InteropServices;
using System.Text;
using GlitchyEngine.Math;
using GlitchyEngine.Math.Attributes;
namespace GlitchyEngine.Math;
/// <summary>
/// Represents a vector with two single-precision floating-point values.
/// </summary>
[Vector(typeof(float), 2, "float")]
[ComparableVector]
[VectorMath]
[VectorCast(typeof(int2), true)]
[VectorCast(typeof(double2), true)]
[VectorCast(typeof(half2), true)]
public partial struct float2
{
/// <summary>
/// A vector whose elements are all equal to zero.
/// </summary>
public static readonly float2 Zero = new(0.0f, 0.0f);
/// <summary>
/// The vector (1, 0).
/// </summary>
public static readonly float2 UnitX = new(1.0f, 0.0f);
/// <summary>
/// The vector (0, 1).
/// </summary>
public static readonly float2 UnitY = new(0.0f, 1.0f);
/// <summary>
/// A vector whose elements are all equal to one.
/// </summary>
public static readonly float2 One = new(0.0f, 0.0f);
public static explicit operator Vector2(float2 self) => new(self.X, self.Y);
public static explicit operator float2(Vector2 self) => new(self.X, self.Y);
}
/// <summary>
/// Represents a vector with three single-precision floating-point values.
/// </summary>
[Vector(typeof(float), 3, "float")]
[ComparableVector]
[VectorMath]
[VectorCast(typeof(int3), true)]
[VectorCast(typeof(double3), true)]
[VectorCast(typeof(half3), true)]
public partial struct float3
{
/// <summary>
/// A vector whose elements are all equal to zero.
/// </summary>
public static readonly float3 Zero = new(0.0f, 0.0f, 0.0f);
/// <summary>
/// The vector (1, 0, 0).
/// </summary>
public static readonly float3 UnitX = new(1.0f, 0.0f, 0.0f);
/// <summary>
/// The vector (0, 1, 0).
/// </summary>
public static readonly float3 UnitY = new(0.0f, 1.0f, 0.0f);
/// <summary>
/// The vector (0, 0, 1).
/// </summary>
public static readonly float3 UnitZ = new(0.0f, 0.0f, 1.0f);
/// <summary>
/// A vector whose elements are all equal to one.
/// </summary>
public static readonly float3 One = new(0.0f, 0.0f, 0.0f);
/// <summary>
/// The vector (0, 0, 1).
/// </summary>
public static readonly float3 Forward = new(0.0f, 0.0f, 1.0f);
/// <summary>
/// The vector (0, 0, -1).
/// </summary>
public static readonly float3 Backward = new(0.0f, 0.0f, -1.0f);
/// <summary>
/// The vector (-1, 0, 0).
/// </summary>
public static readonly float3 Left = new(-1.0f, 0.0f, 0.0f);
/// <summary>
/// The vector (1, 0, 0).
/// </summary>
public static readonly float3 Right = new(1.0f, 0.0f, 0.0f);
/// <summary>
/// The vector (0, 1, 0).
/// </summary>
public static readonly float3 Up = new(0.0f, 1.0f, 0.0f);
/// <summary>
/// The vector (0, -1, 0).
/// </summary>
public static readonly float3 Down = new(0.0f, -1.0f, 0.0f);
public static explicit operator Vector3(float3 self) => new(self.X, self.Y, self.Z);
public static explicit operator float3(Vector3 self) => new(self.X, self.Y, self.Z);
}
/// <summary>
/// Represents a vector with four single-precision floating-point values.
/// </summary>
[Vector(typeof(float), 4, "float")]
[ComparableVector]
[VectorMath]
[VectorCast(typeof(int4), true)]
[VectorCast(typeof(double4), true)]
[VectorCast(typeof(half4), true)]
public partial struct float4
{
/// <summary>
/// A vector whose elements are all equal to zero.
/// </summary>
public static readonly float4 Zero = new(0f, 0f, 0f, 0f);
/// <summary>
/// The vector (1, 0, 0, 0).
/// </summary>
public static readonly float4 UnitX = new(1f, 0f, 0f, 0f);
/// <summary>
/// The vector (0, 1, 0, 0).
/// </summary>
public static readonly float4 UnitY = new(0f, 1f, 0f, 0f);
/// <summary>
/// The vector (0, 0, 1, 0).
/// </summary>
public static readonly float4 UnitZ = new(0f, 0f, 1f, 0f);
/// <summary>
/// The vector (0, 0, 0, 1).
/// </summary>
public static readonly float4 UnitW = new(0f, 0f, 0f, 1f);
/// <summary>
/// A vector whose elements are all equal to one.
/// </summary>
public static readonly float4 One = new(1f, 1f, 1f, 1f);
public static explicit operator Vector4(float4 self) => new(self.X, self.Y, self.Z, self.W);
public static explicit operator float4(Vector4 self) => new(self.X, self.Y, self.Z, self.W);
}
+40
View File
@@ -0,0 +1,40 @@
using System;
using GlitchyEngine.Math.Attributes;
namespace GlitchyEngine.Math;
/// <summary>
/// Represents a vector with two half-precision floating-point values.
/// </summary>
/// <inheritdoc cref="Half" select="remarks" />
[Vector(typeof(Half), 2, "half")]
[VectorMath]
[ComparableVector]
[VectorCast(typeof(float2), true)]
public partial struct half2
{
}
/// <summary>
/// Represents a vector with three half-precision floating-point values.
/// </summary>
/// <inheritdoc cref="Half" select="remarks" />
[Vector(typeof(Half), 3, "half")]
[VectorMath]
[ComparableVector]
[VectorCast(typeof(float3), true)]
public partial struct half3
{
}
/// <summary>
/// Represents a vector with four half-precision floating-point values.
/// </summary>
/// <inheritdoc cref="Half" select="remarks" />
[Vector(typeof(Half), 4, "half")]
[VectorMath]
[ComparableVector]
[VectorCast(typeof(float4), true)]
public partial struct half4
{
}
+56
View File
@@ -0,0 +1,56 @@
using System;
using GlitchyEngine.Math;
using GlitchyEngine.Math.Attributes;
namespace GlitchyEngine.Math;
/// <summary>
/// Represents a vector with two 32-bit signed integer values.
/// </summary>
[Vector(typeof(int), 2, "int")]
[VectorMath]
[VectorLogic]
[ComparableVector]
[VectorCast(typeof(float2), true)]
[VectorCast(typeof(uint2), true)]
public partial struct int2
{
public static int2 operator ~(int2 value)
{
return new int2(~value.X, ~value.Y);
}
}
/// <summary>
/// Represents a vector with three 32-bit signed integer values.
/// </summary>
[Vector(typeof(int), 3, "int")]
[VectorMath]
[VectorLogic]
[ComparableVector]
[VectorCast(typeof(float3), true)]
[VectorCast(typeof(uint3), true)]
public partial struct int3
{
public static int3 operator ~(int3 value)
{
return new int3(~value.X, ~value.Y, ~value.Z);
}
}
/// <summary>
/// Represents a vector with four 32-bit signed integer values.
/// </summary>
[Vector(typeof(int), 4, "int")]
[VectorMath]
[VectorLogic]
[ComparableVector]
[VectorCast(typeof(float4), true)]
[VectorCast(typeof(uint4), true)]
public partial struct int4
{
public static int4 operator ~(int4 value)
{
return new int4(~value.X, ~value.Y, ~value.Z, ~value.W);
}
}
+55
View File
@@ -0,0 +1,55 @@
using System;
using GlitchyEngine.Math;
using GlitchyEngine.Math.Attributes;
namespace GlitchyEngine.Math;
// TODO: Currently no VectorMath-Attribute because -uint results in long
/// <summary>
/// Represents a vector with two 32-bit unsigned integer values.
/// </summary>
[Vector(typeof(uint), 2, "uint")]
[VectorLogic]
[ComparableVector]
[VectorCast(typeof(int2), true)]
[VectorCast(typeof(float2), true)]
public partial struct uint2
{
public static uint2 operator ~(uint2 value)
{
return new uint2(~value.X, ~value.Y);
}
}
/// <summary>
/// Represents a vector with three 32-bit unsigned integer values.
/// </summary>
[Vector(typeof(uint), 3, "uint")]
[VectorLogic]
[ComparableVector]
[VectorCast(typeof(int3), true)]
[VectorCast(typeof(float3), true)]
public partial struct uint3
{
public static uint3 operator ~(uint3 value)
{
return new uint3(~value.X, ~value.Y, ~value.Z);
}
}
/// <summary>
/// Represents a vector with four 32-bit unsigned integer values.
/// </summary>
[Vector(typeof(uint), 4, "uint")]
[VectorLogic]
[ComparableVector]
[VectorCast(typeof(int4), true)]
[VectorCast(typeof(float4), true)]
public partial struct uint4
{
public static uint4 operator ~(uint4 value)
{
return new uint4(~value.X, ~value.Y, ~value.Z, ~value.W);
}
}