mirror of
https://github.com/aharabada/glitchy-engine-beef.git
synced 2026-09-05 21:01:52 +00:00
Added explicit conversion from float to Vector
This commit is contained in:
@@ -223,5 +223,8 @@ namespace GlitchyEngine.Math
|
|||||||
|
|
||||||
[Inline]
|
[Inline]
|
||||||
public static implicit operator Self(in DirectX.Math.Vector2 value) => *(Self*)&value;
|
public static implicit operator Self(in DirectX.Math.Vector2 value) => *(Self*)&value;
|
||||||
|
|
||||||
|
[Inline]
|
||||||
|
public static explicit operator Self(float value) => Self(value);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ using System;
|
|||||||
|
|
||||||
namespace GlitchyEngine.Math
|
namespace GlitchyEngine.Math
|
||||||
{
|
{
|
||||||
[SwizzleVector(3, "Vector")]
|
//[SwizzleVector(3, "Vector")]
|
||||||
public struct Vector3
|
public struct Vector3
|
||||||
{
|
{
|
||||||
public const Vector3 Zero = .(0f, 0f, 0f);
|
public const Vector3 Zero = .(0f, 0f, 0f);
|
||||||
@@ -77,6 +77,9 @@ namespace GlitchyEngine.Math
|
|||||||
return X * X + Y * Y + Z * Z;
|
return X * X + Y * Y + Z * Z;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Normalizes this vector.
|
||||||
|
*/
|
||||||
[Checked]
|
[Checked]
|
||||||
public void Normalize() mut
|
public void Normalize() mut
|
||||||
{
|
{
|
||||||
@@ -86,11 +89,34 @@ namespace GlitchyEngine.Math
|
|||||||
this /= Magnitude();
|
this /= Magnitude();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Normalizes this vector.
|
||||||
|
*/
|
||||||
public void Normalize() mut
|
public void Normalize() mut
|
||||||
{
|
{
|
||||||
this /= Magnitude();
|
this /= Magnitude();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns a copy of this Vector with a magnitude of 1.
|
||||||
|
*/
|
||||||
|
[Checked]
|
||||||
|
public Vector3 Normalized()
|
||||||
|
{
|
||||||
|
if(this == .Zero)
|
||||||
|
return .Zero;
|
||||||
|
|
||||||
|
return this / Magnitude();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns a copy of this Vector with a magnitude of 1.
|
||||||
|
*/
|
||||||
|
public Vector3 Normalized()
|
||||||
|
{
|
||||||
|
return this / Magnitude();
|
||||||
|
}
|
||||||
|
|
||||||
public static Vector3 Normalize(Vector3 v)
|
public static Vector3 Normalize(Vector3 v)
|
||||||
{
|
{
|
||||||
return v / v.Magnitude();
|
return v / v.Magnitude();
|
||||||
@@ -125,6 +151,11 @@ namespace GlitchyEngine.Math
|
|||||||
return (a - b * (Dot(a, b) / Dot(b, b)));
|
return (a - b * (Dot(a, b) / Dot(b, b)));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static Vector3 Floor(Vector3 value)
|
||||||
|
{
|
||||||
|
return .(Math.Floor(value.X), Math.Floor(value.Y), Math.Floor(value.Z));
|
||||||
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
// Assignment operators
|
// Assignment operators
|
||||||
//
|
//
|
||||||
@@ -239,6 +270,14 @@ namespace GlitchyEngine.Math
|
|||||||
|
|
||||||
public static Vector3 operator /(float scalar, Vector3 value) => Vector3(scalar / value.X, scalar / value.Y, scalar / value.Z);
|
public static Vector3 operator /(float scalar, Vector3 value) => Vector3(scalar / value.X, scalar / value.Y, scalar / value.Z);
|
||||||
|
|
||||||
|
// Modulo
|
||||||
|
|
||||||
|
public static Vector3 operator %(Vector3 left, Vector3 right) => Vector3(left.X % right.X, left.Y % right.Y, left.Z % right.Z);
|
||||||
|
|
||||||
|
public static Vector3 operator %(Vector3 value, float scalar) => Vector3(value.X % scalar, value.Y % scalar, value.Z % scalar);
|
||||||
|
|
||||||
|
public static Vector3 operator %(float scalar, Vector3 value) => Vector3(scalar % value.X, scalar % value.Y, scalar % value.Z);
|
||||||
|
|
||||||
// Equality
|
// Equality
|
||||||
|
|
||||||
public static bool operator ==(Vector3 left, Vector3 right) => left.X == right.X && left.Y == right.Y && left.Z == right.Z;
|
public static bool operator ==(Vector3 left, Vector3 right) => left.X == right.X && left.Y == right.Y && left.Z == right.Z;
|
||||||
@@ -254,5 +293,8 @@ namespace GlitchyEngine.Math
|
|||||||
|
|
||||||
[Inline]
|
[Inline]
|
||||||
public static implicit operator Self(in DirectX.Math.Vector3 value) => *(Self*)&value;
|
public static implicit operator Self(in DirectX.Math.Vector3 value) => *(Self*)&value;
|
||||||
|
|
||||||
|
[Inline]
|
||||||
|
public static explicit operator Self(float value) => Self(value);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -274,5 +274,8 @@ namespace GlitchyEngine.Math
|
|||||||
|
|
||||||
[Inline]
|
[Inline]
|
||||||
public static implicit operator Self(in DirectX.Math.Vector4 value) => *(Self*)&value;
|
public static implicit operator Self(in DirectX.Math.Vector4 value) => *(Self*)&value;
|
||||||
|
|
||||||
|
[Inline]
|
||||||
|
public static explicit operator Self(float value) => Self(value);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user