132 lines
3.0 KiB
C#
132 lines
3.0 KiB
C#
using StgSharp.Control;
|
|
using StgSharp.Math;
|
|
using System;
|
|
using System.Runtime.InteropServices;
|
|
|
|
namespace StgSharp.Math
|
|
{
|
|
|
|
|
|
public class Vec4d
|
|
{
|
|
internal static readonly Vec4d defaultValue
|
|
= new Vec4d( 0,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; }
|
|
}
|
|
|
|
public unsafe float W
|
|
{
|
|
get { return (*(M128*)_m128Ptr).single_3; }
|
|
set { (*(M128*)_m128Ptr).single_3 = value; }
|
|
}
|
|
|
|
public Vec4d(float x, float y, float z, float w)
|
|
{
|
|
IntPtr a = internalIO.load_internal(x,y,z,w);
|
|
if ((ulong)a>=0)
|
|
{
|
|
this._m128Ptr = a;
|
|
}
|
|
|
|
}
|
|
|
|
/// <summary>
|
|
/// internal constructor to recive a pointer of the M128 value
|
|
/// </summary>
|
|
/// <param name="value"></param>
|
|
internal Vec4d(IntPtr value)
|
|
{
|
|
if ((long)value == -1)
|
|
{
|
|
throw new Exception("Failed to init M128 pointer!");
|
|
}
|
|
else
|
|
{
|
|
_m128Ptr = value;
|
|
}
|
|
}
|
|
|
|
public Vec4d()
|
|
{
|
|
_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)
|
|
{
|
|
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 static Vec4d operator /(Vec4d vec, float value)
|
|
{
|
|
return new Vec4d(
|
|
internalIO.divps_const_internal(vec._m128Ptr, value)
|
|
);
|
|
}
|
|
|
|
public unsafe override string ToString()
|
|
{
|
|
return $"{*(M128*)_m128Ptr}";
|
|
}
|
|
|
|
~Vec4d()
|
|
{
|
|
if (_map == null)
|
|
{
|
|
if (_m128Ptr != defaultValue._m128Ptr)
|
|
{
|
|
internalIO.deinitM128_internal(this._m128Ptr);
|
|
}
|
|
else
|
|
{
|
|
_m128Ptr = IntPtr.Zero;
|
|
}
|
|
}
|
|
else
|
|
{
|
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
}
|
|
}
|