2
0
mirror of https://github.com/raylib-cs/raylib-cs synced 2025-04-05 11:19:39 -04:00

Organising bindings

- Seperated bidning extensions into seperate file. This will make it easier when generating them.
- Added minor fixes I found while using bindings.
This commit is contained in:
ChrisDill 2019-03-15 11:40:41 +00:00
parent d6b62b4e9b
commit 27a555bc97
8 changed files with 636 additions and 603 deletions

View File

@ -1,5 +1,3 @@
// Easings - https://github.com/raysan5/raylib/blob/master/src/easings.h
using System; using System;
using System.Runtime.InteropServices; using System.Runtime.InteropServices;
@ -7,8 +5,6 @@ namespace Raylib
{ {
public static partial class Raylib public static partial class Raylib
{ {
#region Raylib-cs Functions
// Linear Easing functions // Linear Easing functions
[DllImport(nativeLibName,CallingConvention = CallingConvention.Cdecl)] [DllImport(nativeLibName,CallingConvention = CallingConvention.Cdecl)]
public static extern float EaseLinearNone(float t, float b, float c, float d); public static extern float EaseLinearNone(float t, float b, float c, float d);
@ -100,8 +96,6 @@ namespace Raylib
public static extern float EaseElasticOut(float t, float b, float c, float d); public static extern float EaseElasticOut(float t, float b, float c, float d);
[DllImport(nativeLibName,CallingConvention = CallingConvention.Cdecl)] [DllImport(nativeLibName,CallingConvention = CallingConvention.Cdecl)]
public static extern float EaseElasticInOut(float t, float b, float c, float d); public static extern float EaseElasticInOut(float t, float b, float c, float d);
#endregion
} }
} }

336
Bindings/Extensions.cs Normal file
View File

@ -0,0 +1,336 @@
using System;
using System.Runtime.InteropServices;
namespace Raylib
{
public struct Tween
{
public delegate float Callback(float t, float b, float c, float d);
public Callback easer;
public float start;
public float end;
public float currentTime;
public float duration;
public bool completed;
public Tween(Callback easer, float start, float end, float duration)
{
this.easer = easer;
this.start = start;
this.end = end;
this.currentTime = 0f;
this.duration = duration;
this.completed = false;
}
public void Reset()
{
currentTime = 0f;
completed = false;
}
public float Apply(float dt)
{
currentTime += dt;
if (currentTime > duration)
{
currentTime = duration;
completed = true;
}
return easer(currentTime, start, end - start, duration);
}
}
public partial struct Color
{
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);
}
internal string DebugDisplayString
{
get
{
return string.Concat(
r.ToString(), " ",
g.ToString(), " ",
b.ToString(), " ",
a.ToString()
);
}
}
/// <summary>
/// Performs linear interpolation of <see cref="Color"/>.
/// </summary>
/// <param name="value1">Source <see cref="Color"/>.</param>
/// <param name="value2">Destination <see cref="Color"/>.</param>
/// <param name="amount">Interpolation factor.</param>
/// <returns>Interpolated <see cref="Color"/>.</returns>
public static Color Lerp(Color value1, Color value2, float amount)
{
amount = Raylib.Clamp(amount, 0.0f, 1.0f);
return new Color(
(int) Raylib.Lerp(value1.r, value2.r, amount),
(int) Raylib.Lerp(value1.g, value2.g, amount),
(int) Raylib.Lerp(value1.b, value2.b, amount),
(int) Raylib.Lerp(value1.a, value2.a, amount)
);
}
}
// Utlity for accessing math functions through struct
public partial struct Vector2
{
public float X {get{return x;} set {x = value;}}
public float Y {get{return y;} set {y = value;}}
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) => (obj is Vector2) && Equals((Vector2)obj);
public override int GetHashCode() => x.GetHashCode() + y.GetHashCode();
public float Length() => Raylib.Vector2Length(this);
public float LengthSquared() => (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) => (v1.x == v2.x && v1.y == v2.y);
public static bool operator !=(Vector2 v1, Vector2 v2) => !(v1 == v2);
public static bool operator >(Vector2 v1, Vector2 v2) => v1.x > v2.x && v1.y > v2.y;
public static bool operator <(Vector2 v1, Vector2 v2) => v1.x < v2.x && v1.y < v2.y;
public static Vector2 operator +(Vector2 v1, Vector2 v2) => Raylib.Vector2Add(v1, v2);
public static Vector2 operator -(Vector2 v1, Vector2 v2) => Raylib.Vector2Subtract(v1, v2);
public static Vector2 operator *(Vector2 v1, Vector2 v2) => Raylib.Vector2Multiplyv(v1, v2);
public static Vector2 operator *(Vector2 v, float scale) => Raylib.Vector2Scale(v, scale);
public static Vector2 operator *(float scale, Vector2 v) => Raylib.Vector2Scale(v, scale);
public static Vector2 operator /(Vector2 v1, Vector2 v2) => Raylib.Vector2DivideV(v1, v2);
public static Vector2 operator /(Vector2 v1, float div) => Raylib.Vector2Divide(v1, div);
public static Vector2 operator -(Vector2 v1) => Raylib.Vector2Negate(v1);
public static Vector2 Lerp(Vector2 value1, Vector2 value2, float amount)
{
return new Vector2(
Raylib.Lerp(value1.X, value2.X, amount),
Raylib.Lerp(value1.Y, value2.Y, amount)
);
}
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 <see cref="Vector2"/> 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 <see cref="Vector2"/> 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
{
// captial option for xna/fna/monogame compatability
public float X { get => x; set => x = value; }
public float Y { get => y; set => y = value; }
public float Z { get => z; set => z = value; }
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) => (obj is Vector3) && Equals((Vector3)obj);
public override int GetHashCode() => 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) => (v1.x == v2.x && v1.y == v2.y && v1.z == v2.z);
public static bool operator !=(Vector3 v1, Vector3 v2) => !(v1 == v2);
public static bool operator >(Vector3 v1, Vector3 v2) => v1.x > v2.x && v1.y > v2.y && v1.z > v2.z;
public static bool operator <(Vector3 v1, Vector3 v2) => v1.x < v2.x && v1.y < v2.y && v1.z < v2.z;
public static Vector3 operator +(Vector3 v1, Vector3 v2) => Raylib.Vector3Add(v1, v2);
public static Vector3 operator -(Vector3 v1, Vector3 v2) => Raylib.Vector3Subtract(v1, v2);
public static Vector3 operator *(Vector3 v1, Vector3 v2) => Raylib.Vector3MultiplyV(v1, v2);
public static Vector3 operator *(Vector3 v, float scale) => Raylib.Vector3Scale(v, scale);
public static Vector3 operator *(float scale, Vector3 v) => Raylib.Vector3Scale(v, scale);
public static Vector3 operator /(Vector3 v1, Vector3 v2) => Raylib.Vector3DivideV(v1, v2);
public static Vector3 operator /(Vector3 v1, float div) => Raylib.Vector3Divide(v1, div);
public static Vector3 operator -(Vector3 v1) => Raylib.Vector3Negate(v1);
public static Vector3 Lerp(Vector3 value1, Vector3 value2, float amount)
{
return new Vector3(
Raylib.Lerp(value1.X, value2.X, amount),
Raylib.Lerp(value1.Y, value2.Y, amount),
Raylib.Lerp(value1.Z, value2.Z, amount)
);
}
}
// 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)
{
this.x = value;
this.y = value;
this.z = value;
this.w = value;
}
public override bool Equals(object obj) => (obj is Vector4) && Equals((Vector4)obj);
public override int GetHashCode() => 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) => (v1.x == v2.x && v1.y == v2.y && v1.z == v2.z && v1.w == v2.w);
public static bool operator !=(Vector4 v1, Vector4 v2) => !(v1 == v2);
public static bool operator >(Vector4 v1, Vector4 v2) => v1.x > v2.x && v1.y > v2.y && v1.z > v2.z && v2.w > v2.w;
public static bool operator <(Vector4 v1, Vector4 v2) => v1.x < v2.x && v1.y < v2.y && v1.z < v2.z && v1.w < v2.w;
}
}

