daily update on 20241129 by nitload youmu, frameworkDialogue added
This commit is contained in:
@@ -0,0 +1,41 @@
|
||||
//-----------------------------------------------------------------------
|
||||
//-----------------------------------------------------------------------
|
||||
// file="Cordination.cs"
|
||||
// Project: StgSharp
|
||||
// AuthorGroup: Nitload Space
|
||||
// Copyright (c) Nitload Space. 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.
|
||||
//
|
||||
//-----------------------------------------------------------------------
|
||||
//-----------------------------------------------------------------------
|
||||
namespace StgSharp.Math
|
||||
{
|
||||
public enum CoordinatePlain
|
||||
{
|
||||
|
||||
XY,
|
||||
YZ,
|
||||
XZ,
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,50 @@
|
||||
//-----------------------------------------------------------------------
|
||||
//-----------------------------------------------------------------------
|
||||
// file="IVector.cs"
|
||||
// Project: StgSharp
|
||||
// AuthorGroup: Nitload Space
|
||||
// Copyright (c) Nitload Space. 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.
|
||||
//
|
||||
//-----------------------------------------------------------------------
|
||||
//-----------------------------------------------------------------------
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Numerics;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace StgSharp.Math
|
||||
{
|
||||
public interface IVector
|
||||
{
|
||||
/*
|
||||
public static T Create<T>(Vector4 source) where T : IVector
|
||||
{
|
||||
return T
|
||||
}
|
||||
/**/
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
//-----------------------------------------------------------------------
|
||||
//-----------------------------------------------------------------------
|
||||
// file="MatInterface.cs"
|
||||
// Project: StgSharp
|
||||
// AuthorGroup: Nitload Space
|
||||
// Copyright (c) Nitload Space. 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.
|
||||
//
|
||||
//-----------------------------------------------------------------------
|
||||
//-----------------------------------------------------------------------
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
namespace StgSharp.Math
|
||||
{
|
||||
public interface IMat { }
|
||||
}
|
||||
@@ -0,0 +1,177 @@
|
||||
//-----------------------------------------------------------------------
|
||||
//-----------------------------------------------------------------------
|
||||
// file="Matrix22.cs"
|
||||
// Project: StgSharp
|
||||
// AuthorGroup: Nitload Space
|
||||
// Copyright (c) Nitload Space. 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.
|
||||
//
|
||||
//-----------------------------------------------------------------------
|
||||
//-----------------------------------------------------------------------
|
||||
using StgSharp.Data.Intrinsic;
|
||||
|
||||
using System.Numerics;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
namespace StgSharp.Math
|
||||
{
|
||||
[StructLayout(
|
||||
LayoutKind.Explicit,
|
||||
Size = ( 2 * 2 * 4 * sizeof( float ) ) + sizeof( bool ),
|
||||
Pack = 16 )]
|
||||
public struct Matrix22 : IMat
|
||||
{
|
||||
[FieldOffset( 2 * 2 * 4 * sizeof( float ) )]
|
||||
internal bool isTransposed = false;
|
||||
|
||||
[FieldOffset( 0 )]
|
||||
internal ColumnSet2 _mat;
|
||||
[FieldOffset( 2 * 4 * sizeof( float ) )]
|
||||
internal ColumnSet2 _transpose;
|
||||
|
||||
public Matrix22()
|
||||
{
|
||||
Unsafe.SkipInit( out _mat );
|
||||
Unsafe.SkipInit(out _transpose);
|
||||
}
|
||||
|
||||
internal Matrix22( ColumnSet2 mat )
|
||||
{
|
||||
this._mat = mat;
|
||||
}
|
||||
|
||||
internal Matrix22( Vector4 c0, Vector4 c1 )
|
||||
{
|
||||
_mat.colum0 = c0;
|
||||
_mat.colum1 = c1;
|
||||
}
|
||||
|
||||
public Matrix22( float a00, float a01, float a10, float a11 )
|
||||
{
|
||||
_mat.colum0 = new Vector4( a00, a10, 0, 0 );
|
||||
_mat.colum1 = new Vector4( a01, a11, 0, 0 );
|
||||
}
|
||||
|
||||
public Matrix22 Transpose
|
||||
{
|
||||
get
|
||||
{
|
||||
InternalTranspose();
|
||||
return new Matrix22( this._transpose );
|
||||
}
|
||||
}
|
||||
|
||||
[MethodImpl( MethodImplOptions.AggressiveInlining )]
|
||||
public float Det()
|
||||
{
|
||||
return ( _mat.m00 * _mat.m11 ) - ( _mat.m10 * _mat.m01 );
|
||||
}
|
||||
|
||||
[MethodImpl( MethodImplOptions.AggressiveInlining )]
|
||||
internal void InternalTranspose()
|
||||
{
|
||||
if( !isTransposed ) {
|
||||
_transpose = _mat;
|
||||
float cache = _transpose.m10;
|
||||
_transpose.m10 = _transpose.m01;
|
||||
_transpose.m01 = cache;
|
||||
|
||||
isTransposed = true;
|
||||
}
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static unsafe Matrix22 operator +(Matrix22 left, Matrix22 right)
|
||||
{
|
||||
Matrix22 ret = new Matrix22();
|
||||
InternalIO.Intrinsic.add_mat_2( &left._mat, &right._mat, &ret._mat );
|
||||
return ret;
|
||||
}
|
||||
|
||||
[MethodImpl( MethodImplOptions.AggressiveInlining )]
|
||||
public static Matrix22 operator -( Matrix22 left, Matrix22 right )
|
||||
{
|
||||
return new Matrix22(
|
||||
left._mat.colum0 + right._mat.colum0,
|
||||
left._mat.colum1 + right._mat.colum1 );
|
||||
}
|
||||
|
||||
[MethodImpl( MethodImplOptions.AggressiveInlining )]
|
||||
public static Matrix22 operator *( Matrix22 mat, float value )
|
||||
{
|
||||
return new Matrix22(
|
||||
mat._mat.colum0 * value, mat._mat.colum1 * value );
|
||||
}
|
||||
|
||||
[MethodImpl( MethodImplOptions.AggressiveInlining )]
|
||||
public static Matrix22 operator *( Matrix22 left, Matrix22 right )
|
||||
{
|
||||
left.InternalTranspose();
|
||||
return new Matrix22(
|
||||
Vector4.Dot( left._transpose.colum0, right._mat.colum0 ),
|
||||
Vector4.Dot( left._transpose.colum0, right._mat.colum1 ),
|
||||
|
||||
Vector4.Dot( left._transpose.colum1, right._mat.colum0 ),
|
||||
Vector4.Dot( left._transpose.colum1, right._mat.colum1 ));
|
||||
}
|
||||
|
||||
[MethodImpl( MethodImplOptions.AggressiveInlining )]
|
||||
public static Matrix23 operator *( Matrix22 left, Matrix23 right )
|
||||
{
|
||||
left.InternalTranspose();
|
||||
return new Matrix23(
|
||||
Vector4.Dot( left._transpose.colum0, right._mat.colum0 ),
|
||||
Vector4.Dot( left._transpose.colum0, right._mat.colum1 ),
|
||||
Vector4.Dot( left._transpose.colum0, right._mat.colum2 ),
|
||||
|
||||
Vector4.Dot( left._transpose.colum1, right._mat.colum0 ),
|
||||
Vector4.Dot( left._transpose.colum1, right._mat.colum1 ),
|
||||
Vector4.Dot( left._transpose.colum1, right._mat.colum2 ) );
|
||||
}
|
||||
|
||||
[MethodImpl( MethodImplOptions.AggressiveInlining )]
|
||||
public static Matrix24 operator *( Matrix22 left, Matrix24 right )
|
||||
{
|
||||
left.InternalTranspose();
|
||||
return new Matrix24(
|
||||
Vector4.Dot( left._transpose.colum0, right.mat.colum0 ),
|
||||
Vector4.Dot( left._transpose.colum0, right.mat.colum1 ),
|
||||
Vector4.Dot( left._transpose.colum0, right.mat.colum2 ),
|
||||
Vector4.Dot( left._transpose.colum0, right.mat.colum3 ),
|
||||
|
||||
Vector4.Dot( left._transpose.colum1, right.mat.colum0 ),
|
||||
Vector4.Dot( left._transpose.colum1, right.mat.colum1 ),
|
||||
Vector4.Dot( left._transpose.colum1, right.mat.colum2 ),
|
||||
Vector4.Dot( left._transpose.colum1, right.mat.colum3 ) );
|
||||
}
|
||||
|
||||
[MethodImpl( MethodImplOptions.AggressiveInlining )]
|
||||
public static Matrix22 operator /( Matrix22 mat, float value )
|
||||
{
|
||||
return new Matrix22(
|
||||
mat._mat.colum0 / value, mat._mat.colum1 / value );
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,200 @@
|
||||
//-----------------------------------------------------------------------
|
||||
//-----------------------------------------------------------------------
|
||||
// file="Matrix23.cs"
|
||||
// Project: StgSharp
|
||||
// AuthorGroup: Nitload Space
|
||||
// Copyright (c) Nitload Space. 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.
|
||||
//
|
||||
//-----------------------------------------------------------------------
|
||||
//-----------------------------------------------------------------------
|
||||
using StgSharp.Data.Intrinsic;
|
||||
|
||||
using System;
|
||||
using System.Numerics;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
namespace StgSharp.Math
|
||||
{
|
||||
[StructLayout(
|
||||
LayoutKind.Explicit,
|
||||
Size = ( ( 3 + 2 ) * 4 * sizeof( float ) ) + sizeof( bool ),
|
||||
Pack = 16 )]
|
||||
public struct Matrix23 : IMat
|
||||
{
|
||||
|
||||
[FieldOffset( 5 * 4 * sizeof( float ) )] internal bool isTransposed = false;
|
||||
[FieldOffset( 3 * 4 * sizeof( float ) )] internal ColumnSet2 _transpose;
|
||||
[FieldOffset( 0 )] internal ColumnSet3 _mat;
|
||||
|
||||
public Matrix23()
|
||||
{
|
||||
Unsafe.SkipInit( out _mat);
|
||||
Unsafe.SkipInit(out _transpose);
|
||||
}
|
||||
|
||||
internal Matrix23( Vector4 c0, Vector4 c1, Vector4 c2 )
|
||||
{
|
||||
_mat.colum0 = c0;
|
||||
_mat.colum1 = c1;
|
||||
_mat.colum2 = c2;
|
||||
}
|
||||
|
||||
public Matrix23(
|
||||
float a00,
|
||||
float a01,
|
||||
float a02,
|
||||
float a10,
|
||||
float a11,
|
||||
float a12 )
|
||||
{
|
||||
_mat.colum0 = new Vector4( a00, a10, 0, 0 );
|
||||
_mat.colum1 = new Vector4( a01, a11, 0, 0 );
|
||||
_mat.colum2 = new Vector4( a02, a12, 0, 0 );
|
||||
}
|
||||
|
||||
public unsafe float this[ int rowNum, int columNum ]
|
||||
{
|
||||
get
|
||||
{
|
||||
if( ( rowNum > 1 ) || ( rowNum < 0 ) ) {
|
||||
throw new ArgumentOutOfRangeException( nameof( columNum ) );
|
||||
}
|
||||
if( ( columNum > 2 ) || ( columNum < 0 ) ) {
|
||||
throw new ArgumentOutOfRangeException( nameof( columNum ) );
|
||||
}
|
||||
InternalTranspose();
|
||||
fixed( float* p = &this._transpose.m00 ) {
|
||||
ulong pbit = ( ( ulong )p ) + ( ( ( ulong )sizeof( Vector4 ) ) * ( ( ulong )rowNum ) ) + ( ( ( ulong )sizeof( float ) ) * ( ( ulong )columNum ) );
|
||||
return *( float* )pbit;
|
||||
}
|
||||
}
|
||||
set
|
||||
{
|
||||
if( ( rowNum > 1 ) || ( rowNum < 0 ) ) {
|
||||
throw new ArgumentOutOfRangeException( nameof( columNum ) );
|
||||
}
|
||||
if( ( columNum > 2 ) || ( columNum < 0 ) ) {
|
||||
throw new ArgumentOutOfRangeException( nameof( columNum ) );
|
||||
}
|
||||
InternalTranspose();
|
||||
fixed( float* p = &this._transpose.m00 ) {
|
||||
ulong pbit = ( ( ulong )p ) + ( ( ( ulong )sizeof( Vector4 ) ) * ( ( ulong )rowNum ) ) + ( ( ( ulong )sizeof( float ) ) * ( ( ulong )columNum ) );
|
||||
*( float* )pbit = value;
|
||||
}
|
||||
isTransposed = false;
|
||||
}
|
||||
}
|
||||
|
||||
[MethodImpl( MethodImplOptions.AggressiveInlining )]
|
||||
internal unsafe void InternalTranspose()
|
||||
{
|
||||
if( !isTransposed ) {
|
||||
fixed( ColumnSet3* source = &this._mat ) {
|
||||
fixed( ColumnSet2* target = &this._transpose ) {
|
||||
InternalIO.Intrinsic.transpose32( source, target );
|
||||
}
|
||||
}
|
||||
|
||||
isTransposed = true;
|
||||
}
|
||||
}
|
||||
|
||||
[MethodImpl( MethodImplOptions.AggressiveInlining )]
|
||||
public static Matrix23 operator -( Matrix23 left, Matrix23 right )
|
||||
{
|
||||
return new Matrix23(
|
||||
left._mat.colum0 - right._mat.colum0,
|
||||
left._mat.colum1 - right._mat.colum1,
|
||||
left._mat.colum2 - right._mat.colum2 );
|
||||
}
|
||||
|
||||
[MethodImpl( MethodImplOptions.AggressiveInlining )]
|
||||
public static Matrix23 operator *( Matrix23 mat, float value )
|
||||
{
|
||||
return new Matrix23(
|
||||
mat._mat.colum0 * value, mat._mat.colum1 * value,
|
||||
mat._mat.colum2 * value );
|
||||
}
|
||||
|
||||
[MethodImpl( MethodImplOptions.AggressiveInlining )]
|
||||
public static Matrix22 operator *( Matrix23 left, Matrix32 right )
|
||||
{
|
||||
left.InternalTranspose();
|
||||
return new Matrix22(
|
||||
Vector4.Dot( left._transpose.colum0, right.mat.colum0 ),
|
||||
Vector4.Dot( left._transpose.colum0, right.mat.colum1 ),
|
||||
|
||||
Vector4.Dot( left._transpose.colum0, right.mat.colum0 ),
|
||||
Vector4.Dot( left._transpose.colum0, right.mat.colum1 ) );
|
||||
}
|
||||
|
||||
[MethodImpl( MethodImplOptions.AggressiveInlining )]
|
||||
public static Matrix23 operator *( Matrix23 left, Matrix33 right )
|
||||
{
|
||||
left.InternalTranspose();
|
||||
return new Matrix23(
|
||||
Vector4.Dot( left._transpose.colum0, right.mat.colum0 ),
|
||||
Vector4.Dot( left._transpose.colum0, right.mat.colum1 ),
|
||||
Vector4.Dot( left._transpose.colum0, right.mat.colum2 ),
|
||||
|
||||
Vector4.Dot( left._transpose.colum0, right.mat.colum0 ),
|
||||
Vector4.Dot( left._transpose.colum0, right.mat.colum1 ),
|
||||
Vector4.Dot( left._transpose.colum0, right.mat.colum2 ) );
|
||||
}
|
||||
|
||||
[MethodImpl( MethodImplOptions.AggressiveInlining )]
|
||||
public static Matrix24 operator *( Matrix23 left, Matrix34 right )
|
||||
{
|
||||
left.InternalTranspose();
|
||||
return new Matrix24(
|
||||
Vector4.Dot( left._transpose.colum0, right.mat.colum0 ),
|
||||
Vector4.Dot( left._transpose.colum0, right.mat.colum1 ),
|
||||
Vector4.Dot( left._transpose.colum0, right.mat.colum2 ),
|
||||
Vector4.Dot( left._transpose.colum0, right.mat.colum3 ),
|
||||
|
||||
Vector4.Dot( left._transpose.colum0, right.mat.colum0 ),
|
||||
Vector4.Dot( left._transpose.colum0, right.mat.colum1 ),
|
||||
Vector4.Dot( left._transpose.colum0, right.mat.colum2 ),
|
||||
Vector4.Dot( left._transpose.colum0, right.mat.colum3 ) );
|
||||
}
|
||||
|
||||
[MethodImpl( MethodImplOptions.AggressiveInlining )]
|
||||
public static Matrix23 operator /( Matrix23 mat, float value )
|
||||
{
|
||||
return new Matrix23(
|
||||
mat._mat.colum0 / value, mat._mat.colum1 / value,
|
||||
mat._mat.colum2 / value );
|
||||
}
|
||||
|
||||
[MethodImpl( MethodImplOptions.AggressiveInlining )]
|
||||
public static unsafe Matrix23 operator +( Matrix23 left, Matrix23 right )
|
||||
{
|
||||
Matrix23 ret = new Matrix23();
|
||||
InternalIO.Intrinsic.add_mat_3(&left._mat, &right._mat, &ret._mat);
|
||||
return ret;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,213 @@
|
||||
//-----------------------------------------------------------------------
|
||||
//-----------------------------------------------------------------------
|
||||
// file="Matrix24.cs"
|
||||
// Project: StgSharp
|
||||
// AuthorGroup: Nitload Space
|
||||
// Copyright (c) Nitload Space. 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.
|
||||
//
|
||||
//-----------------------------------------------------------------------
|
||||
//-----------------------------------------------------------------------
|
||||
using StgSharp.Data.Intrinsic;
|
||||
|
||||
using System;
|
||||
using System.Numerics;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
namespace StgSharp.Math
|
||||
{
|
||||
[StructLayout(
|
||||
LayoutKind.Explicit,
|
||||
Size = ( ( 4 + 2 ) * 4 * sizeof( float ) ) + sizeof( bool ),
|
||||
Pack = 16 )]
|
||||
public struct Matrix24 : IMat
|
||||
{
|
||||
|
||||
[FieldOffset( 6 * 4 * sizeof( float ) )] internal bool isTransposed;
|
||||
[FieldOffset( 4 * 4 * sizeof( float ) )] internal ColumnSet2 transpose;
|
||||
|
||||
[FieldOffset( 0 )] internal ColumnSet4 mat;
|
||||
|
||||
[FieldOffset( 0 )] public Vec2 Colum0;
|
||||
[FieldOffset( 16 )] public Vec2 Colum1;
|
||||
[FieldOffset( 32 )] public Vec2 Colum2;
|
||||
[FieldOffset( 48 )] public Vec2 Colum3;
|
||||
|
||||
internal Matrix24( Vector4 c0, Vector4 c1, Vector4 c2, Vector4 c3 )
|
||||
{
|
||||
mat.colum0 = c0;
|
||||
mat.colum1 = c1;
|
||||
mat.colum2 = c2;
|
||||
mat.colum3 = c3;
|
||||
}
|
||||
|
||||
public Matrix24(
|
||||
float a00,
|
||||
float a01,
|
||||
float a02,
|
||||
float a03,
|
||||
float a10,
|
||||
float a11,
|
||||
float a12,
|
||||
float a13 )
|
||||
{
|
||||
mat.colum0 = new Vector4( a00, a10, 0, 0 );
|
||||
mat.colum1 = new Vector4( a01, a11, 0, 0 );
|
||||
mat.colum2 = new Vector4( a02, a12, 0, 0 );
|
||||
mat.colum3 = new Vector4( a03, a13, 0, 0 );
|
||||
}
|
||||
|
||||
public unsafe float this[ int rowNum, int columNum ]
|
||||
{
|
||||
get
|
||||
{
|
||||
if( ( rowNum > 1 ) || ( rowNum < 0 ) ) {
|
||||
throw new ArgumentOutOfRangeException( nameof( columNum ) );
|
||||
}
|
||||
if( ( columNum > 3 ) || ( columNum < 0 ) ) {
|
||||
throw new ArgumentOutOfRangeException( nameof( columNum ) );
|
||||
}
|
||||
InternalTranspose();
|
||||
fixed( float* p = &this.transpose.m00 ) {
|
||||
ulong pbit = ( ( ulong )p ) + ( ( ( ulong )sizeof( Vector4 ) ) * ( ( ulong )rowNum ) ) + ( ( ( ulong )sizeof( float ) ) * ( ( ulong )columNum ) );
|
||||
return *( float* )pbit;
|
||||
}
|
||||
}
|
||||
set
|
||||
{
|
||||
if( ( rowNum > 1 ) || ( rowNum < 0 ) ) {
|
||||
throw new ArgumentOutOfRangeException( nameof( columNum ) );
|
||||
}
|
||||
if( ( columNum > 3 ) || ( columNum < 0 ) ) {
|
||||
throw new ArgumentOutOfRangeException( nameof( columNum ) );
|
||||
}
|
||||
InternalTranspose();
|
||||
fixed( float* p = &this.transpose.m00 ) {
|
||||
ulong pbit = ( ( ulong )p ) + ( ( ( ulong )sizeof( Vector4 ) ) * ( ( ulong )rowNum ) ) + ( ( ( ulong )sizeof( float ) ) * ( ( ulong )columNum ) );
|
||||
*( float* )pbit = value;
|
||||
}
|
||||
isTransposed = false;
|
||||
}
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
InternalTranspose();
|
||||
return $"{$"[{mat.m00},{mat.m01},{mat.m02},{mat.m03}],"}{$"[{mat.m10},{mat.m11},{mat.m12},{mat.m13}]"}";
|
||||
}
|
||||
|
||||
[MethodImpl( MethodImplOptions.AggressiveInlining )]
|
||||
internal unsafe void InternalTranspose()
|
||||
{
|
||||
if( !isTransposed ) {
|
||||
fixed( ColumnSet4* source = &this.mat ) {
|
||||
fixed( ColumnSet2* target = &this.transpose ) {
|
||||
InternalIO.Intrinsic.transpose42( source, target );
|
||||
}
|
||||
}
|
||||
|
||||
isTransposed = true;
|
||||
}
|
||||
}
|
||||
|
||||
[MethodImpl( MethodImplOptions.AggressiveInlining )]
|
||||
public static Matrix24 operator -( Matrix24 left, Matrix24 right )
|
||||
{
|
||||
return new Matrix24(
|
||||
left.mat.colum0 - right.mat.colum0,
|
||||
left.mat.colum1 - right.mat.colum1,
|
||||
left.mat.colum2 - right.mat.colum2,
|
||||
left.mat.colum3 - right.mat.colum3 );
|
||||
}
|
||||
|
||||
[MethodImpl( MethodImplOptions.AggressiveInlining )]
|
||||
public static Matrix24 operator *( Matrix24 mat, float value )
|
||||
{
|
||||
return new Matrix24(
|
||||
mat.mat.colum0 * value, mat.mat.colum1 * value,
|
||||
mat.mat.colum2 * value, mat.mat.colum3 * value );
|
||||
}
|
||||
|
||||
[MethodImpl( MethodImplOptions.AggressiveInlining )]
|
||||
public static Matrix22 operator *( Matrix24 left, Matrix42 right )
|
||||
{
|
||||
left.InternalTranspose();
|
||||
return new Matrix22(
|
||||
Vector4.Dot( left.transpose.colum0, right.mat.colum0 ),
|
||||
Vector4.Dot( left.transpose.colum0, right.mat.colum1 ),
|
||||
|
||||
Vector4.Dot( left.transpose.colum1, right.mat.colum0 ),
|
||||
Vector4.Dot( left.transpose.colum1, right.mat.colum1 ) );
|
||||
}
|
||||
|
||||
[MethodImpl( MethodImplOptions.AggressiveInlining )]
|
||||
public static Matrix23 operator *( Matrix24 left, Matrix43 right )
|
||||
{
|
||||
left.InternalTranspose();
|
||||
return new Matrix23(
|
||||
Vector4.Dot( left.transpose.colum0, right.mat.colum0 ),
|
||||
Vector4.Dot( left.transpose.colum0, right.mat.colum1 ),
|
||||
Vector4.Dot( left.transpose.colum0, right.mat.colum2 ),
|
||||
|
||||
Vector4.Dot( left.transpose.colum1, right.mat.colum0 ),
|
||||
Vector4.Dot( left.transpose.colum1, right.mat.colum1 ),
|
||||
Vector4.Dot( left.transpose.colum1, right.mat.colum2 ) );
|
||||
}
|
||||
|
||||
[MethodImpl( MethodImplOptions.AggressiveInlining )]
|
||||
public static Matrix24 operator *( Matrix24 left, Matrix44 right )
|
||||
{
|
||||
left.InternalTranspose();
|
||||
return new Matrix24(
|
||||
Vector4.Dot( left.transpose.colum0, right.mat.colum0 ),
|
||||
Vector4.Dot( left.transpose.colum0, right.mat.colum1 ),
|
||||
Vector4.Dot( left.transpose.colum0, right.mat.colum2 ),
|
||||
Vector4.Dot( left.transpose.colum0, right.mat.colum3 ),
|
||||
|
||||
Vector4.Dot( left.transpose.colum1, right.mat.colum0 ),
|
||||
Vector4.Dot( left.transpose.colum1, right.mat.colum1 ),
|
||||
Vector4.Dot( left.transpose.colum1, right.mat.colum2 ),
|
||||
Vector4.Dot( left.transpose.colum1, right.mat.colum3 ) );
|
||||
}
|
||||
|
||||
[MethodImpl( MethodImplOptions.AggressiveInlining )]
|
||||
public static Matrix24 operator /( Matrix24 mat, float value )
|
||||
{
|
||||
return new Matrix24(
|
||||
mat.mat.colum0 / value, mat.mat.colum1 / value,
|
||||
mat.mat.colum2 / value, mat.mat.colum3 / value );
|
||||
}
|
||||
|
||||
[MethodImpl( MethodImplOptions.AggressiveInlining )]
|
||||
public static Matrix24 operator +( Matrix24 left, Matrix24 right )
|
||||
{
|
||||
return new Matrix24(
|
||||
left.mat.colum0 + right.mat.colum0,
|
||||
left.mat.colum1 + right.mat.colum1,
|
||||
left.mat.colum2 + right.mat.colum2,
|
||||
left.mat.colum3 + right.mat.colum3 );
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,215 @@
|
||||
//-----------------------------------------------------------------------
|
||||
//-----------------------------------------------------------------------
|
||||
// file="Matrix32.cs"
|
||||
// Project: StgSharp
|
||||
// AuthorGroup: Nitload Space
|
||||
// Copyright (c) Nitload Space. 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.
|
||||
//
|
||||
//-----------------------------------------------------------------------
|
||||
//-----------------------------------------------------------------------
|
||||
using StgSharp.Data.Intrinsic;
|
||||
|
||||
using System;
|
||||
using System.Numerics;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
namespace StgSharp.Math
|
||||
{
|
||||
[StructLayout(
|
||||
LayoutKind.Explicit,
|
||||
Size = ( 5 * 4 * sizeof( float ) ) + sizeof( bool ),
|
||||
Pack = 16 )]
|
||||
public struct Matrix32 : IMat
|
||||
{
|
||||
|
||||
[FieldOffset( 5 * 4 * sizeof( float ) )] internal bool isTransposed;
|
||||
|
||||
[FieldOffset( 0 )] internal ColumnSet2 mat;
|
||||
[FieldOffset( 2 * 4 * sizeof( float ) )] internal ColumnSet3 transpose;
|
||||
|
||||
[FieldOffset( 0 )] internal Vec3 colum0;
|
||||
[FieldOffset( 4 * 4 )] internal Vec3 colum1;
|
||||
|
||||
internal Matrix32( Vector4 c0, Vector4 c1 )
|
||||
{
|
||||
mat.colum0 = c0;
|
||||
mat.colum1 = c1;
|
||||
}
|
||||
|
||||
public unsafe Matrix32(
|
||||
float a00,
|
||||
float a01,
|
||||
float a10,
|
||||
float a11,
|
||||
float a20,
|
||||
float a21 )
|
||||
{
|
||||
#if NET5_0_OR_GREATER
|
||||
Unsafe.SkipInit( out colum0 );
|
||||
Unsafe.SkipInit( out colum1 );
|
||||
Unsafe.SkipInit( out transpose );
|
||||
#endif
|
||||
mat.colum0 = new Vector4( a00, a10, a20, 0 );
|
||||
mat.colum1 = new Vector4( a01, a11, a21, 0 );
|
||||
}
|
||||
|
||||
public unsafe float this[ int rowNum, int columNum ]
|
||||
{
|
||||
get
|
||||
{
|
||||
if( ( rowNum > 2 ) || ( rowNum < 0 ) ) {
|
||||
throw new ArgumentOutOfRangeException( nameof( columNum ) );
|
||||
}
|
||||
if( ( columNum > 1 ) || ( columNum < 0 ) ) {
|
||||
throw new ArgumentOutOfRangeException( nameof( columNum ) );
|
||||
}
|
||||
InternalTranspose();
|
||||
fixed( float* p = &this.transpose.m00 ) {
|
||||
ulong pbit = ( ( ulong )p ) + ( ( ( ulong )sizeof( Vector4 ) ) * ( ( ulong )rowNum ) ) + ( ( ( ulong )sizeof( float ) ) * ( ( ulong )columNum ) );
|
||||
return *( float* )pbit;
|
||||
}
|
||||
}
|
||||
set
|
||||
{
|
||||
if( ( rowNum > 2 ) || ( rowNum < 0 ) ) {
|
||||
throw new ArgumentOutOfRangeException( nameof( columNum ) );
|
||||
}
|
||||
if( ( columNum > 1 ) || ( columNum < 0 ) ) {
|
||||
throw new ArgumentOutOfRangeException( nameof( columNum ) );
|
||||
}
|
||||
InternalTranspose();
|
||||
fixed( float* p = &this.transpose.m00 ) {
|
||||
ulong pbit = ( ( ulong )p ) + ( ( ( ulong )sizeof( Vector4 ) ) * ( ( ulong )rowNum ) ) + ( ( ( ulong )sizeof( float ) ) * ( ( ulong )columNum ) );
|
||||
*( float* )pbit = value;
|
||||
}
|
||||
isTransposed = false;
|
||||
}
|
||||
}
|
||||
|
||||
public Vec3 VerticalVecMultiply( Vec2 vec )
|
||||
{
|
||||
return ( colum0 * vec.X ) + ( colum1 * vec.Y );
|
||||
}
|
||||
|
||||
[MethodImpl( MethodImplOptions.AggressiveInlining )]
|
||||
internal unsafe void InternalTranspose()
|
||||
{
|
||||
if( !isTransposed ) {
|
||||
fixed( ColumnSet2* source = &this.mat ) {
|
||||
fixed( ColumnSet3* target = &this.transpose ) {
|
||||
InternalIO.Intrinsic.transpose23( source, target );
|
||||
}
|
||||
}
|
||||
|
||||
isTransposed = true;
|
||||
}
|
||||
}
|
||||
|
||||
[MethodImpl( MethodImplOptions.AggressiveInlining )]
|
||||
public static Matrix32 operator -( Matrix32 left, Matrix32 right )
|
||||
{
|
||||
return new Matrix32(
|
||||
left.mat.colum0 - right.mat.colum0,
|
||||
left.mat.colum1 - right.mat.colum1 );
|
||||
}
|
||||
|
||||
[MethodImpl( MethodImplOptions.AggressiveInlining )]
|
||||
public static Matrix32 operator *( Matrix32 mat, float value )
|
||||
{
|
||||
return new Matrix32(
|
||||
mat.mat.colum0 * value, mat.mat.colum1 * value );
|
||||
}
|
||||
|
||||
[MethodImpl( MethodImplOptions.AggressiveInlining )]
|
||||
public static Matrix32 operator *( Matrix32 left, Matrix22 right )
|
||||
{
|
||||
left.InternalTranspose();
|
||||
return new Matrix32(
|
||||
Vector4.Dot( left.transpose.colum0, right._mat.colum0 ),
|
||||
Vector4.Dot( left.transpose.colum0, right._mat.colum1 ),
|
||||
|
||||
Vector4.Dot( left.transpose.colum1, right._mat.colum0 ),
|
||||
Vector4.Dot( left.transpose.colum1, right._mat.colum1 ),
|
||||
|
||||
Vector4.Dot( left.transpose.colum2, right._mat.colum0 ),
|
||||
Vector4.Dot( left.transpose.colum2, right._mat.colum1 ) );
|
||||
}
|
||||
|
||||
[MethodImpl( MethodImplOptions.AggressiveInlining )]
|
||||
public static Matrix33 operator *( Matrix32 left, Matrix23 right )
|
||||
{
|
||||
left.InternalTranspose();
|
||||
return new Matrix33(
|
||||
Vector4.Dot( left.transpose.colum0, right._mat.colum0 ),
|
||||
Vector4.Dot( left.transpose.colum0, right._mat.colum1 ),
|
||||
Vector4.Dot( left.transpose.colum0, right._mat.colum2 ),
|
||||
|
||||
Vector4.Dot( left.transpose.colum1, right._mat.colum0 ),
|
||||
Vector4.Dot( left.transpose.colum1, right._mat.colum1 ),
|
||||
Vector4.Dot( left.transpose.colum1, right._mat.colum2 ),
|
||||
|
||||
Vector4.Dot( left.transpose.colum2, right._mat.colum0 ),
|
||||
Vector4.Dot( left.transpose.colum2, right._mat.colum1 ),
|
||||
Vector4.Dot( left.transpose.colum2, right._mat.colum2 ) );
|
||||
}
|
||||
|
||||
[MethodImpl( MethodImplOptions.AggressiveInlining )]
|
||||
public static Matrix34 operator *( Matrix32 left, Matrix24 right )
|
||||
{
|
||||
left.InternalTranspose();
|
||||
return new Matrix34(
|
||||
Vector4.Dot( left.transpose.colum0, right.mat.colum0 ),
|
||||
Vector4.Dot( left.transpose.colum0, right.mat.colum1 ),
|
||||
Vector4.Dot( left.transpose.colum0, right.mat.colum2 ),
|
||||
Vector4.Dot( left.transpose.colum0, right.mat.colum3 ),
|
||||
|
||||
Vector4.Dot( left.transpose.colum1, right.mat.colum0 ),
|
||||
Vector4.Dot( left.transpose.colum1, right.mat.colum1 ),
|
||||
Vector4.Dot( left.transpose.colum1, right.mat.colum2 ),
|
||||
Vector4.Dot( left.transpose.colum1, right.mat.colum3 ),
|
||||
|
||||
Vector4.Dot( left.transpose.colum2, right.mat.colum0 ),
|
||||
Vector4.Dot( left.transpose.colum2, right.mat.colum1 ),
|
||||
Vector4.Dot( left.transpose.colum2, right.mat.colum2 ),
|
||||
Vector4.Dot( left.transpose.colum2, right.mat.colum3 ) );
|
||||
}
|
||||
|
||||
[MethodImpl( MethodImplOptions.AggressiveInlining )]
|
||||
public static Matrix32 operator /( Matrix32 mat, float value )
|
||||
{
|
||||
return new Matrix32(
|
||||
mat.mat.colum0 / value, mat.mat.colum1 / value );
|
||||
}
|
||||
|
||||
[MethodImpl( MethodImplOptions.AggressiveInlining )]
|
||||
public static Matrix32 operator +( Matrix32 left, Matrix32 right )
|
||||
{
|
||||
return new Matrix32(
|
||||
left.mat.colum0 + right.mat.colum0,
|
||||
left.mat.colum1 + right.mat.colum1 );
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,231 @@
|
||||
//-----------------------------------------------------------------------
|
||||
//-----------------------------------------------------------------------
|
||||
// file="Matrix33.cs"
|
||||
// Project: StgSharp
|
||||
// AuthorGroup: Nitload Space
|
||||
// Copyright (c) Nitload Space. 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.
|
||||
//
|
||||
//-----------------------------------------------------------------------
|
||||
//-----------------------------------------------------------------------
|
||||
using StgSharp.Data.Intrinsic;
|
||||
|
||||
using System;
|
||||
using System.Numerics;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
namespace StgSharp.Math
|
||||
{
|
||||
[StructLayout(
|
||||
LayoutKind.Explicit,
|
||||
Size = ( 6 * 4 * sizeof( float ) ) + sizeof( bool ),
|
||||
Pack = 16 )]
|
||||
public struct Matrix33 : IMat
|
||||
{
|
||||
|
||||
[FieldOffset( 6 * 4 * sizeof( float ) )] internal bool isTransposed;
|
||||
|
||||
[FieldOffset( 0 )] internal ColumnSet3 mat;
|
||||
[FieldOffset( 3 * 4 * sizeof( float ) )] internal ColumnSet3 transpose;
|
||||
[FieldOffset( 0 * 4 * sizeof( float ) )] public Vec3 Colum0;
|
||||
[FieldOffset( 1 * 4 * sizeof( float ) )] public Vec3 Colum1;
|
||||
[FieldOffset( 2 * 4 * sizeof( float ) )] public Vec3 Colum2;
|
||||
|
||||
internal Matrix33( Vector4 c0, Vector4 c1, Vector4 c2 )
|
||||
{
|
||||
mat.colum0 = c0;
|
||||
mat.colum1 = c1;
|
||||
mat.colum2 = c2;
|
||||
}
|
||||
|
||||
public Matrix33(
|
||||
float a00,
|
||||
float a01,
|
||||
float a02,
|
||||
float a10,
|
||||
float a11,
|
||||
float a12,
|
||||
float a20,
|
||||
float a21,
|
||||
float a22 )
|
||||
{
|
||||
mat.colum0 = new Vector4( a00, a10, a20, 0 );
|
||||
mat.colum1 = new Vector4( a01, a11, a21, 0 );
|
||||
mat.colum2 = new Vector4( a02, a12, a22, 0 );
|
||||
}
|
||||
|
||||
public unsafe float this[ int rowNum, int columNum ]
|
||||
{
|
||||
get
|
||||
{
|
||||
if( ( rowNum > 2 ) || ( rowNum < 0 ) ) {
|
||||
throw new ArgumentOutOfRangeException( nameof( columNum ) );
|
||||
}
|
||||
if( ( columNum > 2 ) || ( columNum < 0 ) ) {
|
||||
throw new ArgumentOutOfRangeException( nameof( columNum ) );
|
||||
}
|
||||
InternalTranspose();
|
||||
fixed( float* p = &this.transpose.m00 ) {
|
||||
ulong pbit = ( ( ulong )p ) + ( ( ( ulong )sizeof( Vector4 ) ) * ( ( ulong )rowNum ) ) + ( ( ( ulong )sizeof( float ) ) * ( ( ulong )columNum ) );
|
||||
return *( float* )pbit;
|
||||
}
|
||||
}
|
||||
set
|
||||
{
|
||||
if( ( rowNum > 2 ) || ( rowNum < 0 ) ) {
|
||||
throw new ArgumentOutOfRangeException( nameof( columNum ) );
|
||||
}
|
||||
if( ( columNum > 2 ) || ( columNum < 0 ) ) {
|
||||
InternalIO.InternalWriteLog(
|
||||
$"Attempt to write unused space in {GetType().Name} {nameof(mat)}",
|
||||
LogType.Error );
|
||||
}
|
||||
InternalTranspose();
|
||||
fixed( float* p = &this.transpose.m00 ) {
|
||||
ulong pbit = ( ( ulong )p ) + ( ( ( ulong )sizeof( Vector4 ) ) * ( ( ulong )rowNum ) ) + ( ( ( ulong )sizeof( float ) ) * ( ( ulong )columNum ) );
|
||||
*( float* )pbit = value;
|
||||
}
|
||||
isTransposed = false;
|
||||
}
|
||||
}
|
||||
|
||||
[MethodImpl( MethodImplOptions.AggressiveInlining )]
|
||||
public unsafe float Det()
|
||||
{
|
||||
fixed( ColumnSet3* mat = &this.mat ) {
|
||||
return InternalIO.Intrinsic.det_mat_3( mat, ( ColumnSet3* )0 );
|
||||
}
|
||||
}
|
||||
|
||||
[MethodImpl( MethodImplOptions.AggressiveInlining )]
|
||||
internal unsafe void InternalTranspose()
|
||||
{
|
||||
if( !isTransposed ) {
|
||||
fixed( ColumnSet3* source = &this.mat, target = &this.transpose ) {
|
||||
InternalIO.Intrinsic.transpose33( source, target );
|
||||
}
|
||||
isTransposed = true;
|
||||
}
|
||||
}
|
||||
|
||||
[MethodImpl( MethodImplOptions.AggressiveInlining )]
|
||||
public static Matrix33 operator -( Matrix33 left, Matrix33 right )
|
||||
{
|
||||
return new Matrix33(
|
||||
left.mat.colum0 - right.mat.colum0,
|
||||
left.mat.colum1 - right.mat.colum1,
|
||||
left.mat.colum2 + right.mat.colum2 );
|
||||
}
|
||||
|
||||
[MethodImpl( MethodImplOptions.AggressiveInlining )]
|
||||
public static Matrix33 operator *( Matrix33 mat, float value )
|
||||
{
|
||||
return new Matrix33(
|
||||
mat.mat.colum0 * value, mat.mat.colum1 * value,
|
||||
mat.mat.colum2 * value );
|
||||
}
|
||||
|
||||
[MethodImpl( MethodImplOptions.AggressiveInlining )]
|
||||
public static Vec3 operator *( Matrix33 left, Vec3 right )
|
||||
{
|
||||
left.InternalTranspose();
|
||||
return new Vec3(
|
||||
Vector4.Dot( left.transpose.colum0, right.vec ),
|
||||
Vector4.Dot( left.transpose.colum1, right.vec ),
|
||||
Vector4.Dot( left.transpose.colum2, right.vec ) );
|
||||
}
|
||||
|
||||
[MethodImpl( MethodImplOptions.AggressiveInlining )]
|
||||
public static Matrix32 operator *( Matrix33 left, Matrix32 right )
|
||||
{
|
||||
left.InternalTranspose();
|
||||
return new Matrix32(
|
||||
Vector4.Dot( left.transpose.colum0, right.mat.colum0 ),
|
||||
Vector4.Dot( left.transpose.colum0, right.mat.colum1 ),
|
||||
|
||||
Vector4.Dot( left.transpose.colum1, right.mat.colum0 ),
|
||||
Vector4.Dot( left.transpose.colum1, right.mat.colum1 ),
|
||||
|
||||
Vector4.Dot( left.transpose.colum2, right.mat.colum0 ),
|
||||
Vector4.Dot( left.transpose.colum2, right.mat.colum1 ) );
|
||||
}
|
||||
|
||||
[MethodImpl( MethodImplOptions.AggressiveInlining )]
|
||||
public static Matrix33 operator *( Matrix33 left, Matrix33 right )
|
||||
{
|
||||
left.InternalTranspose();
|
||||
return new Matrix33(
|
||||
Vector4.Dot( left.transpose.colum0, right.mat.colum0 ),
|
||||
Vector4.Dot( left.transpose.colum0, right.mat.colum1 ),
|
||||
Vector4.Dot( left.transpose.colum0, right.mat.colum2 ),
|
||||
|
||||
Vector4.Dot( left.transpose.colum1, right.mat.colum0 ),
|
||||
Vector4.Dot( left.transpose.colum1, right.mat.colum1 ),
|
||||
Vector4.Dot( left.transpose.colum1, right.mat.colum2 ),
|
||||
|
||||
Vector4.Dot( left.transpose.colum2, right.mat.colum0 ),
|
||||
Vector4.Dot( left.transpose.colum2, right.mat.colum1 ),
|
||||
Vector4.Dot( left.transpose.colum2, right.mat.colum2 ) );
|
||||
}
|
||||
|
||||
[MethodImpl( MethodImplOptions.AggressiveInlining )]
|
||||
public static Matrix34 operator *( Matrix33 left, Matrix34 right )
|
||||
{
|
||||
left.InternalTranspose();
|
||||
return new Matrix34(
|
||||
Vector4.Dot( left.transpose.colum0, right.mat.colum0 ),
|
||||
Vector4.Dot( left.transpose.colum0, right.mat.colum1 ),
|
||||
Vector4.Dot( left.transpose.colum0, right.mat.colum2 ),
|
||||
Vector4.Dot( left.transpose.colum0, right.mat.colum3 ),
|
||||
|
||||
Vector4.Dot( left.transpose.colum1, right.mat.colum0 ),
|
||||
Vector4.Dot( left.transpose.colum1, right.mat.colum1 ),
|
||||
Vector4.Dot( left.transpose.colum1, right.mat.colum2 ),
|
||||
Vector4.Dot( left.transpose.colum1, right.mat.colum3 ),
|
||||
|
||||
Vector4.Dot( left.transpose.colum2, right.mat.colum0 ),
|
||||
Vector4.Dot( left.transpose.colum2, right.mat.colum1 ),
|
||||
Vector4.Dot( left.transpose.colum2, right.mat.colum2 ),
|
||||
Vector4.Dot( left.transpose.colum2, right.mat.colum3 ) );
|
||||
}
|
||||
|
||||
[MethodImpl( MethodImplOptions.AggressiveInlining )]
|
||||
public static Matrix33 operator /( Matrix33 mat, float value )
|
||||
{
|
||||
return new Matrix33(
|
||||
mat.mat.colum0 / value, mat.mat.colum1 / value,
|
||||
mat.mat.colum2 / value );
|
||||
}
|
||||
|
||||
[MethodImpl( MethodImplOptions.AggressiveInlining )]
|
||||
public static Matrix33 operator +( Matrix33 left, Matrix33 right )
|
||||
{
|
||||
return new Matrix33(
|
||||
left.mat.colum0 + right.mat.colum0,
|
||||
left.mat.colum1 + right.mat.colum1,
|
||||
left.mat.colum2 + right.mat.colum2 );
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,228 @@
|
||||
//-----------------------------------------------------------------------
|
||||
//-----------------------------------------------------------------------
|
||||
// file="Matrix34.cs"
|
||||
// Project: StgSharp
|
||||
// AuthorGroup: Nitload Space
|
||||
// Copyright (c) Nitload Space. 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.
|
||||
//
|
||||
//-----------------------------------------------------------------------
|
||||
//-----------------------------------------------------------------------
|
||||
using StgSharp.Data.Intrinsic;
|
||||
|
||||
using System;
|
||||
using System.Drawing;
|
||||
using System.Numerics;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
namespace StgSharp.Math
|
||||
{
|
||||
[StructLayout(
|
||||
LayoutKind.Explicit,
|
||||
Size = ( 7 * 4 * sizeof( float ) ) + sizeof( bool ),
|
||||
Pack = 16 )]
|
||||
public struct Matrix34 : IMat
|
||||
{
|
||||
|
||||
[FieldOffset( 7 * 4 * sizeof( float ) )] internal bool isTransposed;
|
||||
[FieldOffset( 4 * 4 * sizeof( float ) )] internal ColumnSet3 transpose;
|
||||
|
||||
[FieldOffset( 0 )] internal ColumnSet4 mat;
|
||||
|
||||
[FieldOffset( 0 * 4 * sizeof( float ) )] public Vec3 Colum0;
|
||||
[FieldOffset( 1 * 4 * sizeof( float ) )] public Vec3 Colum1;
|
||||
[FieldOffset( 2 * 4 * sizeof( float ) )] public Vec3 Colum2;
|
||||
[FieldOffset( 3 * 4 * sizeof( float ) )] public Vec3 Colum3;
|
||||
|
||||
internal Matrix34( ColumnSet4 mat )
|
||||
{
|
||||
this.mat = mat;
|
||||
}
|
||||
|
||||
internal Matrix34( Vector4 c0, Vector4 c1, Vector4 c2, Vector4 c3 )
|
||||
{
|
||||
mat.colum0 = c0;
|
||||
mat.colum1 = c1;
|
||||
mat.colum2 = c2;
|
||||
mat.colum3 = c3;
|
||||
}
|
||||
|
||||
public Matrix34(
|
||||
float a00,
|
||||
float a01,
|
||||
float a02,
|
||||
float a03,
|
||||
float a10,
|
||||
float a11,
|
||||
float a12,
|
||||
float a13,
|
||||
float a20,
|
||||
float a21,
|
||||
float a22,
|
||||
float a23 )
|
||||
{
|
||||
mat.colum0 = new Vector4( a00, a10, a20, 0 );
|
||||
mat.colum0 = new Vector4( a01, a11, a21, 0 );
|
||||
mat.colum0 = new Vector4( a02, a12, a22, 0 );
|
||||
mat.colum0 = new Vector4( a03, a13, a23, 0 );
|
||||
}
|
||||
|
||||
public unsafe float this[ int rowNum, int columNum ]
|
||||
{
|
||||
get
|
||||
{
|
||||
if( ( rowNum > 2 ) || ( rowNum < 0 ) ) {
|
||||
throw new ArgumentOutOfRangeException( nameof( columNum ) );
|
||||
}
|
||||
if( ( columNum > 3 ) || ( columNum < 0 ) ) {
|
||||
throw new ArgumentOutOfRangeException( nameof( columNum ) );
|
||||
}
|
||||
InternalTranspose();
|
||||
fixed( float* p = &this.transpose.m00 ) {
|
||||
ulong pbit = ( ( ulong )p ) + ( ( ( ulong )sizeof( Vector4 ) ) * ( ( ulong )rowNum ) ) + ( ( ( ulong )sizeof( float ) ) * ( ( ulong )columNum ) );
|
||||
return *( float* )pbit;
|
||||
}
|
||||
}
|
||||
set
|
||||
{
|
||||
if( ( rowNum > 2 ) || ( rowNum < 0 ) ) {
|
||||
throw new ArgumentOutOfRangeException( nameof( columNum ) );
|
||||
}
|
||||
if( ( columNum > 3 ) || ( columNum < 0 ) ) {
|
||||
throw new ArgumentOutOfRangeException( nameof( columNum ) );
|
||||
}
|
||||
InternalTranspose();
|
||||
fixed( float* p = &this.transpose.m00 ) {
|
||||
ulong pbit = ( ( ulong )p ) + ( ( ( ulong )sizeof( Vector4 ) ) * ( ( ulong )rowNum ) ) + ( ( ( ulong )sizeof( float ) ) * ( ( ulong )columNum ) );
|
||||
*( float* )pbit = value;
|
||||
}
|
||||
isTransposed = false;
|
||||
}
|
||||
}
|
||||
|
||||
internal unsafe void InternalTranspose()
|
||||
{
|
||||
if( !isTransposed ) {
|
||||
fixed( ColumnSet4* source = &this.mat ) {
|
||||
fixed( ColumnSet3* target = &this.transpose ) {
|
||||
InternalIO.Intrinsic.transpose43( source, target );
|
||||
}
|
||||
}
|
||||
|
||||
isTransposed = true;
|
||||
}
|
||||
}
|
||||
|
||||
[MethodImpl( MethodImplOptions.AggressiveInlining )]
|
||||
public static Matrix34 operator -( Matrix34 left, Matrix34 right )
|
||||
{
|
||||
return new Matrix34(
|
||||
left.mat.colum0 - right.mat.colum0,
|
||||
left.mat.colum1 - right.mat.colum1,
|
||||
left.mat.colum2 - right.mat.colum2,
|
||||
left.mat.colum3 - right.mat.colum3 );
|
||||
}
|
||||
|
||||
[MethodImpl( MethodImplOptions.AggressiveInlining )]
|
||||
public static Matrix34 operator *( Matrix34 mat, float value )
|
||||
{
|
||||
return new Matrix34(
|
||||
mat.mat.colum0 * value, mat.mat.colum1 * value,
|
||||
mat.mat.colum2 * value, mat.mat.colum3 * value );
|
||||
}
|
||||
|
||||
[MethodImpl( MethodImplOptions.AggressiveInlining )]
|
||||
public static Matrix32 operator *( Matrix34 left, Matrix42 right )
|
||||
{
|
||||
left.InternalTranspose();
|
||||
return new Matrix32(
|
||||
Vector4.Dot( left.transpose.colum0, right.mat.colum0 ),
|
||||
Vector4.Dot( left.transpose.colum0, right.mat.colum1 ),
|
||||
|
||||
Vector4.Dot( left.transpose.colum1, right.mat.colum0 ),
|
||||
Vector4.Dot( left.transpose.colum1, right.mat.colum1 ),
|
||||
|
||||
Vector4.Dot( left.transpose.colum2, right.mat.colum0 ),
|
||||
Vector4.Dot( left.transpose.colum2, right.mat.colum1 ) );
|
||||
}
|
||||
|
||||
[MethodImpl( MethodImplOptions.AggressiveInlining )]
|
||||
public static Matrix33 operator *( Matrix34 left, Matrix43 right )
|
||||
{
|
||||
left.InternalTranspose();
|
||||
return new Matrix33(
|
||||
Vector4.Dot( left.transpose.colum0, right.mat.colum0 ),
|
||||
Vector4.Dot( left.transpose.colum0, right.mat.colum1 ),
|
||||
Vector4.Dot( left.transpose.colum0, right.mat.colum2 ),
|
||||
|
||||
Vector4.Dot( left.transpose.colum1, right.mat.colum0 ),
|
||||
Vector4.Dot( left.transpose.colum1, right.mat.colum1 ),
|
||||
Vector4.Dot( left.transpose.colum1, right.mat.colum2 ),
|
||||
|
||||
Vector4.Dot( left.transpose.colum2, right.mat.colum0 ),
|
||||
Vector4.Dot( left.transpose.colum2, right.mat.colum1 ),
|
||||
Vector4.Dot( left.transpose.colum2, right.mat.colum2 ) );
|
||||
}
|
||||
|
||||
[MethodImpl( MethodImplOptions.AggressiveInlining )]
|
||||
public static Matrix34 operator *( Matrix34 left, Matrix44 right )
|
||||
{
|
||||
left.InternalTranspose();
|
||||
return new Matrix34(
|
||||
Vector4.Dot( left.transpose.colum0, right.mat.colum0 ),
|
||||
Vector4.Dot( left.transpose.colum0, right.mat.colum1 ),
|
||||
Vector4.Dot( left.transpose.colum0, right.mat.colum2 ),
|
||||
Vector4.Dot( left.transpose.colum0, right.mat.colum3 ),
|
||||
|
||||
Vector4.Dot( left.transpose.colum1, right.mat.colum0 ),
|
||||
Vector4.Dot( left.transpose.colum1, right.mat.colum1 ),
|
||||
Vector4.Dot( left.transpose.colum1, right.mat.colum2 ),
|
||||
Vector4.Dot( left.transpose.colum1, right.mat.colum3 ),
|
||||
|
||||
Vector4.Dot( left.transpose.colum2, right.mat.colum0 ),
|
||||
Vector4.Dot( left.transpose.colum2, right.mat.colum1 ),
|
||||
Vector4.Dot( left.transpose.colum2, right.mat.colum2 ),
|
||||
Vector4.Dot( left.transpose.colum2, right.mat.colum3 ) );
|
||||
}
|
||||
|
||||
[MethodImpl( MethodImplOptions.AggressiveInlining )]
|
||||
public static Matrix34 operator /( Matrix34 mat, float value )
|
||||
{
|
||||
return new Matrix34(
|
||||
mat.mat.colum0 / value, mat.mat.colum1 / value,
|
||||
mat.mat.colum2 / value, mat.mat.colum3 / value );
|
||||
}
|
||||
|
||||
[MethodImpl( MethodImplOptions.AggressiveInlining )]
|
||||
public static Matrix34 operator +( Matrix34 left, Matrix34 right )
|
||||
{
|
||||
return new Matrix34(
|
||||
left.mat.colum0 + right.mat.colum0,
|
||||
left.mat.colum1 + right.mat.colum1,
|
||||
left.mat.colum2 + right.mat.colum2,
|
||||
left.mat.colum3 + right.mat.colum3 );
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,231 @@
|
||||
//-----------------------------------------------------------------------
|
||||
//-----------------------------------------------------------------------
|
||||
// file="Matrix42.cs"
|
||||
// Project: StgSharp
|
||||
// AuthorGroup: Nitload Space
|
||||
// Copyright (c) Nitload Space. 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.
|
||||
//
|
||||
//-----------------------------------------------------------------------
|
||||
//-----------------------------------------------------------------------
|
||||
using StgSharp.Data.Intrinsic;
|
||||
|
||||
using System;
|
||||
using System.Numerics;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
namespace StgSharp.Math
|
||||
{
|
||||
[StructLayout(
|
||||
LayoutKind.Explicit,
|
||||
Size = ( ( 16 + 8 ) * sizeof( float ) ) + sizeof( bool ),
|
||||
Pack = 16 )]
|
||||
public struct Matrix42 : IMat
|
||||
{
|
||||
|
||||
[FieldOffset( ( 16 + 8 ) * sizeof( float ) )] internal bool isTransposed;
|
||||
|
||||
[FieldOffset( 0 )] internal ColumnSet2 mat;
|
||||
[FieldOffset( 8 * sizeof( float ) )] internal ColumnSet4 transpose;
|
||||
|
||||
internal Matrix42( ColumnSet2 mat )
|
||||
{
|
||||
this.mat = mat;
|
||||
}
|
||||
|
||||
internal Matrix42( Vector4 c0, Vector4 c1 )
|
||||
{
|
||||
mat.colum0 = c0;
|
||||
mat.colum1 = c1;
|
||||
}
|
||||
|
||||
public Matrix42(
|
||||
float a00,
|
||||
float a01,
|
||||
float a10,
|
||||
float a11,
|
||||
float a20,
|
||||
float a21,
|
||||
float a30,
|
||||
float a31 )
|
||||
{
|
||||
mat.colum0 = new Vector4( a00, a10, a20, a30 );
|
||||
mat.colum1 = new Vector4( a01, a11, a21, a31 );
|
||||
}
|
||||
|
||||
public unsafe float this[ int rowNum, int columNum ]
|
||||
{
|
||||
get
|
||||
{
|
||||
if( ( rowNum > 3 ) || ( rowNum < 0 ) ) {
|
||||
throw new ArgumentOutOfRangeException( nameof( columNum ) );
|
||||
}
|
||||
if( ( columNum > 1 ) || ( columNum < 0 ) ) {
|
||||
throw new ArgumentOutOfRangeException( nameof( columNum ) );
|
||||
}
|
||||
InternalTranspose();
|
||||
fixed( float* p = &this.transpose.m00 ) {
|
||||
ulong pbit = ( ( ulong )p ) + ( ( ( ulong )sizeof( Vector4 ) ) * ( ( ulong )rowNum ) ) + ( ( ( ulong )sizeof( float ) ) * ( ( ulong )columNum ) );
|
||||
return *( float* )pbit;
|
||||
}
|
||||
}
|
||||
set
|
||||
{
|
||||
if( ( rowNum > 3 ) || ( rowNum < 0 ) ) {
|
||||
throw new ArgumentOutOfRangeException( nameof( columNum ) );
|
||||
}
|
||||
if( ( columNum > 1 ) || ( columNum < 0 ) ) {
|
||||
throw new ArgumentOutOfRangeException( nameof( columNum ) );
|
||||
}
|
||||
InternalTranspose();
|
||||
fixed( float* p = &this.transpose.m00 ) {
|
||||
ulong pbit = ( ( ulong )p ) + ( ( ( ulong )sizeof( Vector4 ) ) * ( ( ulong )rowNum ) ) + ( ( ( ulong )sizeof( float ) ) * ( ( ulong )columNum ) );
|
||||
*( float* )pbit = value;
|
||||
}
|
||||
isTransposed = false;
|
||||
}
|
||||
}
|
||||
|
||||
public override int GetHashCode()
|
||||
{
|
||||
return HashCode.Combine(
|
||||
mat.colum0.GetHashCode(), mat.colum1.GetHashCode() );
|
||||
}
|
||||
|
||||
[MethodImpl( MethodImplOptions.AggressiveInlining )]
|
||||
internal unsafe void InternalTranspose()
|
||||
{
|
||||
if( !isTransposed ) {
|
||||
fixed( ColumnSet2* source = &this.mat ) {
|
||||
fixed( ColumnSet4* target = &this.transpose ) {
|
||||
InternalIO.Intrinsic.transpose24( source, target );
|
||||
}
|
||||
}
|
||||
|
||||
isTransposed = true;
|
||||
}
|
||||
}
|
||||
|
||||
[MethodImpl( MethodImplOptions.AggressiveInlining )]
|
||||
public static unsafe Matrix42 operator -(
|
||||
Matrix42 left,
|
||||
Matrix42 right )
|
||||
{
|
||||
return new Matrix42(
|
||||
left.mat.colum0 - right.mat.colum0,
|
||||
left.mat.colum0 - right.mat.colum0 );
|
||||
}
|
||||
|
||||
[MethodImpl( MethodImplOptions.AggressiveInlining )]
|
||||
public static Matrix42 operator *( Matrix42 mat, float value )
|
||||
{
|
||||
return new Matrix42(
|
||||
mat.mat.colum0 * value, mat.mat.colum1 * value );
|
||||
}
|
||||
|
||||
[MethodImpl( MethodImplOptions.AggressiveInlining )]
|
||||
public static Matrix42 operator *( Matrix42 left, Matrix22 right )
|
||||
{
|
||||
left.InternalTranspose();
|
||||
return new Matrix42(
|
||||
Vector4.Dot( left.transpose.colum0, right._mat.colum0 ),
|
||||
Vector4.Dot( left.transpose.colum0, right._mat.colum1 ),
|
||||
|
||||
Vector4.Dot( left.transpose.colum1, right._mat.colum0 ),
|
||||
Vector4.Dot( left.transpose.colum1, right._mat.colum1 ),
|
||||
|
||||
Vector4.Dot( left.transpose.colum2, right._mat.colum0 ),
|
||||
Vector4.Dot( left.transpose.colum2, right._mat.colum1 ),
|
||||
|
||||
Vector4.Dot( left.transpose.colum3, right._mat.colum0 ),
|
||||
Vector4.Dot( left.transpose.colum3, right._mat.colum1 ) );
|
||||
}
|
||||
|
||||
[MethodImpl( MethodImplOptions.AggressiveInlining )]
|
||||
public static Matrix43 operator *( Matrix42 left, Matrix23 right )
|
||||
{
|
||||
left.InternalTranspose();
|
||||
return new Matrix43(
|
||||
Vector4.Dot( left.transpose.colum0, right._mat.colum0 ),
|
||||
Vector4.Dot( left.transpose.colum0, right._mat.colum1 ),
|
||||
Vector4.Dot( left.transpose.colum0, right._mat.colum2 ),
|
||||
|
||||
Vector4.Dot( left.transpose.colum1, right._mat.colum0 ),
|
||||
Vector4.Dot( left.transpose.colum1, right._mat.colum1 ),
|
||||
Vector4.Dot( left.transpose.colum1, right._mat.colum2 ),
|
||||
|
||||
Vector4.Dot( left.transpose.colum2, right._mat.colum0 ),
|
||||
Vector4.Dot( left.transpose.colum2, right._mat.colum1 ),
|
||||
Vector4.Dot( left.transpose.colum2, right._mat.colum2 ),
|
||||
|
||||
Vector4.Dot( left.transpose.colum3, right._mat.colum0 ),
|
||||
Vector4.Dot( left.transpose.colum3, right._mat.colum1 ),
|
||||
Vector4.Dot( left.transpose.colum3, right._mat.colum2 ) );
|
||||
}
|
||||
|
||||
[MethodImpl( MethodImplOptions.AggressiveInlining )]
|
||||
public static Matrix44 operator *( Matrix42 left, Matrix24 right )
|
||||
{
|
||||
left.InternalTranspose();
|
||||
return new Matrix44(
|
||||
Vector4.Dot( left.transpose.colum0, right.mat.colum0 ),
|
||||
Vector4.Dot( left.transpose.colum0, right.mat.colum1 ),
|
||||
Vector4.Dot( left.transpose.colum0, right.mat.colum2 ),
|
||||
Vector4.Dot( left.transpose.colum0, right.mat.colum2 ),
|
||||
|
||||
Vector4.Dot( left.transpose.colum1, right.mat.colum0 ),
|
||||
Vector4.Dot( left.transpose.colum1, right.mat.colum1 ),
|
||||
Vector4.Dot( left.transpose.colum1, right.mat.colum2 ),
|
||||
Vector4.Dot( left.transpose.colum1, right.mat.colum2 ),
|
||||
|
||||
Vector4.Dot( left.transpose.colum2, right.mat.colum0 ),
|
||||
Vector4.Dot( left.transpose.colum2, right.mat.colum1 ),
|
||||
Vector4.Dot( left.transpose.colum2, right.mat.colum2 ),
|
||||
Vector4.Dot( left.transpose.colum2, right.mat.colum2 ),
|
||||
|
||||
Vector4.Dot( left.transpose.colum3, right.mat.colum0 ),
|
||||
Vector4.Dot( left.transpose.colum3, right.mat.colum1 ),
|
||||
Vector4.Dot( left.transpose.colum3, right.mat.colum2 ),
|
||||
Vector4.Dot( left.transpose.colum3, right.mat.colum2 ) );
|
||||
}
|
||||
|
||||
[MethodImpl( MethodImplOptions.AggressiveInlining )]
|
||||
public static Matrix42 operator /( Matrix42 mat, float value )
|
||||
{
|
||||
return new Matrix42(
|
||||
mat.mat.colum0 / value, mat.mat.colum1 / value );
|
||||
}
|
||||
|
||||
[MethodImpl( MethodImplOptions.AggressiveInlining )]
|
||||
public static unsafe Matrix42 operator +(
|
||||
Matrix42 left,
|
||||
Matrix42 right )
|
||||
{
|
||||
return new Matrix42(
|
||||
left.mat.colum0 + right.mat.colum0,
|
||||
left.mat.colum0 + right.mat.colum0 );
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,259 @@
|
||||
//-----------------------------------------------------------------------
|
||||
//-----------------------------------------------------------------------
|
||||
// file="Matrix43.cs"
|
||||
// Project: StgSharp
|
||||
// AuthorGroup: Nitload Space
|
||||
// Copyright (c) Nitload Space. 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.
|
||||
//
|
||||
//-----------------------------------------------------------------------
|
||||
//-----------------------------------------------------------------------
|
||||
using StgSharp.Data.Intrinsic;
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Numerics;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
namespace StgSharp.Math
|
||||
{
|
||||
[StructLayout(
|
||||
LayoutKind.Explicit,
|
||||
Size = ( 7 * 4 * sizeof( float ) ) + sizeof( bool ),
|
||||
Pack = 16 )]
|
||||
public struct Matrix43 : IEquatable<Matrix43>, IMat
|
||||
{
|
||||
|
||||
[FieldOffset( 7 * 4 * sizeof( float ) )]
|
||||
internal bool isTransposed;
|
||||
|
||||
[FieldOffset( 0 )]
|
||||
internal ColumnSet3 mat;
|
||||
|
||||
[FieldOffset( 3 * 4 * sizeof( float ) )]
|
||||
internal ColumnSet4 transpose;
|
||||
|
||||
internal Matrix43( Vector4 c0, Vector4 c1, Vector4 c2 )
|
||||
{
|
||||
mat.colum0 = c0;
|
||||
mat.colum1 = c1;
|
||||
mat.colum2 = c2;
|
||||
}
|
||||
|
||||
public Matrix43(
|
||||
float a00,
|
||||
float a01,
|
||||
float a02,
|
||||
float a10,
|
||||
float a11,
|
||||
float a12,
|
||||
float a20,
|
||||
float a21,
|
||||
float a22,
|
||||
float a30,
|
||||
float a31,
|
||||
float a32 )
|
||||
{
|
||||
mat.colum0 = new Vector4( a00, a10, a20, a30 );
|
||||
mat.colum1 = new Vector4( a01, a11, a21, a31 );
|
||||
mat.colum2 = new Vector4( a02, a12, a22, a32 );
|
||||
}
|
||||
|
||||
public unsafe float this[ int rowNum, int columNum ]
|
||||
{
|
||||
get
|
||||
{
|
||||
if( ( rowNum > 3 ) || ( rowNum < 0 ) ) {
|
||||
throw new ArgumentOutOfRangeException( nameof( columNum ) );
|
||||
}
|
||||
if( ( columNum > 2 ) || ( columNum < 0 ) ) {
|
||||
throw new ArgumentOutOfRangeException( nameof( columNum ) );
|
||||
}
|
||||
InternalTranspose();
|
||||
fixed( float* p = &this.transpose.m00 ) {
|
||||
ulong pbit = ( ( ulong )p ) + ( ( ( ulong )sizeof( Vector4 ) ) * ( ( ulong )rowNum ) ) + ( ( ( ulong )sizeof( float ) ) * ( ( ulong )columNum ) );
|
||||
return *( float* )pbit;
|
||||
}
|
||||
}
|
||||
set
|
||||
{
|
||||
if( ( rowNum > 3 ) || ( rowNum < 0 ) ) {
|
||||
throw new ArgumentOutOfRangeException( nameof( columNum ) );
|
||||
}
|
||||
if( ( columNum > 2 ) || ( columNum < 0 ) ) {
|
||||
throw new ArgumentOutOfRangeException( nameof( columNum ) );
|
||||
}
|
||||
InternalTranspose();
|
||||
fixed( float* p = &this.transpose.m00 ) {
|
||||
ulong pbit = ( ( ulong )p ) + ( ( ( ulong )sizeof( Vector4 ) ) * ( ( ulong )rowNum ) ) + ( ( ( ulong )sizeof( float ) ) * ( ( ulong )columNum ) );
|
||||
*( float* )pbit = value;
|
||||
}
|
||||
isTransposed = false;
|
||||
}
|
||||
}
|
||||
|
||||
public override bool Equals( object? obj )
|
||||
{
|
||||
return ( obj is Matrix43 x ) && Equals( x );
|
||||
}
|
||||
|
||||
public bool Equals( Matrix43 other )
|
||||
{
|
||||
return EqualityComparer<ColumnSet3>.Default.Equals( mat,
|
||||
other.mat );
|
||||
}
|
||||
|
||||
public override int GetHashCode()
|
||||
{
|
||||
return HashCode.Combine(
|
||||
mat.colum0.GetHashCode(), mat.colum1.GetHashCode(),
|
||||
mat.colum2.GetHashCode() );
|
||||
}
|
||||
|
||||
[MethodImpl( MethodImplOptions.AggressiveInlining )]
|
||||
internal unsafe void InternalTranspose()
|
||||
{
|
||||
if( !isTransposed ) {
|
||||
fixed( ColumnSet3* source = &this.mat ) {
|
||||
fixed( ColumnSet4* target = &this.transpose ) {
|
||||
InternalIO.Intrinsic.transpose34( source, target );
|
||||
}
|
||||
}
|
||||
|
||||
isTransposed = true;
|
||||
}
|
||||
}
|
||||
|
||||
[MethodImpl( MethodImplOptions.AggressiveInlining )]
|
||||
public static Matrix43 operator -( Matrix43 left, Matrix43 right )
|
||||
{
|
||||
return new Matrix43(
|
||||
left.mat.colum0 - right.mat.colum0,
|
||||
left.mat.colum1 - right.mat.colum1,
|
||||
left.mat.colum2 - right.mat.colum2 );
|
||||
}
|
||||
|
||||
public static bool operator !=( Matrix43 left, Matrix43 right )
|
||||
{
|
||||
return !( left == right );
|
||||
}
|
||||
|
||||
[MethodImpl( MethodImplOptions.AggressiveInlining )]
|
||||
public static Matrix43 operator *( Matrix43 mat, float value )
|
||||
{
|
||||
return new Matrix43(
|
||||
mat.mat.colum0 * value, mat.mat.colum1 * value,
|
||||
mat.mat.colum2 * value );
|
||||
}
|
||||
|
||||
[MethodImpl( MethodImplOptions.AggressiveInlining )]
|
||||
public static Matrix42 operator *( Matrix43 left, Matrix32 right )
|
||||
{
|
||||
left.InternalTranspose();
|
||||
return new Matrix42(
|
||||
Vector4.Dot( left.transpose.colum0, right.mat.colum0 ),
|
||||
Vector4.Dot( left.transpose.colum0, right.mat.colum1 ),
|
||||
|
||||
Vector4.Dot( left.transpose.colum1, right.mat.colum0 ),
|
||||
Vector4.Dot( left.transpose.colum1, right.mat.colum1 ),
|
||||
|
||||
Vector4.Dot( left.transpose.colum2, right.mat.colum0 ),
|
||||
Vector4.Dot( left.transpose.colum2, right.mat.colum1 ),
|
||||
|
||||
Vector4.Dot( left.transpose.colum3, right.mat.colum0 ),
|
||||
Vector4.Dot( left.transpose.colum3, right.mat.colum1 ) );
|
||||
}
|
||||
|
||||
[MethodImpl( MethodImplOptions.AggressiveInlining )]
|
||||
public static Matrix43 operator *( Matrix43 left, Matrix33 right )
|
||||
{
|
||||
left.InternalTranspose();
|
||||
return new Matrix43(
|
||||
Vector4.Dot( left.transpose.colum0, right.mat.colum0 ),
|
||||
Vector4.Dot( left.transpose.colum0, right.mat.colum1 ),
|
||||
Vector4.Dot( left.transpose.colum0, right.mat.colum2 ),
|
||||
|
||||
Vector4.Dot( left.transpose.colum1, right.mat.colum0 ),
|
||||
Vector4.Dot( left.transpose.colum1, right.mat.colum1 ),
|
||||
Vector4.Dot( left.transpose.colum1, right.mat.colum2 ),
|
||||
|
||||
Vector4.Dot( left.transpose.colum2, right.mat.colum0 ),
|
||||
Vector4.Dot( left.transpose.colum2, right.mat.colum1 ),
|
||||
Vector4.Dot( left.transpose.colum2, right.mat.colum2 ),
|
||||
|
||||
Vector4.Dot( left.transpose.colum3, right.mat.colum0 ),
|
||||
Vector4.Dot( left.transpose.colum3, right.mat.colum1 ),
|
||||
Vector4.Dot( left.transpose.colum3, right.mat.colum2 ) );
|
||||
}
|
||||
|
||||
[MethodImpl( MethodImplOptions.AggressiveInlining )]
|
||||
public static Matrix44 operator *( Matrix43 left, Matrix34 right )
|
||||
{
|
||||
left.InternalTranspose();
|
||||
return new Matrix44(
|
||||
Vector4.Dot( left.transpose.colum0, right.mat.colum0 ),
|
||||
Vector4.Dot( left.transpose.colum0, right.mat.colum1 ),
|
||||
Vector4.Dot( left.transpose.colum0, right.mat.colum2 ),
|
||||
Vector4.Dot( left.transpose.colum0, right.mat.colum3 ),
|
||||
|
||||
Vector4.Dot( left.transpose.colum1, right.mat.colum0 ),
|
||||
Vector4.Dot( left.transpose.colum1, right.mat.colum1 ),
|
||||
Vector4.Dot( left.transpose.colum1, right.mat.colum2 ),
|
||||
Vector4.Dot( left.transpose.colum1, right.mat.colum3 ),
|
||||
|
||||
Vector4.Dot( left.transpose.colum2, right.mat.colum0 ),
|
||||
Vector4.Dot( left.transpose.colum2, right.mat.colum1 ),
|
||||
Vector4.Dot( left.transpose.colum2, right.mat.colum2 ),
|
||||
Vector4.Dot( left.transpose.colum2, right.mat.colum3 ),
|
||||
|
||||
Vector4.Dot( left.transpose.colum3, right.mat.colum0 ),
|
||||
Vector4.Dot( left.transpose.colum3, right.mat.colum1 ),
|
||||
Vector4.Dot( left.transpose.colum3, right.mat.colum2 ),
|
||||
Vector4.Dot( left.transpose.colum3, right.mat.colum3 ) );
|
||||
}
|
||||
|
||||
[MethodImpl( MethodImplOptions.AggressiveInlining )]
|
||||
public static Matrix43 operator /( Matrix43 mat, float value )
|
||||
{
|
||||
return new Matrix43(
|
||||
mat.mat.colum0 / value, mat.mat.colum1 / value,
|
||||
mat.mat.colum2 / value );
|
||||
}
|
||||
|
||||
[MethodImpl( MethodImplOptions.AggressiveInlining )]
|
||||
public static Matrix43 operator +( Matrix43 left, Matrix43 right )
|
||||
{
|
||||
return new Matrix43(
|
||||
left.mat.colum0 + right.mat.colum0,
|
||||
left.mat.colum1 + right.mat.colum1,
|
||||
left.mat.colum2 + right.mat.colum2 );
|
||||
}
|
||||
|
||||
public static bool operator ==( Matrix43 left, Matrix43 right )
|
||||
{
|
||||
return left.Equals( right );
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,315 @@
|
||||
//-----------------------------------------------------------------------
|
||||
//-----------------------------------------------------------------------
|
||||
// file="Matrix44.cs"
|
||||
// Project: StgSharp
|
||||
// AuthorGroup: Nitload Space
|
||||
// Copyright (c) Nitload Space. 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.
|
||||
//
|
||||
//-----------------------------------------------------------------------
|
||||
//-----------------------------------------------------------------------
|
||||
using StgSharp.Data.Intrinsic;
|
||||
|
||||
using System;
|
||||
using System.ComponentModel;
|
||||
using System.Drawing;
|
||||
using System.Numerics;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
namespace StgSharp.Math
|
||||
{
|
||||
[StructLayout(
|
||||
LayoutKind.Explicit,
|
||||
Size = ( 2 * 16 * sizeof( float ) ) + sizeof( bool ),
|
||||
Pack = 16 )]
|
||||
public unsafe struct Matrix44 : IEquatable<Matrix44>, IMat
|
||||
{
|
||||
|
||||
[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;
|
||||
|
||||
internal Matrix44( ColumnSet4 mat )
|
||||
{
|
||||
this.mat = mat;
|
||||
}
|
||||
|
||||
internal Matrix44(
|
||||
Vector4 vec0,
|
||||
Vector4 vec1,
|
||||
Vector4 vec2,
|
||||
Vector4 vec3 )
|
||||
{
|
||||
mat.colum0 = vec0;
|
||||
mat.colum1 = vec1;
|
||||
mat.colum2 = vec2;
|
||||
mat.colum3 = vec3;
|
||||
}
|
||||
|
||||
public unsafe Matrix44(
|
||||
float a00,
|
||||
float a01,
|
||||
float a02,
|
||||
float a03,
|
||||
float a10,
|
||||
float a11,
|
||||
float a12,
|
||||
float a13,
|
||||
float a20,
|
||||
float a21,
|
||||
float a22,
|
||||
float a23,
|
||||
float a30,
|
||||
float a31,
|
||||
float a32,
|
||||
float a33 )
|
||||
{
|
||||
mat.colum0 = new Vector4( a00, a10, a20, a30 );
|
||||
mat.colum1 = new Vector4( a01, a11, a21, a31 );
|
||||
mat.colum2 = new Vector4( a02, a12, a22, a32 );
|
||||
mat.colum3 = new Vector4( a03, a13, a23, a33 );
|
||||
}
|
||||
|
||||
public unsafe float this[ int rowNum, int columNum ]
|
||||
{
|
||||
get
|
||||
{
|
||||
#if DEBUG
|
||||
if( ( rowNum > 3 ) || ( rowNum < 0 ) ) {
|
||||
throw new ArgumentOutOfRangeException( nameof( columNum ) );
|
||||
}
|
||||
if( ( columNum > 3 ) || ( columNum < 0 ) ) {
|
||||
throw new ArgumentOutOfRangeException( nameof( columNum ) );
|
||||
}
|
||||
#endif
|
||||
InternalTranspose();
|
||||
fixed( float* p = &this.transpose.m00 ) {
|
||||
ulong pbit = ( ( ulong )p ) + ( ( ( ulong )sizeof( Vector4 ) ) * ( ( ulong )rowNum ) ) + ( ( ( ulong )sizeof( float ) ) * ( ( ulong )columNum ) );
|
||||
return *( float* )pbit;
|
||||
}
|
||||
}
|
||||
set
|
||||
{
|
||||
#if DEBUG
|
||||
if( ( rowNum > 3 ) || ( rowNum < 0 ) ) {
|
||||
throw new ArgumentOutOfRangeException( nameof( columNum ) );
|
||||
}
|
||||
if( ( columNum > 3 ) || ( columNum < 0 ) ) {
|
||||
throw new ArgumentOutOfRangeException( nameof( columNum ) );
|
||||
}
|
||||
#endif
|
||||
InternalTranspose();
|
||||
fixed( float* p = &this.transpose.m00 ) {
|
||||
ulong pbit = ( ( ulong )p ) + ( ( ( ulong )sizeof( Vector4 ) ) * ( ( ulong )rowNum ) ) + ( ( ( ulong )sizeof( float ) ) * ( ( ulong )columNum ) );
|
||||
*( float* )pbit = value;
|
||||
}
|
||||
isTransposed = false;
|
||||
}
|
||||
}
|
||||
|
||||
public Matrix44 Transpose
|
||||
{
|
||||
get
|
||||
{
|
||||
InternalTranspose();
|
||||
return new Matrix44( this.transpose );
|
||||
}
|
||||
}
|
||||
|
||||
public static Matrix44 Unit => new Matrix44(
|
||||
1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1 );
|
||||
|
||||
public static Matrix44 WNegativeUnit => new Matrix44(
|
||||
1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, -1 );
|
||||
|
||||
public static Matrix44 XNegativeUnit => new Matrix44(
|
||||
-1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1 );
|
||||
|
||||
public static Matrix44 YNegativeUnit => new Matrix44(
|
||||
1, 0, 0, 0, 0, -1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1 );
|
||||
|
||||
public static Matrix44 ZNegativeUnit => new Matrix44(
|
||||
1, 0, 0, 0, 0, 1, 0, 0, 0, 0, -1, 0, 0, 0, 0, 1 );
|
||||
|
||||
[MethodImpl( MethodImplOptions.AggressiveInlining )]
|
||||
public unsafe float Det()
|
||||
{
|
||||
InternalTranspose();
|
||||
fixed( ColumnSet4* _this = &mat, _trans = &transpose ) {
|
||||
return InternalIO.Intrinsic.det_mat_4( _this, _trans );
|
||||
}
|
||||
}
|
||||
|
||||
public override bool Equals( object? obj )
|
||||
{
|
||||
return ( obj is Matrix44 x ) && Equals( x );
|
||||
}
|
||||
|
||||
public bool Equals( Matrix44 other )
|
||||
{
|
||||
return mat.Equals( other.mat );
|
||||
}
|
||||
|
||||
public override int GetHashCode()
|
||||
{
|
||||
return HashCode.Combine(
|
||||
mat.colum0.GetHashCode(), mat.colum1.GetHashCode(),
|
||||
mat.colum2.GetHashCode(), mat.colum3.GetHashCode() );
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
InternalTranspose();
|
||||
return $"{transpose.colum0}{transpose.colum1}{transpose.colum2}{transpose.colum3}";
|
||||
}
|
||||
|
||||
[MethodImpl( MethodImplOptions.AggressiveInlining )]
|
||||
internal unsafe void InternalTranspose()
|
||||
{
|
||||
if( !isTransposed ) {
|
||||
fixed( ColumnSet4* source = &mat, target = &transpose ) {
|
||||
InternalIO.Intrinsic.transpose44( source, target );
|
||||
}
|
||||
|
||||
isTransposed = true;
|
||||
}
|
||||
}
|
||||
|
||||
[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 );
|
||||
}
|
||||
|
||||
public static bool operator !=( Matrix44 left, Matrix44 right )
|
||||
{
|
||||
return !( left == right );
|
||||
}
|
||||
|
||||
[MethodImpl( MethodImplOptions.AggressiveInlining )]
|
||||
public static unsafe Matrix44 operator *( Matrix44 mat, float value )
|
||||
{
|
||||
return new Matrix44(
|
||||
mat.mat.colum0 * value, mat.mat.colum1 * value,
|
||||
mat.mat.colum2 * value, mat.mat.colum3 * value );
|
||||
}
|
||||
|
||||
[MethodImpl( MethodImplOptions.AggressiveInlining )]
|
||||
public static unsafe Matrix42 operator *(
|
||||
Matrix44 left,
|
||||
Matrix42 right )
|
||||
{
|
||||
left.InternalTranspose();
|
||||
return new Matrix42(
|
||||
Vector4.Dot( left.transpose.colum0, right.mat.colum0 ),
|
||||
Vector4.Dot( left.transpose.colum0, right.mat.colum1 ),
|
||||
|
||||
Vector4.Dot( left.transpose.colum1, right.mat.colum0 ),
|
||||
Vector4.Dot( left.transpose.colum1, right.mat.colum1 ),
|
||||
|
||||
Vector4.Dot( left.transpose.colum2, right.mat.colum0 ),
|
||||
Vector4.Dot( left.transpose.colum2, right.mat.colum1 ),
|
||||
|
||||
Vector4.Dot( left.transpose.colum3, right.mat.colum0 ),
|
||||
Vector4.Dot( left.transpose.colum3, right.mat.colum1 ) );
|
||||
}
|
||||
|
||||
[MethodImpl( MethodImplOptions.AggressiveInlining )]
|
||||
public static Matrix43 operator *( Matrix44 left, Matrix43 right )
|
||||
{
|
||||
left.InternalTranspose();
|
||||
return new Matrix43(
|
||||
Vector4.Dot( left.transpose.colum0, right.mat.colum0 ),
|
||||
Vector4.Dot( left.transpose.colum0, right.mat.colum1 ),
|
||||
Vector4.Dot( left.transpose.colum0, right.mat.colum2 ),
|
||||
|
||||
Vector4.Dot( left.transpose.colum1, right.mat.colum0 ),
|
||||
Vector4.Dot( left.transpose.colum1, right.mat.colum1 ),
|
||||
Vector4.Dot( left.transpose.colum1, right.mat.colum2 ),
|
||||
|
||||
Vector4.Dot( left.transpose.colum2, right.mat.colum0 ),
|
||||
Vector4.Dot( left.transpose.colum2, right.mat.colum1 ),
|
||||
Vector4.Dot( left.transpose.colum2, right.mat.colum2 ),
|
||||
|
||||
Vector4.Dot( left.transpose.colum3, right.mat.colum0 ),
|
||||
Vector4.Dot( left.transpose.colum3, right.mat.colum1 ),
|
||||
Vector4.Dot( left.transpose.colum3, right.mat.colum2 ) );
|
||||
}
|
||||
|
||||
[MethodImpl( MethodImplOptions.AggressiveInlining )]
|
||||
public static Matrix44 operator *( Matrix44 left, Matrix44 right )
|
||||
{
|
||||
left.InternalTranspose();
|
||||
return new Matrix44(
|
||||
Vector4.Dot( left.transpose.colum0, right.mat.colum0 ),
|
||||
Vector4.Dot( left.transpose.colum0, right.mat.colum1 ),
|
||||
Vector4.Dot( left.transpose.colum0, right.mat.colum2 ),
|
||||
Vector4.Dot( left.transpose.colum0, right.mat.colum3 ),
|
||||
|
||||
Vector4.Dot( left.transpose.colum1, right.mat.colum0 ),
|
||||
Vector4.Dot( left.transpose.colum1, right.mat.colum1 ),
|
||||
Vector4.Dot( left.transpose.colum1, right.mat.colum2 ),
|
||||
Vector4.Dot( left.transpose.colum1, right.mat.colum3 ),
|
||||
|
||||
Vector4.Dot( left.transpose.colum2, right.mat.colum0 ),
|
||||
Vector4.Dot( left.transpose.colum2, right.mat.colum1 ),
|
||||
Vector4.Dot( left.transpose.colum2, right.mat.colum2 ),
|
||||
Vector4.Dot( left.transpose.colum2, right.mat.colum3 ),
|
||||
|
||||
Vector4.Dot( left.transpose.colum3, right.mat.colum0 ),
|
||||
Vector4.Dot( left.transpose.colum3, right.mat.colum1 ),
|
||||
Vector4.Dot( left.transpose.colum3, right.mat.colum2 ),
|
||||
Vector4.Dot( left.transpose.colum3, right.mat.colum3 ) );
|
||||
}
|
||||
|
||||
[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 );
|
||||
}
|
||||
|
||||
public static bool operator ==( Matrix44 left, Matrix44 right )
|
||||
{
|
||||
return left.Equals( right );
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,133 @@
|
||||
//-----------------------------------------------------------------------
|
||||
//-----------------------------------------------------------------------
|
||||
// file="Vec2.cs"
|
||||
// Project: StgSharp
|
||||
// AuthorGroup: Nitload Space
|
||||
// Copyright (c) Nitload Space. 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.
|
||||
//
|
||||
//-----------------------------------------------------------------------
|
||||
//-----------------------------------------------------------------------
|
||||
using System.Numerics;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
namespace StgSharp.Math
|
||||
{
|
||||
/// <summary>
|
||||
/// A two dimension vector defined by two elements. Vec2Ds in StgSharp are default used as colum
|
||||
/// vector.
|
||||
/// </summary>
|
||||
[StructLayout( LayoutKind.Explicit, Size = 16, Pack = 16 )]
|
||||
public struct Vec2 : IVector
|
||||
{
|
||||
|
||||
[FieldOffset( 0 )] internal unsafe fixed float num[ 2 ];
|
||||
|
||||
[FieldOffset( 0 )]
|
||||
internal Vector2 v;
|
||||
|
||||
[FieldOffset( 0 )]
|
||||
internal Vector4 vec;
|
||||
|
||||
[FieldOffset( 0 )]
|
||||
public float X;
|
||||
[FieldOffset( 4 )]
|
||||
public float Y;
|
||||
|
||||
internal Vec2( Vector2 vec )
|
||||
{
|
||||
v = vec;
|
||||
}
|
||||
|
||||
internal Vec2( Vector4 vec )
|
||||
{
|
||||
this.vec = vec;
|
||||
}
|
||||
|
||||
public Vec2( float x, float y )
|
||||
{
|
||||
v = new Vector2( x, y );
|
||||
}
|
||||
|
||||
public static Vec2 Unit => new Vec2( 1, 1 );
|
||||
|
||||
public static Vec2 Zero => new Vec2( 0, 0 );
|
||||
|
||||
[MethodImpl( MethodImplOptions.AggressiveInlining )]
|
||||
public float Cross( Vec2 right )
|
||||
{
|
||||
return ( X * right.Y ) - ( Y * right.X );
|
||||
}
|
||||
|
||||
[MethodImpl( MethodImplOptions.AggressiveInlining )]
|
||||
public float Dot( Vec2 vec )
|
||||
{
|
||||
return Vector2.Dot( v, vec.v );
|
||||
}
|
||||
|
||||
[MethodImpl( MethodImplOptions.AggressiveInlining )]
|
||||
public static Vec2 operator -( Vec2 left, Vec2 right )
|
||||
{
|
||||
return new Vec2( left.v - right.v );
|
||||
}
|
||||
|
||||
public static bool operator !=( Vec2 left, Vec2 right )
|
||||
{
|
||||
return !( left == right );
|
||||
}
|
||||
|
||||
public static Vec2 operator *( Vec2 vec, float value )
|
||||
{
|
||||
return new Vec2( vec.v * value );
|
||||
}
|
||||
public static Vec2 operator *( float value, Vec2 vec )
|
||||
{
|
||||
return new Vec2( vec.v * value );
|
||||
}
|
||||
|
||||
public static Vec2 operator /( Vec2 vec, float value )
|
||||
{
|
||||
return new Vec2( vec.v / value );
|
||||
}
|
||||
|
||||
[MethodImpl( MethodImplOptions.AggressiveInlining )]
|
||||
public static Vec2 operator +( Vec2 left, Vec2 right )
|
||||
{
|
||||
return new Vec2( left.v + right.v );
|
||||
}
|
||||
|
||||
[MethodImpl( MethodImplOptions.AggressiveInlining )]
|
||||
public static bool operator ==( Vec2 left, Vec2 right )
|
||||
{
|
||||
return left.v == right.v;
|
||||
}
|
||||
|
||||
[MethodImpl( MethodImplOptions.AggressiveInlining )]
|
||||
public static implicit operator Vec2( (float, float) tuple )
|
||||
{
|
||||
return new Vec2( tuple.Item1, tuple.Item2 );
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,227 @@
|
||||
//-----------------------------------------------------------------------
|
||||
//-----------------------------------------------------------------------
|
||||
// file="Vec3.cs"
|
||||
// Project: StgSharp
|
||||
// AuthorGroup: Nitload Space
|
||||
// Copyright (c) Nitload Space. 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.
|
||||
//
|
||||
//-----------------------------------------------------------------------
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
using StgSharp.Data.Intrinsic;
|
||||
using System;
|
||||
using System.Numerics;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Security.AccessControl;
|
||||
|
||||
namespace StgSharp.Math
|
||||
{
|
||||
[StructLayout( LayoutKind.Explicit, Size = 16, Pack = 16 )]
|
||||
public struct Vec3 : IEquatable<Vec3>, IVector
|
||||
{
|
||||
|
||||
[FieldOffset( 0 )] internal unsafe fixed float num[ 3 ];
|
||||
[FieldOffset( 0 )]
|
||||
internal M128 reg;
|
||||
|
||||
[FieldOffset( 0 )]
|
||||
internal Vector3 v;
|
||||
|
||||
[FieldOffset( 0 )]
|
||||
internal Vector4 vec;
|
||||
|
||||
[FieldOffset( 0 )] public float X;
|
||||
[FieldOffset( 4 )] public float Y;
|
||||
[FieldOffset( 8 )] public float Z;
|
||||
|
||||
internal Vec3( Vector4 vector )
|
||||
{
|
||||
vec = vector;
|
||||
}
|
||||
|
||||
internal Vec3( Vector3 vector )
|
||||
{
|
||||
v = vector;
|
||||
}
|
||||
|
||||
public Vec3( Vec2 xy, float z )
|
||||
{
|
||||
vec = xy.vec;
|
||||
Z = z;
|
||||
}
|
||||
|
||||
public Vec3( float x, float y, float z )
|
||||
{
|
||||
#if NET5_0_OR_GREATER
|
||||
Unsafe.SkipInit( out vec );
|
||||
#endif
|
||||
v = new Vector3( x, y, z );
|
||||
}
|
||||
|
||||
public unsafe Vec2 XY
|
||||
{
|
||||
get => new Vec2( this.vec );
|
||||
set
|
||||
{
|
||||
fixed( Vector3* vptr = &v ) {
|
||||
*( Vector2* )vptr = value.v;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public Vec3 XYZ
|
||||
{
|
||||
get { return new Vec3( v ); }
|
||||
}
|
||||
|
||||
public static Vec3 Zero
|
||||
{
|
||||
get => new Vec3( 0, 0, 0 );
|
||||
}
|
||||
|
||||
public static Vec3 One => new Vec3( 1, 1, 1 );
|
||||
|
||||
public static Vec3 UnitX => new Vec3( 1, 0, 0 );
|
||||
|
||||
public static Vec3 UnitY => new Vec3( 0, 1, 0 );
|
||||
|
||||
public static Vec3 UnitZ => new Vec3( 0, 0, 1 );
|
||||
|
||||
[MethodImpl( MethodImplOptions.AggressiveInlining )]
|
||||
public static Vec3 Cross( Vec3 left, Vec3 right )
|
||||
{
|
||||
return Linear.Cross( left, right );
|
||||
}
|
||||
|
||||
[MethodImpl( MethodImplOptions.AggressiveInlining )]
|
||||
public float Dot( Vec3 right )
|
||||
{
|
||||
return Vector3.Dot( v, right.v );
|
||||
}
|
||||
|
||||
public bool Equals( Vec3 other )
|
||||
{
|
||||
return this.vec == other.vec;
|
||||
}
|
||||
|
||||
public override bool Equals( object obj )
|
||||
{
|
||||
if( obj is Vec3 ) {
|
||||
return this == ( Vec3 )obj;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public override unsafe int GetHashCode()
|
||||
{
|
||||
fixed( float* add = &X ) {
|
||||
return HashCode.Combine( X, Y, Z, ( ulong )add );
|
||||
}
|
||||
}
|
||||
|
||||
[MethodImpl( MethodImplOptions.AggressiveInlining )]
|
||||
public float GetMaxValue()
|
||||
{
|
||||
float ret = X;
|
||||
ret = ( ret > Y ) ? ret : Y;
|
||||
ret = ( ret > Z ) ? ret : Z;
|
||||
return ret;
|
||||
}
|
||||
|
||||
public static bool IsParallel( Vec3 left, Vec3 right )
|
||||
{
|
||||
return Cross( left, right ) == Zero;
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return $"[{X},{Y},{Z}]";
|
||||
}
|
||||
|
||||
public string ToString( string sample )
|
||||
{
|
||||
return $"[{X.ToString(sample)},{Y.ToString(sample)},{Z.ToString(sample)}]";
|
||||
}
|
||||
|
||||
[MethodImpl( MethodImplOptions.AggressiveInlining )]
|
||||
public static Vec3 operator -( Vec3 vec )
|
||||
{
|
||||
return new Vec3( -vec.vec );
|
||||
}
|
||||
|
||||
[MethodImpl( MethodImplOptions.AggressiveInlining )]
|
||||
public static Vec3 operator -( Vec3 left, Vec3 right )
|
||||
{
|
||||
return new Vec3( left.v - right.v );
|
||||
}
|
||||
|
||||
[MethodImpl( MethodImplOptions.AggressiveInlining )]
|
||||
public static bool operator !=( Vec3 left, Vec3 right )
|
||||
{
|
||||
return left.v != right.v;
|
||||
}
|
||||
|
||||
[MethodImpl( MethodImplOptions.AggressiveInlining )]
|
||||
public static Vec3 operator *( Vec3 vec, float value )
|
||||
{
|
||||
return new Vec3( vec.v * value );
|
||||
}
|
||||
|
||||
[MethodImpl( MethodImplOptions.AggressiveInlining )]
|
||||
public static float operator *( Vec3 left, Vec3 right )
|
||||
{
|
||||
return Vector3.Dot( left.v, right.v );
|
||||
}
|
||||
|
||||
[MethodImpl( MethodImplOptions.AggressiveInlining )]
|
||||
public static Vec3 operator /( Vec3 vec, float value )
|
||||
{
|
||||
return new Vec3( vec.v / value );
|
||||
}
|
||||
|
||||
[MethodImpl( MethodImplOptions.AggressiveInlining )]
|
||||
public static Vec3 operator +( Vec3 left, Vec3 right )
|
||||
{
|
||||
return new Vec3( left.vec + right.vec );
|
||||
}
|
||||
|
||||
[MethodImpl( MethodImplOptions.AggressiveInlining )]
|
||||
public static bool operator ==( Vec3 left, Vec3 right )
|
||||
{
|
||||
return left.v == right.v;
|
||||
}
|
||||
|
||||
[MethodImpl( MethodImplOptions.AggressiveInlining )]
|
||||
public static unsafe implicit operator Vec3(
|
||||
(float, float, float) tuple )
|
||||
{
|
||||
Vec3 v = *( Vec3* )&tuple;
|
||||
v.vec.W = 0.0f;
|
||||
return v;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,175 @@
|
||||
//-----------------------------------------------------------------------
|
||||
//-----------------------------------------------------------------------
|
||||
// file="Vec4.cs"
|
||||
// Project: StgSharp
|
||||
// AuthorGroup: Nitload Space
|
||||
// Copyright (c) Nitload Space. 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.
|
||||
//
|
||||
//-----------------------------------------------------------------------
|
||||
//-----------------------------------------------------------------------
|
||||
using StgSharp.Data.Intrinsic;
|
||||
using StgSharp.Math;
|
||||
|
||||
using System;
|
||||
using System.Data.Common;
|
||||
using System.Numerics;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
namespace StgSharp.Math
|
||||
{
|
||||
[StructLayout( LayoutKind.Explicit, Size = 16, Pack = 16 )]
|
||||
public struct Vec4 : IEquatable<Vec4>, IVector
|
||||
{
|
||||
|
||||
[FieldOffset( 0 )] internal unsafe fixed float num[ 4 ];
|
||||
|
||||
[FieldOffset( 0 )] internal M128 reg;
|
||||
|
||||
[FieldOffset( 0 )] internal Vector4 vec;
|
||||
[FieldOffset( 12 )] public float W;
|
||||
|
||||
[FieldOffset( 0 )] public float X;
|
||||
[FieldOffset( 4 )] public float Y;
|
||||
[FieldOffset( 8 )] public float Z;
|
||||
|
||||
internal Vec4( Vector4 v )
|
||||
{
|
||||
vec = v;
|
||||
}
|
||||
|
||||
public Vec4( Vec3 v, float w )
|
||||
{
|
||||
vec = v.vec;
|
||||
W = w;
|
||||
}
|
||||
|
||||
public Vec4( float x, float y, float z, float w )
|
||||
{
|
||||
vec = new Vector4( x, y, z, w );
|
||||
}
|
||||
|
||||
public unsafe Vec2 XY
|
||||
{
|
||||
get => new Vec2( vec );
|
||||
set
|
||||
{
|
||||
X = value.X;
|
||||
Y = value.Y;
|
||||
}
|
||||
}
|
||||
|
||||
public unsafe Vec3 XYZ
|
||||
{
|
||||
get => new Vec3( vec );
|
||||
set
|
||||
{
|
||||
float w = W;
|
||||
vec = value.vec;
|
||||
W = w;
|
||||
}
|
||||
}
|
||||
|
||||
public static Vec4 One
|
||||
{
|
||||
get => new Vec4( Vector4.One );
|
||||
}
|
||||
|
||||
public static Vec4 Zero
|
||||
{
|
||||
get => new Vec4( Vector4.Zero );
|
||||
}
|
||||
|
||||
[MethodImpl( MethodImplOptions.AggressiveInlining )]
|
||||
public static Vec4 Add( Vec4 left, Vec4 right )
|
||||
{
|
||||
return left + right;
|
||||
}
|
||||
|
||||
public override bool Equals( object obj )
|
||||
{
|
||||
return ( obj is Vec4 v ) ? ( v == this ) : false;
|
||||
}
|
||||
|
||||
public override int GetHashCode()
|
||||
{
|
||||
return vec.GetHashCode();
|
||||
}
|
||||
|
||||
[MethodImpl( MethodImplOptions.AggressiveInlining )]
|
||||
public static Vec4 Subtract( Vec4 left, Vec4 right )
|
||||
{
|
||||
return left - right;
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return vec.ToString();
|
||||
}
|
||||
|
||||
[MethodImpl( MethodImplOptions.AggressiveInlining )]
|
||||
public static Vec4 operator -( Vec4 left, Vec4 right )
|
||||
{
|
||||
return new Vec4( left.vec - right.vec );
|
||||
}
|
||||
|
||||
public static bool operator !=( Vec4 left, Vec4 right )
|
||||
{
|
||||
return !( left == right );
|
||||
}
|
||||
|
||||
[MethodImpl( MethodImplOptions.AggressiveInlining )]
|
||||
public static Vec4 operator *( Matrix44 mat, Vec4 vec )
|
||||
{
|
||||
mat.InternalTranspose();
|
||||
return new Vec4(
|
||||
Vector4.Dot( mat.transpose.colum0, vec.vec ),
|
||||
Vector4.Dot( mat.transpose.colum1, vec.vec ),
|
||||
Vector4.Dot( mat.transpose.colum2, vec.vec ),
|
||||
Vector4.Dot( mat.transpose.colum3, vec.vec ) );
|
||||
}
|
||||
|
||||
[MethodImpl( MethodImplOptions.AggressiveInlining )]
|
||||
public static Vec4 operator +( Vec4 left, Vec4 right )
|
||||
{
|
||||
return new Vec4( left.vec + right.vec );
|
||||
}
|
||||
|
||||
public static bool operator ==( Vec4 left, Vec4 right )
|
||||
{
|
||||
return left.vec == right.vec;
|
||||
}
|
||||
|
||||
public static implicit operator M128( Vec4 vec )
|
||||
{
|
||||
return vec.reg;
|
||||
}
|
||||
|
||||
bool IEquatable<Vec4>.Equals( Vec4 other )
|
||||
{
|
||||
return vec == other.vec;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,50 @@
|
||||
//-----------------------------------------------------------------------
|
||||
//-----------------------------------------------------------------------
|
||||
// file="Vector.Cross.cs"
|
||||
// Project: StgSharp
|
||||
// AuthorGroup: Nitload Space
|
||||
// Copyright (c) Nitload Space. 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.
|
||||
//
|
||||
//-----------------------------------------------------------------------
|
||||
//-----------------------------------------------------------------------
|
||||
namespace StgSharp.Math
|
||||
{
|
||||
public static unsafe partial class Linear
|
||||
{
|
||||
|
||||
public static float Cross( Vec2 vec1, Vec2 vec2 )
|
||||
{
|
||||
return ( vec1.X * vec2.Y ) - ( vec1.Y * vec2.X );
|
||||
}
|
||||
|
||||
public static Vec3 Cross( Vec3 vec1, Vec3 vec2 )
|
||||
{
|
||||
return new Vec3(
|
||||
( vec1.Y * vec2.Z ) - ( vec1.Z * vec2.Y ),
|
||||
( vec1.X * vec2.Z ) - ( vec1.Z * vec2.X ),
|
||||
( vec1.X * vec2.Y ) - ( vec1.Y * vec2.X ) );
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,51 @@
|
||||
//-----------------------------------------------------------------------
|
||||
//-----------------------------------------------------------------------
|
||||
// file="Vector.GetAngle.cs"
|
||||
// Project: StgSharp
|
||||
// AuthorGroup: Nitload Space
|
||||
// Copyright (c) Nitload Space. 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.
|
||||
//
|
||||
//-----------------------------------------------------------------------
|
||||
//-----------------------------------------------------------------------
|
||||
namespace StgSharp.Math
|
||||
{
|
||||
public static unsafe partial class Linear
|
||||
{
|
||||
|
||||
public static float GetAngle( Vec2 vec1, Vec2 vec2 )
|
||||
{
|
||||
return Scaler.ACos(
|
||||
1
|
||||
//vec1.multiple(vec2)
|
||||
/ ( vec1.GetLength() * vec2.GetLength() ) );
|
||||
}
|
||||
|
||||
public static float GetAngle( Vec3 vec1, Vec3 vec2 )
|
||||
{
|
||||
return Scaler.ACos(
|
||||
( vec1 * vec2 ) / ( vec1.GetLength() * vec2.GetLength() ) );
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,47 @@
|
||||
//-----------------------------------------------------------------------
|
||||
//-----------------------------------------------------------------------
|
||||
// file="Vector.GetLength.cs"
|
||||
// Project: StgSharp
|
||||
// AuthorGroup: Nitload Space
|
||||
// Copyright (c) Nitload Space. 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.
|
||||
//
|
||||
//-----------------------------------------------------------------------
|
||||
//-----------------------------------------------------------------------
|
||||
namespace StgSharp.Math
|
||||
{
|
||||
public static unsafe partial class Linear
|
||||
{
|
||||
|
||||
public static float GetLength( this Vec3 vec )
|
||||
{
|
||||
return Scaler.Sqrt( vec.Dot( vec ) );
|
||||
}
|
||||
|
||||
public static float GetLength( this Vec2 vec )
|
||||
{
|
||||
return Scaler.Sqrt( vec.Dot( vec ) );
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,89 @@
|
||||
//-----------------------------------------------------------------------
|
||||
//-----------------------------------------------------------------------
|
||||
// file="Vector.Normalize.cs"
|
||||
// Project: StgSharp
|
||||
// AuthorGroup: Nitload Space
|
||||
// Copyright (c) Nitload Space. 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.
|
||||
//
|
||||
//-----------------------------------------------------------------------
|
||||
//-----------------------------------------------------------------------
|
||||
using StgSharp.Data;
|
||||
using StgSharp.Math;
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Numerics;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace StgSharp.Math
|
||||
{
|
||||
public static partial class Linear
|
||||
{
|
||||
|
||||
public static Vec4 Normalize( Vec4 vec )
|
||||
{
|
||||
return new Vec4 { vec = Vector4.Normalize( vec.vec ) };
|
||||
}
|
||||
|
||||
public static Vec3 Normalize( Vec3 vec )
|
||||
{
|
||||
return new Vec3 { vec = Vector4.Normalize( vec.vec ) };
|
||||
}
|
||||
|
||||
public static unsafe void Normalize( ref Vec4 source, ref Vec4 target )
|
||||
{
|
||||
Vector4 s = source.vec;
|
||||
Vector4 t = target.vec;
|
||||
|
||||
s = Vector4.Normalize( s );
|
||||
|
||||
float dotProduct = Vector4.Dot( s, t );
|
||||
Vector4 projection = Vector4.Multiply( s, t );
|
||||
|
||||
t -= projection;
|
||||
|
||||
source.vec = s;
|
||||
target.vec = t;
|
||||
}
|
||||
|
||||
public static unsafe void Normalize( ref Vec3 source, ref Vec3 target )
|
||||
{
|
||||
Vector3 s = source.v;
|
||||
Vector3 t = target.v;
|
||||
|
||||
s = Vector3.Normalize( s );
|
||||
Vector3 projection = ( Vector3.Dot( t, s ) / Vector3.Dot( s,
|
||||
s ) ) * s;
|
||||
t -= projection;
|
||||
t = Vector3.Normalize( t );
|
||||
|
||||
source.v = s;
|
||||
target.v = t;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,115 @@
|
||||
//-----------------------------------------------------------------------
|
||||
//-----------------------------------------------------------------------
|
||||
// file="Vector.Orthogonalize.cs"
|
||||
// Project: StgSharp
|
||||
// AuthorGroup: Nitload Space
|
||||
// Copyright (c) Nitload Space. 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.
|
||||
//
|
||||
//-----------------------------------------------------------------------
|
||||
//-----------------------------------------------------------------------
|
||||
using StgSharp.Data.Intrinsic;
|
||||
using StgSharp.Math;
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Numerics;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace StgSharp
|
||||
{
|
||||
internal static partial class InternalIO
|
||||
{
|
||||
|
||||
[DllImport(
|
||||
SSC_libName,
|
||||
EntryPoint = "normalize",
|
||||
CallingConvention = CallingConvention.Cdecl )]
|
||||
internal static extern unsafe void Normalize(
|
||||
M128* source,
|
||||
M128* target );
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
namespace StgSharp.Math
|
||||
{
|
||||
public static partial class Linear
|
||||
{
|
||||
|
||||
public static Vec4 Orthogonalize( Vec4 vec )
|
||||
{
|
||||
return new Vec4 { vec = Vector4.Normalize( vec.vec ) };
|
||||
}
|
||||
|
||||
public static Vec3 Orthogonalize( Vec3 vec )
|
||||
{
|
||||
return new Vec3 { vec = Vector4.Normalize( vec.vec ) };
|
||||
}
|
||||
|
||||
public static unsafe void Orthogonalize(
|
||||
ref Vec4 source,
|
||||
ref Vec4 target )
|
||||
{
|
||||
Vector4 s = source.vec;
|
||||
Vector4 t = target.vec;
|
||||
|
||||
s = Vector4.Normalize( s );
|
||||
|
||||
float dotProduct = Vector4.Dot( s, t );
|
||||
Vector4 projection = Vector4.Multiply( s, t );
|
||||
|
||||
t -= projection;
|
||||
|
||||
source.vec = s;
|
||||
target.vec = t;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Orthogonalize two <see cref="Vec3" />s, let their length be 1 and perpendicular to each
|
||||
/// other.
|
||||
/// </summary>
|
||||
/// <param name="source"></param>
|
||||
/// <param name="target"></param>
|
||||
public static unsafe void Orthogonalize(
|
||||
ref Vec3 source,
|
||||
ref Vec3 target )
|
||||
{
|
||||
Vector3 s = source.v;
|
||||
Vector3 t = target.v;
|
||||
|
||||
s = Vector3.Normalize( s );
|
||||
Vector3 projection = ( Vector3.Dot( t, s ) / Vector3.Dot( s,
|
||||
s ) ) * s;
|
||||
t -= projection;
|
||||
t = Vector3.Normalize( t );
|
||||
|
||||
source.v = s;
|
||||
target.v = t;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user