mirror of
https://github.com/raylib-cs/raylib-cs
synced 2025-06-30 19:03:42 -04:00
BREAKING CHANGE. Replaced Vector2, Vector3 and Vector4 with System.Numerics.
- Testing out a breaking change so we can use System.Numerics.
This commit is contained in:
@ -7,282 +7,12 @@
|
||||
*/
|
||||
|
||||
using System;
|
||||
using System.Numerics;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Security;
|
||||
|
||||
namespace Raylib_cs
|
||||
{
|
||||
// Vector2 type
|
||||
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Ansi)]
|
||||
public struct Vector2
|
||||
{
|
||||
public float x;
|
||||
public float y;
|
||||
|
||||
public Vector2(float x, float y)
|
||||
{
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
}
|
||||
|
||||
public Vector2(float value)
|
||||
{
|
||||
this.x = value;
|
||||
this.y = value;
|
||||
}
|
||||
|
||||
public override bool Equals(object obj)
|
||||
{
|
||||
return (obj is Vector2) && Equals((Vector2)obj);
|
||||
}
|
||||
|
||||
public override int GetHashCode()
|
||||
{
|
||||
return x.GetHashCode() + y.GetHashCode();
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return "Vector2(" + x + " " + y + ")";
|
||||
}
|
||||
|
||||
// Common values
|
||||
public static Vector2 Zero { get { return Raymath.Vector2Zero(); } }
|
||||
public static Vector2 One { get { return Raymath.Vector2One(); } }
|
||||
public static Vector2 UnitX { get { return new Vector2(1, 0); } }
|
||||
public static Vector2 UnitY { get { return new Vector2(0, 1); } }
|
||||
|
||||
// Convienient operators
|
||||
public static bool operator ==(Vector2 v1, Vector2 v2)
|
||||
{
|
||||
return (v1.x == v2.x && v1.y == v2.y);
|
||||
}
|
||||
|
||||
public static bool operator !=(Vector2 v1, Vector2 v2)
|
||||
{
|
||||
return !(v1 == v2);
|
||||
}
|
||||
|
||||
public static bool operator >(Vector2 v1, Vector2 v2)
|
||||
{
|
||||
return v1.x > v2.x && v1.y > v2.y;
|
||||
}
|
||||
|
||||
public static bool operator <(Vector2 v1, Vector2 v2)
|
||||
{
|
||||
return v1.x < v2.x && v1.y < v2.y;
|
||||
}
|
||||
|
||||
public static Vector2 operator +(Vector2 v1, Vector2 v2)
|
||||
{
|
||||
return Raymath.Vector2Add(v1, v2);
|
||||
}
|
||||
|
||||
public static Vector2 operator -(Vector2 v1, Vector2 v2)
|
||||
{
|
||||
return Raymath.Vector2Subtract(v1, v2);
|
||||
}
|
||||
|
||||
public static Vector2 operator *(Vector2 v1, Vector2 v2)
|
||||
{
|
||||
return Raymath.Vector2MultiplyV(v1, v2);
|
||||
}
|
||||
|
||||
public static Vector2 operator *(Vector2 v, float scale)
|
||||
{
|
||||
return Raymath.Vector2Scale(v, scale);
|
||||
}
|
||||
|
||||
public static Vector2 operator *(float scale, Vector2 v)
|
||||
{
|
||||
return Raymath.Vector2Scale(v, scale);
|
||||
}
|
||||
|
||||
public static Vector2 operator /(Vector2 v1, Vector2 v2)
|
||||
{
|
||||
return Raymath.Vector2DivideV(v1, v2);
|
||||
}
|
||||
|
||||
public static Vector2 operator /(Vector2 v1, float div)
|
||||
{
|
||||
return Raymath.Vector2Divide(v1, div);
|
||||
}
|
||||
|
||||
public static Vector2 operator -(Vector2 v1)
|
||||
{
|
||||
return Raymath.Vector2Negate(v1);
|
||||
}
|
||||
}
|
||||
|
||||
// Vector3 type
|
||||
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Ansi)]
|
||||
public struct Vector3
|
||||
{
|
||||
public float x;
|
||||
public float y;
|
||||
public float z;
|
||||
|
||||
public Vector3(float x, float y, float z)
|
||||
{
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
this.z = z;
|
||||
}
|
||||
|
||||
public Vector3(float value)
|
||||
{
|
||||
this.x = value;
|
||||
this.y = value;
|
||||
this.z = value;
|
||||
}
|
||||
|
||||
// Extensions
|
||||
public override bool Equals(object obj)
|
||||
{
|
||||
return (obj is Vector3) && Equals((Vector3)obj);
|
||||
}
|
||||
|
||||
public override int GetHashCode()
|
||||
{
|
||||
return x.GetHashCode() + y.GetHashCode() + z.GetHashCode();
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return "Vector3(" + x + " " + y + " " + z + ")";
|
||||
}
|
||||
|
||||
// Common values
|
||||
public static Vector3 Zero { get { return Raymath.Vector3Zero(); } }
|
||||
public static Vector3 One { get { return Raymath.Vector3One(); } }
|
||||
public static Vector3 UnitX { get { return new Vector3(1, 0, 0); } }
|
||||
public static Vector3 UnitY { get { return new Vector3(0, 1, 0); } }
|
||||
public static Vector3 UnitZ { get { return new Vector3(0, 0, 1); } }
|
||||
|
||||
// Convienient operators
|
||||
public static bool operator ==(Vector3 v1, Vector3 v2)
|
||||
{
|
||||
return (v1.x == v2.x && v1.y == v2.y && v1.z == v2.z);
|
||||
}
|
||||
|
||||
public static bool operator !=(Vector3 v1, Vector3 v2)
|
||||
{
|
||||
return !(v1 == v2);
|
||||
}
|
||||
|
||||
public static bool operator >(Vector3 v1, Vector3 v2)
|
||||
{
|
||||
return v1.x > v2.x && v1.y > v2.y && v1.z > v2.z;
|
||||
}
|
||||
|
||||
public static bool operator <(Vector3 v1, Vector3 v2)
|
||||
{
|
||||
return v1.x < v2.x && v1.y < v2.y && v1.z < v2.z;
|
||||
}
|
||||
|
||||
public static Vector3 operator +(Vector3 v1, Vector3 v2)
|
||||
{
|
||||
return Raymath.Vector3Add(v1, v2);
|
||||
}
|
||||
|
||||
public static Vector3 operator -(Vector3 v1, Vector3 v2)
|
||||
{
|
||||
return Raymath.Vector3Subtract(v1, v2);
|
||||
}
|
||||
|
||||
public static Vector3 operator *(Vector3 v1, Vector3 v2)
|
||||
{
|
||||
return Raymath.Vector3MultiplyV(v1, v2);
|
||||
}
|
||||
|
||||
public static Vector3 operator *(Vector3 v, float scale)
|
||||
{
|
||||
return Raymath.Vector3Scale(v, scale);
|
||||
}
|
||||
|
||||
public static Vector3 operator *(float scale, Vector3 v)
|
||||
{
|
||||
return Raymath.Vector3Scale(v, scale);
|
||||
}
|
||||
|
||||
public static Vector3 operator /(Vector3 v1, Vector3 v2)
|
||||
{
|
||||
return Raymath.Vector3DivideV(v1, v2);
|
||||
}
|
||||
|
||||
public static Vector3 operator /(Vector3 v1, float div)
|
||||
{
|
||||
return Raymath.Vector3Divide(v1, div);
|
||||
}
|
||||
|
||||
public static Vector3 operator -(Vector3 v1)
|
||||
{
|
||||
return Raymath.Vector3Negate(v1);
|
||||
}
|
||||
}
|
||||
|
||||
// Vector4 type
|
||||
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Ansi)]
|
||||
public struct Vector4
|
||||
{
|
||||
public float x;
|
||||
public float y;
|
||||
public float z;
|
||||
public float w;
|
||||
|
||||
public Vector4(float x, float y, float z, float w)
|
||||
{
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
this.z = z;
|
||||
this.w = w;
|
||||
}
|
||||
|
||||
public Vector4(float value)
|
||||
{
|
||||
x = value;
|
||||
y = value;
|
||||
z = value;
|
||||
w = value;
|
||||
}
|
||||
|
||||
public override bool Equals(object obj)
|
||||
{
|
||||
return (obj is Vector4) && Equals((Vector4)obj);
|
||||
}
|
||||
|
||||
public override int GetHashCode()
|
||||
{
|
||||
return x.GetHashCode() + y.GetHashCode() + z.GetHashCode() + w.GetHashCode();
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return "Vector4(" + x + " " + y + " " + z + " " + w + ")";
|
||||
}
|
||||
|
||||
// convienient operators
|
||||
public static bool operator ==(Vector4 v1, Vector4 v2)
|
||||
{
|
||||
return (v1.x == v2.x && v1.y == v2.y && v1.z == v2.z && v1.w == v2.w);
|
||||
}
|
||||
|
||||
public static bool operator !=(Vector4 v1, Vector4 v2)
|
||||
{
|
||||
return !(v1 == v2);
|
||||
}
|
||||
|
||||
public static bool operator >(Vector4 v1, Vector4 v2)
|
||||
{
|
||||
return v1.x > v2.x && v1.y > v2.y && v1.z > v2.z && v1.w > v2.w;
|
||||
}
|
||||
|
||||
public static bool operator <(Vector4 v1, Vector4 v2)
|
||||
{
|
||||
return v1.x < v2.x && v1.y < v2.y && v1.z < v2.z && v1.w < v2.w;
|
||||
}
|
||||
}
|
||||
|
||||
// Matrix type (OpenGL style 4x4 - right handed, column major)
|
||||
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Ansi)]
|
||||
public struct Matrix
|
||||
|
Reference in New Issue
Block a user