View File

@ -1,5 +1,3 @@
// Physac - https://github.com/raysan5/raylib/blob/master/src/physac.h
using System; using System;
using System.Runtime.InteropServices; using System.Runtime.InteropServices;
@ -27,31 +25,63 @@ namespace Raylib
public float m11; public float m11;
} }
// [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Ansi)] // @TODO Custom array marshall issue https://github.com/ChrisDill/Raylib-cs/issues/9
[StructLayout(LayoutKind.Explicit, Size = 388)] // hack same as raylib.cs _MaterialMap_e_FixedBuffer
public unsafe struct PolygonData // no easy way to marshall arrays of custom types. no idea why?!?!
// Span<T> seems to need ref struct.
public unsafe struct _Polygon_e_FixedBuffer
{ {
[FieldOffset(0)] public Vector2 v0;
public uint vertexCount; // Current used vertex and normals count public Vector2 v1;
[FieldOffset(4)] public Vector2 v2;
public unsafe Vector2* positions; public Vector2 v3;
[FieldOffset(196)] public Vector2 v4;
public unsafe Vector2* normals; public Vector2 v5;
public Vector2 v6;
public Vector2 v7;
public Vector2 v8;
public Vector2 v9;
public Vector2 v10;
public Vector2 v11;
public Vector2 v12;
public Vector2 v13;
public Vector2 v14;
public Vector2 v15;
public Vector2 v16;
public Vector2 v17;
public Vector2 v18;
public Vector2 v19;
public Vector2 v20;
public Vector2 v21;
public Vector2 v22;
public Vector2 v23;
public Vector2 v24;
public Vector2 this[int index]
{
get
{
fixed (Vector2* e = &v0)
return e[index];
}
}
} }
// [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Ansi)] [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Ansi)]
[StructLayout(LayoutKind.Explicit, Size = 424)] public struct PolygonData
{
public uint vertexCount; // Current used vertex and normals count
public _Polygon_e_FixedBuffer positions; // Polygon vertex positions vectors
public _Polygon_e_FixedBuffer normals; // Polygon vertex normals vectors
}
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Ansi)]
public struct PhysicsShape public struct PhysicsShape
{ {
[FieldOffset(0)]
public PhysicsShapeType type; // Physics shape type (circle or polygon) public PhysicsShapeType type; // Physics shape type (circle or polygon)
[FieldOffset(8)]
public IntPtr body; // Shape physics body reference public IntPtr body; // Shape physics body reference
[FieldOffset(16)]
public float radius; // Circle shape radius (used for circle shapes) public float radius; // Circle shape radius (used for circle shapes)
[FieldOffset(20)]
public Mat2 transform; // Vertices transform matrix 2x2 public Mat2 transform; // Vertices transform matrix 2x2
[FieldOffset(36)]
public PolygonData vertexData; // Polygon shape vertices position and normals data (just used for polygon shapes) public PolygonData vertexData; // Polygon shape vertices position and normals data (just used for polygon shapes)
} }
@ -59,6 +89,7 @@ namespace Raylib
public partial struct PhysicsBodyData public partial struct PhysicsBodyData
{ {
public uint id; public uint id;
[MarshalAs(UnmanagedType.Bool)]
public bool enabled; public bool enabled;
public Vector2 position; public Vector2 position;
public Vector2 velocity; public Vector2 velocity;
@ -73,48 +104,26 @@ namespace Raylib
public float staticFriction; public float staticFriction;
public float dynamicFriction; public float dynamicFriction;
public float restitution; public float restitution;
[MarshalAs(UnmanagedType.Bool)]
public bool useGravity; public bool useGravity;
[MarshalAs(UnmanagedType.Bool)]
public bool isGrounded; public bool isGrounded;
[MarshalAs(UnmanagedType.Bool)]
public bool freezeOrient; public bool freezeOrient;
public PhysicsShape shape; public PhysicsShape shape;
// convert c bool(stored as byte) to bool
/*public bool enabled
{
get { return Convert.ToBoolean(bEnabled); }
set {
bEnabled = Convert.ToByte(value); }
}
public bool useGravity
{
get { return Convert.ToBoolean(bUseGravity); }
set { bUseGravity = Convert.ToByte(value); }
}
public bool isGrounded
{
get { return bIsGrounded != 0; }
set { bIsGrounded = (byte)(value ? 1 : 0); }
}
public bool freezeOrient
{
get { return Convert.ToBoolean(bFreezeOrient); }
set { bFreezeOrient = Convert.ToByte(value); }
}*/
} }
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Ansi)] [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Ansi)]
public unsafe struct PhysicsManifoldData public struct PhysicsManifoldData
{ {
public uint id; // Reference unique identifier public uint id; // Reference unique identifier
public IntPtr bodyA; // Manifold first physics body reference public IntPtr bodyA; // Manifold first physics body reference
public IntPtr bodyB; // Manifold second physics body reference public IntPtr bodyB; // Manifold second physics body reference
public float penetration; // Depth of penetration from collision public float penetration; // Depth of penetration from collision
public Vector2 normal; // Normal direction vector from 'a' to 'b' public Vector2 normal; // Normal direction vector from 'a' to 'b'
public unsafe Vector2* contacts; // Points of contact during collision public Vector2 contactsA; // Points of contact during collision
public uint contactsCount; // Current collision number of contacts public Vector2 contactsB; // Points of contact during collision
public uint contactsCount; // Current collision number of contacts
public float restitution; // Mixed restitution during collision public float restitution; // Mixed restitution during collision
public float dynamicFriction; // Mixed dynamic friction during collision public float dynamicFriction; // Mixed dynamic friction during collision
public float staticFriction; // Mixed static friction during collision public float staticFriction; // Mixed static friction during collision

View File

@ -1,207 +1,129 @@
// Raygui - https://github.com/raysan5/raygui/blob/master/src/raygui.h
using System; using System;
using System.Runtime.InteropServices; using System.Runtime.InteropServices;
using System.Text;
namespace Raylib namespace Raylib
{ {
#region Raylib-cs Enums // Gui global state enum
enum GuiControlState
// Gui properties enumeration
enum GuiProperty
{ {
//-------------------------------------------- GUI_STATE_NORMAL = 0,
// NOTE: This first set of properties is for general style, GUI_STATE_FOCUSED,
// following control-specific properties overwritte those styles GUI_STATE_PRESSED,
DEFAULT_BACKGROUND_COLOR = 0, GUI_STATE_DISABLED,
DEFAULT_LINES_COLOR,
DEFAULT_TEXT_FONT,
DEFAULT_TEXT_SIZE,
DEFAULT_BORDER_WIDTH,
DEFAULT_BORDER_COLOR_NORMAL,
DEFAULT_BASE_COLOR_NORMAL,
DEFAULT_TEXT_COLOR_NORMAL,
DEFAULT_BORDER_COLOR_FOCUSED,
DEFAULT_BASE_COLOR_FOCUSED,
DEFAULT_TEXT_COLOR_FOCUSED,
DEFAULT_BORDER_COLOR_PRESSED,
DEFAULT_BASE_COLOR_PRESSED,
DEFAULT_TEXT_COLOR_PRESSED,
DEFAULT_BORDER_COLOR_DISABLED,
DEFAULT_BASE_COLOR_DISABLED,
DEFAULT_TEXT_COLOR_DISABLED,
//--------------------------------------------
// Label
LABEL_TEXT_COLOR_NORMAL,
LABEL_TEXT_COLOR_FOCUSED,
LABEL_TEXT_COLOR_PRESSED,
LABEL_TEXT_COLOR_DISABLED,
// Button
BUTTON_BORDER_WIDTH,
BUTTON_BORDER_COLOR_NORMAL,
BUTTON_BASE_COLOR_NORMAL,
BUTTON_TEXT_COLOR_NORMAL,
BUTTON_BORDER_COLOR_FOCUSED,
BUTTON_BASE_COLOR_FOCUSED,
BUTTON_TEXT_COLOR_FOCUSED,
BUTTON_BORDER_COLOR_PRESSED,
BUTTON_BASE_COLOR_PRESSED,
BUTTON_TEXT_COLOR_PRESSED,
BUTTON_BORDER_COLOR_DISABLED,
BUTTON_BASE_COLOR_DISABLED,
BUTTON_TEXT_COLOR_DISABLED,
// Toggle
TOGGLE_BORDER_WIDTH,
TOGGLE_BORDER_COLOR_NORMAL,
TOGGLE_BASE_COLOR_NORMAL,
TOGGLE_TEXT_COLOR_NORMAL,
TOGGLE_BORDER_COLOR_FOCUSED,
TOGGLE_BASE_COLOR_FOCUSED,
TOGGLE_TEXT_COLOR_FOCUSED,
TOGGLE_BORDER_COLOR_PRESSED,
TOGGLE_BASE_COLOR_PRESSED,
TOGGLE_TEXT_COLOR_PRESSED,
TOGGLE_BORDER_COLOR_DISABLED,
TOGGLE_BASE_COLOR_DISABLED,
TOGGLE_TEXT_COLOR_DISABLED,
TOGGLEGROUP_PADDING,
// Slider
SLIDER_BORDER_WIDTH,
SLIDER_SLIDER_WIDTH,
SLIDER_BORDER_COLOR_NORMAL,
SLIDER_BASE_COLOR_NORMAL,
SLIDER_BORDER_COLOR_FOCUSED,
SLIDER_BASE_COLOR_FOCUSED,
SLIDER_BORDER_COLOR_PRESSED,
SLIDER_BASE_COLOR_PRESSED,
SLIDER_BORDER_COLOR_DISABLED,
SLIDER_BASE_COLOR_DISABLED,
// SliderBar
SLIDERBAR_INNER_PADDING,
SLIDERBAR_BORDER_WIDTH,
SLIDERBAR_BORDER_COLOR_NORMAL,
SLIDERBAR_BASE_COLOR_NORMAL,
SLIDERBAR_BORDER_COLOR_FOCUSED,
SLIDERBAR_BASE_COLOR_FOCUSED,
SLIDERBAR_BORDER_COLOR_PRESSED,
SLIDERBAR_BASE_COLOR_PRESSED,
SLIDERBAR_BORDER_COLOR_DISABLED,
SLIDERBAR_BASE_COLOR_DISABLED,
// ProgressBar
PROGRESSBAR_INNER_PADDING,
PROGRESSBAR_BORDER_WIDTH,
PROGRESSBAR_BORDER_COLOR_NORMAL,
PROGRESSBAR_BASE_COLOR_NORMAL,
PROGRESSBAR_BORDER_COLOR_FOCUSED,
PROGRESSBAR_BASE_COLOR_FOCUSED,
PROGRESSBAR_BORDER_COLOR_PRESSED,
PROGRESSBAR_BASE_COLOR_PRESSED,
PROGRESSBAR_BORDER_COLOR_DISABLED,
PROGRESSBAR_BASE_COLOR_DISABLED,
// ValueBox
VALUEBOX_BUTTON_PADDING,
VALUEBOX_BUTTONS_WIDTH,
VALUEBOX_BORDER_COLOR_NORMAL,
VALUEBOX_BASE_COLOR_NORMAL,
VALUEBOX_TEXT_COLOR_NORMAL,
VALUEBOX_BORDER_COLOR_FOCUSED,
VALUEBOX_BASE_COLOR_FOCUSED,
VALUEBOX_TEXT_COLOR_FOCUSED,
VALUEBOX_BORDER_COLOR_PRESSED,
VALUEBOX_BASE_COLOR_PRESSED,
VALUEBOX_TEXT_COLOR_PRESSED,
VALUEBOX_BORDER_COLOR_DISABLED,
VALUEBOX_BASE_COLOR_DISABLED,
VALUEBOX_TEXT_COLOR_DISABLED,
// ComboBox
COMBOBOX_BORDER_WIDTH,
COMBOBOX_BUTTON_PADDING,
COMBOBOX_SELECTOR_WIDTH,
COMBOBOX_BORDER_COLOR_NORMAL,
COMBOBOX_BASE_COLOR_NORMAL,
COMBOBOX_TEXT_COLOR_NORMAL,
COMBOBOX_BORDER_COLOR_FOCUSED,
COMBOBOX_BASE_COLOR_FOCUSED,
COMBOBOX_TEXT_COLOR_FOCUSED,
COMBOBOX_BORDER_COLOR_PRESSED,
COMBOBOX_BASE_COLOR_PRESSED,
COMBOBOX_TEXT_COLOR_PRESSED,
COMBOBOX_BORDER_COLOR_DISABLED,
COMBOBOX_BASE_COLOR_DISABLED,
COMBOBOX_TEXT_COLOR_DISABLED,
// CheckBox
CHECKBOX_BORDER_WIDTH,
CHECKBOX_INNER_PADDING,
CHECKBOX_BORDER_COLOR_NORMAL,
CHECKBOX_BASE_COLOR_NORMAL,
CHECKBOX_BORDER_COLOR_FOCUSED,
CHECKBOX_BASE_COLOR_FOCUSED,
CHECKBOX_BORDER_COLOR_PRESSED,
CHECKBOX_BASE_COLOR_PRESSED,
CHECKBOX_BORDER_COLOR_DISABLED,
CHECKBOX_BASE_COLOR_DISABLED,
// TextBox
TEXTBOX_BORDER_WIDTH,
TEXTBOX_BORDER_COLOR_NORMAL,
TEXTBOX_BASE_COLOR_NORMAL,
TEXTBOX_TEXT_COLOR_NORMAL,
TEXTBOX_BORDER_COLOR_FOCUSED,
TEXTBOX_BASE_COLOR_FOCUSED,
TEXTBOX_TEXT_COLOR_FOCUSED,
TEXTBOX_BORDER_COLOR_PRESSED,
TEXTBOX_BASE_COLOR_PRESSED,
TEXTBOX_TEXT_COLOR_PRESSED,
TEXTBOX_BORDER_COLOR_DISABLED,
TEXTBOX_BASE_COLOR_DISABLED,
TEXTBOX_TEXT_COLOR_DISABLED,
// ColorPicker
COLORPICKER_BARS_THICK,
COLORPICKER_BARS_PADDING,
COLORPICKER_BORDER_COLOR_NORMAL,
COLORPICKER_BASE_COLOR_NORMAL,
COLORPICKER_BORDER_COLOR_FOCUSED,
COLORPICKER_BASE_COLOR_FOCUSED,
COLORPICKER_BORDER_COLOR_PRESSED,
COLORPICKER_BASE_COLOR_PRESSED,
COLORPICKER_BORDER_COLOR_DISABLED,
COLORPICKER_BASE_COLOR_DISABLED,
// ListView
LISTVIEW_ELEMENTS_HEIGHT,
LISTVIEW_ELEMENTS_PADDING,
LISTVIEW_BAR_WIDTH,
LISTVIEW_BORDER_COLOR_NORMAL,
LISTVIEW_BASE_COLOR_NORMAL,
LISTVIEW_TEXT_COLOR_NORMAL,
LISTVIEW_BORDER_COLOR_FOCUSED,
LISTVIEW_BASE_COLOR_FOCUSED,
LISTVIEW_TEXT_COLOR_FOCUSED,
LISTVIEW_BORDER_COLOR_PRESSED,
LISTVIEW_BASE_COLOR_PRESSED,
LISTVIEW_TEXT_COLOR_PRESSED,
LISTVIEW_BORDER_COLOR_DISABLED,
LISTVIEW_BASE_COLOR_DISABLED,
LISTVIEW_TEXT_COLOR_DISABLED
} }
// GUI controls state // Gui standard controls
public enum GuiControlState enum GuiControlStandard
{ {
DISABLED = 0, DEFAULT = 0,
NORMAL, LABEL, // LABELBUTTON
FOCUSED, BUTTON, // IMAGEBUTTON
PRESSED TOGGLE, // TOGGLEGROUP
SLIDER, // SLIDERBAR
PROGRESSBAR,
CHECKBOX,
COMBOBOX,
DROPDOWNBOX,
TEXTBOX, // VALUEBOX, SPINNER
LISTVIEW,
COLORPICKER
} }
#endregion // Gui default properties for every control
enum GuiControlProperty
{
BORDER_COLOR_NORMAL = 0,
BASE_COLOR_NORMAL,
TEXT_COLOR_NORMAL,
BORDER_COLOR_FOCUSED,
BASE_COLOR_FOCUSED,
TEXT_COLOR_FOCUSED,
BORDER_COLOR_PRESSED,
BASE_COLOR_PRESSED,
TEXT_COLOR_PRESSED,
BORDER_COLOR_DISABLED,
BASE_COLOR_DISABLED,
TEXT_COLOR_DISABLED,
BORDER_WIDTH,
INNER_PADDING,
RESERVED01,
RESERVED02
}
// Gui extended properties depending on control type
// NOTE: We reserve a fixed size of additional properties per control (8)
// Default properties
enum GuiDefaultProperty
{
TEXT_SIZE = 16,
TEXT_SPACING,
LINES_COLOR,
BACKGROUND_COLOR,
}
// Toggle / ToggleGroup
enum GuiToggleProperty
{
GROUP_PADDING = 16,
}
// Slider / SliderBar
enum GuiSliderProperty
{
SLIDER_WIDTH = 16,
EX_TEXT_PADDING
}
// TextBox / ValueBox / Spinner
enum GuiTextBoxProperty
{
MULTILINE_PADDING = 16,
SPINNER_BUTTON_WIDTH,
SPINNER_BUTTON_PADDING,
SPINNER_BUTTON_BORDER_WIDTH
}
// CheckBox
enum GuiCheckBoxProperty
{
CHECK_TEXT_PADDING = 16
}
// ComboBox
enum GuiComboBoxProperty
{
SELECTOR_WIDTH = 16,
SELECTOR_PADDING
}
// DropdownBox
enum GuiDropdownBoxProperty
{
ARROW_RIGHT_PADDING = 16,
}
// ColorPicker
enum GuiColorPickerProperty
{
COLOR_SELECTOR_SIZE = 16,
BAR_WIDTH, // Lateral bar width
BAR_PADDING, // Lateral bar separation from panel
BAR_SELECTOR_HEIGHT, // Lateral bar selector height
BAR_SELECTOR_PADDING // Lateral bar selector outer padding
}
// ListView
enum GuiListViewProperty
{
ELEMENTS_HEIGHT = 16,
ELEMENTS_PADDING,
SCROLLBAR_WIDTH,
}
public static partial class Raylib public static partial class Raylib
{ {
#region Raylib-cs Variables
#endregion
#region Raylib-cs Functions
// Global gui modification functions // Global gui modification functions
// Enable gui controls (global state) // Enable gui controls (global state)
[DllImport(nativeLibName,CallingConvention = CallingConvention.Cdecl)] [DllImport(nativeLibName,CallingConvention = CallingConvention.Cdecl)]
@ -209,8 +131,24 @@ namespace Raylib
// Disable gui controls (global state) // Disable gui controls (global state)
[DllImport(nativeLibName,CallingConvention = CallingConvention.Cdecl)] [DllImport(nativeLibName,CallingConvention = CallingConvention.Cdecl)]
public static extern void GuiDisable(); public static extern void GuiDisable();
// Lock gui controls (global state)
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
public static extern void GuiLock();
// Unlock gui controls (global state)
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
public static extern void GuiUnlock();
// Set gui state (global state)
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
public static extern void GuiState(int state);
// Set gui custom font (global state)
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
public static extern void GuiFont(Font font);
// Set gui controls alpha (global state), alpha goes from 0.0f to 1.0f // Set gui controls alpha (global state), alpha goes from 0.0f to 1.0f
[DllImport(nativeLibName,CallingConvention = CallingConvention.Cdecl)] [DllImport(nativeLibName,CallingConvention = CallingConvention.Cdecl)]
public static extern void GuiFade(float alpha); public static extern void GuiFade(float alpha);
@ -218,11 +156,11 @@ namespace Raylib
// Style set/get functions // Style set/get functions
// Set one style property // Set one style property
[DllImport(nativeLibName,CallingConvention = CallingConvention.Cdecl)] [DllImport(nativeLibName,CallingConvention = CallingConvention.Cdecl)]
public static extern void GuiSetStyleProperty(int guiProperty, int value); public static extern void GuiSetStyle(int control, int property, int value);
// Get one style property // Get one style property
[DllImport(nativeLibName,CallingConvention = CallingConvention.Cdecl)] [DllImport(nativeLibName,CallingConvention = CallingConvention.Cdecl)]
public static extern int GuiGetStyleProperty(int guiProperty); public static extern int GuiGetStyle(int control, int property);
// Container/separator controls, useful for controls organization // Container/separator controls, useful for controls organization
// Window Box control, shows a window that can be closed // Window Box control, shows a window that can be closed
@ -300,11 +238,11 @@ namespace Raylib
// Text Box control, updates input text // Text Box control, updates input text
[DllImport(nativeLibName,CallingConvention = CallingConvention.Cdecl)] [DllImport(nativeLibName,CallingConvention = CallingConvention.Cdecl)]
public static extern bool GuiTextBox(Rectangle bounds, char text, int textSize, bool freeEdit); public static extern bool GuiTextBox(Rectangle bounds, StringBuilder text, int textSize, bool freeEdit);
// Text Box control with multiple lines // Text Box control with multiple lines
[DllImport(nativeLibName,CallingConvention = CallingConvention.Cdecl)] [DllImport(nativeLibName,CallingConvention = CallingConvention.Cdecl)]
public static extern bool GuiTextBoxMulti(Rectangle bounds, string text, int textSize, bool editMode); public static extern bool GuiTextBoxMulti(Rectangle bounds, StringBuilder text, int textSize, bool editMode);
// Slider control, returns selected value // Slider control, returns selected value
[DllImport(nativeLibName,CallingConvention = CallingConvention.Cdecl)] [DllImport(nativeLibName,CallingConvention = CallingConvention.Cdecl)]
@ -349,8 +287,6 @@ namespace Raylib
// Message Box control, displays a message // Message Box control, displays a message
[DllImport(nativeLibName,CallingConvention = CallingConvention.Cdecl)] [DllImport(nativeLibName,CallingConvention = CallingConvention.Cdecl)]
public static extern bool GuiMessageBox(Rectangle bounds, string windowTitle, string message); public static extern bool GuiMessageBox(Rectangle bounds, string windowTitle, string message);
#endregion
} }
} }

View File

@ -1,13 +1,9 @@
// Raylib - https://github.com/raysan5/raylib/blob/master/src/raylib.h
using System; using System;
using System.Runtime.InteropServices; using System.Runtime.InteropServices;
using System.Security; using System.Security;
namespace Raylib namespace Raylib
{ {
#region Raylib-cs Enums
//---------------------------------------------------------------------------------- //----------------------------------------------------------------------------------
// Enumerators Definition // Enumerators Definition
//---------------------------------------------------------------------------------- //----------------------------------------------------------------------------------
@ -426,35 +422,15 @@ namespace Raylib
NPT_3PATCH_HORIZONTAL // Npatch defined by 3x1 tiles NPT_3PATCH_HORIZONTAL // Npatch defined by 3x1 tiles
} }
#endregion
#region Raylib-cs Types
// Color type, RGBA (32bit) // Color type, RGBA (32bit)
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Ansi)] [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Ansi)]
public struct Color public partial struct Color
{ {
public byte r; public byte r;
public byte g; public byte g;
public byte b; public byte b;
public byte a; public byte a;
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);
}
// extension to access colours from struct // extension to access colours from struct
// Custom raylib color palette for amazing visuals // Custom raylib color palette for amazing visuals
public static Color LIGHTGRAY = new Color(200, 200, 200, 255); public static Color LIGHTGRAY = new Color(200, 200, 200, 255);
@ -648,6 +624,7 @@ namespace Raylib
public float value; public float value;
} }
// @TODO Custom array marshall issue https://github.com/ChrisDill/Raylib-cs/issues/9
public unsafe struct _MaterialMap_e_FixedBuffer public unsafe struct _MaterialMap_e_FixedBuffer
{ {
public MaterialMap maps0; public MaterialMap maps0;
@ -782,24 +759,52 @@ namespace Raylib
public fixed float chromaAbCorrection[4]; public fixed float chromaAbCorrection[4];
} }
#endregion
[SuppressUnmanagedCodeSecurity] [SuppressUnmanagedCodeSecurity]
public static partial class Raylib public static partial class Raylib
{ {
#region Raylib-cs Variables
// Used by DllImport to load the native library. // Used by DllImport to load the native library.
public const string nativeLibName = "raylib"; public const string nativeLibName = "raylib";
public const float DEG2RAD = (float)Math.PI / 180.0f; public const float DEG2RAD = (float)Math.PI / 180.0f;
public const float RAD2DEG = 180.0f / (float)Math.PI; public const float RAD2DEG = 180.0f / (float)Math.PI;
// 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 const int MAX_SHADER_LOCATIONS = 32; public const int MAX_SHADER_LOCATIONS = 32;
public const int MAX_MATERIAL_MAPS = 12; public const int MAX_MATERIAL_MAPS = 12;
#endregion
#region Raylib-cs Functions
//------------------------------------------------------------------------------------ //------------------------------------------------------------------------------------
// Window and Graphics Device Functions (Module: core) // Window and Graphics Device Functions (Module: core)
@ -890,12 +895,12 @@ namespace Raylib
public static extern IntPtr GetWindowHandle(); public static extern IntPtr GetWindowHandle();
// Get current clipboard text // Get current clipboard text
//[DllImport(nativeLibName,CallingConvention = CallingConvention.Cdecl)] [DllImport(nativeLibName,CallingConvention = CallingConvention.Cdecl)]
//public static extern string GetClipboard(); public static extern string GetClipboard();
// Set current clipboard text // Set current clipboard text
//[DllImport(nativeLibName,CallingConvention = CallingConvention.Cdecl)] [DllImport(nativeLibName,CallingConvention = CallingConvention.Cdecl)]
//public static extern void SetClipboard(string text); public static extern void SetClipboard(string text);
// Cursor-related functions // Cursor-related functions
// Shows cursor // Shows cursor
@ -1165,11 +1170,11 @@ namespace Raylib
// Detect if a gamepad button has been released once // Detect if a gamepad button has been released once
[DllImport(nativeLibName,CallingConvention = CallingConvention.Cdecl)] [DllImport(nativeLibName,CallingConvention = CallingConvention.Cdecl)]
public static extern bool IsGamepadButtonReleased(int gamepad, int button); public static extern bool IsGamepadButtonReleased(GamepadNumber gamepad, int button);
// Detect if a gamepad button is NOT being pressed // Detect if a gamepad button is NOT being pressed
[DllImport(nativeLibName,CallingConvention = CallingConvention.Cdecl)] [DllImport(nativeLibName,CallingConvention = CallingConvention.Cdecl)]
public static extern bool IsGamepadButtonUp(int gamepad, int button); public static extern bool IsGamepadButtonUp(GamepadNumber gamepad, int button);
// Get the last gamepad button pressed // Get the last gamepad button pressed
[DllImport(nativeLibName,CallingConvention = CallingConvention.Cdecl)] [DllImport(nativeLibName,CallingConvention = CallingConvention.Cdecl)]
@ -1684,6 +1689,10 @@ namespace Raylib
[DllImport(nativeLibName,CallingConvention = CallingConvention.Cdecl)] [DllImport(nativeLibName,CallingConvention = CallingConvention.Cdecl)]
public static extern void DrawTextureRec(Texture2D texture, Rectangle sourceRec, Vector2 position, Color tint); public static extern void DrawTextureRec(Texture2D texture, Rectangle sourceRec, Vector2 position, Color tint);
// Draw texture quad with tiling and offset parameters
[DllImport(nativeLibName,CallingConvention = CallingConvention.Cdecl)]
public static extern void DrawTextureQuad(Texture2D texture, Vector2 tiling, Vector2 offset, Rectangle quad, Color tint);
// Draw a part of a texture defined by a rectangle with 'pro' parameters // Draw a part of a texture defined by a rectangle with 'pro' parameters
[DllImport(nativeLibName,CallingConvention = CallingConvention.Cdecl)] [DllImport(nativeLibName,CallingConvention = CallingConvention.Cdecl)]
public static extern void DrawTexturePro(Texture2D texture, Rectangle sourceRec, Rectangle destRec, Vector2 origin, float rotation, Color tint); public static extern void DrawTexturePro(Texture2D texture, Rectangle sourceRec, Rectangle destRec, Vector2 origin, float rotation, Color tint);
@ -2307,8 +2316,6 @@ namespace Raylib
// Set pitch for audio stream (1.0 is base level) // Set pitch for audio stream (1.0 is base level)
[DllImport(nativeLibName,CallingConvention = CallingConvention.Cdecl)] [DllImport(nativeLibName,CallingConvention = CallingConvention.Cdecl)]
public static extern void SetAudioStreamPitch(AudioStream stream, float pitch); public static extern void SetAudioStreamPitch(AudioStream stream, float pitch);
#endregion
} }
} }

