Daily update on 20250618-051714 by Nitload Youmu. Additional Message : Brief support to collection operation in EXPRESS. A collection type added in core lib and compilestack.
Signed-off-by: Nitload <YoumuLiu_NSI@whv0t.onmicrosoft.com>
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
//-----------------------------------------------------------------------
|
||||
//-----------------------------------------------------------------------
|
||||
// file="Camera.cs"
|
||||
// Project: StgSharp
|
||||
// Project: StepVisualizer
|
||||
// AuthorGroup: Nitload Space
|
||||
// Copyright (c) Nitload Space. All rights reserved.
|
||||
//
|
||||
@@ -96,28 +96,34 @@ namespace StgSharp.Graphics
|
||||
}
|
||||
}
|
||||
|
||||
public Matrix44 CameraMatrix()
|
||||
{
|
||||
return Projection * View;
|
||||
}
|
||||
|
||||
public void DisplayGLtypeDefinition()
|
||||
{
|
||||
Console.WriteLine( "uniform matrix4x4 cameraName;" );
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Get all uniform related to this <see cref="Camera" />.
|
||||
/// Get all uniform related to this <see cref="Camera" />.
|
||||
/// </summary>
|
||||
/// <param _name="source"> Shader program requires this camera. </param>
|
||||
/// <param _name="uniformName">
|
||||
/// ContextName of all related uniforms. If you fallow form from <see
|
||||
/// cref="IglConvertable.DisplayGLtypeDefinition" />
|
||||
/// <param _label="source">
|
||||
/// Shader program requires this camera.
|
||||
/// </param>
|
||||
/// <exception cref="ArgumentException"></exception>
|
||||
public unsafe void GainAllUniforms(
|
||||
ShaderProgram source,
|
||||
params string[] uniformName )
|
||||
/// <param _label="uniformName">
|
||||
/// ContextName of all related uniforms. If you fallow form from <see
|
||||
/// cref="IglConvertable.DisplayGLtypeDefinition" />
|
||||
/// </param>
|
||||
/// <exception cref="ArgumentException">
|
||||
///
|
||||
/// </exception>
|
||||
public unsafe void GainAllUniforms( ShaderProgram source, params string[] uniformName )
|
||||
{
|
||||
if( uniformName is null || uniformName.Length != 1 ) {
|
||||
throw new ArgumentException(
|
||||
"Camera needs exactly one uniform.",
|
||||
nameof( uniformName ) );
|
||||
"Camera needs exactly one uniform.", nameof( uniformName ) );
|
||||
}
|
||||
convertedUniform = source.GetUniform<Matrix44>( uniformName[ 0 ] );
|
||||
}
|
||||
@@ -143,19 +149,19 @@ namespace StgSharp.Graphics
|
||||
public unsafe void SetAllUniforms()
|
||||
{
|
||||
//Console.WriteLine(Projection * ViewBase);
|
||||
OpenGL.OpenGLFunction.CurrentGL
|
||||
.SetUniformValue( convertedUniform, Projection * View );
|
||||
OpenGL.OpenGLFunction.CurrentGL.SetUniformValue( convertedUniform, Projection * View );
|
||||
}
|
||||
|
||||
public void SetViewDirection( Vec3 position, Vec3 target, Vec3 up )
|
||||
{
|
||||
Vec3 direction = position - target;
|
||||
if( ( position.reg == cameraAtt.colum3.reg ) && ( this.up == up ) && ( cameraAtt.colum2.reg ==
|
||||
direction.reg ) ) {
|
||||
//no difference with precious value
|
||||
if( ( position.reg == cameraAtt.colum3.reg ) &&
|
||||
( this.up == up ) &&
|
||||
( cameraAtt.colum2.reg == direction.reg ) ) {
|
||||
return;
|
||||
}
|
||||
if( direction.GetLength() == 0 ) {
|
||||
if( direction.GetLength() == 0 )
|
||||
{
|
||||
//deadlock
|
||||
throw new ArgumentException();
|
||||
}
|
||||
@@ -171,10 +177,10 @@ namespace StgSharp.Graphics
|
||||
|
||||
Vec3 right = Linear.Orthogonalize( Linear.Cross( up, direction ) );
|
||||
|
||||
cameraAtt.colum0.reg = right. reg;
|
||||
cameraAtt.colum0.reg = right.reg;
|
||||
cameraAtt.colum1.reg = up.reg;
|
||||
cameraAtt.colum2.reg = direction.reg;
|
||||
cameraAtt.colum3.reg = position. reg;
|
||||
cameraAtt.colum3.reg = position.reg;
|
||||
|
||||
InternalPitch();
|
||||
InternalRow();
|
||||
@@ -182,10 +188,10 @@ namespace StgSharp.Graphics
|
||||
}
|
||||
|
||||
public void SetViewRange(
|
||||
Radius fovRadius,
|
||||
Vec2 size,
|
||||
Vec2 offset,
|
||||
(float front, float back) dephRange )
|
||||
Radius fovRadius,
|
||||
Vec2 size,
|
||||
Vec2 offset,
|
||||
(float front, float back) dephRange )
|
||||
{
|
||||
float
|
||||
distance = _target.GetLength(),
|
||||
@@ -193,8 +199,7 @@ namespace StgSharp.Graphics
|
||||
far = distance + dephRange.back,
|
||||
offsetX = offset.X,
|
||||
offsetY = offset.Y,
|
||||
width = Scaler.Abs(
|
||||
GeometryScaler.Tan( fovRadius / 2 ) * near * 2 ),
|
||||
width = Scaler.Abs( GeometryScaler.Tan( fovRadius / 2 ) * near * 2 ),
|
||||
height = ( width * size.Y ) / size.X;
|
||||
|
||||
_projection.colum0.X = ( 2 * near ) / width;
|
||||
@@ -257,8 +262,7 @@ namespace StgSharp.Graphics
|
||||
{
|
||||
_isLookAtAvailable = false;
|
||||
|
||||
Matrix32 partialCoord = new Matrix32(
|
||||
cameraAtt.colum1.vec, cameraAtt.colum2.vec );
|
||||
Matrix32 partialCoord = new Matrix32( cameraAtt.colum1.vec, cameraAtt.colum2.vec );
|
||||
float angle = _pitch._radius;
|
||||
|
||||
Matrix22 rotation = new Matrix22(
|
||||
@@ -275,8 +279,7 @@ namespace StgSharp.Graphics
|
||||
{
|
||||
_isLookAtAvailable = false;
|
||||
|
||||
Matrix32 partialCoord = new Matrix32(
|
||||
cameraAtt.colum0.vec, cameraAtt.colum1.vec );
|
||||
Matrix32 partialCoord = new Matrix32( cameraAtt.colum0.vec, cameraAtt.colum1.vec );
|
||||
float angle = _row._radius;
|
||||
|
||||
Matrix22 rotation = new Matrix22(
|
||||
@@ -293,8 +296,7 @@ namespace StgSharp.Graphics
|
||||
{
|
||||
_isLookAtAvailable = false;
|
||||
|
||||
Matrix32 partialCoord = new Matrix32(
|
||||
cameraAtt.colum0.vec, cameraAtt.colum2.vec );
|
||||
Matrix32 partialCoord = new Matrix32( cameraAtt.colum0.vec, cameraAtt.colum2.vec );
|
||||
float angle = _yaw._radius;
|
||||
Matrix22 rotation = new Matrix22(
|
||||
Scaler.Cos( angle ), -Scaler.Sin( angle ), Scaler.Sin( angle ),
|
||||
|
||||
@@ -0,0 +1,67 @@
|
||||
//-----------------------------------------------------------------------
|
||||
//-----------------------------------------------------------------------
|
||||
// file="Vec2HP.cs"
|
||||
// Project: World
|
||||
// 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.HighPerformance;
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Runtime.Intrinsics;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace StgSharp.Math.HighPrecision
|
||||
{
|
||||
[StructLayout( LayoutKind.Explicit, Pack = 16 )]
|
||||
public struct Vec2HP : IVector<Vec2HP>
|
||||
{
|
||||
|
||||
[FieldOffset( 0 )] private M256 buffer;
|
||||
[FieldOffset( 0 )] private Vector256<float> clrBuffer;
|
||||
|
||||
[FieldOffset( 0 * sizeof( double ) )] public double X;
|
||||
[FieldOffset( 1 * sizeof( double ) )] public double Y;
|
||||
|
||||
public Vec2HP( double x, double y )
|
||||
{
|
||||
this.X = x;
|
||||
this.Y = y;
|
||||
Unsafe.SkipInit( out buffer );
|
||||
Unsafe.SkipInit( out clrBuffer );
|
||||
}
|
||||
|
||||
public static Vec2HP Zero => new Vec2HP( 0, 0 );
|
||||
|
||||
public static Vec2HP One => new Vec2HP( 1, 1 );
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,86 @@
|
||||
//-----------------------------------------------------------------------
|
||||
//-----------------------------------------------------------------------
|
||||
// file="Vec3HP.cs"
|
||||
// Project: StepVisualizer
|
||||
// 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.HighPerformance;
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Drawing;
|
||||
using System.Linq;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Runtime.Intrinsics;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace StgSharp.Math.HighPrecision
|
||||
{
|
||||
[StructLayout( LayoutKind.Explicit, Pack = 16 )]
|
||||
public struct Vec3HP : IVector<Vec3HP>
|
||||
{
|
||||
|
||||
[FieldOffset( 0 )] internal M256 buffer;
|
||||
[FieldOffset( 0 )] internal Vector256<float> clrBuffer;
|
||||
[FieldOffset( 0 * sizeof( double ) )] public double X;
|
||||
[FieldOffset( 1 * sizeof( double ) )] public double Y;
|
||||
[FieldOffset( 2 * sizeof( double ) )] public double Z;
|
||||
|
||||
public Vec3HP() : this( 0, 0, 0 ) { }
|
||||
|
||||
public Vec3HP( Vector256<float> clrBuffer )
|
||||
{
|
||||
this.X = 0;
|
||||
this.Y = 0;
|
||||
this.Z = 0;
|
||||
Unsafe.SkipInit( out buffer );
|
||||
Unsafe.SkipInit( out this.clrBuffer );
|
||||
this.clrBuffer = clrBuffer;
|
||||
}
|
||||
|
||||
public Vec3HP( double x, double y, double z )
|
||||
{
|
||||
this.X = x;
|
||||
this.Y = y;
|
||||
this.Z = z;
|
||||
Unsafe.SkipInit( out buffer );
|
||||
Unsafe.SkipInit( out clrBuffer );
|
||||
}
|
||||
|
||||
public static Vec3HP Zero => new Vec3HP( 1, 1, 1 );
|
||||
|
||||
public static Vec3HP One => throw new NotImplementedException();
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return $"Double precision 3D Vector<{X},{Y},{Z}>";
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,70 @@
|
||||
//-----------------------------------------------------------------------
|
||||
//-----------------------------------------------------------------------
|
||||
// file="Vec4HP.cs"
|
||||
// Project: World
|
||||
// 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.HighPerformance;
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Runtime.Intrinsics;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace StgSharp.Math.HighPrecision
|
||||
{
|
||||
[StructLayout( LayoutKind.Explicit, Pack =16 )]
|
||||
public struct Vec4HP : IVector<Vec4HP>
|
||||
{
|
||||
|
||||
[FieldOffset( 0 )] private M256 buffer;
|
||||
[FieldOffset( 0 )] private Vector256<float> clrBuffer;
|
||||
[FieldOffset( 3 * sizeof( double ) )] public double W;
|
||||
[FieldOffset( 0 * sizeof( double ) )] public double X;
|
||||
[FieldOffset( 1 * sizeof( double ) )] public double Y;
|
||||
[FieldOffset( 2 * sizeof( double ) )] public double Z;
|
||||
|
||||
public Vec4HP( double x, double y, double z, double w )
|
||||
{
|
||||
this.X = x;
|
||||
this.Y = y;
|
||||
this.Z = z;
|
||||
this.W = w;
|
||||
Unsafe.SkipInit( out buffer );
|
||||
Unsafe.SkipInit( out clrBuffer );
|
||||
}
|
||||
|
||||
public static Vec4HP Zero => new Vec4HP( 0, 0, 0, 0 );
|
||||
|
||||
public static Vec4HP One => new Vec4HP( 1, 1, 1, 1 );
|
||||
|
||||
}
|
||||
}
|
||||
@@ -40,27 +40,9 @@ namespace StgSharp.Math
|
||||
public interface IVector<TSelf> where TSelf: struct, IVector<TSelf>
|
||||
{
|
||||
|
||||
public static abstract TSelf Zero
|
||||
{
|
||||
get;
|
||||
}
|
||||
public static abstract TSelf Zero { get; }
|
||||
|
||||
public static abstract TSelf One
|
||||
{
|
||||
get;
|
||||
}
|
||||
|
||||
public Vec2 XY
|
||||
{
|
||||
get;
|
||||
set;
|
||||
}
|
||||
|
||||
public Vec3 XYZ
|
||||
{
|
||||
get;
|
||||
set;
|
||||
}
|
||||
public static abstract TSelf One { get; }
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -96,7 +96,8 @@ namespace StgSharp.Math
|
||||
[MethodImpl( MethodImplOptions.AggressiveInlining )]
|
||||
internal void InternalTranspose()
|
||||
{
|
||||
if( !isTransposed ) {
|
||||
if( !isTransposed )
|
||||
{
|
||||
_transpose = _mat;
|
||||
float cache = _transpose.m10;
|
||||
_transpose.m10 = _transpose.m01;
|
||||
@@ -106,21 +107,17 @@ namespace StgSharp.Math
|
||||
}
|
||||
|
||||
[MethodImpl( MethodImplOptions.AggressiveInlining )]
|
||||
public static unsafe Matrix22 operator -(
|
||||
Matrix22 left,
|
||||
Matrix22 right )
|
||||
public static unsafe Matrix22 operator -( Matrix22 left, Matrix22 right )
|
||||
{
|
||||
Matrix22 ret = new Matrix22();
|
||||
InternalIO.Intrinsic.sub_mat_2( &left._mat, &right._mat,
|
||||
&ret._mat );
|
||||
InternalIO.Intrinsic.sub_mat_2( &left._mat, &right._mat, &ret._mat );
|
||||
return ret;
|
||||
}
|
||||
|
||||
[MethodImpl( MethodImplOptions.AggressiveInlining )]
|
||||
public static Matrix22 operator *( Matrix22 mat, float value )
|
||||
{
|
||||
return new Matrix22(
|
||||
mat._mat.colum0 * value, mat._mat.colum1 * value );
|
||||
return new Matrix22( mat._mat.colum0 * value, mat._mat.colum1 * value );
|
||||
}
|
||||
|
||||
[MethodImpl( MethodImplOptions.AggressiveInlining )]
|
||||
@@ -168,18 +165,14 @@ namespace StgSharp.Math
|
||||
[MethodImpl( MethodImplOptions.AggressiveInlining )]
|
||||
public static Matrix22 operator /( Matrix22 mat, float value )
|
||||
{
|
||||
return new Matrix22(
|
||||
mat._mat.colum0 / value, mat._mat.colum1 / value );
|
||||
return new Matrix22( mat._mat.colum0 / value, mat._mat.colum1 / value );
|
||||
}
|
||||
|
||||
[MethodImpl( MethodImplOptions.AggressiveInlining )]
|
||||
public static unsafe Matrix22 operator +(
|
||||
Matrix22 left,
|
||||
Matrix22 right )
|
||||
public static unsafe Matrix22 operator +( Matrix22 left, Matrix22 right )
|
||||
{
|
||||
Matrix22 ret = new Matrix22();
|
||||
InternalIO.Intrinsic.add_mat_2( &left._mat, &right._mat,
|
||||
&ret._mat );
|
||||
InternalIO.Intrinsic.add_mat_2( &left._mat, &right._mat, &ret._mat );
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
@@ -61,13 +61,7 @@ namespace StgSharp.Math
|
||||
Unsafe.SkipInit( out _transpose );
|
||||
}
|
||||
|
||||
public Matrix23(
|
||||
float a00,
|
||||
float a01,
|
||||
float a02,
|
||||
float a10,
|
||||
float a11,
|
||||
float a12 )
|
||||
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 );
|
||||
@@ -85,7 +79,8 @@ namespace StgSharp.Math
|
||||
throw new ArgumentOutOfRangeException( nameof( columNum ) );
|
||||
}
|
||||
InternalTranspose();
|
||||
fixed( float* p = &this._transpose.m00 ) {
|
||||
fixed( float* p = &this._transpose.m00 )
|
||||
{
|
||||
ulong pbit = ( ( ulong )p ) + ( ( ( ulong )sizeof( Vector4 ) ) * ( ( ulong )rowNum ) ) + ( ( ( ulong )sizeof( float ) ) * ( ( ulong )columNum ) );
|
||||
return *( float* )pbit;
|
||||
}
|
||||
@@ -99,7 +94,8 @@ namespace StgSharp.Math
|
||||
throw new ArgumentOutOfRangeException( nameof( columNum ) );
|
||||
}
|
||||
InternalTranspose();
|
||||
fixed( float* p = &this._transpose.m00 ) {
|
||||
fixed( float* p = &this._transpose.m00 )
|
||||
{
|
||||
ulong pbit = ( ( ulong )p ) + ( ( ( ulong )sizeof( Vector4 ) ) * ( ( ulong )rowNum ) ) + ( ( ( ulong )sizeof( float ) ) * ( ( ulong )columNum ) );
|
||||
*( float* )pbit = value;
|
||||
}
|
||||
@@ -110,8 +106,10 @@ namespace StgSharp.Math
|
||||
[MethodImpl( MethodImplOptions.AggressiveInlining )]
|
||||
internal unsafe void InternalTranspose()
|
||||
{
|
||||
if( !isTransposed ) {
|
||||
fixed( ColumnSet3* source = &this._mat ) {
|
||||
if( !isTransposed )
|
||||
{
|
||||
fixed( ColumnSet3* source = &this._mat )
|
||||
{
|
||||
fixed( ColumnSet2* target = &this._transpose ) {
|
||||
InternalIO.Intrinsic.transpose32( source, target );
|
||||
}
|
||||
@@ -122,13 +120,10 @@ namespace StgSharp.Math
|
||||
}
|
||||
|
||||
[MethodImpl( MethodImplOptions.AggressiveInlining )]
|
||||
public static unsafe Matrix23 operator -(
|
||||
Matrix23 left,
|
||||
Matrix23 right )
|
||||
public static unsafe Matrix23 operator -( Matrix23 left, Matrix23 right )
|
||||
{
|
||||
Matrix23 ret = new Matrix23();
|
||||
InternalIO.Intrinsic.sub_mat_3( &left._mat, &right._mat,
|
||||
&ret._mat );
|
||||
InternalIO.Intrinsic.sub_mat_3( &left._mat, &right._mat, &ret._mat );
|
||||
return ret;
|
||||
}
|
||||
|
||||
@@ -136,8 +131,7 @@ namespace StgSharp.Math
|
||||
public static Matrix23 operator *( Matrix23 mat, float value )
|
||||
{
|
||||
return new Matrix23(
|
||||
mat._mat.colum0 * value, mat._mat.colum1 * value,
|
||||
mat._mat.colum2 * value );
|
||||
mat._mat.colum0 * value, mat._mat.colum1 * value, mat._mat.colum2 * value );
|
||||
}
|
||||
|
||||
[MethodImpl( MethodImplOptions.AggressiveInlining )]
|
||||
@@ -186,18 +180,14 @@ namespace StgSharp.Math
|
||||
public static Matrix23 operator /( Matrix23 mat, float value )
|
||||
{
|
||||
return new Matrix23(
|
||||
mat._mat.colum0 / value, mat._mat.colum1 / value,
|
||||
mat._mat.colum2 / value );
|
||||
mat._mat.colum0 / value, mat._mat.colum1 / value, mat._mat.colum2 / value );
|
||||
}
|
||||
|
||||
[MethodImpl( MethodImplOptions.AggressiveInlining )]
|
||||
public static unsafe Matrix23 operator +(
|
||||
Matrix23 left,
|
||||
Matrix23 right )
|
||||
public static unsafe Matrix23 operator +( Matrix23 left, Matrix23 right )
|
||||
{
|
||||
Matrix23 ret = new Matrix23();
|
||||
InternalIO.Intrinsic.add_mat_3( &left._mat, &right._mat,
|
||||
&ret._mat );
|
||||
InternalIO.Intrinsic.add_mat_3( &left._mat, &right._mat, &ret._mat );
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
//-----------------------------------------------------------------------
|
||||
//-----------------------------------------------------------------------
|
||||
// file="Matrix24.cs"
|
||||
// Project: StgSharp
|
||||
// Project: World
|
||||
// AuthorGroup: Nitload Space
|
||||
// Copyright (c) Nitload Space. All rights reserved.
|
||||
//
|
||||
|
||||
@@ -66,13 +66,7 @@ namespace StgSharp.Math
|
||||
isTransposed = false;
|
||||
}
|
||||
|
||||
public unsafe Matrix32(
|
||||
float a00,
|
||||
float a01,
|
||||
float a10,
|
||||
float a11,
|
||||
float a20,
|
||||
float a21 )
|
||||
public unsafe Matrix32( float a00, float a01, float a10, float a11, float a20, float a21 )
|
||||
{
|
||||
Unsafe.SkipInit( out this );
|
||||
isTransposed = false;
|
||||
@@ -91,7 +85,8 @@ namespace StgSharp.Math
|
||||
throw new ArgumentOutOfRangeException( nameof( columNum ) );
|
||||
}
|
||||
InternalTranspose();
|
||||
fixed( float* p = &this.transpose.m00 ) {
|
||||
fixed( float* p = &this.transpose.m00 )
|
||||
{
|
||||
ulong pbit = ( ( ulong )p ) + ( ( ( ulong )sizeof( Vector4 ) ) * ( ( ulong )rowNum ) ) + ( ( ( ulong )sizeof( float ) ) * ( ( ulong )columNum ) );
|
||||
return *( float* )pbit;
|
||||
}
|
||||
@@ -105,7 +100,8 @@ namespace StgSharp.Math
|
||||
throw new ArgumentOutOfRangeException( nameof( columNum ) );
|
||||
}
|
||||
InternalTranspose();
|
||||
fixed( float* p = &this.transpose.m00 ) {
|
||||
fixed( float* p = &this.transpose.m00 )
|
||||
{
|
||||
ulong pbit = ( ( ulong )p ) + ( ( ( ulong )sizeof( Vector4 ) ) * ( ( ulong )rowNum ) ) + ( ( ( ulong )sizeof( float ) ) * ( ( ulong )columNum ) );
|
||||
*( float* )pbit = value;
|
||||
}
|
||||
@@ -121,8 +117,10 @@ namespace StgSharp.Math
|
||||
[MethodImpl( MethodImplOptions.AggressiveInlining )]
|
||||
internal unsafe void InternalTranspose()
|
||||
{
|
||||
if( !isTransposed ) {
|
||||
fixed( ColumnSet2* source = &this.mat ) {
|
||||
if( !isTransposed )
|
||||
{
|
||||
fixed( ColumnSet2* source = &this.mat )
|
||||
{
|
||||
fixed( ColumnSet3* target = &this.transpose ) {
|
||||
InternalIO.Intrinsic.transpose23( source, target );
|
||||
}
|
||||
@@ -136,15 +134,13 @@ namespace StgSharp.Math
|
||||
public static Matrix32 operator -( Matrix32 left, Matrix32 right )
|
||||
{
|
||||
return new Matrix32(
|
||||
left.mat.colum0 - right.mat.colum0,
|
||||
left.mat.colum1 - right.mat.colum1 );
|
||||
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 );
|
||||
return new Matrix32( mat.mat.colum0 * value, mat.mat.colum1 * value );
|
||||
}
|
||||
|
||||
[MethodImpl( MethodImplOptions.AggressiveInlining )]
|
||||
@@ -204,14 +200,11 @@ namespace StgSharp.Math
|
||||
[MethodImpl( MethodImplOptions.AggressiveInlining )]
|
||||
public static Matrix32 operator /( Matrix32 mat, float value )
|
||||
{
|
||||
return new Matrix32(
|
||||
mat.mat.colum0 / value, mat.mat.colum1 / value );
|
||||
return new Matrix32( mat.mat.colum0 / value, mat.mat.colum1 / value );
|
||||
}
|
||||
|
||||
[MethodImpl( MethodImplOptions.AggressiveInlining )]
|
||||
public static unsafe Matrix32 operator +(
|
||||
Matrix32 left,
|
||||
Matrix32 right )
|
||||
public static unsafe Matrix32 operator +( Matrix32 left, Matrix32 right )
|
||||
{
|
||||
Matrix32 ret = new Matrix32();
|
||||
InternalIO.Intrinsic.add_mat_2( &left.mat, &right.mat, &ret.mat );
|
||||
|
||||
@@ -68,15 +68,15 @@ namespace StgSharp.Math
|
||||
}
|
||||
|
||||
public Matrix33(
|
||||
float a00,
|
||||
float a01,
|
||||
float a02,
|
||||
float a10,
|
||||
float a11,
|
||||
float a12,
|
||||
float a20,
|
||||
float a21,
|
||||
float a22 )
|
||||
float a00,
|
||||
float a01,
|
||||
float a02,
|
||||
float a10,
|
||||
float a11,
|
||||
float a12,
|
||||
float a20,
|
||||
float a21,
|
||||
float a22 )
|
||||
{
|
||||
Unsafe.SkipInit( out this );
|
||||
isTransposed = false;
|
||||
@@ -96,7 +96,8 @@ namespace StgSharp.Math
|
||||
throw new ArgumentOutOfRangeException( nameof( columNum ) );
|
||||
}
|
||||
InternalTranspose();
|
||||
fixed( float* p = &this.transpose.m00 ) {
|
||||
fixed( float* p = &this.transpose.m00 )
|
||||
{
|
||||
ulong pbit = ( ( ulong )p ) + ( ( ( ulong )sizeof( Vector4 ) ) * ( ( ulong )rowNum ) ) + ( ( ( ulong )sizeof( float ) ) * ( ( ulong )columNum ) );
|
||||
return *( float* )pbit;
|
||||
}
|
||||
@@ -112,7 +113,8 @@ namespace StgSharp.Math
|
||||
LogType.Error );
|
||||
}
|
||||
InternalTranspose();
|
||||
fixed( float* p = &this.transpose.m00 ) {
|
||||
fixed( float* p = &this.transpose.m00 )
|
||||
{
|
||||
ulong pbit = ( ( ulong )p ) + ( ( ( ulong )sizeof( Vector4 ) ) * ( ( ulong )rowNum ) ) + ( ( ( ulong )sizeof( float ) ) * ( ( ulong )columNum ) );
|
||||
*( float* )pbit = value;
|
||||
}
|
||||
@@ -131,7 +133,8 @@ namespace StgSharp.Math
|
||||
[MethodImpl( MethodImplOptions.AggressiveInlining )]
|
||||
internal unsafe void InternalTranspose()
|
||||
{
|
||||
if( !isTransposed ) {
|
||||
if( !isTransposed )
|
||||
{
|
||||
fixed( ColumnSet3* source = &this.mat, target = &this.transpose ) {
|
||||
InternalIO.Intrinsic.transpose33( source, target );
|
||||
}
|
||||
@@ -140,9 +143,7 @@ namespace StgSharp.Math
|
||||
}
|
||||
|
||||
[MethodImpl( MethodImplOptions.AggressiveInlining )]
|
||||
public static unsafe Matrix33 operator -(
|
||||
Matrix33 left,
|
||||
Matrix33 right )
|
||||
public static unsafe Matrix33 operator -( Matrix33 left, Matrix33 right )
|
||||
{
|
||||
Matrix33 ret = new Matrix33();
|
||||
InternalIO.Intrinsic.sub_mat_3( &left.mat, &right.mat, &ret.mat );
|
||||
@@ -153,8 +154,7 @@ namespace StgSharp.Math
|
||||
public static Matrix33 operator *( Matrix33 mat, float value )
|
||||
{
|
||||
return new Matrix33(
|
||||
mat.mat.colum0 * value, mat.mat.colum1 * value,
|
||||
mat.mat.colum2 * value );
|
||||
mat.mat.colum0 * value, mat.mat.colum1 * value, mat.mat.colum2 * value );
|
||||
}
|
||||
|
||||
[MethodImpl( MethodImplOptions.AggressiveInlining )]
|
||||
@@ -225,14 +225,11 @@ namespace StgSharp.Math
|
||||
public static Matrix33 operator /( Matrix33 mat, float value )
|
||||
{
|
||||
return new Matrix33(
|
||||
mat.mat.colum0 / value, mat.mat.colum1 / value,
|
||||
mat.mat.colum2 / value );
|
||||
mat.mat.colum0 / value, mat.mat.colum1 / value, mat.mat.colum2 / value );
|
||||
}
|
||||
|
||||
[MethodImpl( MethodImplOptions.AggressiveInlining )]
|
||||
public static unsafe Matrix33 operator +(
|
||||
Matrix33 left,
|
||||
Matrix33 right )
|
||||
public static unsafe Matrix33 operator +( Matrix33 left, Matrix33 right )
|
||||
{
|
||||
Matrix33 ret = new Matrix33();
|
||||
InternalIO.Intrinsic.add_mat_3( &left.mat, &right.mat, &ret.mat );
|
||||
|
||||
@@ -79,18 +79,18 @@ namespace StgSharp.Math
|
||||
}
|
||||
|
||||
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 )
|
||||
float a00,
|
||||
float a01,
|
||||
float a02,
|
||||
float a03,
|
||||
float a10,
|
||||
float a11,
|
||||
float a12,
|
||||
float a13,
|
||||
float a20,
|
||||
float a21,
|
||||
float a22,
|
||||
float a23 )
|
||||
{
|
||||
Unsafe.SkipInit( out this );
|
||||
isTransposed = false;
|
||||
@@ -111,7 +111,8 @@ namespace StgSharp.Math
|
||||
throw new ArgumentOutOfRangeException( nameof( columNum ) );
|
||||
}
|
||||
InternalTranspose();
|
||||
fixed( float* p = &this.transpose.m00 ) {
|
||||
fixed( float* p = &this.transpose.m00 )
|
||||
{
|
||||
ulong pbit = ( ( ulong )p ) + ( ( ( ulong )sizeof( Vector4 ) ) * ( ( ulong )rowNum ) ) + ( ( ( ulong )sizeof( float ) ) * ( ( ulong )columNum ) );
|
||||
return *( float* )pbit;
|
||||
}
|
||||
@@ -125,7 +126,8 @@ namespace StgSharp.Math
|
||||
throw new ArgumentOutOfRangeException( nameof( columNum ) );
|
||||
}
|
||||
InternalTranspose();
|
||||
fixed( float* p = &this.transpose.m00 ) {
|
||||
fixed( float* p = &this.transpose.m00 )
|
||||
{
|
||||
ulong pbit = ( ( ulong )p ) + ( ( ( ulong )sizeof( Vector4 ) ) * ( ( ulong )rowNum ) ) + ( ( ( ulong )sizeof( float ) ) * ( ( ulong )columNum ) );
|
||||
*( float* )pbit = value;
|
||||
}
|
||||
@@ -135,8 +137,10 @@ namespace StgSharp.Math
|
||||
|
||||
internal unsafe void InternalTranspose()
|
||||
{
|
||||
if( !isTransposed ) {
|
||||
fixed( ColumnSet4* source = &this.mat ) {
|
||||
if( !isTransposed )
|
||||
{
|
||||
fixed( ColumnSet4* source = &this.mat )
|
||||
{
|
||||
fixed( ColumnSet3* target = &this.transpose ) {
|
||||
InternalIO.Intrinsic.transpose43( source, target );
|
||||
}
|
||||
@@ -147,9 +151,7 @@ namespace StgSharp.Math
|
||||
}
|
||||
|
||||
[MethodImpl( MethodImplOptions.AggressiveInlining )]
|
||||
public static unsafe Matrix34 operator -(
|
||||
Matrix34 left,
|
||||
Matrix34 right )
|
||||
public static unsafe Matrix34 operator -( Matrix34 left, Matrix34 right )
|
||||
{
|
||||
Matrix34 ret = new Matrix34();
|
||||
InternalIO.Intrinsic.sub_mat_4( &left.mat, &right.mat, &ret.mat );
|
||||
@@ -160,8 +162,8 @@ namespace StgSharp.Math
|
||||
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 );
|
||||
mat.mat.colum0 * value, mat.mat.colum1 * value, mat.mat.colum2 * value,
|
||||
mat.mat.colum3 * value );
|
||||
}
|
||||
|
||||
[MethodImpl( MethodImplOptions.AggressiveInlining )]
|
||||
@@ -222,14 +224,12 @@ namespace StgSharp.Math
|
||||
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 );
|
||||
mat.mat.colum0 / value, mat.mat.colum1 / value, mat.mat.colum2 / value,
|
||||
mat.mat.colum3 / value );
|
||||
}
|
||||
|
||||
[MethodImpl( MethodImplOptions.AggressiveInlining )]
|
||||
public static unsafe Matrix34 operator +(
|
||||
Matrix34 left,
|
||||
Matrix34 right )
|
||||
public static unsafe Matrix34 operator +( Matrix34 left, Matrix34 right )
|
||||
{
|
||||
Matrix34 ret = new Matrix34();
|
||||
InternalIO.Intrinsic.add_mat_4( &left.mat, &right.mat, &ret.mat );
|
||||
|
||||
@@ -71,14 +71,14 @@ namespace StgSharp.Math
|
||||
}
|
||||
|
||||
public Matrix42(
|
||||
float a00,
|
||||
float a01,
|
||||
float a10,
|
||||
float a11,
|
||||
float a20,
|
||||
float a21,
|
||||
float a30,
|
||||
float a31 )
|
||||
float a00,
|
||||
float a01,
|
||||
float a10,
|
||||
float a11,
|
||||
float a20,
|
||||
float a21,
|
||||
float a30,
|
||||
float a31 )
|
||||
{
|
||||
Unsafe.SkipInit( out this );
|
||||
isTransposed = false;
|
||||
@@ -97,7 +97,8 @@ namespace StgSharp.Math
|
||||
throw new ArgumentOutOfRangeException( nameof( columNum ) );
|
||||
}
|
||||
InternalTranspose();
|
||||
fixed( float* p = &this.transpose.m00 ) {
|
||||
fixed( float* p = &this.transpose.m00 )
|
||||
{
|
||||
ulong pbit = ( ( ulong )p ) + ( ( ( ulong )sizeof( Vector4 ) ) * ( ( ulong )rowNum ) ) + ( ( ( ulong )sizeof( float ) ) * ( ( ulong )columNum ) );
|
||||
return *( float* )pbit;
|
||||
}
|
||||
@@ -111,7 +112,8 @@ namespace StgSharp.Math
|
||||
throw new ArgumentOutOfRangeException( nameof( columNum ) );
|
||||
}
|
||||
InternalTranspose();
|
||||
fixed( float* p = &this.transpose.m00 ) {
|
||||
fixed( float* p = &this.transpose.m00 )
|
||||
{
|
||||
ulong pbit = ( ( ulong )p ) + ( ( ( ulong )sizeof( Vector4 ) ) * ( ( ulong )rowNum ) ) + ( ( ( ulong )sizeof( float ) ) * ( ( ulong )columNum ) );
|
||||
*( float* )pbit = value;
|
||||
}
|
||||
@@ -121,15 +123,16 @@ namespace StgSharp.Math
|
||||
|
||||
public override int GetHashCode()
|
||||
{
|
||||
return HashCode.Combine(
|
||||
mat.colum0.GetHashCode(), mat.colum1.GetHashCode() );
|
||||
return HashCode.Combine( mat.colum0.GetHashCode(), mat.colum1.GetHashCode() );
|
||||
}
|
||||
|
||||
[MethodImpl( MethodImplOptions.AggressiveInlining )]
|
||||
internal unsafe void InternalTranspose()
|
||||
{
|
||||
if( !isTransposed ) {
|
||||
fixed( ColumnSet2* source = &this.mat ) {
|
||||
if( !isTransposed )
|
||||
{
|
||||
fixed( ColumnSet2* source = &this.mat )
|
||||
{
|
||||
fixed( ColumnSet4* target = &this.transpose ) {
|
||||
InternalIO.Intrinsic.transpose24( source, target );
|
||||
}
|
||||
@@ -140,9 +143,7 @@ namespace StgSharp.Math
|
||||
}
|
||||
|
||||
[MethodImpl( MethodImplOptions.AggressiveInlining )]
|
||||
public static unsafe Matrix42 operator -(
|
||||
Matrix42 left,
|
||||
Matrix42 right )
|
||||
public static unsafe Matrix42 operator -( Matrix42 left, Matrix42 right )
|
||||
{
|
||||
Matrix42 ret = new Matrix42();
|
||||
InternalIO.Intrinsic.sub_mat_2( &left.mat, &right.mat, &ret.mat );
|
||||
@@ -152,8 +153,7 @@ namespace StgSharp.Math
|
||||
[MethodImpl( MethodImplOptions.AggressiveInlining )]
|
||||
public static Matrix42 operator *( Matrix42 mat, float value )
|
||||
{
|
||||
return new Matrix42(
|
||||
mat.mat.colum0 * value, mat.mat.colum1 * value );
|
||||
return new Matrix42( mat.mat.colum0 * value, mat.mat.colum1 * value );
|
||||
}
|
||||
|
||||
[MethodImpl( MethodImplOptions.AggressiveInlining )]
|
||||
@@ -225,14 +225,11 @@ namespace StgSharp.Math
|
||||
[MethodImpl( MethodImplOptions.AggressiveInlining )]
|
||||
public static Matrix42 operator /( Matrix42 mat, float value )
|
||||
{
|
||||
return new Matrix42(
|
||||
mat.mat.colum0 / value, mat.mat.colum1 / value );
|
||||
return new Matrix42( mat.mat.colum0 / value, mat.mat.colum1 / value );
|
||||
}
|
||||
|
||||
[MethodImpl( MethodImplOptions.AggressiveInlining )]
|
||||
public static unsafe Matrix42 operator +(
|
||||
Matrix42 left,
|
||||
Matrix42 right )
|
||||
public static unsafe Matrix42 operator +( Matrix42 left, Matrix42 right )
|
||||
{
|
||||
Matrix42 ret = new Matrix42();
|
||||
InternalIO.Intrinsic.add_mat_2( &left.mat, &right.mat, &ret.mat );
|
||||
|
||||
@@ -70,18 +70,18 @@ namespace StgSharp.Math
|
||||
}
|
||||
|
||||
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 )
|
||||
float a00,
|
||||
float a01,
|
||||
float a02,
|
||||
float a10,
|
||||
float a11,
|
||||
float a12,
|
||||
float a20,
|
||||
float a21,
|
||||
float a22,
|
||||
float a30,
|
||||
float a31,
|
||||
float a32 )
|
||||
{
|
||||
Unsafe.SkipInit( out this );
|
||||
isTransposed = false;
|
||||
@@ -101,7 +101,8 @@ namespace StgSharp.Math
|
||||
throw new ArgumentOutOfRangeException( nameof( columNum ) );
|
||||
}
|
||||
InternalTranspose();
|
||||
fixed( float* p = &this.transpose.m00 ) {
|
||||
fixed( float* p = &this.transpose.m00 )
|
||||
{
|
||||
ulong pbit = ( ( ulong )p ) + ( ( ( ulong )sizeof( Vector4 ) ) * ( ( ulong )rowNum ) ) + ( ( ( ulong )sizeof( float ) ) * ( ( ulong )columNum ) );
|
||||
return *( float* )pbit;
|
||||
}
|
||||
@@ -115,7 +116,8 @@ namespace StgSharp.Math
|
||||
throw new ArgumentOutOfRangeException( nameof( columNum ) );
|
||||
}
|
||||
InternalTranspose();
|
||||
fixed( float* p = &this.transpose.m00 ) {
|
||||
fixed( float* p = &this.transpose.m00 )
|
||||
{
|
||||
ulong pbit = ( ( ulong )p ) + ( ( ( ulong )sizeof( Vector4 ) ) * ( ( ulong )rowNum ) ) + ( ( ( ulong )sizeof( float ) ) * ( ( ulong )columNum ) );
|
||||
*( float* )pbit = value;
|
||||
}
|
||||
@@ -130,22 +132,22 @@ namespace StgSharp.Math
|
||||
|
||||
public bool Equals( Matrix43 other )
|
||||
{
|
||||
return EqualityComparer<ColumnSet3>.Default.Equals( mat,
|
||||
other.mat );
|
||||
return EqualityComparer<ColumnSet3>.Default.Equals( mat, other.mat );
|
||||
}
|
||||
|
||||
public override int GetHashCode()
|
||||
{
|
||||
return HashCode.Combine(
|
||||
mat.colum0.GetHashCode(), mat.colum1.GetHashCode(),
|
||||
mat.colum2.GetHashCode() );
|
||||
mat.colum0.GetHashCode(), mat.colum1.GetHashCode(), mat.colum2.GetHashCode() );
|
||||
}
|
||||
|
||||
[MethodImpl( MethodImplOptions.AggressiveInlining )]
|
||||
internal unsafe void InternalTranspose()
|
||||
{
|
||||
if( !isTransposed ) {
|
||||
fixed( ColumnSet3* source = &this.mat ) {
|
||||
if( !isTransposed )
|
||||
{
|
||||
fixed( ColumnSet3* source = &this.mat )
|
||||
{
|
||||
fixed( ColumnSet4* target = &this.transpose ) {
|
||||
InternalIO.Intrinsic.transpose34( source, target );
|
||||
}
|
||||
@@ -159,8 +161,7 @@ namespace StgSharp.Math
|
||||
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.colum0 - right.mat.colum0, left.mat.colum1 - right.mat.colum1,
|
||||
left.mat.colum2 - right.mat.colum2 );
|
||||
}
|
||||
|
||||
@@ -173,8 +174,7 @@ namespace StgSharp.Math
|
||||
public static unsafe Matrix43 operator *( Matrix43 mat, float value )
|
||||
{
|
||||
return new Matrix43(
|
||||
mat.mat.colum0 * value, mat.mat.colum1 * value,
|
||||
mat.mat.colum2 * value );
|
||||
mat.mat.colum0 * value, mat.mat.colum1 * value, mat.mat.colum2 * value );
|
||||
}
|
||||
|
||||
[MethodImpl( MethodImplOptions.AggressiveInlining )]
|
||||
@@ -247,14 +247,11 @@ namespace StgSharp.Math
|
||||
public static Matrix43 operator /( Matrix43 mat, float value )
|
||||
{
|
||||
return new Matrix43(
|
||||
mat.mat.colum0 / value, mat.mat.colum1 / value,
|
||||
mat.mat.colum2 / value );
|
||||
mat.mat.colum0 / value, mat.mat.colum1 / value, mat.mat.colum2 / value );
|
||||
}
|
||||
|
||||
[MethodImpl( MethodImplOptions.AggressiveInlining )]
|
||||
public static unsafe Matrix43 operator +(
|
||||
Matrix43 left,
|
||||
Matrix43 right )
|
||||
public static unsafe Matrix43 operator +( Matrix43 left, Matrix43 right )
|
||||
{
|
||||
Matrix43 ret = new Matrix43();
|
||||
InternalIO.Intrinsic.add_mat_3( &left.mat, &right.mat, &ret.mat );
|
||||
|
||||
@@ -62,11 +62,7 @@ namespace StgSharp.Math
|
||||
this.mat = mat;
|
||||
}
|
||||
|
||||
internal Matrix44(
|
||||
Vector4 vec0,
|
||||
Vector4 vec1,
|
||||
Vector4 vec2,
|
||||
Vector4 vec3 )
|
||||
internal Matrix44( Vector4 vec0, Vector4 vec1, Vector4 vec2, Vector4 vec3 )
|
||||
{
|
||||
Unsafe.SkipInit( out this );
|
||||
isTransposed = false;
|
||||
@@ -83,22 +79,22 @@ namespace StgSharp.Math
|
||||
}
|
||||
|
||||
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 )
|
||||
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 )
|
||||
{
|
||||
Unsafe.SkipInit( out this );
|
||||
isTransposed = false;
|
||||
@@ -113,7 +109,8 @@ namespace StgSharp.Math
|
||||
get
|
||||
{
|
||||
#if DEBUG
|
||||
if( ( rowNum > 3 ) || ( rowNum < 0 ) ) {
|
||||
if( ( rowNum > 3 ) || ( rowNum < 0 ) )
|
||||
{
|
||||
throw new ArgumentOutOfRangeException( nameof( columNum ) );
|
||||
}
|
||||
if( ( columNum > 3 ) || ( columNum < 0 ) ) {
|
||||
@@ -121,7 +118,8 @@ namespace StgSharp.Math
|
||||
}
|
||||
#endif
|
||||
InternalTranspose();
|
||||
fixed( float* p = &this.transpose.m00 ) {
|
||||
fixed( float* p = &this.transpose.m00 )
|
||||
{
|
||||
ulong pbit = ( ( ulong )p ) + ( ( ( ulong )sizeof( Vector4 ) ) * ( ( ulong )rowNum ) ) + ( ( ( ulong )sizeof( float ) ) * ( ( ulong )columNum ) );
|
||||
return *( float* )pbit;
|
||||
}
|
||||
@@ -129,7 +127,8 @@ namespace StgSharp.Math
|
||||
set
|
||||
{
|
||||
#if DEBUG
|
||||
if( ( rowNum > 3 ) || ( rowNum < 0 ) ) {
|
||||
if( ( rowNum > 3 ) || ( rowNum < 0 ) )
|
||||
{
|
||||
throw new ArgumentOutOfRangeException( nameof( columNum ) );
|
||||
}
|
||||
if( ( columNum > 3 ) || ( columNum < 0 ) ) {
|
||||
@@ -137,7 +136,8 @@ namespace StgSharp.Math
|
||||
}
|
||||
#endif
|
||||
InternalTranspose();
|
||||
fixed( float* p = &this.transpose.m00 ) {
|
||||
fixed( float* p = &this.transpose.m00 )
|
||||
{
|
||||
ulong pbit = ( ( ulong )p ) + ( ( ( ulong )sizeof( Vector4 ) ) * ( ( ulong )rowNum ) ) + ( ( ( ulong )sizeof( float ) ) * ( ( ulong )columNum ) );
|
||||
*( float* )pbit = value;
|
||||
}
|
||||
@@ -191,8 +191,8 @@ namespace StgSharp.Math
|
||||
public override int GetHashCode()
|
||||
{
|
||||
return HashCode.Combine(
|
||||
mat.colum0.GetHashCode(), mat.colum1.GetHashCode(),
|
||||
mat.colum2.GetHashCode(), mat.colum3.GetHashCode() );
|
||||
mat.colum0.GetHashCode(), mat.colum1.GetHashCode(), mat.colum2.GetHashCode(),
|
||||
mat.colum3.GetHashCode() );
|
||||
}
|
||||
|
||||
[MethodImpl( MethodImplOptions.AggressiveInlining )]
|
||||
@@ -200,7 +200,8 @@ namespace StgSharp.Math
|
||||
{
|
||||
InternalTranspose();
|
||||
Matrix42 ans = new Matrix42();
|
||||
fixed( ColumnSet4* lptr = &transpose ) {
|
||||
fixed( ColumnSet4* lptr = &transpose )
|
||||
{
|
||||
fixed( Vector4* rptr = &right.mat.colum0 ) {
|
||||
InternalIO.Intrinsic.dot_42( lptr, rptr, &ans.mat.colum0 );
|
||||
}
|
||||
@@ -215,7 +216,8 @@ namespace StgSharp.Math
|
||||
|
||||
Matrix43 ans = new Matrix43();
|
||||
|
||||
fixed( Vector4* rptr = &right.mat.colum0 ) {
|
||||
fixed( Vector4* rptr = &right.mat.colum0 )
|
||||
{
|
||||
fixed( ColumnSet4* lptr = &transpose ) {
|
||||
InternalIO.Intrinsic.dot_43( lptr, rptr, &ans.mat.colum0 );
|
||||
}
|
||||
@@ -233,7 +235,8 @@ namespace StgSharp.Math
|
||||
[MethodImpl( MethodImplOptions.AggressiveInlining )]
|
||||
internal unsafe void InternalTranspose()
|
||||
{
|
||||
if( !isTransposed ) {
|
||||
if( !isTransposed )
|
||||
{
|
||||
fixed( ColumnSet4* source = &mat, target = &transpose ) {
|
||||
InternalIO.Intrinsic.transpose44( source, target );
|
||||
}
|
||||
@@ -242,15 +245,11 @@ namespace StgSharp.Math
|
||||
}
|
||||
|
||||
[MethodImpl( MethodImplOptions.AggressiveInlining )]
|
||||
public static unsafe Matrix44 operator -(
|
||||
Matrix44 left,
|
||||
Matrix44 right )
|
||||
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 );
|
||||
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 )
|
||||
@@ -262,17 +261,15 @@ namespace StgSharp.Math
|
||||
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 );
|
||||
mat.mat.colum0 * value, mat.mat.colum1 * value, mat.mat.colum2 * value,
|
||||
mat.mat.colum3 * value );
|
||||
}
|
||||
|
||||
[Obsolete(
|
||||
"The operand may cause performance loss, use Matrix.Multiple() method instead.",
|
||||
false )]
|
||||
[MethodImpl( MethodImplOptions.AggressiveInlining )]
|
||||
public static unsafe Matrix42 operator *(
|
||||
Matrix44 left,
|
||||
Matrix42 right )
|
||||
public static unsafe Matrix42 operator *( Matrix44 left, Matrix42 right )
|
||||
{
|
||||
return left.Multiple( right );
|
||||
}
|
||||
@@ -313,9 +310,7 @@ namespace StgSharp.Math
|
||||
}
|
||||
|
||||
[MethodImpl( MethodImplOptions.AggressiveInlining )]
|
||||
public static unsafe Matrix44 operator +(
|
||||
Matrix44 left,
|
||||
Matrix44 right )
|
||||
public static unsafe Matrix44 operator +( Matrix44 left, Matrix44 right )
|
||||
{
|
||||
Matrix44 ret = new Matrix44();
|
||||
InternalIO.Intrinsic.add_mat_4( &left.mat, &right.mat, &ret.mat );
|
||||
|
||||
@@ -38,8 +38,8 @@ using System.Runtime.InteropServices;
|
||||
namespace StgSharp.Math
|
||||
{
|
||||
/// <summary>
|
||||
/// A two dimension vector defined by two elements. Vec2 in StgSharp are default used as colum
|
||||
/// vector.
|
||||
/// A two dimension vector defined by two elements. Vec2 in World are default used as colum
|
||||
/// vector.
|
||||
/// </summary>
|
||||
[StructLayout( LayoutKind.Explicit, Size = 16, Pack = 16 )]
|
||||
public struct Vec2 : IVector<Vec2>
|
||||
|
||||
@@ -28,7 +28,6 @@
|
||||
//
|
||||
//-----------------------------------------------------------------------
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
using StgSharp.HighPerformance;
|
||||
using System;
|
||||
using System.Numerics;
|
||||
@@ -133,9 +132,11 @@ namespace StgSharp.Math
|
||||
|
||||
public override bool Equals( object obj )
|
||||
{
|
||||
if( obj is Vec3 ) {
|
||||
if( obj is Vec3 )
|
||||
{
|
||||
return this == ( Vec3 )obj;
|
||||
} else {
|
||||
} else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -220,8 +221,7 @@ namespace StgSharp.Math
|
||||
}
|
||||
|
||||
[MethodImpl( MethodImplOptions.AggressiveInlining )]
|
||||
public static unsafe implicit operator Vec3(
|
||||
(float, float, float) tuple )
|
||||
public static unsafe implicit operator Vec3( (float, float, float) tuple )
|
||||
{
|
||||
Vec3 vec = new Vec3( *( Vector3* )&tuple );
|
||||
return vec;
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
//-----------------------------------------------------------------------
|
||||
//-----------------------------------------------------------------------
|
||||
// file="Vector.Cross.cs"
|
||||
// Project: StgSharp
|
||||
// Project: World
|
||||
// AuthorGroup: Nitload Space
|
||||
// Copyright (c) Nitload Space. All rights reserved.
|
||||
//
|
||||
|
||||
@@ -43,8 +43,7 @@ namespace StgSharp.Math
|
||||
|
||||
public static float GetAngle( Vec3 vec1, Vec3 vec2 )
|
||||
{
|
||||
return Scaler.ACos(
|
||||
( vec1 * vec2 ) / ( vec1.GetLength() * vec2.GetLength() ) );
|
||||
return Scaler.ACos( ( vec1 * vec2 ) / ( vec1.GetLength() * vec2.GetLength() ) );
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -46,12 +46,18 @@ namespace StgSharp.Math
|
||||
|
||||
public static Vec4 Normalize( Vec4 vec )
|
||||
{
|
||||
return new Vec4 { vec = Vector4.Normalize( vec.vec ) };
|
||||
return new Vec4
|
||||
{
|
||||
vec = Vector4.Normalize( vec.vec )
|
||||
};
|
||||
}
|
||||
|
||||
public static Vec3 Normalize( Vec3 vec )
|
||||
{
|
||||
return new Vec3 { v = Vector3.Normalize( vec.v ) };
|
||||
return new Vec3
|
||||
{
|
||||
v = Vector3.Normalize( vec.v )
|
||||
};
|
||||
}
|
||||
|
||||
public static unsafe void Normalize( ref Vec4 source, ref Vec4 target )
|
||||
@@ -76,8 +82,7 @@ namespace StgSharp.Math
|
||||
Vector3 t = target.v;
|
||||
|
||||
s = Vector3.Normalize( s );
|
||||
Vector3 projection = ( Vector3.Dot( t, s ) / Vector3.Dot( s,
|
||||
s ) ) * s;
|
||||
Vector3 projection = ( Vector3.Dot( t, s ) / Vector3.Dot( s, s ) ) * s;
|
||||
t -= projection;
|
||||
t = Vector3.Normalize( t );
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
//-----------------------------------------------------------------------
|
||||
//-----------------------------------------------------------------------
|
||||
// file="Vector.Orthogonalize.cs"
|
||||
// Project: StgSharp
|
||||
// Project: World
|
||||
// AuthorGroup: Nitload Space
|
||||
// Copyright (c) Nitload Space. All rights reserved.
|
||||
//
|
||||
@@ -46,17 +46,21 @@ namespace StgSharp.Math
|
||||
|
||||
public static Vec4 Orthogonalize( Vec4 vec )
|
||||
{
|
||||
return new Vec4 { vec = Vector4.Normalize( vec.vec ) };
|
||||
return new Vec4
|
||||
{
|
||||
vec = Vector4.Normalize( vec.vec )
|
||||
};
|
||||
}
|
||||
|
||||
public static Vec3 Orthogonalize( Vec3 vec )
|
||||
{
|
||||
return new Vec3 { v = Vector3.Normalize( vec.v ) };
|
||||
return new Vec3
|
||||
{
|
||||
v = Vector3.Normalize( vec.v )
|
||||
};
|
||||
}
|
||||
|
||||
public static unsafe void Orthogonalize(
|
||||
ref Vec4 source,
|
||||
ref Vec4 target )
|
||||
public static unsafe void Orthogonalize( ref Vec4 source, ref Vec4 target )
|
||||
{
|
||||
Vector4 s = source.vec;
|
||||
Vector4 t = target.vec;
|
||||
@@ -73,21 +77,22 @@ namespace StgSharp.Math
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Orthogonalize two <see cref="Vec3" />s, let their length be 1 and perpendicular to each
|
||||
/// other.
|
||||
/// 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 )
|
||||
/// <param _label="source">
|
||||
///
|
||||
/// </param>
|
||||
/// <param _label="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;
|
||||
Vector3 projection = ( Vector3.Dot( t, s ) / Vector3.Dot( s, s ) ) * s;
|
||||
t -= projection;
|
||||
t = Vector3.Normalize( t );
|
||||
|
||||
|
||||
@@ -41,11 +41,17 @@ namespace StgSharp.Math
|
||||
piby2 = 1.5707963705e+00f; /* 0x3fc90fdb */
|
||||
|
||||
/// <summary>
|
||||
/// Reurns the value of ArcSin(x)
|
||||
/// Reurns the value of ArcSin(x)
|
||||
/// </summary>
|
||||
/// <param _name="x"> The sine value of the angle </param>
|
||||
/// <returns></returns>
|
||||
/// <exception cref="ArgumentException"></exception>
|
||||
/// <param _label="x">
|
||||
/// The sine value of the angle
|
||||
/// </param>
|
||||
/// <returns>
|
||||
///
|
||||
/// </returns>
|
||||
/// <exception cref="ArgumentException">
|
||||
///
|
||||
/// </exception>
|
||||
public static float ASin( float x )
|
||||
{
|
||||
return MathF.Asin( x );
|
||||
|
||||
@@ -53,8 +53,7 @@ namespace StgSharp.Math
|
||||
return *( int* )a;
|
||||
}
|
||||
|
||||
internal static string GetListSeparator(
|
||||
IFormatProvider formatProvider )
|
||||
internal static string GetListSeparator( IFormatProvider formatProvider )
|
||||
{
|
||||
if( formatProvider is CultureInfo cultureInfo ) {
|
||||
return cultureInfo.TextInfo.ListSeparator;
|
||||
|
||||
@@ -42,7 +42,8 @@ namespace StgSharp.Math
|
||||
public static float MaxOf( params float[] stream )
|
||||
{
|
||||
float ret = stream[ 0 ];
|
||||
foreach( float num in stream ) {
|
||||
foreach( float num in stream )
|
||||
{
|
||||
if( ret < num ) {
|
||||
ret = num;
|
||||
}
|
||||
@@ -53,7 +54,8 @@ namespace StgSharp.Math
|
||||
public static float MinOf( params float[] stream )
|
||||
{
|
||||
float ret = stream[ 0 ];
|
||||
foreach( float num in stream ) {
|
||||
foreach( float num in stream )
|
||||
{
|
||||
if( ret > num ) {
|
||||
ret = num;
|
||||
}
|
||||
|
||||
@@ -47,16 +47,13 @@ namespace StgSharp.Math
|
||||
|
||||
[DllImport( "Kernel32.dll", EntryPoint = "VirtualAlloc" )]
|
||||
private static extern IntPtr VirtualAlloc(
|
||||
IntPtr address,
|
||||
int size,
|
||||
uint allocType,
|
||||
uint protect );
|
||||
IntPtr address,
|
||||
int size,
|
||||
uint allocType,
|
||||
uint protect );
|
||||
|
||||
[DllImport( "Kernel32.dll", EntryPoint = "VirtualFree" )]
|
||||
private static extern bool VirtualFree(
|
||||
IntPtr address,
|
||||
int size,
|
||||
uint freeType );
|
||||
private static extern bool VirtualFree( IntPtr address, int size, uint freeType );
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -36,10 +36,14 @@ namespace StgSharp.Math
|
||||
public const float E = 2.718281828f;
|
||||
|
||||
/// <summary>
|
||||
/// Get the value of E ^ x;
|
||||
/// Get the value of E ^ x;
|
||||
/// </summary>
|
||||
/// <param _name="x"></param>
|
||||
/// <returns></returns>
|
||||
/// <param _label="x">
|
||||
///
|
||||
/// </param>
|
||||
/// <returns>
|
||||
///
|
||||
/// </returns>
|
||||
public static unsafe float Exp( float x )
|
||||
{
|
||||
if( x == 1 ) {
|
||||
@@ -50,15 +54,18 @@ namespace StgSharp.Math
|
||||
}
|
||||
|
||||
bool sign = false;
|
||||
if( x < 0 ) {
|
||||
if( x < 0 )
|
||||
{
|
||||
sign = true;
|
||||
x = -x;
|
||||
}
|
||||
|
||||
float z = x, t;
|
||||
if( x < 0.5f ) {
|
||||
if( x < 0.5f )
|
||||
{
|
||||
t = 1.0f + ( x * ( 1.0f + ( x * ( 0.5f + ( x * ( 0.1666666667f + ( x * ( 0.0416666666667f + ( x * 8.333333333e-3f ) ) ) ) ) ) ) ) );
|
||||
} else {
|
||||
} else
|
||||
{
|
||||
/*
|
||||
* define z = n * 2 ^ m
|
||||
* n is between 0 and 0.5
|
||||
|
||||
@@ -42,9 +42,11 @@ namespace StgSharp.Math
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <param _name="x"></param>
|
||||
/// <param _label="x">
|
||||
///
|
||||
/// </param>
|
||||
/// <returns>
|
||||
/// Returns the value of ln(x).
|
||||
/// Returns the value of ln(x).
|
||||
/// </returns>
|
||||
public static unsafe float Log( float x )
|
||||
{
|
||||
|
||||
@@ -34,11 +34,17 @@ namespace StgSharp.Math
|
||||
{
|
||||
|
||||
/// <summary>
|
||||
/// calculate the value of x^y
|
||||
/// calculate the value of x^y
|
||||
/// </summary>
|
||||
/// <param _name="x"></param>
|
||||
/// <param _name="y"></param>
|
||||
/// <returns> Returns the value of x^y </returns>
|
||||
/// <param _label="x">
|
||||
///
|
||||
/// </param>
|
||||
/// <param _label="y">
|
||||
///
|
||||
/// </param>
|
||||
/// <returns>
|
||||
/// Returns the value of x^y
|
||||
/// </returns>
|
||||
public static unsafe float Pow( float x, float y )
|
||||
{
|
||||
/*
|
||||
@@ -67,14 +73,17 @@ namespace StgSharp.Math
|
||||
z = Scaler.Log( x ) * y;
|
||||
|
||||
bool sign = false;
|
||||
if( z < 0 ) {
|
||||
if( z < 0 )
|
||||
{
|
||||
sign = true;
|
||||
z = -z;
|
||||
}
|
||||
|
||||
if( z < 0.5f ) {
|
||||
if( z < 0.5f )
|
||||
{
|
||||
t = 1.0f + ( z * ( 1.0f + ( z * ( 0.5f + ( z * ( 0.1666666667f + ( z * ( 0.0416666666667f + ( z * 8.333333333e-3f ) ) ) ) ) ) ) ) );
|
||||
} else {
|
||||
} else
|
||||
{
|
||||
uint zBit = *( uint* )&z;
|
||||
uint zBitAbs = zBit & 0b_0111_1111_1111_1111_1111_1111_1111_1111;
|
||||
uint uintm = zBitAbs >> 23;
|
||||
|
||||
@@ -28,7 +28,6 @@
|
||||
//
|
||||
//-----------------------------------------------------------------------
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
using StgSharp.Math;
|
||||
|
||||
using System;
|
||||
@@ -56,9 +55,11 @@ namespace StgSharp.Math
|
||||
#endif
|
||||
|
||||
/// <summary>
|
||||
/// returns a random float number between 0 and 1.
|
||||
/// returns a random float number between 0 and 1.
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
/// <returns>
|
||||
///
|
||||
/// </returns>
|
||||
public static unsafe float LowProceisionRandom()
|
||||
{
|
||||
float seed = currentSeed;
|
||||
@@ -75,7 +76,8 @@ namespace StgSharp.Math
|
||||
sample2 *= 1000000;
|
||||
|
||||
float result = sample2 - ( ( int )sample2 );
|
||||
if( result == 0 ) {
|
||||
if( result == 0 )
|
||||
{
|
||||
currentSeed = sample2 + 0.1f;
|
||||
result = Scaler.LowProceisionRandom();
|
||||
}
|
||||
@@ -85,19 +87,21 @@ namespace StgSharp.Math
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
/// <returns>
|
||||
///
|
||||
/// </returns>
|
||||
[MethodImpl( MethodImplOptions.AggressiveInlining )]
|
||||
public static T Random<T>() where T: struct, IConvertible, INumber<T>
|
||||
|
||||
{
|
||||
if( randomSeed == null ) {
|
||||
if( randomSeed == null )
|
||||
{
|
||||
randomSeed = new byte[64];
|
||||
string originSeed =
|
||||
( $"{((Assembly.GetEntryAssembly() == null) ? (Assembly.GetAssembly(typeof(StgSharp))!) :
|
||||
( $"{((Assembly.GetEntryAssembly() == null) ? (Assembly.GetAssembly(typeof(World))!) :
|
||||
Assembly.GetEntryAssembly())}" ) + ( $"{DateTime.UtcNow.ToString("o")}" );
|
||||
using( SHA256 sha = SHA256.Create() ) {
|
||||
randomSeed = sha.ComputeHash(
|
||||
Encoding.UTF8.GetBytes( originSeed ) );
|
||||
randomSeed = sha.ComputeHash( Encoding.UTF8.GetBytes( originSeed ) );
|
||||
}
|
||||
}
|
||||
using( SHA256 sha = SHA256.Create() ) {
|
||||
@@ -109,9 +113,11 @@ namespace StgSharp.Math
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Generates a random seed in int value.
|
||||
/// Generates a random seed in int value.
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
/// <returns>
|
||||
///
|
||||
/// </returns>
|
||||
public static unsafe int RandomSeed()
|
||||
{
|
||||
float seedValue1 = LowProceisionRandom();
|
||||
|
||||
@@ -47,9 +47,9 @@ namespace StgSharp.Math
|
||||
* 在进一步简化操作后,计算精度达到0.5%,速度约为.Net库函数的3倍
|
||||
*/
|
||||
|
||||
if( x < 0 ) {
|
||||
throw new ArgumentOutOfRangeException(
|
||||
"Input is smaller than zero!" );
|
||||
if( x < 0 )
|
||||
{
|
||||
throw new ArgumentOutOfRangeException( "Input is smaller than zero!" );
|
||||
}
|
||||
if( x == 0 ) {
|
||||
return 0;
|
||||
@@ -60,7 +60,8 @@ namespace StgSharp.Math
|
||||
* 故不考虑正负号
|
||||
*/
|
||||
|
||||
if( x < 0 ) {
|
||||
if( x < 0 )
|
||||
{
|
||||
throw new ArgumentOutOfRangeException();
|
||||
}
|
||||
if( x <= 1e-12 ) {
|
||||
|
||||
@@ -47,8 +47,8 @@ namespace StgSharp.Math
|
||||
float sin = ( 0.1570796327f * refer ) - ( 6.459640975e-4f * refer * refer2 );
|
||||
float cos = ( 1 - ( 0.0123370055f * refer2 ) ) + ( 2.536695709e-5f * refer2 * refer2 );
|
||||
|
||||
return ( ( sinData[ a ] * cos ) + ( cosData[ a ] * sin ) ) / ( ( cosData[
|
||||
a ] * cos ) - ( sinData[ a ] * sin ) );
|
||||
return ( ( sinData[ a ] * cos ) + ( cosData[ a ] * sin ) ) / ( ( cosData[ a ] * cos ) - ( sinData[
|
||||
a ] * sin ) );
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user