mirror of
https://github.com/aharabada/glitchy-engine-beef.git
synced 2026-09-05 21:01:52 +00:00
Replaced IntX by intX, Basic AssetViewer (can view Textures, kind of)
This commit is contained in:
@@ -13,12 +13,32 @@ namespace System
|
||||
}
|
||||
|
||||
[Inline]
|
||||
public Int2 XX => Int2((int32)this);
|
||||
public int2 XX => (int32)this;
|
||||
|
||||
[Inline]
|
||||
public Int3 XXX => Int3((int32)this);
|
||||
public int3 XXX => (int32)this;
|
||||
|
||||
[Inline]
|
||||
public Int4 XXXX => Int4((int32)this);
|
||||
public int4 XXXX => (int32)this;
|
||||
}
|
||||
|
||||
extension UInt32
|
||||
{
|
||||
public uint32 X
|
||||
{
|
||||
[Inline]
|
||||
get => (uint32)this;
|
||||
[Inline]
|
||||
set mut => this = value;
|
||||
}
|
||||
|
||||
[Inline]
|
||||
public uint2 XX => (uint32)this;
|
||||
|
||||
[Inline]
|
||||
public uint3 XXX => (uint32)this;
|
||||
|
||||
[Inline]
|
||||
public uint4 XXXX => (uint32)this;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,299 +0,0 @@
|
||||
using Bon;
|
||||
using System;
|
||||
|
||||
namespace GlitchyEngine.Math
|
||||
{
|
||||
[BonTarget]
|
||||
[SwizzleVector(2, "GlitchyEngine.Math.Vector")]
|
||||
public struct Vector2
|
||||
{
|
||||
public const Vector2 Zero = .(0f, 0f);
|
||||
public const Vector2 UnitX = .(1f, 0f);
|
||||
public const Vector2 UnitY = .(0f, 1f);
|
||||
public const Vector2 One = .(1f, 1f);
|
||||
|
||||
public const int ComponentCount = 2;
|
||||
|
||||
public float X, Y;
|
||||
|
||||
public this() => this = default;
|
||||
|
||||
public this(float value)
|
||||
{
|
||||
X = value;
|
||||
Y = value;
|
||||
}
|
||||
|
||||
public this(float x, float y)
|
||||
{
|
||||
X = x;
|
||||
Y = y;
|
||||
}
|
||||
|
||||
public ref float this[int index]
|
||||
{
|
||||
[Checked]
|
||||
get mut
|
||||
{
|
||||
if(index < 0 || index >= ComponentCount)
|
||||
Internal.ThrowIndexOutOfRange(1);
|
||||
|
||||
return ref (&X)[index];
|
||||
}
|
||||
|
||||
[Inline]
|
||||
get mut => ref (&X)[index];
|
||||
}
|
||||
|
||||
public float this[int index]
|
||||
{
|
||||
[Checked]
|
||||
get
|
||||
{
|
||||
if(index < 0 || index >= ComponentCount)
|
||||
Internal.ThrowIndexOutOfRange(1);
|
||||
|
||||
if(index == 0)
|
||||
return X;
|
||||
else
|
||||
return Y;
|
||||
}
|
||||
|
||||
[Inline]
|
||||
get
|
||||
{
|
||||
if(index == 0)
|
||||
return X;
|
||||
else
|
||||
return Y;
|
||||
}
|
||||
|
||||
[Checked]
|
||||
set mut
|
||||
{
|
||||
if(index < 0 || index >= ComponentCount)
|
||||
Internal.ThrowIndexOutOfRange(1);
|
||||
|
||||
if(index == 0)
|
||||
X = value;
|
||||
else
|
||||
Y = value;
|
||||
}
|
||||
|
||||
[Inline]
|
||||
set mut
|
||||
{
|
||||
if(index == 0)
|
||||
X = value;
|
||||
else
|
||||
Y = value;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Calculates the magnitude (length) of this vector.
|
||||
* @remarks MagnitudeSquared might be used if only the relative length is relevant.
|
||||
*/
|
||||
public float Magnitude()
|
||||
{
|
||||
return Math.Sqrt(X * X + Y * Y);
|
||||
}
|
||||
|
||||
/**
|
||||
* Calculates the squared magnitude (length) of this vector.
|
||||
*/
|
||||
public float MagnitudeSquared()
|
||||
{
|
||||
return X * X + Y * Y;
|
||||
}
|
||||
|
||||
//TODO: Normalization interface is bad
|
||||
[Checked]
|
||||
public void Normalize() mut
|
||||
{
|
||||
if(this == .Zero)
|
||||
return;
|
||||
|
||||
this /= Magnitude();
|
||||
}
|
||||
|
||||
public void Normalize() mut
|
||||
{
|
||||
this /= Magnitude();
|
||||
}
|
||||
|
||||
public static Vector2 Normalize(Vector2 v)
|
||||
{
|
||||
return v / v.Magnitude();
|
||||
}
|
||||
|
||||
public static float Dot(Vector2 l, Vector2 r)
|
||||
{
|
||||
return l.X * r.X + l.Y * r.Y;
|
||||
}
|
||||
|
||||
/**
|
||||
* Calculates the projection of a onto b
|
||||
*/
|
||||
public static Vector2 Project(Vector2 a, Vector2 b)
|
||||
{
|
||||
return (b * (Dot(a, b) / Dot(b, b)));
|
||||
}
|
||||
|
||||
/**
|
||||
* Calculates the rejection of a from b
|
||||
*/
|
||||
public static Vector2 Reject(Vector2 a, Vector2 b)
|
||||
{
|
||||
return (a - b * (Dot(a, b) / Dot(b, b)));
|
||||
}
|
||||
|
||||
/**
|
||||
* Interpolates linearly between two given vectors.
|
||||
* @param a The first vector.
|
||||
* @param b The second vector.
|
||||
* @param interpolationValue The value that linearly interpolates between a and b.
|
||||
* (0 means a will be returned, 1 means b will be returned.)
|
||||
* @returns The resulting linear interpolation.
|
||||
*/
|
||||
public static Vector2 Lerp(Vector2 a, Vector2 b, float interpolationValue)
|
||||
{
|
||||
return a + interpolationValue * (b - a);
|
||||
}
|
||||
|
||||
public static Vector2 Min(Vector2 a, Vector2 b)
|
||||
{
|
||||
return .(Math.Min(a.X, b.X), Math.Min(a.Y, b.Y));
|
||||
}
|
||||
|
||||
public static Vector2 Max(Vector2 a, Vector2 b)
|
||||
{
|
||||
return .(Math.Max(a.X, b.X), Math.Max(a.Y, b.Y));
|
||||
}
|
||||
|
||||
//
|
||||
// Assignment operators
|
||||
//
|
||||
|
||||
// Addition
|
||||
|
||||
public void operator +=(Vector2 value) mut
|
||||
{
|
||||
X += value.X;
|
||||
Y += value.Y;
|
||||
}
|
||||
|
||||
public void operator +=(float scalar) mut
|
||||
{
|
||||
X += scalar;
|
||||
Y += scalar;
|
||||
}
|
||||
|
||||
// Subtraction
|
||||
|
||||
public void operator -=(Vector2 value) mut
|
||||
{
|
||||
X -= value.X;
|
||||
Y -= value.Y;
|
||||
}
|
||||
|
||||
public void operator -=(float scalar) mut
|
||||
{
|
||||
X -= scalar;
|
||||
Y -= scalar;
|
||||
}
|
||||
|
||||
// Multiplication
|
||||
|
||||
public void operator *=(Vector2 value) mut
|
||||
{
|
||||
X *= value.X;
|
||||
Y *= value.Y;
|
||||
}
|
||||
|
||||
public void operator *=(float scalar) mut
|
||||
{
|
||||
X *= scalar;
|
||||
Y *= scalar;
|
||||
}
|
||||
|
||||
// Division
|
||||
|
||||
public void operator /=(float scalar) mut
|
||||
{
|
||||
float f = 1.0f / scalar;
|
||||
X *= f;
|
||||
Y *= f;
|
||||
}
|
||||
|
||||
public void operator /=(Vector2 value) mut
|
||||
{
|
||||
X /= value.X;
|
||||
Y /= value.Y;
|
||||
}
|
||||
|
||||
//
|
||||
// operators
|
||||
//
|
||||
|
||||
// Addition
|
||||
|
||||
public static Vector2 operator +(Vector2 left, Vector2 right) => Vector2(left.X + right.X, left.Y + right.Y);
|
||||
|
||||
public static Vector2 operator +(Vector2 value, float scalar) => Vector2(value.X + scalar, value.Y + scalar);
|
||||
|
||||
public static Vector2 operator +(float scalar, Vector2 value) => Vector2(scalar + value.X, scalar + value.Y);
|
||||
|
||||
public static Vector2 operator +(Vector2 value) => value;
|
||||
|
||||
// Subtraction
|
||||
|
||||
public static Vector2 operator -(Vector2 left, Vector2 right) => Vector2(left.X - right.X, left.Y - right.Y);
|
||||
|
||||
public static Vector2 operator -(Vector2 value, float scalar) => Vector2(value.X - scalar, value.Y - scalar);
|
||||
|
||||
public static Vector2 operator -(float scalar, Vector2 value) => Vector2(scalar - value.X, scalar - value.Y);
|
||||
|
||||
public static Vector2 operator -(Vector2 value) => Vector2(-value.X, -value.Y);
|
||||
|
||||
// Multiplication
|
||||
|
||||
public static Vector2 operator *(Vector2 left, Vector2 right) => Vector2(left.X * right.X, left.Y * right.Y);
|
||||
|
||||
public static Vector2 operator *(Vector2 value, float scalar) => Vector2(value.X * scalar, value.Y * scalar);
|
||||
|
||||
public static Vector2 operator *(float scalar, Vector2 value) => Vector2(scalar * value.X, scalar * value.Y);
|
||||
|
||||
// Division
|
||||
|
||||
public static Vector2 operator /(Vector2 left, Vector2 right) => Vector2(left.X / right.X, left.Y / right.Y);
|
||||
|
||||
public static Vector2 operator /(Vector2 value, float scalar)
|
||||
{
|
||||
float inv = 1.0f / scalar;
|
||||
return Vector2(value.X * inv, value.Y * inv);
|
||||
}
|
||||
|
||||
public static Vector2 operator /(float scalar, Vector2 value) => Vector2(scalar / value.X, scalar / value.Y);
|
||||
|
||||
// Equality
|
||||
|
||||
public static bool operator ==(Vector2 left, Vector2 right) => left.X == right.X && left.Y == right.Y;
|
||||
|
||||
public static bool operator !=(Vector2 left, Vector2 right) => left.X != right.X || left.Y != right.Y;
|
||||
|
||||
public override void ToString(String strBuffer) => strBuffer.AppendF("X:{0} Y:{1}", X, Y);
|
||||
|
||||
public bool Equals(Vector2 v, float epsilon = Math.[Friend]sMachineEpsilonFloat)
|
||||
{
|
||||
return (Math.Abs(v.X - X) < epsilon) && (Math.Abs(v.Y - Y) < epsilon);
|
||||
}
|
||||
|
||||
[Inline]
|
||||
public static explicit operator Self(float value) => Self(value);
|
||||
|
||||
[Inline]
|
||||
#unwarn
|
||||
public static explicit operator float[2](Vector2 value) => *(float[2]*)&value;
|
||||
}
|
||||
}
|
||||
@@ -1,349 +0,0 @@
|
||||
using Bon;
|
||||
using System;
|
||||
|
||||
namespace GlitchyEngine.Math
|
||||
{
|
||||
[BonTarget]
|
||||
[SwizzleVector(3, "GlitchyEngine.Math.Vector")]
|
||||
public struct float3
|
||||
{
|
||||
public const float3 Zero = .(0f, 0f, 0f);
|
||||
public const float3 UnitX = .(1f, 0f, 0f);
|
||||
public const float3 UnitY = .(0f, 1f, 0f);
|
||||
public const float3 UnitZ = .(0f, 0f, 1f);
|
||||
public const float3 One = .(1f, 1f, 1f);
|
||||
|
||||
public const float3 Forward = .(0f, 0f, 1f);
|
||||
public const float3 Backward = .(0f, 0f, -1f);
|
||||
public const float3 Left = .(-1f, 0f, 0f);
|
||||
public const float3 Right = .(1f, 0f, 0f);
|
||||
public const float3 Up = .(0f, 1f, 0f);
|
||||
public const float3 Down = .(0f, -1f, 0f);
|
||||
|
||||
public const int ComponentCount = 3;
|
||||
|
||||
public float X, Y, Z;
|
||||
|
||||
public this() => this = default;
|
||||
|
||||
public this(float value)
|
||||
{
|
||||
X = value;
|
||||
Y = value;
|
||||
Z = value;
|
||||
}
|
||||
|
||||
public this(Vector2 value, float z = 0.0f)
|
||||
{
|
||||
X = value.X;
|
||||
Y = value.Y;
|
||||
Z = z;
|
||||
}
|
||||
|
||||
public this(float x, float y, float z)
|
||||
{
|
||||
X = x;
|
||||
Y = y;
|
||||
Z = z;
|
||||
}
|
||||
|
||||
public this(float3 value)
|
||||
{
|
||||
X = value.X;
|
||||
Y = value.Y;
|
||||
Z = value.Z;
|
||||
}
|
||||
|
||||
public this(float4 value)
|
||||
{
|
||||
X = value.X;
|
||||
Y = value.Y;
|
||||
Z = value.Z;
|
||||
}
|
||||
|
||||
public ref float this[int index]
|
||||
{
|
||||
[Checked]
|
||||
get mut
|
||||
{
|
||||
if(index < 0 || index >= ComponentCount)
|
||||
Internal.ThrowIndexOutOfRange(1);
|
||||
|
||||
return ref (&X)[index];
|
||||
}
|
||||
|
||||
[Inline]
|
||||
get mut => ref (&X)[index];
|
||||
}
|
||||
|
||||
public float this[int index]
|
||||
{
|
||||
get
|
||||
{
|
||||
switch(index)
|
||||
{
|
||||
case 0: return X;
|
||||
case 1: return Y;
|
||||
case 2: return Z;
|
||||
default: Internal.ThrowIndexOutOfRange(1);
|
||||
}
|
||||
}
|
||||
|
||||
set mut
|
||||
{
|
||||
switch(index)
|
||||
{
|
||||
case 0: X = value;
|
||||
case 1: Y = value;
|
||||
case 2: Z = value;
|
||||
default: Internal.ThrowIndexOutOfRange(1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Calculates the magnitude (length) of this vector.
|
||||
* @remarks If the exact magnitude isn't needed (e.g. for comparisons) consider using MagnitudeSquared which doesn't use the square root operation.
|
||||
*/
|
||||
public float Magnitude() => Math.Sqrt(X * X + Y * Y + Z * Z);
|
||||
|
||||
/**
|
||||
* Calculates the squared magnitude (length) of this vector.
|
||||
* @remarks This function avoids the square root operation to calculate the magnitude and is thus more suitable for comparisons where the exact magnitude isn't needed.
|
||||
*/
|
||||
public float MagnitudeSquared() => X * X + Y * Y + Z * Z;
|
||||
|
||||
/// Normalizes this vector.
|
||||
[Checked]
|
||||
public void Normalize() mut
|
||||
{
|
||||
if(this == .Zero)
|
||||
return;
|
||||
|
||||
this /= Magnitude();
|
||||
}
|
||||
|
||||
/// Normalizes this vector.
|
||||
public void Normalize() mut
|
||||
{
|
||||
this /= Magnitude();
|
||||
}
|
||||
|
||||
/// Returns a copy of this Vector with a magnitude of 1.
|
||||
[Checked]
|
||||
public float3 Normalized()
|
||||
{
|
||||
if(this == .Zero)
|
||||
return .Zero;
|
||||
|
||||
return this / Magnitude();
|
||||
}
|
||||
|
||||
/// Returns a copy of this Vector with a magnitude of 1.
|
||||
public float3 Normalized()
|
||||
{
|
||||
return this / Magnitude();
|
||||
}
|
||||
|
||||
/// Returns a copy of the given Vector with a magnitude of 1.
|
||||
public static float3 Normalize(float3 v)
|
||||
{
|
||||
return v / v.Magnitude();
|
||||
}
|
||||
|
||||
/// Calculates the dot product of two vectors.
|
||||
public static float Dot(float3 l, float3 r) => l.X * r.X + l.Y * r.Y + l.Z * r.Z;
|
||||
|
||||
/// Calculates the distance between two vectors.
|
||||
public static float Distance(float3 a, float3 b) => (a - b).[Inline]Magnitude();
|
||||
|
||||
/// Calculates the squared distance between two vectors.
|
||||
public static float DistanceSquared(float3 a, float3 b) => (a - b).[Inline]MagnitudeSquared();
|
||||
|
||||
/// Calculates the cross product of two vectors.
|
||||
public static float3 Cross(float3 l, float3 r)
|
||||
{
|
||||
return .(l.Y * r.Z - l.Z * r.Y,
|
||||
l.Z * r.X - l.X * r.Z,
|
||||
l.X * r.Y - l.Y * r.X);
|
||||
}
|
||||
|
||||
/// Calculates the projection of a onto b.
|
||||
public static float3 Project(float3 a, float3 b)
|
||||
{
|
||||
return (b * (Dot(a, b) / Dot(b, b)));
|
||||
}
|
||||
|
||||
/// Calculates the rejection of a from b.
|
||||
public static float3 Reject(float3 a, float3 b)
|
||||
{
|
||||
return (a - b * (Dot(a, b) / Dot(b, b)));
|
||||
}
|
||||
|
||||
public static float3 Floor(float3 value) => .(Math.Floor(value.X), Math.Floor(value.Y), Math.Floor(value.Z));
|
||||
|
||||
public static float3 Ceiling(float3 value) => .(Math.Ceiling(value.X), Math.Ceiling(value.Y), Math.Ceiling(value.Z));
|
||||
|
||||
/**
|
||||
* Interpolates linearly between two given vectors.
|
||||
* @param a The first vector.
|
||||
* @param b The second vector.
|
||||
* @param interpolationValue The value that linearly interpolates between a and b.
|
||||
* (0 means a will be returned, 1 means b will be returned.)
|
||||
* @returns The resulting linear interpolation.
|
||||
*/
|
||||
public static float3 Lerp(float3 a, float3 b, float interpolationValue)
|
||||
{
|
||||
return a + interpolationValue * (b - a);
|
||||
}
|
||||
|
||||
public static float3 Min(float3 a, float3 b) => .(Math.Min(a.X, b.X), Math.Min(a.Y, b.Y), Math.Min(a.Z, b.Z));
|
||||
|
||||
public static float3 Max(float3 a, float3 b) => .(Math.Max(a.X, b.X), Math.Max(a.Y, b.Y), Math.Min(a.Z, b.Z));
|
||||
|
||||
public static float3 Abs(float3 v) => .(Math.Abs(v.X), Math.Abs(v.Y), Math.Abs(v.Z));
|
||||
|
||||
public static float3 Clamp(float3 v, float3 min, float3 max)
|
||||
{
|
||||
return .(Math.Clamp(v.X, min.X, max.X),
|
||||
Math.Clamp(v.Y, min.Y, max.Y),
|
||||
Math.Clamp(v.X, min.Z, max.Z));
|
||||
}
|
||||
|
||||
//
|
||||
// Assignment operators
|
||||
//
|
||||
|
||||
// Addition
|
||||
|
||||
public void operator +=(float3 value) mut
|
||||
{
|
||||
X += value.X;
|
||||
Y += value.Y;
|
||||
Z += value.Z;
|
||||
}
|
||||
|
||||
public void operator +=(float scalar) mut
|
||||
{
|
||||
X += scalar;
|
||||
Y += scalar;
|
||||
Z += scalar;
|
||||
}
|
||||
|
||||
// Subtraction
|
||||
|
||||
public void operator -=(float3 value) mut
|
||||
{
|
||||
X -= value.X;
|
||||
Y -= value.Y;
|
||||
Z -= value.Z;
|
||||
}
|
||||
|
||||
public void operator -=(float scalar) mut
|
||||
{
|
||||
X -= scalar;
|
||||
Y -= scalar;
|
||||
Z -= scalar;
|
||||
}
|
||||
|
||||
// Multiplication
|
||||
|
||||
public void operator *=(float3 value) mut
|
||||
{
|
||||
X *= value.X;
|
||||
Y *= value.Y;
|
||||
Z *= value.Z;
|
||||
}
|
||||
|
||||
public void operator *=(float scalar) mut
|
||||
{
|
||||
X *= scalar;
|
||||
Y *= scalar;
|
||||
Z *= scalar;
|
||||
}
|
||||
|
||||
// Division
|
||||
|
||||
public void operator /=(float3 value) mut
|
||||
{
|
||||
X /= value.X;
|
||||
Y /= value.Y;
|
||||
Z /= value.Z;
|
||||
}
|
||||
|
||||
public void operator /=(float scalar) mut
|
||||
{
|
||||
float inv = 1.0f / scalar;
|
||||
X *= inv;
|
||||
Y *= inv;
|
||||
Z *= inv;
|
||||
}
|
||||
|
||||
//
|
||||
// operators
|
||||
//
|
||||
|
||||
// Addition
|
||||
|
||||
public static float3 operator +(float3 left, float3 right) => float3(left.X + right.X, left.Y + right.Y, left.Z + right.Z);
|
||||
|
||||
public static float3 operator +(float3 value, float scalar) => float3(value.X + scalar, value.Y + scalar, value.Z + scalar);
|
||||
|
||||
public static float3 operator +(float scalar, float3 value) => float3(scalar + value.X, scalar + value.Y, scalar + value.Z);
|
||||
|
||||
public static float3 operator +(float3 value) => value;
|
||||
|
||||
// Subtraction
|
||||
|
||||
public static float3 operator -(float3 left, float3 right) => float3(left.X - right.X, left.Y - right.Y, left.Z - right.Z);
|
||||
|
||||
public static float3 operator -(float3 value, float scalar) => float3(value.X - scalar, value.Y - scalar, value.Z - scalar);
|
||||
|
||||
public static float3 operator -(float scalar, float3 value) => float3(scalar - value.X, scalar - value.Y, scalar - value.Z);
|
||||
|
||||
public static float3 operator -(float3 value) => float3(-value.X, -value.Y, -value.Z);
|
||||
|
||||
// Multiplication
|
||||
|
||||
public static float3 operator *(float3 left, float3 right) => float3(left.X * right.X, left.Y * right.Y, left.Z * right.Z);
|
||||
|
||||
public static float3 operator *(float3 value, float scalar) => float3(value.X * scalar, value.Y * scalar, value.Z * scalar);
|
||||
|
||||
public static float3 operator *(float scalar, float3 value) => float3(scalar * value.X, scalar * value.Y, scalar * value.Z);
|
||||
|
||||
// Division
|
||||
|
||||
public static float3 operator /(float3 left, float3 right) => float3(left.X / right.X, left.Y / right.Y, left.Z / right.Z);
|
||||
|
||||
public static float3 operator /(float3 value, float scalar)
|
||||
{
|
||||
float inv = 1.0f / scalar;
|
||||
return float3(value.X * inv, value.Y * inv, value.Z * inv);
|
||||
}
|
||||
|
||||
public static float3 operator /(float scalar, float3 value) => float3(scalar / value.X, scalar / value.Y, scalar / value.Z);
|
||||
|
||||
// Modulo
|
||||
|
||||
public static float3 operator %(float3 left, float3 right) => float3(left.X % right.X, left.Y % right.Y, left.Z % right.Z);
|
||||
|
||||
public static float3 operator %(float3 value, float scalar) => float3(value.X % scalar, value.Y % scalar, value.Z % scalar);
|
||||
|
||||
public static float3 operator %(float scalar, float3 value) => float3(scalar % value.X, scalar % value.Y, scalar % value.Z);
|
||||
|
||||
// Equality
|
||||
|
||||
public static bool operator ==(float3 left, float3 right) => left.X == right.X && left.Y == right.Y && left.Z == right.Z;
|
||||
|
||||
public static bool operator !=(float3 left, float3 right) => left.X != right.X || left.Y != right.Y || left.Z != right.Z;
|
||||
|
||||
public override void ToString(String strBuffer) => strBuffer.AppendF("X:{0} Y:{1} Z:{2}", X, Y, Z);
|
||||
|
||||
[Inline]
|
||||
public static explicit operator Self(float value) => Self(value);
|
||||
|
||||
[Inline]
|
||||
#unwarn
|
||||
public static explicit operator float[3](float3 value) => *(float[3]*)&value;
|
||||
}
|
||||
}
|
||||
@@ -1,330 +0,0 @@
|
||||
using Bon;
|
||||
using System;
|
||||
|
||||
namespace GlitchyEngine.Math
|
||||
{
|
||||
[BonTarget]
|
||||
[SwizzleVector(4, "GlitchyEngine.Math.Vector")]
|
||||
public struct float4
|
||||
{
|
||||
public const float4 Zero = .(0f, 0f, 0f, 0f);
|
||||
public const float4 UnitX = .(1f, 0f, 0f, 0f);
|
||||
public const float4 UnitY = .(0f, 1f, 0f, 0f);
|
||||
public const float4 UnitZ = .(0f, 0f, 1f, 0f);
|
||||
public const float4 UnitW = .(0f, 0f, 0f, 1f);
|
||||
public const float4 One = .(1f, 1f, 1f, 1f);
|
||||
|
||||
public const int ComponentCount = 4;
|
||||
|
||||
public float X, Y, Z, W;
|
||||
|
||||
public this() => this = default;
|
||||
|
||||
public this(float value)
|
||||
{
|
||||
X = value;
|
||||
Y = value;
|
||||
Z = value;
|
||||
W = value;
|
||||
}
|
||||
|
||||
public this(Vector2 value, float z, float w)
|
||||
{
|
||||
X = value.X;
|
||||
Y = value.Y;
|
||||
Z = z;
|
||||
W = w;
|
||||
}
|
||||
|
||||
public this(Vector2 value1, Vector2 value2)
|
||||
{
|
||||
X = value1.X;
|
||||
Y = value1.Y;
|
||||
Z = value2.X;
|
||||
W = value2.Y;
|
||||
}
|
||||
|
||||
public this(float3 value, float w)
|
||||
{
|
||||
X = value.X;
|
||||
Y = value.Y;
|
||||
Z = value.Z;
|
||||
W = w;
|
||||
}
|
||||
|
||||
public this(float x, float y, float z, float w)
|
||||
{
|
||||
X = x;
|
||||
Y = y;
|
||||
Z = z;
|
||||
W = w;
|
||||
}
|
||||
|
||||
public ref float this[int index]
|
||||
{
|
||||
[Checked]
|
||||
get mut
|
||||
{
|
||||
if(index < 0 || index >= ComponentCount)
|
||||
Internal.ThrowIndexOutOfRange(1);
|
||||
|
||||
return ref (&X)[index];
|
||||
}
|
||||
|
||||
[Inline]
|
||||
get mut => ref (&X)[index];
|
||||
}
|
||||
|
||||
public float this[int index]
|
||||
{
|
||||
get
|
||||
{
|
||||
switch(index)
|
||||
{
|
||||
case 0: return X;
|
||||
case 1: return Y;
|
||||
case 2: return Z;
|
||||
case 3: return W;
|
||||
default: Internal.ThrowIndexOutOfRange(1);
|
||||
}
|
||||
}
|
||||
|
||||
set mut
|
||||
{
|
||||
switch(index)
|
||||
{
|
||||
case 0: X = value;
|
||||
case 1: Y = value;
|
||||
case 2: Z = value;
|
||||
case 3: W = value;
|
||||
default: Internal.ThrowIndexOutOfRange(1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Calculates the magnitude (length) of this vector.
|
||||
* @remarks MagnitudeSquared might be used if only the relative length is relevant.
|
||||
*/
|
||||
public float Magnitude()
|
||||
{
|
||||
return Math.Sqrt(X * X + Y * Y + Z * Z + W * W);
|
||||
}
|
||||
|
||||
/**
|
||||
* Calculates the squared magnitude (length) of this vector.
|
||||
*/
|
||||
public float MagnitudeSquared()
|
||||
{
|
||||
return X * X + Y * Y + Z * Z + W * W;
|
||||
}
|
||||
|
||||
[Checked]
|
||||
public void Normalize() mut
|
||||
{
|
||||
if(this == .Zero)
|
||||
return;
|
||||
|
||||
this /= Magnitude();
|
||||
}
|
||||
|
||||
public void Normalize() mut
|
||||
{
|
||||
this /= Magnitude();
|
||||
}
|
||||
|
||||
public static float4 Normalize(float4 v)
|
||||
{
|
||||
if(v == .Zero)
|
||||
return .Zero;
|
||||
|
||||
return v / v.Magnitude();
|
||||
}
|
||||
|
||||
[Unchecked]
|
||||
public static float4 Normalize(float4 v)
|
||||
{
|
||||
return v / v.Magnitude();
|
||||
}
|
||||
|
||||
public static float Dot(float4 l, float4 r)
|
||||
{
|
||||
return l.X * r.X + l.Y * r.Y + l.Z * r.Z + l.W * r.W;
|
||||
}
|
||||
|
||||
/**
|
||||
* Calculates the projection of a onto b
|
||||
*/
|
||||
public static float4 Project(float4 a, float4 b)
|
||||
{
|
||||
return (b * (Dot(a, b) / Dot(b, b)));
|
||||
}
|
||||
|
||||
/**
|
||||
* Calculates the rejection of a from b
|
||||
*/
|
||||
public static float4 Reject(float4 a, float4 b)
|
||||
{
|
||||
return (a - b * (Dot(a, b) / Dot(b, b)));
|
||||
}
|
||||
|
||||
/**
|
||||
* Interpolates linearly between two given vectors.
|
||||
* @param a The first vector.
|
||||
* @param b The second vector.
|
||||
* @param interpolationValue The value that linearly interpolates between a and b.
|
||||
* (0 means a will be returned, 1 means b will be returned.)
|
||||
* @returns The resulting linear interpolation.
|
||||
*/
|
||||
public static float4 Lerp(float4 a, float4 b, float interpolationValue)
|
||||
{
|
||||
return a + interpolationValue * (b - a);
|
||||
}
|
||||
|
||||
public static float4 Min(float4 a, float4 b)
|
||||
{
|
||||
return .(Math.Min(a.X, b.X), Math.Min(a.Y, b.Y), Math.Min(a.Z, b.Z), Math.Min(a.W, b.W));
|
||||
}
|
||||
|
||||
public static float4 Max(float4 a, float4 b)
|
||||
{
|
||||
return .(Math.Max(a.X, b.X), Math.Max(a.Y, b.Y), Math.Min(a.Z, b.Z), Math.Min(a.W, b.W));
|
||||
}
|
||||
|
||||
//
|
||||
// Assignment operators
|
||||
//
|
||||
|
||||
// Addition
|
||||
|
||||
public void operator +=(float4 value) mut
|
||||
{
|
||||
X += value.X;
|
||||
Y += value.Y;
|
||||
Z += value.Z;
|
||||
W += value.W;
|
||||
}
|
||||
|
||||
public void operator +=(float scalar) mut
|
||||
{
|
||||
X += scalar;
|
||||
Y += scalar;
|
||||
Z += scalar;
|
||||
W += scalar;
|
||||
}
|
||||
|
||||
// Subtraction
|
||||
|
||||
public void operator -=(float4 value) mut
|
||||
{
|
||||
X -= value.X;
|
||||
Y -= value.Y;
|
||||
Z -= value.Z;
|
||||
W -= value.W;
|
||||
}
|
||||
|
||||
public void operator -=(float scalar) mut
|
||||
{
|
||||
X -= scalar;
|
||||
Y -= scalar;
|
||||
Z -= scalar;
|
||||
W -= scalar;
|
||||
}
|
||||
|
||||
// Multiplication
|
||||
|
||||
public void operator *=(float4 value) mut
|
||||
{
|
||||
X *= value.X;
|
||||
Y *= value.Y;
|
||||
Z *= value.Z;
|
||||
W *= value.W;
|
||||
}
|
||||
|
||||
public void operator *=(float scalar) mut
|
||||
{
|
||||
X *= scalar;
|
||||
Y *= scalar;
|
||||
Z *= scalar;
|
||||
W *= scalar;
|
||||
}
|
||||
|
||||
// Division
|
||||
|
||||
public void operator /=(float scalar) mut
|
||||
{
|
||||
float f = 1.0f / scalar;
|
||||
X *= f;
|
||||
Y *= f;
|
||||
Z *= f;
|
||||
W *= f;
|
||||
}
|
||||
|
||||
public void operator /=(float4 value) mut
|
||||
{
|
||||
X /= value.X;
|
||||
Y /= value.Y;
|
||||
Z /= value.Z;
|
||||
W /= value.W;
|
||||
}
|
||||
|
||||
//
|
||||
// operators
|
||||
//
|
||||
|
||||
// Addition
|
||||
|
||||
public static float4 operator +(float4 left, float4 right) => float4(left.X + right.X, left.Y + right.Y, left.Z + right.Z, left.W + right.W);
|
||||
|
||||
public static float4 operator +(float4 value, float scalar) => float4(value.X + scalar, value.Y + scalar, value.Z + scalar, value.W + scalar);
|
||||
|
||||
public static float4 operator +(float scalar, float4 value) => float4(scalar + value.X, scalar + value.Y, scalar + value.Z, scalar + value.W);
|
||||
|
||||
public static float4 operator +(float4 value) => value;
|
||||
|
||||
// Subtraction
|
||||
|
||||
public static float4 operator -(float4 left, float4 right) => float4(left.X - right.X, left.Y - right.Y, left.Z - right.Z, left.W - right.W);
|
||||
|
||||
public static float4 operator -(float4 value, float scalar) => float4(value.X - scalar, value.Y - scalar, value.Z - scalar, value.W - scalar);
|
||||
|
||||
public static float4 operator -(float scalar, float4 value) => float4(scalar - value.X, scalar - value.Y, scalar - value.Z, scalar - value.W);
|
||||
|
||||
public static float4 operator -(float4 value) => float4(-value.X, -value.Y, -value.Z, -value.W);
|
||||
|
||||
// Multiplication
|
||||
|
||||
public static float4 operator *(float4 left, float4 right) => float4(left.X * right.X, left.Y * right.Y, left.Z * right.Z, left.W * right.W);
|
||||
|
||||
public static float4 operator *(float4 value, float scalar) => float4(value.X * scalar, value.Y * scalar, value.Z * scalar, value.W * scalar);
|
||||
|
||||
public static float4 operator *(float scalar, float4 value) => float4(scalar * value.X, scalar * value.Y, scalar * value.Z, scalar * value.W);
|
||||
|
||||
// Division
|
||||
|
||||
public static float4 operator /(float4 left, float4 right) => float4(left.X / right.X, left.Y / right.Y, left.Z / right.Z, left.W / right.W);
|
||||
|
||||
public static float4 operator /(float4 value, float scalar)
|
||||
{
|
||||
float inv = 1.0f / scalar;
|
||||
return float4(value.X * inv, value.Y * inv, value.Z * inv, value.W * inv);
|
||||
}
|
||||
|
||||
public static float4 operator /(float scalar, float4 value) => float4(scalar / value.X, scalar / value.Y, scalar / value.Z, scalar / value.W);
|
||||
|
||||
// Equality
|
||||
|
||||
public static bool operator ==(float4 left, float4 right) => left.X == right.X && left.Y == right.Y && left.Z == right.Z && left.W == right.W;
|
||||
|
||||
public static bool operator !=(float4 left, float4 right) => left.X != right.X || left.Y != right.Y || left.Z != right.Z || left.W != right.W;
|
||||
|
||||
public override void ToString(String strBuffer) => strBuffer.AppendF("X:{0} Y:{1} Z:{2} W:{3}", X, Y, Z, W);
|
||||
|
||||
[Inline]
|
||||
public static explicit operator Self(float value) => Self(value);
|
||||
|
||||
[Inline]
|
||||
#unwarn
|
||||
public static explicit operator float[4](float4 value) => *(float[4]*)&value;
|
||||
}
|
||||
}
|
||||
@@ -1,162 +0,0 @@
|
||||
#pragma warning disable 4204
|
||||
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
|
||||
namespace GlitchyEngine.Math
|
||||
{
|
||||
/**
|
||||
* A Vector with two components of type int32.
|
||||
*/
|
||||
[SwizzleVector(2, "Int")]
|
||||
public struct Int2 : IHashable
|
||||
{
|
||||
public const Int2 Zero = .(0, 0);
|
||||
public const Int2 UnitX = .(1, 0);
|
||||
public const Int2 UnitY = .(0, 1);
|
||||
public const Int2 One = .(1, 1);
|
||||
|
||||
public int32 X, Y;
|
||||
|
||||
public this() => this = default;
|
||||
|
||||
public this(int32 value)
|
||||
{
|
||||
X = value;
|
||||
Y = value;
|
||||
}
|
||||
|
||||
public this(int value)
|
||||
{
|
||||
X = (.)value;
|
||||
Y = (.)value;
|
||||
}
|
||||
|
||||
public this(int32 x, int32 y)
|
||||
{
|
||||
X = x;
|
||||
Y = y;
|
||||
}
|
||||
|
||||
public this(int x, int y)
|
||||
{
|
||||
X = (.)x;
|
||||
Y = (.)y;
|
||||
}
|
||||
|
||||
public ref int32 this[int index]
|
||||
{
|
||||
[Inline]
|
||||
get
|
||||
{
|
||||
#if DEBUG
|
||||
if(index < 0 || index >= 2)
|
||||
Internal.ThrowIndexOutOfRange(1);
|
||||
#endif
|
||||
|
||||
return ref (&X)[index];
|
||||
}
|
||||
}
|
||||
|
||||
public int32 MagnitudeSquared() => X * X + Y * Y;
|
||||
|
||||
public float Magnitude() => Math.Sqrt(X * X + Y * Y);
|
||||
|
||||
public Int2 Abs() => .(Math.Abs(X), Math.Abs(Y));
|
||||
|
||||
//
|
||||
// Assignment operators
|
||||
//
|
||||
|
||||
public void operator +=(Int2 value) mut
|
||||
{
|
||||
X += value.X;
|
||||
Y += value.Y;
|
||||
}
|
||||
|
||||
public void operator +=(int32 value) mut
|
||||
{
|
||||
X += value;
|
||||
Y += value;
|
||||
}
|
||||
|
||||
public void operator -=(Int2 value) mut
|
||||
{
|
||||
X -= value.X;
|
||||
Y -= value.Y;
|
||||
}
|
||||
|
||||
public void operator -=(int32 value) mut
|
||||
{
|
||||
X -= value;
|
||||
Y -= value;
|
||||
}
|
||||
|
||||
public void operator *=(Int2 value) mut
|
||||
{
|
||||
X *= value.X;
|
||||
Y *= value.Y;
|
||||
}
|
||||
|
||||
public void operator *=(int32 value) mut
|
||||
{
|
||||
X *= value;
|
||||
Y *= value;
|
||||
}
|
||||
|
||||
public void operator /=(Int2 value) mut
|
||||
{
|
||||
X /= value.X;
|
||||
Y /= value.Y;
|
||||
}
|
||||
|
||||
public void operator /=(int32 value) mut
|
||||
{
|
||||
X /= value;
|
||||
Y /= value;
|
||||
}
|
||||
|
||||
// Operators
|
||||
|
||||
public static Int2 operator +(Int2 value) => value;
|
||||
public static Int2 operator +(Int2 left, Int2 right) => .(left.X + right.X, left.Y + right.Y);
|
||||
public static Int2 operator +(Int2 left, int32 right) => .(left.X + right, left.Y + right);
|
||||
public static Int2 operator +(int32 left, Int2 right) => .(left + right.X, left + right.Y);
|
||||
|
||||
public static Int2 operator -(Int2 value) => .(-value.X, -value.Y);
|
||||
public static Int2 operator -(Int2 left, Int2 right) => .(left.X - right.X, left.Y - right.Y);
|
||||
public static Int2 operator -(Int2 left, int32 right) => .(left.X - right, left.Y - right);
|
||||
public static Int2 operator -(int32 left, Int2 right) => .(left - right.X, left - right.Y);
|
||||
|
||||
public static Int2 operator *(Int2 left, Int2 right) => .(left.X * right.X, left.Y * right.Y);
|
||||
public static Int2 operator *(Int2 left, int32 right) => .(left.X * right, left.Y * right);
|
||||
public static Int2 operator *(int32 left, Int2 right) => .(left * right.X, left * right.Y);
|
||||
|
||||
public static Int2 operator /(Int2 left, Int2 right) => .(left.X / right.X, left.Y / right.Y);
|
||||
public static Int2 operator /(Int2 left, int32 right) => .(left.X / right, left.Y / right);
|
||||
public static Int2 operator /(int32 left, Int2 right) => .(left / right.X, left / right.Y);
|
||||
|
||||
public static Int2 operator %(Int2 left, Int2 right) => .(left.X % right.X, left.Y % right.Y);
|
||||
public static Int2 operator %(Int2 left, int32 right) => .(left.X % right, left.Y % right);
|
||||
public static Int2 operator %(int32 left, Int2 right) => .(left % right.X, left % right.Y);
|
||||
|
||||
public static bool operator ==(Int2 left, Int2 right) => left.X == right.X && left.Y == right.Y;
|
||||
public static bool operator ==(Int2 left, int32 right) => left.X == right && left.Y == right;
|
||||
public static bool operator ==(int32 left, Int2 right) => left == right.X && left == right.Y;
|
||||
|
||||
public static bool operator !=(Int2 left, Int2 right) => left.X != right.X || left.Y != right.Y;
|
||||
public static bool operator !=(Int2 left, int32 right) => left.X != right || left.Y != right;
|
||||
public static bool operator !=(int32 left, Int2 right) => left != right.X || left != right.Y;
|
||||
|
||||
public override void ToString(String strBuffer) => strBuffer.AppendF($"X:{X} Y:{Y}");
|
||||
|
||||
public static explicit operator float2(Int2 point) => .(point.X, point.Y);
|
||||
|
||||
public static explicit operator Int2(float2 point) => .((int32)point.X, (int32)point.Y);
|
||||
|
||||
public int GetHashCode()
|
||||
{
|
||||
return (X * 39) ^ Y;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,206 +0,0 @@
|
||||
#pragma warning disable 4204
|
||||
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
|
||||
namespace GlitchyEngine.Math
|
||||
{
|
||||
/**
|
||||
* A Vector with three components of type int32.
|
||||
*/
|
||||
[SwizzleVector(3, "Int")]
|
||||
public struct Int3 : IHashable
|
||||
{
|
||||
public const Int3 Zero = .(0, 0, 0);
|
||||
public const Int3 UnitX = .(1, 0, 0);
|
||||
public const Int3 UnitY = .(0, 1, 0);
|
||||
public const Int3 UnitZ = .(0, 0, 1);
|
||||
public const Int3 One = .(1, 1, 1);
|
||||
|
||||
public int32 X, Y, Z;
|
||||
|
||||
public this() => this = default;
|
||||
|
||||
public this(int32 value)
|
||||
{
|
||||
X = value;
|
||||
Y = value;
|
||||
Z = value;
|
||||
}
|
||||
|
||||
public this(int value)
|
||||
{
|
||||
X = (.)value;
|
||||
Y = (.)value;
|
||||
Z = (.)value;
|
||||
}
|
||||
|
||||
public this(int32 x, int32 y, int32 z)
|
||||
{
|
||||
X = x;
|
||||
Y = y;
|
||||
Z = z;
|
||||
}
|
||||
|
||||
public this(Int2 xy, int32 z)
|
||||
{
|
||||
X = xy.X;
|
||||
Y = xy.Y;
|
||||
Z = z;
|
||||
}
|
||||
|
||||
public this(int32 x, Int2 yz)
|
||||
{
|
||||
X = x;
|
||||
Y = yz.X;
|
||||
Z = yz.Y;
|
||||
}
|
||||
|
||||
public this(int x, int y, int z)
|
||||
{
|
||||
X = (.)x;
|
||||
Y = (.)y;
|
||||
Z = (.)z;
|
||||
}
|
||||
|
||||
public this(Int2 xy, int z)
|
||||
{
|
||||
X = xy.X;
|
||||
Y = xy.Y;
|
||||
Z = (.)z;
|
||||
}
|
||||
|
||||
public this(int x, Int2 yz)
|
||||
{
|
||||
X = (.)x;
|
||||
Y = yz.X;
|
||||
Z = yz.Y;
|
||||
}
|
||||
|
||||
public ref int32 this[int index]
|
||||
{
|
||||
[Inline]
|
||||
get
|
||||
{
|
||||
#if DEBUG
|
||||
if(index < 0 || index >= 3)
|
||||
Internal.ThrowIndexOutOfRange(1);
|
||||
#endif
|
||||
|
||||
return ref (&X)[index];
|
||||
}
|
||||
}
|
||||
|
||||
public int32 MagnitudeSquared() => X * X + Y * Y + Z * Z;
|
||||
|
||||
public float Magnitude() => Math.Sqrt(X * X + Y * Y + Z * Z);
|
||||
|
||||
public Int3 Abs() => .(Math.Abs(X), Math.Abs(Y), Math.Abs(Z));
|
||||
|
||||
//
|
||||
// Assignment operators
|
||||
//
|
||||
|
||||
public void operator +=(Int3 value) mut
|
||||
{
|
||||
X += value.X;
|
||||
Y += value.Y;
|
||||
Z += value.Z;
|
||||
}
|
||||
|
||||
public void operator +=(int32 value) mut
|
||||
{
|
||||
X += value;
|
||||
Y += value;
|
||||
Z += value;
|
||||
}
|
||||
|
||||
public void operator -=(Int3 value) mut
|
||||
{
|
||||
X -= value.X;
|
||||
Y -= value.Y;
|
||||
Z -= value.Z;
|
||||
}
|
||||
|
||||
public void operator -=(int32 value) mut
|
||||
{
|
||||
X -= value;
|
||||
Y -= value;
|
||||
Z -= value;
|
||||
}
|
||||
|
||||
public void operator *=(Int3 value) mut
|
||||
{
|
||||
X *= value.X;
|
||||
Y *= value.Y;
|
||||
Z *= value.Z;
|
||||
}
|
||||
|
||||
public void operator *=(int32 value) mut
|
||||
{
|
||||
X *= value;
|
||||
Y *= value;
|
||||
Z *= value;
|
||||
}
|
||||
|
||||
public void operator /=(Int3 value) mut
|
||||
{
|
||||
X /= value.X;
|
||||
Y /= value.Y;
|
||||
Z /= value.Z;
|
||||
}
|
||||
|
||||
public void operator /=(int32 value) mut
|
||||
{
|
||||
X /= value;
|
||||
Y /= value;
|
||||
Z /= value;
|
||||
}
|
||||
|
||||
// Operators
|
||||
|
||||
public static Int3 operator +(Int3 value) => value;
|
||||
public static Int3 operator +(Int3 left, Int3 right) => .(left.X + right.X, left.Y + right.Y, left.Z + right.Z);
|
||||
public static Int3 operator +(Int3 left, int32 right) => .(left.X + right, left.Y + right, left.Z + right);
|
||||
public static Int3 operator +(int32 left, Int3 right) => .(left + right.X, left + right.Y, left + right.Z);
|
||||
|
||||
public static Int3 operator -(Int3 value) => .(-value.X, -value.Y, -value.Z);
|
||||
public static Int3 operator -(Int3 left, Int3 right) => .(left.X - right.X, left.Y - right.Y, left.Z - right.Z);
|
||||
public static Int3 operator -(Int3 left, int32 right) => .(left.X - right, left.Y - right, left.Z- right);
|
||||
public static Int3 operator -(int32 left, Int3 right) => .(left - right.X, left - right.Y, left - right.Z);
|
||||
|
||||
public static Int3 operator *(Int3 left, Int3 right) => .(left.X * right.X, left.Y * right.Y, left.Z * right.Z);
|
||||
public static Int3 operator *(Int3 left, int32 right) => .(left.X * right, left.Y * right, left.Z * right);
|
||||
public static Int3 operator *(int32 left, Int3 right) => .(left * right.X, left * right.Y, left * right.Z);
|
||||
|
||||
public static Int3 operator /(Int3 left, Int3 right) => .(left.X / right.X, left.Y / right.Y, left.Z / right.Z);
|
||||
public static Int3 operator /(Int3 left, int32 right) => .(left.X / right, left.Y / right, left.Z / right);
|
||||
public static Int3 operator /(int32 left, Int3 right) => .(left / right.X, left / right.Y, left / right.Z);
|
||||
|
||||
public static Int3 operator %(Int3 left, Int3 right) => .(left.X % right.X, left.Y % right.Y, left.Z % right.Z);
|
||||
public static Int3 operator %(Int3 left, int32 right) => .(left.X % right, left.Y % right, left.Z % right);
|
||||
public static Int3 operator %(int32 left, Int3 right) => .(left % right.X, left % right.Y, left % right.Z);
|
||||
|
||||
public static bool operator ==(Int3 left, Int3 right) => left.X == right.X && left.Y == right.Y && left.Z == right.Z;
|
||||
public static bool operator ==(Int3 left, int32 right) => left.X == right && left.Y == right && left.Z == right;
|
||||
public static bool operator ==(int32 left, Int3 right) => left == right.X && left == right.Y && left == right.Z;
|
||||
|
||||
public static bool operator !=(Int3 left, Int3 right) => left.X != right.X || left.Y != right.Y || left.Z != right.Z;
|
||||
public static bool operator !=(Int3 left, int32 right) => left.X != right || left.Y != right || left.Z != right;
|
||||
public static bool operator !=(int32 left, Int3 right) => left != right.X || left != right.Y || left != right.Z;
|
||||
|
||||
public override void ToString(String strBuffer) => strBuffer.AppendF($"X:{X} Y:{Y} Z:{Z}");
|
||||
|
||||
public static explicit operator float3(Int3 point) => .(point.X, point.Y, point.Z);
|
||||
|
||||
public static explicit operator Int3(float3 point) => .((int32)point.X, (int32)point.Y, (int32)point.Z);
|
||||
|
||||
[Inline]
|
||||
public static explicit operator Int2(in Int3 point) => *(Int2*)&point;
|
||||
|
||||
public int GetHashCode()
|
||||
{
|
||||
return (((X * 39) ^ Y) * 39) ^ Z;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,234 +0,0 @@
|
||||
#pragma warning disable 4204
|
||||
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
|
||||
namespace GlitchyEngine.Math
|
||||
{
|
||||
/**
|
||||
* A Vector with four components of type int32.
|
||||
*/
|
||||
[SwizzleVector(4, "Int")]
|
||||
public struct Int4 : IHashable
|
||||
{
|
||||
public const Int4 Zero = .(0, 0, 0, 0);
|
||||
public const Int4 UnitX = .(1, 0, 0, 0);
|
||||
public const Int4 UnitY = .(0, 1, 0, 0);
|
||||
public const Int4 UnitZ = .(0, 0, 1, 0);
|
||||
public const Int4 UnitW = .(0, 0, 0, 1);
|
||||
public const Int4 One = .(1, 1, 1, 1);
|
||||
|
||||
public int32 X, Y, Z, W;
|
||||
|
||||
public this() => this = default;
|
||||
|
||||
public this(int32 value)
|
||||
{
|
||||
X = value;
|
||||
Y = value;
|
||||
Z = value;
|
||||
W = value;
|
||||
}
|
||||
|
||||
public this(int value)
|
||||
{
|
||||
X = (.)value;
|
||||
Y = (.)value;
|
||||
Z = (.)value;
|
||||
W = (.)value;
|
||||
}
|
||||
|
||||
public this(int32 x, int32 y, int32 z, int32 w)
|
||||
{
|
||||
X = x;
|
||||
Y = y;
|
||||
Z = z;
|
||||
W = w;
|
||||
}
|
||||
|
||||
public this(Int2 xy, int32 z, int32 w)
|
||||
{
|
||||
X = xy.X;
|
||||
Y = xy.Y;
|
||||
Z = z;
|
||||
W = w;
|
||||
}
|
||||
|
||||
public this(int32 x, Int2 yz, int32 w)
|
||||
{
|
||||
X = x;
|
||||
Y = yz.X;
|
||||
Z = yz.Y;
|
||||
W = w;
|
||||
}
|
||||
|
||||
public this(int32 x, int32 y, Int2 zw)
|
||||
{
|
||||
X = x;
|
||||
Y = y;
|
||||
Z = zw.X;
|
||||
W = zw.Y;
|
||||
}
|
||||
|
||||
public this(Int2 xy, Int2 zw)
|
||||
{
|
||||
X = xy.X;
|
||||
Y = xy.Y;
|
||||
Z = zw.X;
|
||||
W = zw.Y;
|
||||
}
|
||||
|
||||
public this(Int3 xyz, int32 w)
|
||||
{
|
||||
X = xyz.X;
|
||||
Y = xyz.Y;
|
||||
Z = xyz.Z;
|
||||
W = w;
|
||||
}
|
||||
|
||||
public this(int32 x, Int3 yzw)
|
||||
{
|
||||
X = x;
|
||||
Y = yzw.X;
|
||||
Z = yzw.Y;
|
||||
W = yzw.Z;
|
||||
}
|
||||
|
||||
public ref int32 this[int index]
|
||||
{
|
||||
[Inline]
|
||||
get
|
||||
{
|
||||
#if DEBUG
|
||||
if(index < 0 || index >= 3)
|
||||
Internal.ThrowIndexOutOfRange(1);
|
||||
#endif
|
||||
|
||||
return ref (&X)[index];
|
||||
}
|
||||
}
|
||||
|
||||
public int32 MagnitudeSquared() => X * X + Y * Y + Z * Z + W * W;
|
||||
|
||||
public float Magnitude() => Math.Sqrt(X * X + Y * Y + Z * Z + W * W);
|
||||
|
||||
public Int4 Abs() => .(Math.Abs(X), Math.Abs(Y), Math.Abs(Z), Math.Abs(W));
|
||||
|
||||
//
|
||||
// Assignment operators
|
||||
//
|
||||
|
||||
public void operator +=(Int4 value) mut
|
||||
{
|
||||
X += value.X;
|
||||
Y += value.Y;
|
||||
Z += value.Z;
|
||||
W += value.W;
|
||||
}
|
||||
|
||||
public void operator +=(int32 value) mut
|
||||
{
|
||||
X += value;
|
||||
Y += value;
|
||||
Z += value;
|
||||
W += value;
|
||||
}
|
||||
|
||||
public void operator -=(Int4 value) mut
|
||||
{
|
||||
X -= value.X;
|
||||
Y -= value.Y;
|
||||
Z -= value.Z;
|
||||
W -= value.W;
|
||||
}
|
||||
|
||||
public void operator -=(int32 value) mut
|
||||
{
|
||||
X -= value;
|
||||
Y -= value;
|
||||
Z -= value;
|
||||
W -= value;
|
||||
}
|
||||
|
||||
public void operator *=(Int4 value) mut
|
||||
{
|
||||
X *= value.X;
|
||||
Y *= value.Y;
|
||||
Z *= value.Z;
|
||||
W *= value.W;
|
||||
}
|
||||
|
||||
public void operator *=(int32 value) mut
|
||||
{
|
||||
X *= value;
|
||||
Y *= value;
|
||||
Z *= value;
|
||||
W *= value;
|
||||
}
|
||||
|
||||
public void operator /=(Int4 value) mut
|
||||
{
|
||||
X /= value.X;
|
||||
Y /= value.Y;
|
||||
Z /= value.Z;
|
||||
W /= value.W;
|
||||
}
|
||||
|
||||
public void operator /=(int32 value) mut
|
||||
{
|
||||
X /= value;
|
||||
Y /= value;
|
||||
Z /= value;
|
||||
W /= value;
|
||||
}
|
||||
|
||||
// Operators
|
||||
|
||||
public static Int4 operator +(Int4 value) => value;
|
||||
public static Int4 operator +(Int4 left, Int4 right) => .(left.X + right.X, left.Y + right.Y, left.Z + right.Z, left.W + right.W);
|
||||
public static Int4 operator +(Int4 left, int32 right) => .(left.X + right, left.Y + right, left.Z + right, left.W + right);
|
||||
public static Int4 operator +(int32 left, Int4 right) => .(left + right.X, left + right.Y, left + right.Z, left + right.W);
|
||||
|
||||
public static Int4 operator -(Int4 value) => .(-value.X, -value.Y, -value.Z, -value.W);
|
||||
public static Int4 operator -(Int4 left, Int4 right) => .(left.X - right.X, left.Y - right.Y, left.Z - right.Z, left.W - right.W);
|
||||
public static Int4 operator -(Int4 left, int32 right) => .(left.X - right, left.Y - right, left.Z - right, left.W - right);
|
||||
public static Int4 operator -(int32 left, Int4 right) => .(left - right.X, left - right.Y, left - right.Z, left - right.W);
|
||||
|
||||
public static Int4 operator *(Int4 left, Int4 right) => .(left.X * right.X, left.Y * right.Y, left.Z * right.Z, left.W * right.W);
|
||||
public static Int4 operator *(Int4 left, int32 right) => .(left.X * right, left.Y * right, left.Z * right, left.W * right);
|
||||
public static Int4 operator *(int32 left, Int4 right) => .(left * right.X, left * right.Y, left * right.Z, left * right.W);
|
||||
|
||||
public static Int4 operator /(Int4 left, Int4 right) => .(left.X / right.X, left.Y / right.Y, left.Z / right.Z, left.W / right.W);
|
||||
public static Int4 operator /(Int4 left, int32 right) => .(left.X / right, left.Y / right, left.Z / right, left.W / right);
|
||||
public static Int4 operator /(int32 left, Int4 right) => .(left / right.X, left / right.Y, left / right.Z, left / right.W);
|
||||
|
||||
public static Int4 operator %(Int4 left, Int4 right) => .(left.X % right.X, left.Y % right.Y, left.Z % right.Z, left.W % right.W);
|
||||
public static Int4 operator %(Int4 left, int32 right) => .(left.X % right, left.Y % right, left.Z % right, left.W % right);
|
||||
public static Int4 operator %(int32 left, Int4 right) => .(left % right.X, left % right.Y, left % right.Z, left % right.W);
|
||||
|
||||
public static bool operator ==(Int4 left, Int4 right) => left.X == right.X && left.Y == right.Y && left.Z == right.Z && left.W == right.W;
|
||||
public static bool operator ==(Int4 left, int32 right) => left.X == right && left.Y == right && left.Z == right && left.W == right;
|
||||
public static bool operator ==(int32 left, Int4 right) => left == right.X && left == right.Y && left == right.Z && left == right.W;
|
||||
|
||||
public static bool operator !=(Int4 left, Int4 right) => left.X != right.X || left.Y != right.Y || left.Z != right.Z || left.W != right.W;
|
||||
public static bool operator !=(Int4 left, int32 right) => left.X != right || left.Y != right || left.Z != right || left.W != right;
|
||||
public static bool operator !=(int32 left, Int4 right) => left != right.X || left != right.Y || left != right.Z || left != right.W;
|
||||
|
||||
public override void ToString(String strBuffer) => strBuffer.AppendF($"X:{X} Y:{Y} Z:{Z} W:{W}");
|
||||
|
||||
public static explicit operator float4(Int4 point) => .(point.X, point.Y, point.Z, point.W);
|
||||
|
||||
public static explicit operator Int4(float4 point) => .((int32)point.X, (int32)point.Y, (int32)point.Z, (int32)point.W);
|
||||
|
||||
[Inline]
|
||||
public static explicit operator Int2(in Int4 point) => *(Int2*)&point;
|
||||
|
||||
[Inline]
|
||||
public static explicit operator Int3(in Int4 point) => *(Int3*)&point;
|
||||
|
||||
public int GetHashCode()
|
||||
{
|
||||
return (((((X * 39) ^ Y) * 39) ^ Z) * 39) ^ W;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,113 @@
|
||||
using Bon;
|
||||
using System;
|
||||
|
||||
namespace GlitchyEngine.Math;
|
||||
|
||||
[BonTarget]
|
||||
[Vector<double, 2>]
|
||||
[ComparableVector<double, 2>]
|
||||
[VectorMath<double, 2>]
|
||||
[SwizzleVector(2, "GlitchyEngine.Math.double")]
|
||||
public struct double2
|
||||
{
|
||||
public const double2 Zero = .(0, 0);
|
||||
public const double2 UnitX = .(1, 0);
|
||||
public const double2 UnitY = .(0, 1);
|
||||
public const double2 One = .(1, 1);
|
||||
|
||||
public static explicit operator int2(double2 value)
|
||||
{
|
||||
return int2((int32)value.X, (int32)value.Y);
|
||||
}
|
||||
|
||||
public static explicit operator uint2(double2 value)
|
||||
{
|
||||
return uint2((uint32)value.X, (uint32)value.Y);
|
||||
}
|
||||
|
||||
public static explicit operator half2(double2 value)
|
||||
{
|
||||
return half2((half)value.X, (half)value.Y);
|
||||
}
|
||||
|
||||
public static explicit operator float2(double2 value)
|
||||
{
|
||||
return float2((float)value.X, (float)value.Y);
|
||||
}
|
||||
}
|
||||
|
||||
[BonTarget]
|
||||
[Vector<double, 3>]
|
||||
[ComparableVector<double, 3>]
|
||||
[VectorMath<double, 3>]
|
||||
[SwizzleVector(3, "GlitchyEngine.Math.double")]
|
||||
public struct double3
|
||||
{
|
||||
public const double3 Zero = .(0, 0, 0);
|
||||
public const double3 UnitX = .(1, 0, 0);
|
||||
public const double3 UnitY = .(0, 1, 0);
|
||||
public const double3 UnitZ = .(0, 0, 1);
|
||||
public const double3 One = .(1, 1, 1);
|
||||
|
||||
public const double3 Forward = .(0, 0, 1);
|
||||
public const double3 Backward = .(0, 0, -1);
|
||||
public const double3 Left = .(-1, 0, 0);
|
||||
public const double3 Right = .(1, 0, 0);
|
||||
public const double3 Up = .(0, 1, 0);
|
||||
public const double3 Down = .(0, -1, 0);
|
||||
|
||||
public static explicit operator int3(double3 value)
|
||||
{
|
||||
return int3((int32)value.X, (int32)value.Y, (int32)value.Z);
|
||||
}
|
||||
|
||||
public static explicit operator uint3(double3 value)
|
||||
{
|
||||
return uint3((uint32)value.X, (uint32)value.Y, (uint32)value.Z);
|
||||
}
|
||||
|
||||
public static explicit operator half3(double3 value)
|
||||
{
|
||||
return half3((half)(float)value.X, (half)(float)value.Y, (half)(float)value.Z);
|
||||
}
|
||||
|
||||
public static explicit operator float3(double3 value)
|
||||
{
|
||||
return float3((float)value.X, (float)value.Y, (float)value.Z);
|
||||
}
|
||||
}
|
||||
|
||||
[BonTarget]
|
||||
[Vector<double, 4>]
|
||||
[ComparableVector<double, 4>]
|
||||
[VectorMath<double, 4>]
|
||||
[SwizzleVector(4, "GlitchyEngine.Math.double")]
|
||||
public struct double4
|
||||
{
|
||||
public const double4 Zero = .(0, 0, 0, 0);
|
||||
public const double4 UnitX = .(1, 0, 0, 0);
|
||||
public const double4 UnitY = .(0, 1, 0, 0);
|
||||
public const double4 UnitZ = .(0, 0, 1, 0);
|
||||
public const double4 UnitW = .(0, 0, 0, 1);
|
||||
public const double4 One = .(1, 1, 1, 1);
|
||||
|
||||
public static explicit operator int4(double4 value)
|
||||
{
|
||||
return int4((int32)value.X, (int32)value.Y, (int32)value.Z, (int32)value.W);
|
||||
}
|
||||
|
||||
public static explicit operator uint4(double4 value)
|
||||
{
|
||||
return uint4((uint32)value.X, (uint32)value.Y, (uint32)value.Z, (uint32)value.W);
|
||||
}
|
||||
|
||||
public static explicit operator half4(double4 value)
|
||||
{
|
||||
return half4((half)(float)value.X, (half)(float)value.Y, (half)(float)value.Z, (half)(float)value.W);
|
||||
}
|
||||
|
||||
public static explicit operator float4(double4 value)
|
||||
{
|
||||
return float4((float)value.X, (float)value.Y, (float)value.Z, (float)value.W);
|
||||
}
|
||||
}
|
||||
@@ -10,10 +10,20 @@ namespace GlitchyEngine.Math;
|
||||
[SwizzleVector(2, "GlitchyEngine.Math.int")]
|
||||
public struct int2
|
||||
{
|
||||
public const int2 Zero = .(0, 0);
|
||||
public const int2 UnitX = .(1, 0);
|
||||
public const int2 UnitY = .(0, 1);
|
||||
public const int2 One = .(1, 1);
|
||||
|
||||
public static implicit operator float2(int2 value)
|
||||
{
|
||||
return float2(value.X, value.Y);
|
||||
}
|
||||
|
||||
public static explicit operator uint2(int2 value)
|
||||
{
|
||||
return uint2((uint32)value.X, (uint32)value.Y);
|
||||
}
|
||||
}
|
||||
|
||||
[BonTarget]
|
||||
@@ -23,10 +33,21 @@ public struct int2
|
||||
[SwizzleVector(3, "GlitchyEngine.Math.int")]
|
||||
public struct int3
|
||||
{
|
||||
public const int3 Zero = .(0, 0, 0);
|
||||
public const int3 UnitX = .(1, 0, 0);
|
||||
public const int3 UnitY = .(0, 1, 0);
|
||||
public const int3 UnitZ = .(0, 0, 1);
|
||||
public const int3 One = .(1, 1, 1);
|
||||
|
||||
public static implicit operator float3(int3 value)
|
||||
{
|
||||
return float3(value.X, value.Y, value.Z);
|
||||
}
|
||||
|
||||
public static explicit operator uint3(int3 value)
|
||||
{
|
||||
return uint3((uint32)value.X, (uint32)value.Y, (uint32)value.Z);
|
||||
}
|
||||
}
|
||||
|
||||
[BonTarget]
|
||||
@@ -36,8 +57,92 @@ public struct int3
|
||||
[SwizzleVector(4, "GlitchyEngine.Math.int")]
|
||||
public struct int4
|
||||
{
|
||||
public const int4 Zero = .(0, 0, 0, 0);
|
||||
public const int4 UnitX = .(1, 0, 0, 0);
|
||||
public const int4 UnitY = .(0, 1, 0, 0);
|
||||
public const int4 UnitZ = .(0, 0, 1, 0);
|
||||
public const int4 UnitW = .(0, 0, 0, 1);
|
||||
public const int4 One = .(1, 1, 1, 1);
|
||||
|
||||
public static implicit operator float4(int4 value)
|
||||
{
|
||||
return float4(value.X, value.Y, value.Z, value.W);
|
||||
}
|
||||
}
|
||||
|
||||
public static explicit operator uint4(int4 value)
|
||||
{
|
||||
return uint4((uint32)value.X, (uint32)value.Y, (uint32)value.Z, (uint32)value.W);
|
||||
}
|
||||
}
|
||||
|
||||
[BonTarget]
|
||||
[Vector<uint32, 2>]
|
||||
[ComparableVector<uint32, 2>]
|
||||
//[VectorMath<uint32, 2>]
|
||||
[SwizzleVector(2, "GlitchyEngine.Math.uint")]
|
||||
public struct uint2
|
||||
{
|
||||
public const uint2 Zero = .(0, 0);
|
||||
public const uint2 UnitX = .(1, 0);
|
||||
public const uint2 UnitY = .(0, 1);
|
||||
public const uint2 One = .(1, 1);
|
||||
|
||||
public static implicit operator float2(uint2 value)
|
||||
{
|
||||
return float2(value.X, value.Y);
|
||||
}
|
||||
|
||||
public static explicit operator int2(uint2 value)
|
||||
{
|
||||
return int2((int32)value.X, (int32)value.Y);
|
||||
}
|
||||
}
|
||||
|
||||
[BonTarget]
|
||||
[Vector<uint32, 3>]
|
||||
[ComparableVector<uint32, 3>]
|
||||
//[VectorMath<uint32, 3>]
|
||||
[SwizzleVector(3, "GlitchyEngine.Math.uint")]
|
||||
public struct uint3
|
||||
{
|
||||
public const uint3 Zero = .(0, 0, 0);
|
||||
public const uint3 UnitX = .(1, 0, 0);
|
||||
public const uint3 UnitY = .(0, 1, 0);
|
||||
public const uint3 UnitZ = .(0, 0, 1);
|
||||
public const uint3 One = .(1, 1, 1);
|
||||
|
||||
public static implicit operator float3(uint3 value)
|
||||
{
|
||||
return float3(value.X, value.Y, value.Z);
|
||||
}
|
||||
|
||||
public static explicit operator int3(uint3 value)
|
||||
{
|
||||
return int3((int32)value.X, (int32)value.Y, (int32)value.Z);
|
||||
}
|
||||
}
|
||||
|
||||
[BonTarget]
|
||||
[Vector<uint32, 4>]
|
||||
[ComparableVector<uint32, 4>]
|
||||
//[VectorMath<uint32, 4>]
|
||||
[SwizzleVector(4, "GlitchyEngine.Math.uint")]
|
||||
public struct uint4
|
||||
{
|
||||
public const uint4 Zero = .(0, 0, 0, 0);
|
||||
public const uint4 UnitX = .(1, 0, 0, 0);
|
||||
public const uint4 UnitY = .(0, 1, 0, 0);
|
||||
public const uint4 UnitZ = .(0, 0, 1, 0);
|
||||
public const uint4 UnitW = .(0, 0, 0, 1);
|
||||
public const uint4 One = .(1, 1, 1, 1);
|
||||
|
||||
public static implicit operator float4(uint4 value)
|
||||
{
|
||||
return float4(value.X, value.Y, value.Z, value.W);
|
||||
}
|
||||
|
||||
public static explicit operator int4(uint4 value)
|
||||
{
|
||||
return int4((int32)value.X, (int32)value.Y, (int32)value.Z, (int32)value.W);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user