New opengl api binding and new graphic purpose vector design
Signed-off-by: Nitload <YoumuLiu_NSI@whv0t.onmicrosoft.com>
This commit is contained in:
@@ -21,28 +21,21 @@ namespace StgSharp.Mathematics.Numeric.Graphics
|
||||
/// </summary>
|
||||
[StructLayout(LayoutKind.Sequential, Pack = 16)]
|
||||
public struct Vec3<T> : IUnmanagedVector<Vec3<T>>, IEquatable<Vec3<T>>, IEnumerable<T>
|
||||
where T : unmanaged, INumber<T>
|
||||
where T: unmanaged, INumber<T>
|
||||
{
|
||||
|
||||
public T X;
|
||||
public T Y;
|
||||
public T Z;
|
||||
|
||||
public Vec3(
|
||||
Vec2<T> xy,
|
||||
T z
|
||||
)
|
||||
public Vec3(Vec2<T> xy, T z)
|
||||
{
|
||||
X = xy.X;
|
||||
Y = xy.Y;
|
||||
Z = z;
|
||||
}
|
||||
|
||||
public Vec3(
|
||||
T x,
|
||||
T y,
|
||||
T z
|
||||
)
|
||||
public Vec3(T x, T y, T z)
|
||||
{
|
||||
X = x;
|
||||
Y = y;
|
||||
@@ -80,13 +73,11 @@ namespace StgSharp.Mathematics.Numeric.Graphics
|
||||
public static Vec3<T> UnitZ => new(T.Zero, T.Zero, T.One);
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public readonly T Dot(
|
||||
Vec3<T> right
|
||||
)
|
||||
public readonly T Dot(Vec3<T> right)
|
||||
{
|
||||
if (Unsafe.SizeOf<T>() == 4)
|
||||
if (Unsafe.SizeOf<T>() == 8)
|
||||
{
|
||||
Vec4<T> v = Vec4.FromVector128Unsafe(this.AsVector128Unsafe() * right.AsVector128Unsafe());
|
||||
Vec4<T> v = Vec4.FromVector256Unsafe(this.AsVector256Unsafe() * right.AsVector256Unsafe());
|
||||
return v.X + v.Y + v.Z;
|
||||
}
|
||||
if (Unsafe.SizeOf<T>() == 4)
|
||||
@@ -98,23 +89,23 @@ namespace StgSharp.Mathematics.Numeric.Graphics
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public readonly bool Equals(
|
||||
Vec3<T> other
|
||||
)
|
||||
public readonly bool Equals(Vec3<T> other)
|
||||
{
|
||||
return X == other.X && Y == other.Y && Z == other.Z;
|
||||
if (Unsafe.SizeOf<T>() == 4) {
|
||||
return this.AsVector128Safe() == other.AsVector128Safe();
|
||||
}
|
||||
if (Unsafe.SizeOf<T>() == 8) {
|
||||
return this.AsVector256Safe() == other.AsVector256Safe();
|
||||
}
|
||||
throw GraphicVector.ThrowUnsupportedTypeException<T>();
|
||||
}
|
||||
|
||||
public override readonly bool Equals(
|
||||
object? obj
|
||||
)
|
||||
public override readonly bool Equals(object? obj)
|
||||
{
|
||||
return obj is Vec3<T> other && Equals(other);
|
||||
}
|
||||
|
||||
public static Vec3<T> FromSpan(
|
||||
ReadOnlySpan<T> span
|
||||
)
|
||||
public static Vec3<T> FromSpan(ReadOnlySpan<T> span)
|
||||
{
|
||||
if (span.Length < 3) {
|
||||
throw new ArgumentException("Span length must be at least 3.", nameof(span));
|
||||
@@ -141,18 +132,13 @@ namespace StgSharp.Mathematics.Numeric.Graphics
|
||||
return T.Max(X, T.Max(Y, Z));
|
||||
}
|
||||
|
||||
public static bool IsParallel(
|
||||
Vec3<T> left,
|
||||
Vec3<T> right
|
||||
)
|
||||
public static bool IsParallel(Vec3<T> left, Vec3<T> right)
|
||||
{
|
||||
return Vec3.Cross(left, right) == Zero;
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static Vec3<T> operator -(
|
||||
Vec3<T> value
|
||||
)
|
||||
public static Vec3<T> operator -(Vec3<T> value)
|
||||
{
|
||||
if (Unsafe.SizeOf<T>() == 4) {
|
||||
return Vec3.FromVector128Unsafe(Vector128<T>.Zero - value.AsVector128Unsafe());
|
||||
@@ -164,10 +150,7 @@ namespace StgSharp.Mathematics.Numeric.Graphics
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static Vec3<T> operator -(
|
||||
Vec3<T> left,
|
||||
Vec3<T> right
|
||||
)
|
||||
public static Vec3<T> operator -(Vec3<T> left, Vec3<T> right)
|
||||
{
|
||||
if (Unsafe.SizeOf<T>() == 4)
|
||||
{
|
||||
@@ -185,19 +168,13 @@ namespace StgSharp.Mathematics.Numeric.Graphics
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static bool operator !=(
|
||||
Vec3<T> left,
|
||||
Vec3<T> right
|
||||
)
|
||||
public static bool operator !=(Vec3<T> left, Vec3<T> right)
|
||||
{
|
||||
return !left.Equals(right);
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static Vec3<T> operator *(
|
||||
Vec3<T> vector,
|
||||
T scalar
|
||||
)
|
||||
public static Vec3<T> operator *(Vec3<T> vector, T scalar)
|
||||
{
|
||||
if (Unsafe.SizeOf<T>() == 4)
|
||||
{
|
||||
@@ -215,28 +192,19 @@ namespace StgSharp.Mathematics.Numeric.Graphics
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static Vec3<T> operator *(
|
||||
T scalar,
|
||||
Vec3<T> vector
|
||||
)
|
||||
public static Vec3<T> operator *(T scalar, Vec3<T> vector)
|
||||
{
|
||||
return vector * scalar;
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static T operator *(
|
||||
Vec3<T> left,
|
||||
Vec3<T> right
|
||||
)
|
||||
public static T operator *(Vec3<T> left, Vec3<T> right)
|
||||
{
|
||||
return left.Dot(right);
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static Vec3<T> operator /(
|
||||
Vec3<T> vector,
|
||||
T scalar
|
||||
)
|
||||
public static Vec3<T> operator /(Vec3<T> vector, T scalar)
|
||||
{
|
||||
if (Unsafe.SizeOf<T>() == 4)
|
||||
{
|
||||
@@ -254,10 +222,7 @@ namespace StgSharp.Mathematics.Numeric.Graphics
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static Vec3<T> operator +(
|
||||
Vec3<T> left,
|
||||
Vec3<T> right
|
||||
)
|
||||
public static Vec3<T> operator +(Vec3<T> left, Vec3<T> right)
|
||||
{
|
||||
if (Unsafe.SizeOf<T>() == 4)
|
||||
{
|
||||
@@ -275,18 +240,13 @@ namespace StgSharp.Mathematics.Numeric.Graphics
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static bool operator ==(
|
||||
Vec3<T> left,
|
||||
Vec3<T> right
|
||||
)
|
||||
public static bool operator ==(Vec3<T> left, Vec3<T> right)
|
||||
{
|
||||
return left.Equals(right);
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static implicit operator Vec3<T>(
|
||||
(T X, T Y, T Z) tuple
|
||||
)
|
||||
public static implicit operator Vec3<T>((T X, T Y, T Z) tuple)
|
||||
{
|
||||
return new(tuple.X, tuple.Y, tuple.Z);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user