diff --git a/Bindings/Extensions.cs b/Bindings/Extensions.cs deleted file mode 100644 index f0d312b..0000000 --- a/Bindings/Extensions.cs +++ /dev/null @@ -1,547 +0,0 @@ -/* Extensions.cs -* -* Copyright 2019 Chris Dill -* -* Release under zLib License. -* See LICENSE for details. -*/ - -using System; -using System.Text; -using System.Runtime.InteropServices; - -namespace Raylib -{ - // Extra functions over exsiting bindings - // Feel free to modifiy this to fit your project. - public partial class Raylib - { - public static PhysicsBodyData CreatePhysicsBodyCircleEx(Vector2 pos, float radius, float density) - { - var body = CreatePhysicsBodyCircle(pos, radius, density); - var data = (PhysicsBodyData)Marshal.PtrToStructure(body, typeof(PhysicsBodyData)); - return data; - } - - public static PhysicsBodyData CreatePhysicsBodyRectangleEx(Vector2 pos, float width, float height, float density) - { - var body = CreatePhysicsBodyRectangle(pos, width, height, density); - var data = (PhysicsBodyData)Marshal.PtrToStructure(body, typeof(PhysicsBodyData)); - return data; - } - - public static PhysicsBodyData GetPhysicsBodyEx(int index) - { - var body = GetPhysicsBodyImport(index); - var data = (PhysicsBodyData)Marshal.PtrToStructure(body, typeof(PhysicsBodyData)); - return data; - } - - public static PhysicsBodyData CreatePhysicsBodyPolygonEx(Vector2 pos, float radius, int sides, float density) - { - var body = CreatePhysicsBodyPolygon(pos, radius, sides, density); - var data = (PhysicsBodyData)Marshal.PtrToStructure(body, typeof(PhysicsBodyData)); - return data; - } - - public static void DrawRenderTexture(RenderTexture2D target) - { - int screenWidth = GetScreenWidth(); - int screenHeight = GetScreenHeight(); - - // NOTE: Render texture must be y-flipped due to default OpenGL coordinates (left-bottom) - DrawTexturePro(target.texture, new Rectangle(0, 0, target.texture.width, -target.texture.height), new Rectangle(0, 0, screenWidth, screenHeight), new Vector2(0, 0), 0, Color.WHITE); - } - - // extension providing SubText - public static string SubText(this string input, int position, int length) - { - return input.Substring(position, Math.Min(length, input.Length)); - } - - // Here (in the public method) we hide some low level details - // memory allocation, string manipulations etc. - public static bool CoreGuiTextBox(Rectangle bounds, ref string text, int textSize, bool freeEdit) - { - if (null == text) - { - return false; // or throw exception; or assign "" to text - } - - StringBuilder sb = new StringBuilder(text); - - // If we allow editing we should allocate enough size (Length) within StringBuilder - if (textSize > sb.Length) - { - sb.Length = textSize; - } - - bool result = GuiTextBox(bounds, sb, sb.Length, freeEdit); - - // Back to string (StringBuilder can have been edited) - // You may want to add some logic here; e.g. trim trailing '\0' - text = sb.ToString(); - - return result; - } - - // Text Box control with multiple lines - public static bool CoreTextBoxMulti(Rectangle bounds, ref string text, int textSize, bool freeEdit) - { - if (null == text) - { - return false; // or throw exception; or assign "" to text - } - - StringBuilder sb = new StringBuilder(text); - - // If we allow editing we should allocate enough size (Length) within StringBuilder - if (textSize > sb.Length) - { - sb.Length = textSize; - } - - bool result = GuiTextBoxMulti(bounds, sb, sb.Length, freeEdit); - - // Back to string (StringBuilder can have been edited) - // You may want to add some logic here; e.g. trim trailing '\0' - text = sb.ToString(); - - return result; - } - } - - public partial struct Color - { - // Example - Color.RED instead of RED - // Custom raylib color palette for amazing visuals - public static Color LIGHTGRAY = new Color(200, 200, 200, 255); - public static Color GRAY = new Color(130, 130, 130, 255); - public static Color DARKGRAY = new Color(80, 80, 80, 255); - public static Color YELLOW = new Color(253, 249, 0, 255); - public static Color GOLD = new Color(255, 203, 0, 255); - public static Color ORANGE = new Color(255, 161, 0, 255); - public static Color PINK = new Color(255, 109, 194, 255); - public static Color RED = new Color(230, 41, 55, 255); - public static Color MAROON = new Color(190, 33, 55, 255); - public static Color GREEN = new Color(0, 228, 48, 255); - public static Color LIME = new Color(0, 158, 47, 255); - public static Color DARKGREEN = new Color(0, 117, 44, 255); - public static Color SKYBLUE = new Color(102, 191, 255, 255); - public static Color BLUE = new Color(0, 121, 241, 255); - public static Color DARKBLUE = new Color(0, 82, 172, 255); - public static Color PURPLE = new Color(200, 122, 255, 255); - public static Color VIOLET = new Color(135, 60, 190, 255); - public static Color DARKPURPLE = new Color(112, 31, 126, 255); - public static Color BEIGE = new Color(211, 176, 131, 255); - public static Color BROWN = new Color(127, 106, 79, 255); - public static Color DARKBROWN = new Color(76, 63, 47, 255); - public static Color WHITE = new Color(255, 255, 255, 255); - public static Color BLACK = new Color(0, 0, 0, 255); - public static Color BLANK = new Color(0, 0, 0, 0); - public static Color MAGENTA = new Color(255, 0, 255, 255); - public static Color RAYWHITE = new Color(245, 245, 245, 255); - - public Color(byte r, byte g, byte b, byte a) - { - this.r = r; - this.g = g; - this.b = b; - this.a = a; - } - - public Color(int r, int g, int b, int a) - { - this.r = Convert.ToByte(r); - this.g = Convert.ToByte(g); - this.b = Convert.ToByte(b); - this.a = Convert.ToByte(a); - } - - public override string ToString() - { - return string.Concat(r.ToString(), " ", g.ToString(), " ", b.ToString(), " ", a.ToString()); - } - } - - public partial struct Rectangle - { - public Rectangle(float x, float y, float width, float height) - { - this.x = x; - this.y = y; - this.width = width; - this.height = height; - } - } - - public partial struct Camera3D - { - public Camera3D(Vector3 position, Vector3 target, Vector3 up, float fovy = 90, CameraType type = CameraType.CAMERA_PERSPECTIVE) - { - this.position = position; - this.target = target; - this.up = up; - this.fovy = fovy; - this.type = type; - } - } - - public partial struct Ray - { - public Ray(Vector3 position, Vector3 direction) - { - this.position = position; - this.direction = direction; - } - } - - // Utlity for accessing math functions through struct - public partial struct Vector2 - { - 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 float Length() - { - return Raylib.Vector2Length(this); - } - - public float LengthSquared() - { - return (x * x) + (y * y); - } - - public override string ToString() - { - return "Vector2(" + x + " " + y + ")"; - } - - // common values - public static Vector2 Zero { get { return Raylib.Vector2Zero(); } } - public static Vector2 One { get { return Raylib.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 Raylib.Vector2Add(v1, v2); - } - - public static Vector2 operator -(Vector2 v1, Vector2 v2) - { - return Raylib.Vector2Subtract(v1, v2); - } - - public static Vector2 operator *(Vector2 v1, Vector2 v2) - { - return Raylib.Vector2MultiplyV(v1, v2); - } - - public static Vector2 operator *(Vector2 v, float scale) - { - return Raylib.Vector2Scale(v, scale); - } - - public static Vector2 operator *(float scale, Vector2 v) - { - return Raylib.Vector2Scale(v, scale); - } - - public static Vector2 operator /(Vector2 v1, Vector2 v2) - { - return Raylib.Vector2DivideV(v1, v2); - } - - public static Vector2 operator /(Vector2 v1, float div) - { - return Raylib.Vector2Divide(v1, div); - } - - public static Vector2 operator -(Vector2 v1) - { - return Raylib.Vector2Negate(v1); - } - - public static float Length(Vector2 v) - { - return Raylib.Vector2Length(v); - } - - public static float Dot(Vector2 v1, Vector2 v2) - { - return Raylib.Vector2DotProduct(v1, v2); - } - - public static void Dot(ref Vector2 v1, ref Vector2 v2, out float result) - { - result = Raylib.Vector2DotProduct(v1, v2); - } - - public static float DotProduct(Vector2 v1, Vector2 v2) - { - return Raylib.Vector2DotProduct(v1, v2); - } - - public static float Distance(Vector2 v1, Vector2 v2) - { - return Raylib.Vector2Distance(v1, v2); - } - - public static float DistanceSquared(Vector2 v1, Vector2 v2) - { - float a = v1.x - v2.x, b = v1.y - v2.y; - return (a * a) + (b * b); - } - - public static float Angle(Vector2 v1, Vector2 v2) - { - return Raylib.Vector2Angle(v1, v2); - } - - public static Vector2 Scale(Vector2 v, float scale) - { - return Raylib.Vector2Scale(v, scale); - } - - public static Vector2 Negate(Vector2 v) - { - return Raylib.Vector2Negate(v); - } - - public static Vector2 Divide(Vector2 v, float div) - { - return Raylib.Vector2Divide(v, div); - } - - public static void Normalize(ref Vector2 v) - { - v = Raylib.Vector2Normalize(v); - } - - public static Vector2 Normalize(Vector2 v) - { - return Raylib.Vector2Normalize(v); - } - - // Creates a new that contains a maximal values from the two vectors. - public static Vector2 Max(Vector2 v1, Vector2 v2) - { - return new Vector2( - v1.x > v2.x ? v1.x : v2.x, - v1.y > v2.y ? v1.y : v2.y); - } - - // Creates a new that contains a minimal values from the two vectors. - public static Vector2 Min(Vector2 v1, Vector2 v2) - { - return new Vector2( - v1.x < v2.x ? v1.x : v2.x, - v1.y < v2.y ? v1.y : v2.y); - } - - // Clamps the specified value within a range. - public static Vector2 Clamp(Vector2 value1, Vector2 min, Vector2 max) - { - return new Vector2( - Raylib.Clamp(value1.x, min.x, max.x), - Raylib.Clamp(value1.y, min.y, max.y)); - } - } - - // Vector3 type - public partial struct Vector3 - { - 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 Raylib.Vector3Zero(); } } - public static Vector3 One { get { return Raylib.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 Raylib.Vector3Add(v1, v2); - } - - public static Vector3 operator -(Vector3 v1, Vector3 v2) - { - return Raylib.Vector3Subtract(v1, v2); - } - - public static Vector3 operator *(Vector3 v1, Vector3 v2) - { - return Raylib.Vector3MultiplyV(v1, v2); - } - - public static Vector3 operator *(Vector3 v, float scale) - { - return Raylib.Vector3Scale(v, scale); - } - - public static Vector3 operator *(float scale, Vector3 v) - { - return Raylib.Vector3Scale(v, scale); - } - - public static Vector3 operator /(Vector3 v1, Vector3 v2) - { - return Raylib.Vector3DivideV(v1, v2); - } - - public static Vector3 operator /(Vector3 v1, float div) - { - return Raylib.Vector3Divide(v1, div); - } - - public static Vector3 operator -(Vector3 v1) - { - return Raylib.Vector3Negate(v1); - } - } - - // Vector4 type - public partial struct Vector4 - { - 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; - } - } -} diff --git a/Bindings/Physac.cs b/Bindings/Physac.cs index b1690ed..d4f35ca 100644 --- a/Bindings/Physac.cs +++ b/Bindings/Physac.cs @@ -150,7 +150,7 @@ namespace Raylib // Creates a new circle physics body with generic parameters [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] - private static extern IntPtr CreatePhysicsBodyCircle(Vector2 pos, float radius, float density); + public static extern IntPtr CreatePhysicsBodyCircle(Vector2 pos, float radius, float density); // Creates a new rectangle physics body with generic parameters [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] @@ -178,7 +178,7 @@ namespace Raylib // Returns a physics body of the bodies pool at a specific index [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] - public static extern IntPtr GetPhysicsBodyImport(int index); + public static extern IntPtr GetPhysicsBody(int index); // Returns the physics body shape type (PHYSICS_CIRCLE or PHYSICS_POLYGON) [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] diff --git a/Bindings/Raylib.cs b/Bindings/Raylib.cs index 6d8601a..935b1fa 100644 --- a/Bindings/Raylib.cs +++ b/Bindings/Raylib.cs @@ -14,34 +14,373 @@ namespace Raylib { // Vector2 type [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Ansi)] - public partial struct Vector2 + 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 float Length() + { + return Raylib.Vector2Length(this); + } + + public float LengthSquared() + { + return (x * x) + (y * y); + } + + public override string ToString() + { + return "Vector2(" + x + " " + y + ")"; + } + + // common values + public static Vector2 Zero { get { return Raylib.Vector2Zero(); } } + public static Vector2 One { get { return Raylib.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 Raylib.Vector2Add(v1, v2); + } + + public static Vector2 operator -(Vector2 v1, Vector2 v2) + { + return Raylib.Vector2Subtract(v1, v2); + } + + public static Vector2 operator *(Vector2 v1, Vector2 v2) + { + return Raylib.Vector2MultiplyV(v1, v2); + } + + public static Vector2 operator *(Vector2 v, float scale) + { + return Raylib.Vector2Scale(v, scale); + } + + public static Vector2 operator *(float scale, Vector2 v) + { + return Raylib.Vector2Scale(v, scale); + } + + public static Vector2 operator /(Vector2 v1, Vector2 v2) + { + return Raylib.Vector2DivideV(v1, v2); + } + + public static Vector2 operator /(Vector2 v1, float div) + { + return Raylib.Vector2Divide(v1, div); + } + + public static Vector2 operator -(Vector2 v1) + { + return Raylib.Vector2Negate(v1); + } + + public static float Length(Vector2 v) + { + return Raylib.Vector2Length(v); + } + + public static float Dot(Vector2 v1, Vector2 v2) + { + return Raylib.Vector2DotProduct(v1, v2); + } + + public static void Dot(ref Vector2 v1, ref Vector2 v2, out float result) + { + result = Raylib.Vector2DotProduct(v1, v2); + } + + public static float DotProduct(Vector2 v1, Vector2 v2) + { + return Raylib.Vector2DotProduct(v1, v2); + } + + public static float Distance(Vector2 v1, Vector2 v2) + { + return Raylib.Vector2Distance(v1, v2); + } + + public static float DistanceSquared(Vector2 v1, Vector2 v2) + { + float a = v1.x - v2.x, b = v1.y - v2.y; + return (a * a) + (b * b); + } + + public static float Angle(Vector2 v1, Vector2 v2) + { + return Raylib.Vector2Angle(v1, v2); + } + + public static Vector2 Scale(Vector2 v, float scale) + { + return Raylib.Vector2Scale(v, scale); + } + + public static Vector2 Negate(Vector2 v) + { + return Raylib.Vector2Negate(v); + } + + public static Vector2 Divide(Vector2 v, float div) + { + return Raylib.Vector2Divide(v, div); + } + + public static void Normalize(ref Vector2 v) + { + v = Raylib.Vector2Normalize(v); + } + + public static Vector2 Normalize(Vector2 v) + { + return Raylib.Vector2Normalize(v); + } + + // Creates a new that contains a maximal values from the two vectors. + public static Vector2 Max(Vector2 v1, Vector2 v2) + { + return new Vector2( + v1.x > v2.x ? v1.x : v2.x, + v1.y > v2.y ? v1.y : v2.y); + } + + // Creates a new that contains a minimal values from the two vectors. + public static Vector2 Min(Vector2 v1, Vector2 v2) + { + return new Vector2( + v1.x < v2.x ? v1.x : v2.x, + v1.y < v2.y ? v1.y : v2.y); + } + + // Clamps the specified value within a range. + public static Vector2 Clamp(Vector2 value1, Vector2 min, Vector2 max) + { + return new Vector2( + Raylib.Clamp(value1.x, min.x, max.x), + Raylib.Clamp(value1.y, min.y, max.y)); + } } // Vector3 type [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Ansi)] - public partial struct Vector3 + 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 Raylib.Vector3Zero(); } } + public static Vector3 One { get { return Raylib.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 Raylib.Vector3Add(v1, v2); + } + + public static Vector3 operator -(Vector3 v1, Vector3 v2) + { + return Raylib.Vector3Subtract(v1, v2); + } + + public static Vector3 operator *(Vector3 v1, Vector3 v2) + { + return Raylib.Vector3MultiplyV(v1, v2); + } + + public static Vector3 operator *(Vector3 v, float scale) + { + return Raylib.Vector3Scale(v, scale); + } + + public static Vector3 operator *(float scale, Vector3 v) + { + return Raylib.Vector3Scale(v, scale); + } + + public static Vector3 operator /(Vector3 v1, Vector3 v2) + { + return Raylib.Vector3DivideV(v1, v2); + } + + public static Vector3 operator /(Vector3 v1, float div) + { + return Raylib.Vector3Divide(v1, div); + } + + public static Vector3 operator -(Vector3 v1) + { + return Raylib.Vector3Negate(v1); + } } // Vector4 type [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Ansi)] - public partial struct Vector4 + 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 partial struct Matrix + public struct Matrix { public float m0; public float m4; @@ -63,28 +402,86 @@ namespace Raylib // Color type, RGBA (32bit) [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Ansi)] - public partial struct Color + public struct Color { public byte r; public byte g; public byte b; public byte a; + + // Example - Color.RED instead of RED + // Custom raylib color palette for amazing visuals + public static Color LIGHTGRAY = new Color(200, 200, 200, 255); + public static Color GRAY = new Color(130, 130, 130, 255); + public static Color DARKGRAY = new Color(80, 80, 80, 255); + public static Color YELLOW = new Color(253, 249, 0, 255); + public static Color GOLD = new Color(255, 203, 0, 255); + public static Color ORANGE = new Color(255, 161, 0, 255); + public static Color PINK = new Color(255, 109, 194, 255); + public static Color RED = new Color(230, 41, 55, 255); + public static Color MAROON = new Color(190, 33, 55, 255); + public static Color GREEN = new Color(0, 228, 48, 255); + public static Color LIME = new Color(0, 158, 47, 255); + public static Color DARKGREEN = new Color(0, 117, 44, 255); + public static Color SKYBLUE = new Color(102, 191, 255, 255); + public static Color BLUE = new Color(0, 121, 241, 255); + public static Color DARKBLUE = new Color(0, 82, 172, 255); + public static Color PURPLE = new Color(200, 122, 255, 255); + public static Color VIOLET = new Color(135, 60, 190, 255); + public static Color DARKPURPLE = new Color(112, 31, 126, 255); + public static Color BEIGE = new Color(211, 176, 131, 255); + public static Color BROWN = new Color(127, 106, 79, 255); + public static Color DARKBROWN = new Color(76, 63, 47, 255); + public static Color WHITE = new Color(255, 255, 255, 255); + public static Color BLACK = new Color(0, 0, 0, 255); + public static Color BLANK = new Color(0, 0, 0, 0); + public static Color MAGENTA = new Color(255, 0, 255, 255); + public static Color RAYWHITE = new Color(245, 245, 245, 255); + + public Color(byte r, byte g, byte b, byte a) + { + this.r = r; + this.g = g; + this.b = b; + this.a = a; + } + + public Color(int r, int g, int b, int a) + { + this.r = Convert.ToByte(r); + this.g = Convert.ToByte(g); + this.b = Convert.ToByte(b); + this.a = Convert.ToByte(a); + } + + public override string ToString() + { + return string.Concat(r.ToString(), " ", g.ToString(), " ", b.ToString(), " ", a.ToString()); + } } // Rectangle type [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Ansi)] - public partial struct Rectangle + public struct Rectangle { public float x; public float y; public float width; public float height; + + public Rectangle(float x, float y, float width, float height) + { + this.x = x; + this.y = y; + this.width = width; + this.height = height; + } } // Image type, bpp always RGBA (32bit) // NOTE: Data stored in CPU memory (RAM) [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Ansi)] - public partial struct Image + public struct Image { public IntPtr data; // Image raw data public int width; // Image base width @@ -96,7 +493,7 @@ namespace Raylib // Texture2D type // NOTE: Data stored in GPU memory [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Ansi)] - public partial struct Texture2D + public struct Texture2D { public uint id; // OpenGL texture id public int width; // Texture base width @@ -107,7 +504,7 @@ namespace Raylib // RenderTexture2D type, for texture rendering [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Ansi)] - public partial struct RenderTexture2D + public struct RenderTexture2D { public uint id; // OpenGL Framebuffer Object (FBO) id public Texture2D texture; // Color buffer attachment texture @@ -118,7 +515,7 @@ namespace Raylib // N-Patch layout info [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Ansi)] - public partial struct NPatchInfo + public struct NPatchInfo { public Rectangle sourceRec; // Region in the texture public int left; // left border offset @@ -130,7 +527,7 @@ namespace Raylib // Font character info [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Ansi)] - public partial struct CharInfo + public struct CharInfo { public int value; // Character value (Unicode) public Rectangle rec; // Character rectangle in sprite font @@ -142,7 +539,7 @@ namespace Raylib // Font type, includes texture and charSet array data [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Ansi)] - public partial struct Font + public struct Font { public Texture2D texture; // Font texture public int baseSize; // Base size (default chars height) @@ -152,18 +549,27 @@ namespace Raylib // Camera type, defines a camera position/orientation in 3d space [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Ansi)] - public partial struct Camera3D + public struct Camera3D { public Vector3 position; // Camera position public Vector3 target; // Camera target it looks-at public Vector3 up; // Camera up vector (rotation over its axis) public float fovy; // Camera field-of-view apperture in Y (degrees) in perspective, used as near plane width in orthographic public CameraType type; // Camera type, defines projection type: CAMERA_PERSPECTIVE or CAMERA_ORTHOGRAPHIC + + public Camera3D(Vector3 position, Vector3 target, Vector3 up, float fovy = 90, CameraType type = CameraType.CAMERA_PERSPECTIVE) + { + this.position = position; + this.target = target; + this.up = up; + this.fovy = fovy; + this.type = type; + } } // Camera2D type, defines a 2d camera [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Ansi)] - public partial struct Camera2D + public struct Camera2D { public Vector2 offset; // Camera offset (displacement from target) public Vector2 target; // Camera target (rotation and zoom origin) @@ -174,7 +580,7 @@ namespace Raylib // Vertex data definning a mesh // NOTE: Data stored in CPU memory (and GPU) [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Ansi)] - public partial struct Mesh + public struct Mesh { public int vertexCount; // Number of vertices stored in arrays public int triangleCount; // Number of triangles stored (indexed or not) @@ -204,7 +610,7 @@ namespace Raylib // Material texture map [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Ansi)] - public partial struct MaterialMap + public struct MaterialMap { public Texture2D texture; // Material map texture public Color color; // Material map color @@ -213,7 +619,7 @@ namespace Raylib // Material type (generic) [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Ansi)] - public partial struct Material + public struct Material { public Shader shader; // Material shader [MarshalAs(UnmanagedType.ByValArray, SizeConst = 12)] @@ -223,7 +629,7 @@ namespace Raylib // Transformation properties [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Ansi)] - public partial struct Transform + public struct Transform { public Vector3 translation; // Translation public Vector4 rotation; // Rotation @@ -232,7 +638,7 @@ namespace Raylib // Bone information [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Ansi)] - public partial struct BoneInfo + public struct BoneInfo { [MarshalAs(UnmanagedType.ByValArray, SizeConst = 32)] public char[] name; // Bone name @@ -241,7 +647,7 @@ namespace Raylib // Model type [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Ansi)] - public partial struct Model + public struct Model { public Matrix transform; // Local transform matrix public int meshCount; // Number of meshes @@ -256,7 +662,7 @@ namespace Raylib // Model animation [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Ansi)] - public partial struct ModelAnimation + public struct ModelAnimation { public int boneCount; // Number of bones public BoneInfo[] bones; // Bones information (skeleton) @@ -266,15 +672,21 @@ namespace Raylib // Ray type (useful for raycast) [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Ansi)] - public partial struct Ray + public struct Ray { public Vector3 position; // Ray position (origin) public Vector3 direction; // Ray direction + + public Ray(Vector3 position, Vector3 direction) + { + this.position = position; + this.direction = direction; + } } // Raycast hit information [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Ansi)] - public partial struct RayHitInfo + public struct RayHitInfo { public bool hit; // Did the ray hit something? public float distance; // Distance to nearest hit @@ -284,15 +696,21 @@ namespace Raylib // Bounding box type [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Ansi)] - public partial struct BoundingBox + public struct BoundingBox { public Vector3 min; // Minimum vertex box-corner public Vector3 max; // Maximum vertex box-corner + + public BoundingBox(Vector3 min, Vector3 max) + { + this.min = min; + this.max = max; + } } // Wave type, defines audio wave data [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Ansi)] - public partial struct Wave + public struct Wave { public uint sampleCount; // Number of samples public uint sampleRate; // Frequency (samples per second) @@ -303,7 +721,7 @@ namespace Raylib // Sound source type [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Ansi)] - public partial struct Sound + public struct Sound { public IntPtr audioBuffer; // Pointer to internal data used by the audio system public uint source; // Audio source id @@ -314,7 +732,7 @@ namespace Raylib // Audio stream type // NOTE: Useful to create custom audio streams not bound to a specific file [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Ansi)] - public partial struct AudioStream + public struct AudioStream { public uint sampleRate; // Frequency (samples per second) public uint sampleSize; // Bit depth (bits per sample): 8, 16, 32 (24 not supported) @@ -329,7 +747,7 @@ namespace Raylib // Head-Mounted-Display device parameters [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Ansi)] - public partial struct VrDeviceInfo + public struct VrDeviceInfo { public int hResolution; // HMD horizontal resolution in pixels public int vResolution; // HMD vertical resolution in pixels @@ -760,6 +1178,13 @@ namespace Raylib public const float RAD2DEG = 180.0f / (float)Math.PI; public const int MAX_SHADER_LOCATIONS = 32; public const int MAX_MATERIAL_MAPS = 12; + public const int MAX_TOUCH_POINTS = 10; + + // extension providing SubText + public static string SubText(this string input, int position, int length) + { + return input.Substring(position, Math.Min(length, input.Length)); + } //------------------------------------------------------------------------------------ // Window and Graphics Device Functions (Module: core)