19
Bindings/Raylib.projitems Normal file
View File

@ -0,0 +1,19 @@
<?xml version="1.0" encoding="utf-8"?>
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<MSBuildAllProjects>$(MSBuildAllProjects);$(MSBuildThisFileFullPath)</MSBuildAllProjects>
<HasSharedItems>true</HasSharedItems>
<SharedGUID>f660ff67-d70e-4ae0-9080-d922243e9b6e</SharedGUID>
</PropertyGroup>
<PropertyGroup Label="Configuration">
<Import_RootNamespace>Raylib</Import_RootNamespace>
</PropertyGroup>
<ItemGroup>
<Compile Include="$(MSBuildThisFileDirectory)Easings.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Extensions.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Physac.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Raygui.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Raylib.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Raymath.cs" />
</ItemGroup>
</Project>

13
Bindings/Raylib.shproj Normal file
View File

@ -0,0 +1,13 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup Label="Globals">
<ProjectGuid>f660ff67-d70e-4ae0-9080-d922243e9b6e</ProjectGuid>
<MinimumVisualStudioVersion>14.0</MinimumVisualStudioVersion>
</PropertyGroup>
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<Import Project="$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)\CodeSharing\Microsoft.CodeSharing.Common.Default.props" />
<Import Project="$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)\CodeSharing\Microsoft.CodeSharing.Common.props" />
<PropertyGroup />
<Import Project="Raylib.projitems" Label="Shared" />
<Import Project="$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)\CodeSharing\Microsoft.CodeSharing.CSharp.targets" />
</Project>

