Better L4 and array storage design
This commit is contained in:
@@ -2,8 +2,8 @@
|
||||
// -----------------------------------------------------------------------
|
||||
// file="Vec4"
|
||||
// Project: StgSharp
|
||||
// AuthorGroup: Nitload Space
|
||||
// Copyright (c) Nitload Space. All rights reserved.
|
||||
// AuthorGroup: Nitload
|
||||
// Copyright (c) Nitload. All rights reserved.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
@@ -26,7 +26,7 @@
|
||||
// -----------------------------------------------------------------------
|
||||
// -----------------------------------------------------------------------
|
||||
using StgSharp.Mathematics;
|
||||
using StgSharp.Mathematics.Intrinsic;
|
||||
using StgSharp.Mathematics.Internal;
|
||||
using StgSharp.Mathematics.Numeric;
|
||||
using System;
|
||||
using System.Data.Common;
|
||||
@@ -52,7 +52,9 @@ namespace StgSharp.Mathematics.Graphics
|
||||
[FieldOffset(4)] public float Y;
|
||||
[FieldOffset(8)] public float Z;
|
||||
|
||||
internal Vec4(Vector4 v)
|
||||
internal Vec4(
|
||||
Vector4 v
|
||||
)
|
||||
{
|
||||
Unsafe.SkipInit(out X);
|
||||
Unsafe.SkipInit(out Y);
|
||||
@@ -63,7 +65,9 @@ namespace StgSharp.Mathematics.Graphics
|
||||
vec = v;
|
||||
}
|
||||
|
||||
internal Vec4(M128 v)
|
||||
internal Vec4(
|
||||
M128 v
|
||||
)
|
||||
{
|
||||
Unsafe.SkipInit(out X);
|
||||
Unsafe.SkipInit(out Y);
|
||||
@@ -74,7 +78,10 @@ namespace StgSharp.Mathematics.Graphics
|
||||
reg = v;
|
||||
}
|
||||
|
||||
public Vec4(Vec3 v3, float w)
|
||||
public Vec4(
|
||||
Vec3 v3,
|
||||
float w
|
||||
)
|
||||
{
|
||||
Unsafe.SkipInit(out X);
|
||||
Unsafe.SkipInit(out Y);
|
||||
@@ -84,7 +91,12 @@ namespace StgSharp.Mathematics.Graphics
|
||||
W = w;
|
||||
}
|
||||
|
||||
public Vec4(float x, float y, float z, float w)
|
||||
public Vec4(
|
||||
float x,
|
||||
float y,
|
||||
float z,
|
||||
float w
|
||||
)
|
||||
{
|
||||
vec = new Vector4(x, y, z, w);
|
||||
}
|
||||
@@ -123,7 +135,10 @@ namespace StgSharp.Mathematics.Graphics
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static Vec4 Add(Vec4 left, Vec4 right)
|
||||
public static Vec4 Add(
|
||||
Vec4 left,
|
||||
Vec4 right
|
||||
)
|
||||
{
|
||||
return left + right;
|
||||
}
|
||||
@@ -133,12 +148,16 @@ namespace StgSharp.Mathematics.Graphics
|
||||
return MemoryMarshal.CreateReadOnlySpan(ref reg.Member<float>(0), 4);
|
||||
}
|
||||
|
||||
public override bool Equals(object obj)
|
||||
public override bool Equals(
|
||||
object obj
|
||||
)
|
||||
{
|
||||
return obj is Vec4 v && v == this;
|
||||
}
|
||||
|
||||
public static Vec4 FromSpan(ReadOnlySpan<float> span)
|
||||
public static Vec4 FromSpan(
|
||||
ReadOnlySpan<float> span
|
||||
)
|
||||
{
|
||||
if (span.Length < 4) {
|
||||
throw new ArgumentException("Span length must be at least 4.", nameof(span));
|
||||
@@ -161,7 +180,10 @@ namespace StgSharp.Mathematics.Graphics
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static Vec4 Subtract(Vec4 left, Vec4 right)
|
||||
public static Vec4 Subtract(
|
||||
Vec4 left,
|
||||
Vec4 right
|
||||
)
|
||||
{
|
||||
return left - right;
|
||||
}
|
||||
@@ -172,36 +194,55 @@ namespace StgSharp.Mathematics.Graphics
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static Vec4 operator -(Vec4 left, Vec4 right)
|
||||
public static Vec4 operator -(
|
||||
Vec4 left,
|
||||
Vec4 right
|
||||
)
|
||||
{
|
||||
return new Vec4(left.vec - right.vec);
|
||||
}
|
||||
|
||||
public static bool operator !=(Vec4 left, Vec4 right)
|
||||
public static bool operator !=(
|
||||
Vec4 left,
|
||||
Vec4 right
|
||||
)
|
||||
{
|
||||
return !(left == right);
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static Vec4 operator *(Matrix44 mat, Vec4 vec)
|
||||
public static Vec4 operator *(
|
||||
Matrix44 mat,
|
||||
Vec4 vec
|
||||
)
|
||||
{
|
||||
Matrix44 transpose = mat.Transpose;
|
||||
return new Vec4(Vector4.Dot(transpose.mat.colum0, vec.vec), Vector4.Dot(transpose.mat.colum1, vec.vec),
|
||||
Vector4.Dot(transpose.mat.colum2, vec.vec), Vector4.Dot(transpose.mat.colum3, vec.vec));
|
||||
return new Vec4(Vector4.Dot(transpose.mat.colum0, vec.vec),
|
||||
Vector4.Dot(transpose.mat.colum1, vec.vec),
|
||||
Vector4.Dot(transpose.mat.colum2, vec.vec),
|
||||
Vector4.Dot(transpose.mat.colum3, vec.vec));
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static Vec4 operator +(Vec4 left, Vec4 right)
|
||||
public static Vec4 operator +(
|
||||
Vec4 left,
|
||||
Vec4 right
|
||||
)
|
||||
{
|
||||
return new Vec4(left.vec + right.vec);
|
||||
}
|
||||
|
||||
public static bool operator ==(Vec4 left, Vec4 right)
|
||||
public static bool operator ==(
|
||||
Vec4 left,
|
||||
Vec4 right
|
||||
)
|
||||
{
|
||||
return left.vec == right.vec;
|
||||
}
|
||||
|
||||
bool IEquatable<Vec4>.Equals(Vec4 other)
|
||||
bool IEquatable<Vec4>.Equals(
|
||||
Vec4 other
|
||||
)
|
||||
{
|
||||
return vec == other.vec;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user