vector and matrix optimization
This commit is contained in:
@@ -1,30 +1,27 @@
|
||||
//-----------------------------------------------------------------------
|
||||
// -----------------------------------------------------------------------
|
||||
// file="Camera.cs"
|
||||
// file="Camera"
|
||||
// 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 in the Software without restriction,
|
||||
// including without limitation the rights to use, copy, modify, merge,
|
||||
// publish, distribute, sublicense, and/or sell copies of the Software,
|
||||
// and to permit persons to whom the Software is furnished to do so,
|
||||
// subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and
|
||||
// this permission notice shall be included in all copies
|
||||
// or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED “AS IS”,
|
||||
// WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
|
||||
// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
||||
// IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
|
||||
// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
|
||||
// ARISING FROM, OUT OF OR IN CONNECTION WITH
|
||||
// THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in all
|
||||
// copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
// SOFTWARE.
|
||||
//
|
||||
// -----------------------------------------------------------------------
|
||||
// -----------------------------------------------------------------------
|
||||
@@ -82,7 +79,7 @@ namespace StgSharp.Mathematics.Graphic
|
||||
return _lookAt;
|
||||
}
|
||||
Matrix44 move = Matrix44.Unit;
|
||||
move.colum3.vec -= cameraAtt.colum3.vec;
|
||||
move.column3.vec -= cameraAtt.column3.vec;
|
||||
_lookAt = rotationAtt.Transpose * move;
|
||||
_isLookAtAvailable = true;
|
||||
return _lookAt;
|
||||
@@ -123,19 +120,19 @@ namespace StgSharp.Mathematics.Graphic
|
||||
|
||||
public void MoveNear(float distance)
|
||||
{
|
||||
cameraAtt.colum3.Z -= distance;
|
||||
cameraAtt.column3.Z -= distance;
|
||||
_isLookAtAvailable = false;
|
||||
}
|
||||
|
||||
public void MoveRight(float distance)
|
||||
{
|
||||
cameraAtt.colum3.X -= distance;
|
||||
cameraAtt.column3.X -= distance;
|
||||
_isLookAtAvailable = false;
|
||||
}
|
||||
|
||||
public void MoveUp(float distance)
|
||||
{
|
||||
cameraAtt.colum3.Y -= distance;
|
||||
cameraAtt.column3.Y -= distance;
|
||||
_isLookAtAvailable = false;
|
||||
}
|
||||
|
||||
@@ -148,7 +145,7 @@ namespace StgSharp.Mathematics.Graphic
|
||||
public void SetViewDirection(Vec3 position, Vec3 target, Vec3 up)
|
||||
{
|
||||
Vec3 direction = position - target;
|
||||
if ((position.reg == cameraAtt.colum3.reg) && (this.up == up) && (cameraAtt.colum2.reg == direction.reg)) {
|
||||
if ((position.reg == cameraAtt.column3.reg) && (this.up == up) && (cameraAtt.column2.reg == direction.reg)) {
|
||||
return;
|
||||
}
|
||||
if (direction.GetLength() == 0)
|
||||
@@ -168,10 +165,10 @@ namespace StgSharp.Mathematics.Graphic
|
||||
|
||||
Vec3 right = Linear.Orthogonalize(Linear.Cross(up, direction));
|
||||
|
||||
cameraAtt.colum0.reg = right.reg;
|
||||
cameraAtt.colum1.reg = up.reg;
|
||||
cameraAtt.colum2.reg = direction.reg;
|
||||
cameraAtt.colum3.reg = position.reg;
|
||||
cameraAtt.column0.reg = right.reg;
|
||||
cameraAtt.column1.reg = up.reg;
|
||||
cameraAtt.column2.reg = direction.reg;
|
||||
cameraAtt.column3.reg = position.reg;
|
||||
|
||||
InternalPitch();
|
||||
InternalRow();
|
||||
@@ -189,13 +186,13 @@ namespace StgSharp.Mathematics.Graphic
|
||||
width = Scaler.Abs(GeometryScaler.Tan(fovRadius / 2) * near * 2),
|
||||
height = width * size.Y / size.X;
|
||||
|
||||
_projection.colum0.X = 2 * near / width;
|
||||
_projection.colum1.Y = 2 * near / height;
|
||||
_projection.colum2.X = 2 * offsetX / width;
|
||||
_projection.colum2.Y = 2 * offsetY / height;
|
||||
_projection.colum2.Z = (far + near) / (near - far);
|
||||
_projection.colum2.W = -1;
|
||||
_projection.colum3.Z = 2 * near * far / (near - far);
|
||||
_projection.column0.X = 2 * near / width;
|
||||
_projection.column1.Y = 2 * near / height;
|
||||
_projection.column2.X = 2 * offsetX / width;
|
||||
_projection.column2.Y = 2 * offsetY / height;
|
||||
_projection.column2.Z = (far + near) / (near - far);
|
||||
_projection.column2.W = -1;
|
||||
_projection.column3.Z = 2 * near * far / (near - far);
|
||||
}
|
||||
|
||||
public void Test(params Vec4[] vec)
|
||||
|
||||
@@ -1,38 +1,32 @@
|
||||
//-----------------------------------------------------------------------
|
||||
// -----------------------------------------------------------------------
|
||||
// file="Matrix44.cs"
|
||||
// file="Matrix44"
|
||||
// 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 in the Software without restriction,
|
||||
// including without limitation the rights to use, copy, modify, merge,
|
||||
// publish, distribute, sublicense, and/or sell copies of the Software,
|
||||
// and to permit persons to whom the Software is furnished to do so,
|
||||
// subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and
|
||||
// this permission notice shall be included in all copies
|
||||
// or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED “AS IS”,
|
||||
// WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
|
||||
// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
||||
// IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
|
||||
// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
|
||||
// ARISING FROM, OUT OF OR IN CONNECTION WITH
|
||||
// THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in all
|
||||
// copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
// SOFTWARE.
|
||||
//
|
||||
// -----------------------------------------------------------------------
|
||||
// -----------------------------------------------------------------------
|
||||
using StgSharp.Internal.Intrinsic;
|
||||
using StgSharp.Mathematics.Numeric;
|
||||
using System;
|
||||
using System.ComponentModel;
|
||||
using System.Drawing;
|
||||
using System.Numerics;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Runtime.InteropServices;
|
||||
@@ -40,17 +34,17 @@ using System.Runtime.InteropServices;
|
||||
namespace StgSharp.Mathematics.Graphic
|
||||
{
|
||||
[StructLayout(LayoutKind.Explicit, Size = 2 * 16 * sizeof(float) + sizeof(bool), Pack = 16)]
|
||||
public unsafe struct Matrix44 : IEquatable<Matrix44>, IMatrix<Matrix44>
|
||||
public unsafe struct Matrix44 : IEquatable<Matrix44>, IMatrix<float>
|
||||
{
|
||||
|
||||
[FieldOffset(2 * 64 * sizeof(float))] internal bool isTransposed;
|
||||
|
||||
[FieldOffset(0)] internal ColumnSet4 mat;
|
||||
[FieldOffset(16 * sizeof(float))] internal ColumnSet4 transpose;
|
||||
[FieldOffset(0 * sizeof(float))] internal Vec4 colum0;
|
||||
[FieldOffset(4 * sizeof(float))] internal Vec4 colum1;
|
||||
[FieldOffset(8 * sizeof(float))] internal Vec4 colum2;
|
||||
[FieldOffset(12 * sizeof(float))] internal Vec4 colum3;
|
||||
[FieldOffset(0 * sizeof(float))] internal Vec4 column0;
|
||||
[FieldOffset(4 * sizeof(float))] internal Vec4 column1;
|
||||
[FieldOffset(8 * sizeof(float))] internal Vec4 column2;
|
||||
[FieldOffset(12 * sizeof(float))] internal Vec4 column3;
|
||||
|
||||
internal Matrix44(ColumnSet4 mat)
|
||||
{
|
||||
@@ -161,6 +155,11 @@ namespace StgSharp.Mathematics.Graphic
|
||||
|
||||
public static Matrix44 ZNegativeUnit => new Matrix44(1, 0, 0, 0, 0, 1, 0, 0, 0, 0, -1, 0, 0, 0, 0, 1);
|
||||
|
||||
public ReadOnlySpan<float> AsSpan()
|
||||
{
|
||||
return MemoryMarshal.CreateReadOnlySpan(ref Unsafe.As<ColumnSet4, float>(ref mat), 16);
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public unsafe float Det()
|
||||
{
|
||||
@@ -208,9 +207,13 @@ namespace StgSharp.Mathematics.Graphic
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static unsafe Matrix44 operator -(Matrix44 left, Matrix44 right)
|
||||
{
|
||||
return new Matrix44(
|
||||
right.mat.colum0 - left.mat.colum0, right.mat.colum1 - left.mat.colum1,
|
||||
right.mat.colum2 - left.mat.colum2, right.mat.colum3 - left.mat.colum3);
|
||||
return new Matrix44
|
||||
{
|
||||
column0 = right.column0 - left.column0,
|
||||
column1 = right.column1 - left.column1,
|
||||
column2 = right.column2 - left.column2,
|
||||
column3 = right.column3 - left.column3
|
||||
};
|
||||
}
|
||||
|
||||
public static bool operator !=(Matrix44 left, Matrix44 right)
|
||||
@@ -255,9 +258,13 @@ namespace StgSharp.Mathematics.Graphic
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static unsafe Matrix44 operator +(Matrix44 left, Matrix44 right)
|
||||
{
|
||||
Matrix44 ret = new Matrix44();
|
||||
|
||||
// InternalIO.Intrinsic.add_mat_4(&left.mat, &right.mat, &ret.mat);
|
||||
Matrix44 ret = new()
|
||||
{
|
||||
column0 = left.column0 + right.column0,
|
||||
column1 = left.column1 + right.column1,
|
||||
column2 = left.column2 + right.column2,
|
||||
column3 = left.column3 + right.column3
|
||||
};
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,30 +1,27 @@
|
||||
//-----------------------------------------------------------------------
|
||||
// -----------------------------------------------------------------------
|
||||
// file="Vec2.cs"
|
||||
// file="Vec2"
|
||||
// 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 in the Software without restriction,
|
||||
// including without limitation the rights to use, copy, modify, merge,
|
||||
// publish, distribute, sublicense, and/or sell copies of the Software,
|
||||
// and to permit persons to whom the Software is furnished to do so,
|
||||
// subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and
|
||||
// this permission notice shall be included in all copies
|
||||
// or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED “AS IS”,
|
||||
// WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
|
||||
// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
||||
// IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
|
||||
// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
|
||||
// ARISING FROM, OUT OF OR IN CONNECTION WITH
|
||||
// THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in all
|
||||
// copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
// SOFTWARE.
|
||||
//
|
||||
// -----------------------------------------------------------------------
|
||||
// -----------------------------------------------------------------------
|
||||
@@ -86,6 +83,7 @@ namespace StgSharp.Mathematics.Graphic
|
||||
|
||||
public static Vec2 One
|
||||
{
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
get => new Vec2(1, 1);
|
||||
}
|
||||
|
||||
|
||||
@@ -1,30 +1,27 @@
|
||||
//-----------------------------------------------------------------------
|
||||
// -----------------------------------------------------------------------
|
||||
// file="Vec3.cs"
|
||||
// file="Vec3"
|
||||
// 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 in the Software without restriction,
|
||||
// including without limitation the rights to use, copy, modify, merge,
|
||||
// publish, distribute, sublicense, and/or sell copies of the Software,
|
||||
// and to permit persons to whom the Software is furnished to do so,
|
||||
// subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and
|
||||
// this permission notice shall be included in all copies
|
||||
// or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED “AS IS”,
|
||||
// WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
|
||||
// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
||||
// IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
|
||||
// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
|
||||
// ARISING FROM, OUT OF OR IN CONNECTION WITH
|
||||
// THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in all
|
||||
// copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
// SOFTWARE.
|
||||
//
|
||||
// -----------------------------------------------------------------------
|
||||
// -----------------------------------------------------------------------
|
||||
@@ -55,10 +52,7 @@ namespace StgSharp.Mathematics.Graphic
|
||||
|
||||
internal Vec3(M128 vector)
|
||||
{
|
||||
Unsafe.SkipInit(out X);
|
||||
Unsafe.SkipInit(out Y);
|
||||
Unsafe.SkipInit(out Z);
|
||||
Unsafe.SkipInit(out v);
|
||||
Unsafe.SkipInit(out this);
|
||||
reg = vector;
|
||||
reg.Member<uint>(3) = 0;
|
||||
}
|
||||
@@ -75,49 +69,42 @@ namespace StgSharp.Mathematics.Graphic
|
||||
|
||||
public Vec3(Vec2 xy, float z)
|
||||
{
|
||||
Unsafe.SkipInit(out X);
|
||||
Unsafe.SkipInit(out Y);
|
||||
Unsafe.SkipInit(out Z);
|
||||
Unsafe.SkipInit(out v);
|
||||
Unsafe.SkipInit(out this);
|
||||
reg = xy.reg;
|
||||
Z = z;
|
||||
}
|
||||
|
||||
public Vec3(float x, float y, float z)
|
||||
{
|
||||
Unsafe.SkipInit(out reg);
|
||||
Unsafe.SkipInit(out X);
|
||||
Unsafe.SkipInit(out Y);
|
||||
Unsafe.SkipInit(out Z);
|
||||
Unsafe.SkipInit(out this);
|
||||
v = new Vector3(x, y, z);
|
||||
}
|
||||
|
||||
public unsafe Vec2 XY
|
||||
{
|
||||
get => new Vec2(reg);
|
||||
set
|
||||
{
|
||||
fixed (Vector3* vptr = &v) {
|
||||
*(Vector2*)vptr = value.v;
|
||||
}
|
||||
}
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
readonly get => new(reg);
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
set => Unsafe.As<Vector3, Vector2>(ref v) = value.v;
|
||||
}
|
||||
|
||||
public Vec3 XYZ
|
||||
{
|
||||
get => new(v);
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
readonly get => new(v);
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
set => this = value;
|
||||
}
|
||||
|
||||
public static Vec3 Zero => new Vec3(0, 0, 0);
|
||||
public static Vec3 Zero => new(0, 0, 0);
|
||||
|
||||
public static Vec3 One => new Vec3(1, 1, 1);
|
||||
public static Vec3 One => new(1, 1, 1);
|
||||
|
||||
public static Vec3 UnitX => new Vec3(1, 0, 0);
|
||||
public static Vec3 UnitX => new(1, 0, 0);
|
||||
|
||||
public static Vec3 UnitY => new Vec3(0, 1, 0);
|
||||
public static Vec3 UnitY => new(0, 1, 0);
|
||||
|
||||
public static Vec3 UnitZ => new Vec3(0, 0, 1);
|
||||
public static Vec3 UnitZ => new(0, 0, 1);
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static Vec3 Cross(Vec3 left, Vec3 right)
|
||||
@@ -126,30 +113,24 @@ namespace StgSharp.Mathematics.Graphic
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public float Dot(Vec3 right)
|
||||
public readonly float Dot(Vec3 right)
|
||||
{
|
||||
return Vector3.Dot(v, right.v);
|
||||
}
|
||||
|
||||
public bool Equals(Vec3 other)
|
||||
public readonly bool Equals(Vec3 other)
|
||||
{
|
||||
return reg == other.reg;
|
||||
}
|
||||
|
||||
public override bool Equals(object obj)
|
||||
public override readonly bool Equals(object obj)
|
||||
{
|
||||
if (obj is Vec3)
|
||||
{
|
||||
return this == (Vec3)obj;
|
||||
} else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
return obj is not null && obj is Vec3 vec && this == vec;
|
||||
}
|
||||
|
||||
public static Vec3 FromSpan(ReadOnlySpan<float> span)
|
||||
{
|
||||
Vec3 v = new Vec3();
|
||||
Vec3 v = new();
|
||||
span.CopyTo(MemoryMarshal.CreateSpan(ref v.X, 3));
|
||||
return v;
|
||||
}
|
||||
@@ -169,7 +150,7 @@ namespace StgSharp.Mathematics.Graphic
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public float GetMaxValue()
|
||||
public readonly float GetMaxValue()
|
||||
{
|
||||
float ret = X;
|
||||
ret = ret > Y ? ret : Y;
|
||||
@@ -182,12 +163,12 @@ namespace StgSharp.Mathematics.Graphic
|
||||
return Cross(left, right) == Zero;
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
public override readonly string ToString()
|
||||
{
|
||||
return $"[{X},{Y},{Z}]";
|
||||
}
|
||||
|
||||
public string ToString(string sample)
|
||||
public readonly string ToString(string sample)
|
||||
{
|
||||
return $"[{X.ToString(sample)},{Y.ToString(sample)},{Z.ToString(sample)}]";
|
||||
}
|
||||
@@ -243,8 +224,7 @@ namespace StgSharp.Mathematics.Graphic
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static unsafe implicit operator Vec3((float, float, float) tuple)
|
||||
{
|
||||
Vec3 vec = new Vec3(*(Vector3*)&tuple);
|
||||
return vec;
|
||||
return Unsafe.As<(float,float,float), Vec3>(ref tuple);
|
||||
}
|
||||
|
||||
IEnumerator IEnumerable.GetEnumerator()
|
||||
|
||||
Reference in New Issue
Block a user