View File

@ -1,328 +1,33 @@
// Raymath - https://github.com/raysan5/raylib/blob/master/src/raymath.h
using System; using System;
using System.Runtime.InteropServices; using System.Runtime.InteropServices;
namespace Raylib namespace Raylib
{ {
#region Raylib-cs Types
// Vector2 type // Vector2 type
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Ansi)] [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Ansi)]
public struct Vector2 public partial struct Vector2
{ {
public float x; public float x;
public float y; 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 + ")";
}
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); }
}
public static float Length(Vector2 v)
{
return Raylib.Vector2Length(v);
}
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 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 Vector2 Normalize(Vector2 v)
{
return Raylib.Vector2Normalize(v);
}
#region Public Static 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 /(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);
}
#endregion
} }
// Vector3 type // Vector3 type
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Ansi)] [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Ansi)]
public struct Vector3 public partial struct Vector3
{ {
public float x; public float x;
public float y; public float y;
public float z; 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 + ")";
}
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); }
}
#region Public Static 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 /(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);
}
#endregion
} }
// Vector4 type // Vector4 type
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Ansi)] [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Ansi)]
public struct Vector4 public partial struct Vector4
{ {
public float x; public float x;
public float y; public float y;
public float z; public float z;
public float w; 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)
{
this.x = value;
this.y = value;
this.z = value;
this.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 + ")";
}
} }
// Matrix type (OpenGL style 4x4 - right handed, column major) // Matrix type (OpenGL style 4x4 - right handed, column major)
@ -355,16 +60,32 @@ namespace Raylib
} }
} }
#endregion
public static partial class Raylib public static partial class Raylib
{ {
#region Raylib-cs Functions
// Clamp float value // Clamp float value
[DllImport(nativeLibName,CallingConvention = CallingConvention.Cdecl)] [DllImport(nativeLibName,CallingConvention = CallingConvention.Cdecl)]
public static extern float Clamp(float value, float min, float max); public static extern float Clamp(float value, float min, float max);
/// <summary>
/// Linearly interpolates between two values.
/// </summary>
/// <param name="value1">Source value.</param>
/// <param name="value2">Source value.</param>
/// <param name="amount">
/// Value between 0 and 1 indicating the weight of value2.
/// </param>
/// <returns>Interpolated value.</returns>
/// <remarks>
/// This method performs the linear interpolation based on the following formula.
/// <c>value1 + (value2 - value1) * amount</c>
/// Passing amount a value of 0 will cause value1 to be returned, a value of 1 will
/// cause value2 to be returned.
/// </remarks>
public static float Lerp(float value1, float value2, float amount)
{
return value1 + (value2 - value1) * amount;
}
// Vector with components value 0.0f // Vector with components value 0.0f
[DllImport(nativeLibName,CallingConvention = CallingConvention.Cdecl)] [DllImport(nativeLibName,CallingConvention = CallingConvention.Cdecl)]
public static extern Vector2 Vector2Zero(); public static extern Vector2 Vector2Zero();
@ -671,8 +392,6 @@ namespace Raylib
// Transform a quaternion given a transformation matrix // Transform a quaternion given a transformation matrix
[DllImport(nativeLibName,CallingConvention = CallingConvention.Cdecl)] [DllImport(nativeLibName,CallingConvention = CallingConvention.Cdecl)]
public static extern Quaternion QuaternionTransform(Quaternion q, Matrix mat); public static extern Quaternion QuaternionTransform(Quaternion q, Matrix mat);
#endregion
} }
} }