Daily update on 20230803 by nitload youmu, problem of parameter displacement solved, rewriting other linear math
This commit is contained in:
@@ -6,9 +6,9 @@ namespace StgSharp
|
||||
public static unsafe partial class Geometry
|
||||
{
|
||||
public static unsafe Triangle InitTriagnle<T>(
|
||||
vec3d vertex1,
|
||||
vec3d vertex2,
|
||||
vec3d vertex3
|
||||
Vec3d vertex1,
|
||||
Vec3d vertex2,
|
||||
Vec3d vertex3
|
||||
) where T : Triangle
|
||||
{
|
||||
Triangle t = new Triangle();
|
||||
|
||||
@@ -18,11 +18,11 @@ namespace StgSharp.Geometries
|
||||
|
||||
public override Point RefPoint03 => endPoint;
|
||||
|
||||
public virtual vec3d MoveCenter(uint tick) => movCenterOperation.Invoke(tick);
|
||||
public virtual Vec3d MoveCenter(uint tick) => movCenterOperation.Invoke(tick);
|
||||
|
||||
public virtual vec3d MovBegin(uint tick) => movBeginOperation.Invoke(tick);
|
||||
public virtual Vec3d MovBegin(uint tick) => movBeginOperation.Invoke(tick);
|
||||
|
||||
public virtual vec3d MovEnd(uint tick) => movEndOperation.Invoke(tick);
|
||||
public virtual Vec3d MovEnd(uint tick) => movEndOperation.Invoke(tick);
|
||||
|
||||
internal override void OnRender(uint tick)
|
||||
{
|
||||
|
||||
@@ -19,11 +19,11 @@ namespace StgSharp.Geometries
|
||||
|
||||
public override Point RefPoint03 => pointOnPlain;
|
||||
|
||||
public virtual vec3d MoveCenter(uint tick) => movCenterOperation.Invoke(tick);
|
||||
public virtual Vec3d MoveCenter(uint tick) => movCenterOperation.Invoke(tick);
|
||||
|
||||
public virtual vec3d UpdateRadius(uint tick) => movBeginOperation.Invoke(tick);
|
||||
public virtual Vec3d UpdateRadius(uint tick) => movBeginOperation.Invoke(tick);
|
||||
|
||||
public virtual vec3d UpdatePlain(uint tick) => movEndOperation.Invoke(tick);
|
||||
public virtual Vec3d UpdatePlain(uint tick) => movEndOperation.Invoke(tick);
|
||||
|
||||
public override Plain GetPlain()
|
||||
{
|
||||
|
||||
@@ -7,13 +7,13 @@ namespace StgSharp.Geometries
|
||||
/// </summary>
|
||||
/// <param name="tick"></param>
|
||||
/// <returns>表示位移量的三维矢量</returns>
|
||||
public delegate vec3d GetLocationHandler(uint tick);
|
||||
public delegate Vec3d GetLocationHandler(uint tick);
|
||||
|
||||
public static unsafe class GeometryOperation
|
||||
{
|
||||
public static vec3d DefualtMotion(uint tick)
|
||||
public static Vec3d DefualtMotion(uint tick)
|
||||
{
|
||||
return default(vec3d);
|
||||
return default(Vec3d);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -24,11 +24,11 @@ namespace StgSharp.Geometries
|
||||
public Line() { }
|
||||
|
||||
//计算线起点的方法,通过对线的派生的重写实现功能
|
||||
public virtual vec3d MoveBeginPoint(uint tick)
|
||||
public virtual Vec3d MoveBeginPoint(uint tick)
|
||||
=> movBegin.Invoke(tick);
|
||||
|
||||
//计算线重点的方法,通过对线的派生的重写实现功能
|
||||
public virtual vec3d MoveEndPoint(uint tick)
|
||||
public virtual Vec3d MoveEndPoint(uint tick)
|
||||
=> movEnd.Invoke(tick);
|
||||
|
||||
internal override void OnRender(uint tick)
|
||||
|
||||
@@ -17,7 +17,7 @@ namespace StgSharp.Geometries
|
||||
public GetLocationHandler MovVertex01Operation { get { return movVertex01Operation; } }
|
||||
public GetLocationHandler MovVertex02Operation { get { return movVertex02Operation; } }
|
||||
|
||||
public virtual vec3d MovCenter(uint tick)
|
||||
public virtual Vec3d MovCenter(uint tick)
|
||||
{
|
||||
return movCenterOperation.Invoke(tick);
|
||||
}
|
||||
@@ -28,12 +28,12 @@ namespace StgSharp.Geometries
|
||||
/// <param name="tick">当前游戏刻</param>
|
||||
/// <returns></returns>
|
||||
/// <exception cref="UnusedVertexException">几何体过定义</exception>
|
||||
public sealed override vec3d MovVertex03(uint tick)
|
||||
public sealed override Vec3d MovVertex03(uint tick)
|
||||
{
|
||||
throw new UnusedVertexException();
|
||||
}
|
||||
|
||||
public sealed override vec3d MovVertex04(uint tick)
|
||||
public sealed override Vec3d MovVertex04(uint tick)
|
||||
{
|
||||
throw new UnusedVertexException();
|
||||
}
|
||||
|
||||
@@ -4,14 +4,14 @@ namespace StgSharp.Geometries
|
||||
{
|
||||
public unsafe class Plain
|
||||
{
|
||||
internal vec3d origin;
|
||||
internal vec3d vec1;
|
||||
internal vec3d vec2;
|
||||
internal Vec3d origin;
|
||||
internal Vec3d vec1;
|
||||
internal Vec3d vec2;
|
||||
|
||||
internal vec3d plainParameter;
|
||||
internal Vec3d plainParameter;
|
||||
internal readonly float d = -1;
|
||||
|
||||
public Plain(vec3d o, vec3d v1, vec3d v2)
|
||||
public Plain(Vec3d o, Vec3d v1, Vec3d v2)
|
||||
{
|
||||
this.origin = o;
|
||||
this.vec1 = v1 - v2 * (v1.Y / v2.Y); //计算平面在xz平面上的方向投影
|
||||
@@ -30,9 +30,9 @@ namespace StgSharp.Geometries
|
||||
|
||||
public Plain(Point p1, Point p2, Point p3)
|
||||
{
|
||||
vec3d origin = p1.Position;
|
||||
vec3d v1 = p2.Position - origin;
|
||||
vec3d v2 = p3.Position - origin;
|
||||
Vec3d origin = p1.Position;
|
||||
Vec3d v1 = p2.Position - origin;
|
||||
Vec3d v2 = p3.Position - origin;
|
||||
|
||||
|
||||
vec1 = v1 - v2 * (v1.Y / v2.Y); //计算平面在xz平面上的方向投影
|
||||
|
||||
@@ -1,54 +1,47 @@
|
||||
using StgSharp.Math;
|
||||
using System;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
using System.Threading;
|
||||
|
||||
namespace StgSharp.Geometries
|
||||
{
|
||||
public unsafe class Point
|
||||
{
|
||||
internal vec3d* positionPtr;
|
||||
internal Vec3d position;
|
||||
internal readonly bool isVertex;
|
||||
|
||||
internal Point(vec3d* ptr)
|
||||
internal Point(Vec3d p)
|
||||
{
|
||||
positionPtr = ptr;
|
||||
position = p;
|
||||
}
|
||||
|
||||
public Point()
|
||||
{
|
||||
IntPtr ptr = Marshal.AllocHGlobal(sizeof(vec3d));
|
||||
positionPtr = (vec3d*)ptr.ToPointer();
|
||||
|
||||
}
|
||||
|
||||
public vec3d Position
|
||||
public Vec3d Position
|
||||
{
|
||||
get { return *positionPtr; }
|
||||
set { *positionPtr = value; }
|
||||
}
|
||||
|
||||
public vec3d* PositionPtr
|
||||
{
|
||||
get { return positionPtr; }
|
||||
set { positionPtr = value; }
|
||||
get { return position; }
|
||||
set { position = value; }
|
||||
}
|
||||
|
||||
public float X
|
||||
{
|
||||
get { return (*this.positionPtr).X; }
|
||||
set { (*this.positionPtr).X = value; }
|
||||
get { return position.X; }
|
||||
set { position.X = value; }
|
||||
}
|
||||
|
||||
public float Y
|
||||
{
|
||||
get { return (*this.positionPtr).Y; }
|
||||
set { (*this.positionPtr).Y = value; }
|
||||
get { return position.Y; }
|
||||
set { position.Y = value; }
|
||||
}
|
||||
|
||||
public float Z
|
||||
{
|
||||
get { return (*this.positionPtr).Z; }
|
||||
set { (*this.positionPtr).Z = value; }
|
||||
get { return position.Z; }
|
||||
set { position.Z = value; }
|
||||
}
|
||||
|
||||
|
||||
@@ -70,7 +63,7 @@ namespace StgSharp.Geometries
|
||||
|
||||
public bool IsOnPlain(IPlainGeometry geo)
|
||||
{
|
||||
return (*this.positionPtr) * geo.GetPlain().plainParameter == 1;
|
||||
return position * geo.GetPlain().plainParameter == 1;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -50,13 +50,13 @@ namespace StgSharp.Geometries
|
||||
}
|
||||
|
||||
|
||||
public virtual vec3d MovVertex01(uint tick) => movVertex01Operation.Invoke(tick);
|
||||
public virtual Vec3d MovVertex01(uint tick) => movVertex01Operation.Invoke(tick);
|
||||
|
||||
public virtual vec3d MovVertex02(uint tick) => movVertex01Operation.Invoke(tick);
|
||||
public virtual Vec3d MovVertex02(uint tick) => movVertex01Operation.Invoke(tick);
|
||||
|
||||
public virtual vec3d MovVertex03(uint tick) => movVertex01Operation.Invoke(tick);
|
||||
public virtual Vec3d MovVertex03(uint tick) => movVertex01Operation.Invoke(tick);
|
||||
|
||||
public virtual vec3d MovVertex04(uint tick) => movVertex01Operation.Invoke(tick);
|
||||
public virtual Vec3d MovVertex04(uint tick) => movVertex01Operation.Invoke(tick);
|
||||
|
||||
|
||||
internal override void OnRender(uint tick)
|
||||
|
||||
@@ -36,15 +36,15 @@ namespace StgSharp.Geometries
|
||||
{
|
||||
}
|
||||
|
||||
public virtual vec3d movPoint01(uint tick) => movP01Operation.Invoke(TimeLine.tickCounter._value);
|
||||
public virtual Vec3d movPoint01(uint tick) => movP01Operation.Invoke(TimeLine.tickCounter._value);
|
||||
|
||||
public virtual vec3d movPoint02(uint tick) => movP02Operation.Invoke(TimeLine.tickCounter._value);
|
||||
public virtual Vec3d movPoint02(uint tick) => movP02Operation.Invoke(TimeLine.tickCounter._value);
|
||||
|
||||
public virtual vec3d movPoint03(uint tick) => movP03Operation.Invoke(TimeLine.tickCounter._value);
|
||||
public virtual Vec3d movPoint03(uint tick) => movP03Operation.Invoke(TimeLine.tickCounter._value);
|
||||
|
||||
public virtual vec3d movPoint04(uint tick) => movP04Operation.Invoke(TimeLine.tickCounter._value);
|
||||
public virtual Vec3d movPoint04(uint tick) => movP04Operation.Invoke(TimeLine.tickCounter._value);
|
||||
|
||||
public virtual vec3d movPoint05(uint tick) => movP05Operation.Invoke(TimeLine.tickCounter._value);
|
||||
public virtual Vec3d movPoint05(uint tick) => movP05Operation.Invoke(TimeLine.tickCounter._value);
|
||||
|
||||
|
||||
internal override void OnRender(uint tick)
|
||||
|
||||
@@ -35,32 +35,32 @@ namespace StgSharp.Geometries
|
||||
public GetLocationHandler MovP05Operation { get => movP05Operation; }
|
||||
public GetLocationHandler MovP06Operation { get => movP06Operation; }
|
||||
|
||||
public virtual vec3d movPoint01(uint tick)
|
||||
public virtual Vec3d movPoint01(uint tick)
|
||||
{
|
||||
return movP01Operation.Invoke(TimeLine.tickCounter._value);
|
||||
}
|
||||
|
||||
public virtual vec3d movPoint02(uint tick)
|
||||
public virtual Vec3d movPoint02(uint tick)
|
||||
{
|
||||
return movP02Operation.Invoke(TimeLine.tickCounter._value);
|
||||
}
|
||||
|
||||
public virtual vec3d movPoint03(uint tick)
|
||||
public virtual Vec3d movPoint03(uint tick)
|
||||
{
|
||||
return movP03Operation.Invoke(TimeLine.tickCounter._value);
|
||||
}
|
||||
|
||||
public virtual vec3d movPoint04(uint tick)
|
||||
public virtual Vec3d movPoint04(uint tick)
|
||||
{
|
||||
return movP04Operation.Invoke(TimeLine.tickCounter._value);
|
||||
}
|
||||
|
||||
public virtual vec3d movPoint05(uint tick)
|
||||
public virtual Vec3d movPoint05(uint tick)
|
||||
{
|
||||
return movP05Operation.Invoke(TimeLine.tickCounter._value);
|
||||
}
|
||||
|
||||
public virtual vec3d movPoint06(uint tick)
|
||||
public virtual Vec3d movPoint06(uint tick)
|
||||
{
|
||||
return movP06Operation.Invoke(TimeLine.tickCounter._value);
|
||||
}
|
||||
|
||||
@@ -19,14 +19,14 @@ namespace StgSharp.Geometries
|
||||
/// </summary>
|
||||
/// <param name="tick">当前游戏刻</param>
|
||||
/// <returns></returns>
|
||||
public virtual vec3d MovCenter(uint tick) => default(vec3d);
|
||||
public virtual Vec3d MovCenter(uint tick) => default(Vec3d);
|
||||
|
||||
public sealed override vec3d MovVertex03(uint tick)
|
||||
public sealed override Vec3d MovVertex03(uint tick)
|
||||
{
|
||||
return this.center.Position * 2 - this.vertex01.Position;
|
||||
}
|
||||
|
||||
public sealed override vec3d MovVertex04(uint tick)
|
||||
public sealed override Vec3d MovVertex04(uint tick)
|
||||
{
|
||||
return this.center.Position * 2 - this.vertex02.Position;
|
||||
}
|
||||
|
||||
@@ -8,7 +8,7 @@ namespace StgSharp.Geometries
|
||||
/// </summary>
|
||||
public class Square : Rectangle
|
||||
{
|
||||
public sealed override vec3d MovVertex02(uint tick)
|
||||
public sealed override Vec3d MovVertex02(uint tick)
|
||||
{
|
||||
return this.center.Position * 2 - this.vertex01.Position;
|
||||
}
|
||||
|
||||
@@ -23,11 +23,11 @@ namespace StgSharp.Geometries
|
||||
public GetLocationHandler MovVertex02Operation => this.movVertex02Opearion;
|
||||
public GetLocationHandler MovVertex03Operation => this.movVertex03Opearion;
|
||||
|
||||
public virtual vec3d MovVertex01(uint tick) => movVertex01Opearion.Invoke(tick);
|
||||
public virtual Vec3d MovVertex01(uint tick) => movVertex01Opearion.Invoke(tick);
|
||||
|
||||
public virtual vec3d MovVertex02(uint tick) => movVertex02Opearion.Invoke(tick);
|
||||
public virtual Vec3d MovVertex02(uint tick) => movVertex02Opearion.Invoke(tick);
|
||||
|
||||
public virtual vec3d MovVertex03(uint tick) => movVertex03Opearion.Invoke(tick);
|
||||
public virtual Vec3d MovVertex03(uint tick) => movVertex03Opearion.Invoke(tick);
|
||||
|
||||
public Triangle()
|
||||
{
|
||||
@@ -46,9 +46,9 @@ namespace StgSharp.Geometries
|
||||
}
|
||||
|
||||
public Triangle(
|
||||
vec3d vertex01,
|
||||
vec3d vertex02,
|
||||
vec3d vertex03
|
||||
Vec3d vertex01,
|
||||
Vec3d vertex02,
|
||||
Vec3d vertex03
|
||||
)
|
||||
{
|
||||
vertex1.Position = vertex01;
|
||||
|
||||
@@ -2,35 +2,38 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Text;
|
||||
|
||||
|
||||
|
||||
namespace StgSharp
|
||||
{
|
||||
|
||||
|
||||
|
||||
internal static unsafe partial class internalIO
|
||||
internal static partial class internalIO
|
||||
{
|
||||
[DllImport("StgSharpGraphic.dll", EntryPoint = "VecAddVec",
|
||||
CallingConvention =CallingConvention.Cdecl)]
|
||||
internal static extern M128 VecAddVec(in IntPtr ptr1, in IntPtr ptr2 /**/, in IntPtr ret/**/);
|
||||
|
||||
[DllImport("StgSharpGraphic.dll", EntryPoint = "VecSubVec",
|
||||
[DllImport("StgSharpGraphic.dll", EntryPoint = "load",
|
||||
CallingConvention = CallingConvention.Cdecl)]
|
||||
internal static extern void VecSubVec(IntPtr ptr1, IntPtr ptr2,IntPtr ret);
|
||||
internal static extern IntPtr load_internal(float x,float y, float z, float w);
|
||||
|
||||
[DllImport("StgSharpGraphic.dll", EntryPoint = "VecMulVec",
|
||||
[DllImport("StgSharpGraphic.dll", EntryPoint = "addps",
|
||||
CallingConvention = CallingConvention.Cdecl)]
|
||||
internal static extern void VecMulVec(IntPtr ptr1, IntPtr ptr2, IntPtr ret);
|
||||
internal static extern IntPtr addps_internal(IntPtr ptr1, IntPtr ptr2);
|
||||
|
||||
[DllImport("StgSharpGraphic.dll", EntryPoint = "initSSE")]
|
||||
internal static extern ulong InternalInitSSE();
|
||||
[DllImport("StgSharpGraphic.dll", EntryPoint = "subps",
|
||||
CallingConvention = CallingConvention.Cdecl)]
|
||||
internal static extern IntPtr subps_internal(IntPtr ptr1, IntPtr ptr2);
|
||||
|
||||
[DllImport("StgSharpGraphic.dll", EntryPoint = "InitM128")]
|
||||
internal static unsafe extern IntPtr InternalInitM128(float x,float y,float z,float w);
|
||||
[DllImport("StgSharpGraphic.dll", EntryPoint = "mulps",
|
||||
CallingConvention = CallingConvention.Cdecl)]
|
||||
internal static extern IntPtr mulps_internal(IntPtr ptr1, IntPtr ptr2);
|
||||
|
||||
[DllImport("StgSharpGraphic.dll", EntryPoint = "DeinitM128")]
|
||||
internal static unsafe extern void InternalDeinitM128(IntPtr m128Ptr);
|
||||
[DllImport("StgSharpGraphic.dll", EntryPoint = "mulps_const",
|
||||
CallingConvention = CallingConvention.Cdecl)]
|
||||
internal static extern IntPtr mulps_const_internal(IntPtr ptr, float value);
|
||||
|
||||
|
||||
|
||||
[DllImport("StgSharpGraphic.dll", EntryPoint = "deinitM128",
|
||||
CallingConvention = CallingConvention.Cdecl)]
|
||||
internal static extern void deinitM128_internal(IntPtr M128Ptr);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Text;
|
||||
|
||||
namespace StgSharp.Math
|
||||
@@ -8,17 +10,25 @@ namespace StgSharp.Math
|
||||
{
|
||||
public enum Registor : byte
|
||||
{
|
||||
XMM0=0,
|
||||
XMM1=1,
|
||||
XMM2=2,
|
||||
XMM3=3,
|
||||
XMM4=4,
|
||||
XMM5=5,
|
||||
XMM6=6,
|
||||
XMM7=7
|
||||
XMM0 = 0,
|
||||
XMM1 = 1,
|
||||
XMM2 = 2,
|
||||
XMM3 = 3,
|
||||
XMM4 = 4,
|
||||
XMM5 = 5,
|
||||
XMM6 = 6,
|
||||
XMM7 = 7
|
||||
}
|
||||
|
||||
static SSE()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
public static Vec4d addps(Vec4d vec1, Vec4d vec2)
|
||||
{
|
||||
return new Vec4d(
|
||||
internalIO.addps_internal(vec1._m128Ptr,vec2._m128Ptr)
|
||||
) ;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,9 +8,9 @@
|
||||
return vec1.X * vec2.Y - vec1.Y * vec2.X;
|
||||
}
|
||||
|
||||
public static vec3d Cross(vec3d vec1, vec3d vec2)
|
||||
public static Vec3d Cross(Vec3d vec1, Vec3d vec2)
|
||||
{
|
||||
return new vec3d(
|
||||
return new Vec3d(
|
||||
vec1.Y * vec2.Z - vec1.Z * vec2.Y,
|
||||
vec1.X * vec2.Z - vec1.Z * vec2.X,
|
||||
vec1.X * vec2.Y - vec1.Y * vec2.X
|
||||
|
||||
@@ -8,6 +8,8 @@
|
||||
return Cross(array.row1, array.row2);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
public static unsafe float Det(matrix3x3 array)
|
||||
{
|
||||
float* p = &array.row1.X;
|
||||
@@ -31,5 +33,7 @@
|
||||
+ *(p + 2) * Det(matrix3)
|
||||
;
|
||||
}
|
||||
|
||||
*/
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10,7 +10,7 @@
|
||||
);
|
||||
}
|
||||
|
||||
public static float GetAngle(vec3d vec1, vec3d vec2)
|
||||
public static float GetAngle(Vec3d vec1, Vec3d vec2)
|
||||
{
|
||||
return Calc.ACos(
|
||||
vec1 * vec2
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
{
|
||||
public static unsafe partial class Vector
|
||||
{
|
||||
public static float GetLength(this vec3d vec)
|
||||
public static float GetLength(this Vec3d vec)
|
||||
{
|
||||
return Calc.Sqrt(
|
||||
vec.X * vec.X +
|
||||
|
||||
@@ -1,8 +1,30 @@
|
||||
namespace StgSharp.Math
|
||||
using System;
|
||||
|
||||
namespace StgSharp.Math
|
||||
{
|
||||
public static unsafe partial class VectorCalc
|
||||
{
|
||||
|
||||
public static unsafe float Multiple(Vec3d vec1, Vec4d vec2)
|
||||
{
|
||||
M128* retPtr = (M128*)internalIO.mulps_internal(vec1._m128Ptr,vec2._m128Ptr);
|
||||
|
||||
return
|
||||
retPtr->single_0 +
|
||||
retPtr->single_1 +
|
||||
retPtr->single_2;
|
||||
}
|
||||
|
||||
public static unsafe float Multiple(Vec4d vec1,Vec4d vec2)
|
||||
{
|
||||
M128* retPtr = (M128*)internalIO.mulps_internal(vec1._m128Ptr,vec2._m128Ptr);
|
||||
return
|
||||
retPtr->single_0 +
|
||||
retPtr->single_1 +
|
||||
retPtr->single_2 +
|
||||
retPtr->single_3;
|
||||
}
|
||||
|
||||
public static unsafe Matrix4x4 Multiple(
|
||||
Matrix4x4 matrix1, Matrix4x4 matrix2
|
||||
)
|
||||
@@ -74,7 +96,7 @@
|
||||
);
|
||||
}
|
||||
|
||||
public static float multiple(this vec3d vec, colum3 colum)
|
||||
public static float multiple(this Vec3d vec, colum3 colum)
|
||||
{
|
||||
return vec.X * colum.X + vec.Y * colum.Y + vec.Z * colum.Z;
|
||||
}
|
||||
@@ -85,11 +107,11 @@
|
||||
/// <param name="vec"></param>
|
||||
/// <param name="matrix"></param>
|
||||
/// <returns></returns>
|
||||
public static unsafe vec3d multiple(this vec2d vec, matrix2x3 matrix)
|
||||
public static unsafe Vec3d multiple(this vec2d vec, matrix2x3 matrix)
|
||||
{
|
||||
float* p = &matrix.row1.X;
|
||||
|
||||
return new vec3d(
|
||||
return new Vec3d(
|
||||
vec.X * *(p + 0) + vec.Y * *(p + 3),
|
||||
vec.X * *(p + 1) + vec.Y * *(p + 4),
|
||||
vec.X * *(p + 2) + vec.Y * *(p + 5)
|
||||
|
||||
@@ -2,12 +2,12 @@
|
||||
{
|
||||
public unsafe static partial class Vector
|
||||
{
|
||||
public static vec3d To3D(vec2d vec)
|
||||
public static Vec3d To3D(vec2d vec)
|
||||
{
|
||||
return new vec3d(vec.X, vec.Y, 0.0f);
|
||||
return new Vec3d(vec.X, vec.Y, 0.0f);
|
||||
}
|
||||
|
||||
public static vec2d To2D(vec3d vec, CordinatePlain plain)
|
||||
public static vec2d To2D(Vec3d vec, CordinatePlain plain)
|
||||
{
|
||||
switch (plain)
|
||||
{
|
||||
|
||||
@@ -55,7 +55,7 @@ namespace StgSharp.Math
|
||||
}
|
||||
else
|
||||
{
|
||||
return this.Equals((vec3d)obj);
|
||||
return this.Equals((Vec3d)obj);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -7,11 +7,11 @@ namespace StgSharp.Math
|
||||
public struct matrix2x3 : IEquatable<matrix2x3>
|
||||
{
|
||||
[FieldOffset(0)]
|
||||
public vec3d row1;
|
||||
public Vec3d row1;
|
||||
[FieldOffset(12)]
|
||||
public vec3d row2;
|
||||
public Vec3d row2;
|
||||
|
||||
public matrix2x3(vec3d r1, vec3d r2)
|
||||
public matrix2x3(Vec3d r1, Vec3d r2)
|
||||
{
|
||||
row1 = r1;
|
||||
row2 = r2;
|
||||
@@ -22,8 +22,8 @@ namespace StgSharp.Math
|
||||
float r21, float r22, float r23
|
||||
)
|
||||
{
|
||||
row1 = new vec3d(r11, r12, r13);
|
||||
row2 = new vec3d(r21, r22, r23);
|
||||
row1 = new Vec3d(r11, r12, r13);
|
||||
row2 = new Vec3d(r21, r22, r23);
|
||||
}
|
||||
|
||||
public override bool Equals(object obj)
|
||||
@@ -38,7 +38,7 @@ namespace StgSharp.Math
|
||||
}
|
||||
else
|
||||
{
|
||||
return this.Equals((vec3d)obj);
|
||||
return this.Equals((Vec3d)obj);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -7,13 +7,13 @@ namespace StgSharp.Math
|
||||
public struct matrix3x3 : IEquatable<matrix3x3>
|
||||
{
|
||||
[FieldOffset(0)]
|
||||
public vec3d row1;
|
||||
public Vec3d row1;
|
||||
[FieldOffset(12)]
|
||||
public vec3d row2;
|
||||
public Vec3d row2;
|
||||
[FieldOffset(24)]
|
||||
public vec3d row3;
|
||||
public Vec3d row3;
|
||||
|
||||
public matrix3x3(vec3d r0, vec3d r1, vec3d r2)
|
||||
public matrix3x3(Vec3d r0, Vec3d r1, Vec3d r2)
|
||||
{
|
||||
row1 = r0;
|
||||
row2 = r1;
|
||||
@@ -26,9 +26,9 @@ namespace StgSharp.Math
|
||||
float a31, float a32, float a33
|
||||
)
|
||||
{
|
||||
row1 = new vec3d(a11, a12, a13);
|
||||
row2 = new vec3d(a21, a22, a23);
|
||||
row3 = new vec3d(a31, a32, a33);
|
||||
row1 = new Vec3d(a11, a12, a13);
|
||||
row2 = new Vec3d(a21, a22, a23);
|
||||
row3 = new Vec3d(a31, a32, a33);
|
||||
}
|
||||
|
||||
public override int GetHashCode()
|
||||
|
||||
@@ -8,13 +8,13 @@ namespace StgSharp.Math
|
||||
public struct matrix4x3 : IEquatable<matrix4x3>
|
||||
{
|
||||
[FieldOffset(0)]
|
||||
public vec3d row1;
|
||||
public Vec3d row1;
|
||||
[FieldOffset(12)]
|
||||
public vec3d row2;
|
||||
public Vec3d row2;
|
||||
[FieldOffset(24)]
|
||||
public vec3d row3;
|
||||
public Vec3d row3;
|
||||
[FieldOffset(36)]
|
||||
public vec3d row4;
|
||||
public Vec3d row4;
|
||||
|
||||
public matrix4x3(
|
||||
float a11, float a12, float a13,
|
||||
@@ -23,10 +23,10 @@ namespace StgSharp.Math
|
||||
float a41, float a42, float a43
|
||||
)
|
||||
{
|
||||
row1 = new vec3d(a11, a12, a13);
|
||||
row2 = new vec3d(a21, a22, a23);
|
||||
row3 = new vec3d(a31, a32, a33);
|
||||
row4 = new vec3d(a41, a42, a43);
|
||||
row1 = new Vec3d(a11, a12, a13);
|
||||
row2 = new Vec3d(a21, a22, a23);
|
||||
row3 = new Vec3d(a31, a32, a33);
|
||||
row4 = new Vec3d(a41, a42, a43);
|
||||
}
|
||||
|
||||
public override bool Equals(object obj)
|
||||
|
||||
@@ -13,6 +13,15 @@ namespace StgSharp.Math
|
||||
|
||||
public unsafe class Matrix4x4
|
||||
{
|
||||
public static readonly Matrix4x4 Unit
|
||||
= new Matrix4x4(
|
||||
1,0,0,0,
|
||||
0,1,0,0,
|
||||
0,0,1,0,
|
||||
0,0,0,1
|
||||
);
|
||||
|
||||
|
||||
internal M128Map map;
|
||||
|
||||
internal IntPtr _row0Ptr;
|
||||
@@ -27,11 +36,10 @@ namespace StgSharp.Math
|
||||
|
||||
internal Matrix4x4()
|
||||
{
|
||||
|
||||
_row0Ptr = internalIO.InternalInitM128(0, 0, 0, 0);
|
||||
_row1Ptr = internalIO.InternalInitM128(0, 0, 0, 0);
|
||||
_row2Ptr = internalIO.InternalInitM128(0, 0, 0, 0);
|
||||
_row3Ptr = internalIO.InternalInitM128(0, 0, 0, 0);
|
||||
_row0Ptr = internalIO.load_internal(0,0,0,0);
|
||||
_row1Ptr = internalIO.load_internal(0,0,0,0);
|
||||
_row2Ptr = internalIO.load_internal(0,0,0,0);
|
||||
_row3Ptr = internalIO.load_internal(0,0,0,0);
|
||||
|
||||
_transpose = new Matrix4x4(this);
|
||||
}
|
||||
@@ -39,27 +47,26 @@ namespace StgSharp.Math
|
||||
//Ctor used for the matixes of transposed matrix
|
||||
internal Matrix4x4(Matrix4x4 transpose)
|
||||
{
|
||||
|
||||
_row0Ptr = internalIO.InternalInitM128(0, 0, 0, 0);
|
||||
_row1Ptr = internalIO.InternalInitM128(0, 0, 0, 0);
|
||||
_row2Ptr = internalIO.InternalInitM128(0, 0, 0, 0);
|
||||
_row3Ptr = internalIO.InternalInitM128(0, 0, 0, 0);
|
||||
_row0Ptr = internalIO.load_internal(0, 0, 0, 0);
|
||||
_row1Ptr = internalIO.load_internal(0, 0, 0, 0);
|
||||
_row2Ptr = internalIO.load_internal(0, 0, 0, 0);
|
||||
_row3Ptr = internalIO.load_internal(0, 0, 0, 0);
|
||||
|
||||
_transpose = transpose;
|
||||
this.isTransposed=true;
|
||||
}
|
||||
|
||||
internal unsafe Matrix4x4(M128 row0, M128 row1, M128 row2, M128 row3)
|
||||
internal unsafe Matrix4x4(
|
||||
IntPtr row0Ptr,
|
||||
IntPtr row1Ptr,
|
||||
IntPtr row2Ptr,
|
||||
IntPtr row3Ptr)
|
||||
{
|
||||
|
||||
_row0Ptr = internalIO.InternalInitM128(
|
||||
row0.single_0, row0.single_1, row0.single_2, row0.single_3);
|
||||
_row1Ptr = internalIO.InternalInitM128(
|
||||
row1.single_0, row1.single_1, row1.single_2, row1.single_3);
|
||||
_row2Ptr = internalIO.InternalInitM128(
|
||||
row2.single_0, row2.single_1, row2.single_2, row2.single_3);
|
||||
_row3Ptr = internalIO.InternalInitM128(
|
||||
row3.single_0, row3.single_1, row3.single_2, row3.single_3);
|
||||
_row0Ptr = row0Ptr;
|
||||
_row1Ptr = row1Ptr;
|
||||
_row2Ptr = row2Ptr;
|
||||
_row3Ptr = row3Ptr;
|
||||
|
||||
_transpose = new Matrix4x4(this);
|
||||
}
|
||||
@@ -72,10 +79,10 @@ namespace StgSharp.Math
|
||||
)
|
||||
{
|
||||
|
||||
_row0Ptr = internalIO.InternalInitM128(a00,a01,a02,a03);
|
||||
_row1Ptr = internalIO.InternalInitM128(a10,a11,a12,a13);
|
||||
_row2Ptr = internalIO.InternalInitM128(a20,a21,a22,a23);
|
||||
_row3Ptr = internalIO.InternalInitM128(a30,a31,a32,a33);
|
||||
_row0Ptr = internalIO.load_internal(a00,a01,a02,a03);
|
||||
_row1Ptr = internalIO.load_internal(a10,a11,a12,a13);
|
||||
_row2Ptr = internalIO.load_internal(a20,a21,a22,a23);
|
||||
_row3Ptr = internalIO.load_internal(a30,a31,a32,a33);
|
||||
|
||||
_transpose = new Matrix4x4(this);
|
||||
}
|
||||
@@ -115,10 +122,10 @@ namespace StgSharp.Math
|
||||
{
|
||||
case TransposeMode.New:
|
||||
return new Matrix4x4(
|
||||
*(M128*)_transpose._row0Ptr,
|
||||
*(M128*)_transpose._row1Ptr,
|
||||
*(M128*)_transpose._row2Ptr,
|
||||
*(M128*)_transpose._row3Ptr
|
||||
_transpose._row0Ptr,
|
||||
_transpose._row1Ptr,
|
||||
_transpose._row2Ptr,
|
||||
_transpose._row3Ptr
|
||||
);
|
||||
break;
|
||||
case TransposeMode.Copy:
|
||||
@@ -130,52 +137,39 @@ namespace StgSharp.Math
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
/**/
|
||||
public static Matrix4x4 operator +(Matrix4x4 matrix1, Matrix4x4 matrix2)
|
||||
{
|
||||
return new Matrix4x4(
|
||||
internalIO.VecAddVec(matrix1._row0Ptr, matrix2._row0Ptr),
|
||||
internalIO.VecAddVec(matrix1._row1Ptr, matrix2._row1Ptr),
|
||||
internalIO.VecAddVec(matrix1._row2Ptr, matrix2._row2Ptr),
|
||||
internalIO.VecAddVec(matrix1._row3Ptr, matrix2._row3Ptr)
|
||||
internalIO.addps_internal(matrix1._row0Ptr, matrix2._row0Ptr),
|
||||
internalIO.addps_internal(matrix1._row1Ptr, matrix2._row1Ptr),
|
||||
internalIO.addps_internal(matrix1._row2Ptr, matrix2._row2Ptr),
|
||||
internalIO.addps_internal(matrix1._row3Ptr, matrix2._row3Ptr)
|
||||
) ;
|
||||
}
|
||||
|
||||
public static Matrix4x4 operator *(Matrix4x4 matrix, float value)
|
||||
public static Matrix4x4 operator -(Matrix4x4 matrix1, Matrix4x4 matrix2)
|
||||
{
|
||||
M128 newRow0 = new M128(
|
||||
(*(M128*)matrix._row0Ptr).single_0 * value,
|
||||
(*(M128*)matrix._row0Ptr).single_1 * value,
|
||||
(*(M128*)matrix._row0Ptr).single_2 * value,
|
||||
(*(M128*)matrix._row0Ptr).single_3 * value
|
||||
);
|
||||
|
||||
M128 newRow1 = new M128(
|
||||
(*(M128*)matrix._row1Ptr).single_0 * value,
|
||||
(*(M128*)matrix._row1Ptr).single_1 * value,
|
||||
(*(M128*)matrix._row1Ptr).single_2 * value,
|
||||
(*(M128*)matrix._row1Ptr).single_3 * value
|
||||
);
|
||||
|
||||
M128 newRow2 = new M128(
|
||||
(*(M128*)matrix._row2Ptr).single_0 * value,
|
||||
(*(M128*)matrix._row2Ptr).single_1 * value,
|
||||
(*(M128*)matrix._row2Ptr).single_2 * value,
|
||||
(*(M128*)matrix._row2Ptr).single_3 * value
|
||||
);
|
||||
|
||||
M128 newRow3 = new M128(
|
||||
(*(M128*)matrix._row3Ptr).single_0 * value,
|
||||
(*(M128*)matrix._row3Ptr).single_1 * value,
|
||||
(*(M128*)matrix._row3Ptr).single_2 * value,
|
||||
(*(M128*)matrix._row3Ptr).single_3 * value
|
||||
);
|
||||
|
||||
return new Matrix4x4(
|
||||
newRow0, newRow1, newRow2, newRow3
|
||||
internalIO.subps_internal(matrix1._row0Ptr, matrix2._row0Ptr),
|
||||
internalIO.subps_internal(matrix1._row1Ptr, matrix2._row1Ptr),
|
||||
internalIO.subps_internal(matrix1._row2Ptr, matrix2._row2Ptr),
|
||||
internalIO.subps_internal(matrix1._row3Ptr, matrix2._row3Ptr)
|
||||
);
|
||||
}
|
||||
|
||||
/**/
|
||||
public static Matrix4x4 operator *(Matrix4x4 matrix, float value)
|
||||
{
|
||||
return new Matrix4x4(
|
||||
internalIO.mulps_const_internal(matrix._row0Ptr,value),
|
||||
internalIO.mulps_const_internal(matrix._row1Ptr,value),
|
||||
internalIO.mulps_const_internal(matrix._row2Ptr,value),
|
||||
internalIO.mulps_const_internal(matrix._row3Ptr,value)
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return $"{*(M128*)_row0Ptr}\n{*(M128*)_row1Ptr}\n{*(M128*)_row2Ptr}\n{*(M128*)_row3Ptr}";
|
||||
@@ -187,10 +181,10 @@ namespace StgSharp.Math
|
||||
{
|
||||
if (map==null)
|
||||
{
|
||||
Marshal.FreeHGlobal((IntPtr)_row0Ptr);
|
||||
Marshal.FreeHGlobal((IntPtr)_row1Ptr);
|
||||
Marshal.FreeHGlobal((IntPtr)_row2Ptr);
|
||||
Marshal.FreeHGlobal((IntPtr)_row3Ptr);
|
||||
internalIO.deinitM128_internal(_row0Ptr);
|
||||
internalIO.deinitM128_internal(_row1Ptr);
|
||||
internalIO.deinitM128_internal(_row2Ptr);
|
||||
internalIO.deinitM128_internal(_row3Ptr);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
@@ -1,10 +1,13 @@
|
||||
using System;
|
||||
using StgSharp.Control;
|
||||
using System;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
namespace StgSharp.Math
|
||||
{
|
||||
|
||||
/*
|
||||
[StructLayout(LayoutKind.Explicit, Size = 12, Pack = 16)]
|
||||
public struct vec3d : IEquatable<vec3d>
|
||||
public struct Vec3d : IEquatable<Vec3d>
|
||||
{
|
||||
[FieldOffset(0)]
|
||||
public float X;
|
||||
@@ -13,14 +16,14 @@ namespace StgSharp.Math
|
||||
[FieldOffset(8)]
|
||||
public float Z;
|
||||
|
||||
public vec3d(float x, float y, float z)
|
||||
public Vec3d(float x, float y, float z)
|
||||
{
|
||||
X = x;
|
||||
Y = y;
|
||||
Z = z;
|
||||
}
|
||||
|
||||
bool IEquatable<vec3d>.Equals(vec3d other)
|
||||
bool IEquatable<Vec3d>.Equals(Vec3d other)
|
||||
{
|
||||
if (this.GetHashCode() != other.GetHashCode())
|
||||
{
|
||||
@@ -40,13 +43,13 @@ namespace StgSharp.Math
|
||||
{
|
||||
return false;
|
||||
}
|
||||
else if (obj.GetType() != typeof(vec3d))
|
||||
else if (obj.GetType() != typeof(Vec3d))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
else
|
||||
{
|
||||
return this.Equals((vec3d)obj);
|
||||
return this.Equals((Vec3d)obj);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -65,39 +68,39 @@ namespace StgSharp.Math
|
||||
return $"{X.ToString(sample)}\t{Y.ToString(sample)}\t{Z.ToString(sample)}";
|
||||
}
|
||||
|
||||
public static bool operator ==(vec3d vec1, vec3d vec2)
|
||||
public static bool operator ==(Vec3d vec1, Vec3d vec2)
|
||||
{
|
||||
return vec1.X == vec2.X
|
||||
&& vec1.Y == vec2.Y
|
||||
&& vec1.Z == vec2.Z;
|
||||
}
|
||||
|
||||
public static bool operator !=(vec3d vec1, vec3d vec2)
|
||||
public static bool operator !=(Vec3d vec1, Vec3d vec2)
|
||||
{
|
||||
return !(vec1.X == vec2.X
|
||||
&& vec1.Y == vec2.Y
|
||||
&& vec1.Z == vec2.Z);
|
||||
}
|
||||
|
||||
public static vec3d operator +(vec3d vec1, vec3d vec2)
|
||||
public static Vec3d operator +(Vec3d vec1, Vec3d vec2)
|
||||
{
|
||||
return new vec3d(
|
||||
return new Vec3d(
|
||||
vec1.X + vec2.X,
|
||||
vec1.Y + vec2.Y,
|
||||
vec1.Z + vec2.Z
|
||||
);
|
||||
}
|
||||
|
||||
public static vec3d operator -(vec3d vec1, vec3d vec2)
|
||||
public static Vec3d operator -(Vec3d vec1, Vec3d vec2)
|
||||
{
|
||||
return new vec3d(
|
||||
return new Vec3d(
|
||||
vec1.X - vec2.X,
|
||||
vec1.Y - vec2.Y,
|
||||
vec1.Z - vec2.Z
|
||||
);
|
||||
}
|
||||
|
||||
public static float operator *(vec3d vec1, vec3d vec2)
|
||||
public static float operator *(Vec3d vec1, Vec3d vec2)
|
||||
{
|
||||
return
|
||||
vec1.X * vec2.X
|
||||
@@ -105,41 +108,141 @@ namespace StgSharp.Math
|
||||
+ vec1.Z + vec2.Z;
|
||||
}
|
||||
|
||||
public static vec3d operator *(vec3d vec, float x)
|
||||
public static Vec3d operator *(Vec3d vec, float x)
|
||||
{
|
||||
return new vec3d(
|
||||
return new Vec3d(
|
||||
vec.X * x,
|
||||
vec.Y * x,
|
||||
vec.Z * x
|
||||
);
|
||||
}
|
||||
|
||||
public static vec3d operator *(float x, vec3d vec)
|
||||
public static Vec3d operator *(float x, Vec3d vec)
|
||||
{
|
||||
return new vec3d(
|
||||
return new Vec3d(
|
||||
vec.X * x,
|
||||
vec.Y * x,
|
||||
vec.Z * x
|
||||
);
|
||||
}
|
||||
|
||||
public static vec3d operator /(vec3d vec, float x)
|
||||
public static Vec3d operator /(Vec3d vec, float x)
|
||||
{
|
||||
return new vec3d(
|
||||
return new Vec3d(
|
||||
vec.X / x,
|
||||
vec.Y / x,
|
||||
vec.Z / x
|
||||
);
|
||||
}
|
||||
|
||||
public static implicit operator float[](vec3d vec)
|
||||
public static implicit operator float[](Vec3d vec)
|
||||
{
|
||||
return new float[3] { vec.X, vec.Y, vec.Y };
|
||||
}
|
||||
|
||||
public static implicit operator vec3d(float[] floatArray)
|
||||
public static implicit operator Vec3d(float[] floatArray)
|
||||
{
|
||||
return new vec3d(floatArray[0], floatArray[1], floatArray[2]);
|
||||
return new Vec3d(floatArray[0], floatArray[1], floatArray[2]);
|
||||
}
|
||||
}
|
||||
|
||||
/**/
|
||||
|
||||
|
||||
public class Vec3d
|
||||
{
|
||||
public static Vec3d defaultValue =
|
||||
new Vec3d(0, 0, 0);
|
||||
|
||||
|
||||
internal M128Map _map;
|
||||
internal IntPtr _m128Ptr;
|
||||
|
||||
public unsafe float X
|
||||
{
|
||||
get { return ((M128*)_m128Ptr)->single_0; }
|
||||
set { ((M128*)_m128Ptr)->single_0 = value; }
|
||||
}
|
||||
|
||||
public unsafe float Y
|
||||
{
|
||||
get { return ((M128*)_m128Ptr)->single_1; }
|
||||
set { ((M128*)_m128Ptr)->single_1 = value; }
|
||||
}
|
||||
|
||||
public unsafe float Z
|
||||
{
|
||||
get { return ((M128*)_m128Ptr)->single_2; }
|
||||
set { ((M128*)_m128Ptr)->single_2 = value; }
|
||||
}
|
||||
|
||||
|
||||
internal Vec3d(IntPtr value)
|
||||
{
|
||||
if ((long)value == -1)
|
||||
{
|
||||
throw new Exception("Failed to creat M128 pointer");
|
||||
}
|
||||
else
|
||||
{
|
||||
_m128Ptr = value;
|
||||
}
|
||||
}
|
||||
|
||||
public Vec3d(float x, float y, float z)
|
||||
{
|
||||
_m128Ptr = internalIO.load_internal(x,y,z,0);
|
||||
}
|
||||
|
||||
internal Vec3d()
|
||||
{
|
||||
_m128Ptr = defaultValue._m128Ptr;
|
||||
}
|
||||
|
||||
public static Vec3d operator +(Vec3d vec1, Vec3d vec2)
|
||||
{
|
||||
return new Vec3d(
|
||||
internalIO.addps_internal(vec1._m128Ptr, vec2._m128Ptr)
|
||||
);
|
||||
}
|
||||
|
||||
public static Vec3d operator -(Vec3d vec1, Vec3d vec2)
|
||||
{
|
||||
return new Vec3d(
|
||||
internalIO.subps_internal(vec1._m128Ptr, vec2._m128Ptr)
|
||||
);
|
||||
}
|
||||
|
||||
public static Vec3d operator *(Vec3d vec, float value)
|
||||
{
|
||||
return new Vec3d(
|
||||
internalIO.mulps_const_internal(vec._m128Ptr,value)
|
||||
);
|
||||
}
|
||||
|
||||
public unsafe override string ToString()
|
||||
{
|
||||
return (*(M128*)_m128Ptr).ToString();
|
||||
}
|
||||
|
||||
~Vec3d()
|
||||
{
|
||||
if (_map == null)
|
||||
{
|
||||
if (_m128Ptr != defaultValue._m128Ptr)
|
||||
{
|
||||
internalIO.deinitM128_internal(this._m128Ptr);
|
||||
}
|
||||
else
|
||||
{
|
||||
_m128Ptr = IntPtr.Zero;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,8 +9,11 @@ namespace StgSharp.Math
|
||||
|
||||
public class Vec4d
|
||||
{
|
||||
internal readonly M128Map _map;
|
||||
internal readonly IntPtr _m128Ptr;
|
||||
internal static readonly Vec4d defaultValue
|
||||
= new Vec4d( 0,0,0,0 );
|
||||
|
||||
internal M128Map _map;
|
||||
internal IntPtr _m128Ptr;
|
||||
|
||||
|
||||
public unsafe float X
|
||||
@@ -39,34 +42,57 @@ namespace StgSharp.Math
|
||||
|
||||
public Vec4d(float x, float y, float z, float w)
|
||||
{
|
||||
IntPtr a = internalIO.InternalInitM128(x,y,z,w);
|
||||
IntPtr a = internalIO.load_internal(x,y,z,w);
|
||||
if ((ulong)a>=0)
|
||||
{
|
||||
this._m128Ptr = a;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
internal Vec4d()
|
||||
/// <summary>
|
||||
/// internal constructor to recive a pointer of the M128 value
|
||||
/// </summary>
|
||||
/// <param name="value"></param>
|
||||
internal Vec4d(IntPtr value)
|
||||
{
|
||||
_m128Ptr = internalIO.InternalInitM128(0,0,0,0);
|
||||
if ((long)value == -1)
|
||||
{
|
||||
throw new Exception("Failed to init M128 pointer!");
|
||||
}
|
||||
else
|
||||
{
|
||||
_m128Ptr = value;
|
||||
}
|
||||
}
|
||||
|
||||
public static Vec4d operator +(Vec4d vec1,Vec4d vec2)
|
||||
public Vec4d()
|
||||
{
|
||||
Vec4d result = new Vec4d();
|
||||
internalIO.VecAddVec(vec1._m128Ptr, vec2._m128Ptr/**/,result._m128Ptr/**/);
|
||||
return result;
|
||||
_m128Ptr = defaultValue._m128Ptr;
|
||||
}
|
||||
|
||||
public static unsafe Vec4d operator +(Vec4d vec1,Vec4d vec2)
|
||||
{
|
||||
return new Vec4d(
|
||||
internalIO.addps_internal(vec1._m128Ptr,vec2._m128Ptr)
|
||||
) ;
|
||||
}
|
||||
|
||||
/**/
|
||||
public static Vec4d operator -(Vec4d vec1, Vec4d vec2)
|
||||
{
|
||||
Vec4d result = new Vec4d();
|
||||
internalIO.VecSubVec(vec1._m128Ptr,vec2._m128Ptr,result._m128Ptr);
|
||||
return result;
|
||||
return new Vec4d(
|
||||
internalIO.subps_internal(vec1._m128Ptr,vec2._m128Ptr)
|
||||
);
|
||||
}
|
||||
/**/
|
||||
|
||||
public static Vec4d operator *(Vec4d vec, float value)
|
||||
{
|
||||
return new Vec4d(
|
||||
internalIO.mulps_const_internal(vec._m128Ptr,value)
|
||||
);
|
||||
}
|
||||
|
||||
public unsafe override string ToString()
|
||||
{
|
||||
@@ -77,7 +103,14 @@ namespace StgSharp.Math
|
||||
{
|
||||
if (_map == null)
|
||||
{
|
||||
internalIO.InternalDeinitM128(this._m128Ptr);
|
||||
if (_m128Ptr != defaultValue._m128Ptr)
|
||||
{
|
||||
internalIO.deinitM128_internal(this._m128Ptr);
|
||||
}
|
||||
else
|
||||
{
|
||||
_m128Ptr = IntPtr.Zero;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user