2
0
mirror of https://github.com/raylib-cs/raylib-cs synced 2025-06-30 19:03:42 -04:00

- Improvements for 2.5 release. Alot more work than I expected.

- Examples are out of date and will need to be regenerated before release.
This commit is contained in:
2019-04-22 07:40:01 +01:00
committed by Chris Dill
parent 1236e4979a
commit dd9710fc57
35 changed files with 5867 additions and 11824 deletions

View File

@ -1,273 +1,272 @@
/* Raylib-cs
* Easings.cs - Useful easing functions for values animation
* Copyright 2019 Chris Dill
*
* Release under zLib License.
* See LICENSE for details.
*/
using System;
using System.Runtime.InteropServices;
namespace Raylib
{
public static partial class Raylib
{
// Linear Easing functions
public static float EaseLinearNone(float t, float b, float c, float d)
{
return (c * t / d + b);
}
public static float EaseLinearIn(float t, float b, float c, float d)
{
return (c * t / d + b);
}
public static float EaseLinearOut(float t, float b, float c, float d)
{
return (c * t / d + b);
}
public static float EaseLinearInOut(float t,float b, float c, float d)
{
return (c * t / d + b);
}
// Sine Easing functions
public static float EaseSineIn(float t, float b, float c, float d)
{
return (-c * (float)Math.Cos(t / d * ((float)Math.PI / 2)) + c + b);
}
public static float EaseSineOut(float t, float b, float c, float d)
{
return (c * (float)Math.Sin(t / d * ((float)Math.PI / 2)) + b);
}
public static float EaseSineInOut(float t, float b, float c, float d)
{
return (-c / 2 * ((float)Math.Cos((float)Math.PI * t / d) - 1) + b);
}
// Circular Easing functions
public static float EaseCircIn(float t, float b, float c, float d)
{
return (-c * ((float)Math.Sqrt(1 - (t /= d) * t) - 1) + b);
}
public static float EaseCircOut(float t, float b, float c, float d)
{
return (c * (float)Math.Sqrt(1 - (t = t / d - 1) * t) + b);
}
public static float EaseCircInOut(float t, float b, float c, float d)
{
if ((t /= d / 2) < 1)
{
return (-c / 2 * ((float)Math.Sqrt(1 - t * t) - 1) + b);
}
return (c / 2 * ((float)Math.Sqrt(1 - t * (t -= 2)) + 1) + b);
}
// Cubic Easing functions
public static float EaseCubicIn(float t, float b, float c, float d)
{
return (c*(t /= d) * t * t + b);
}
public static float EaseCubicOut(float t, float b, float c, float d)
{
return (c * ((t = t / d - 1) * t * t + 1) + b);
}
public static float EaseCubicInOut(float t, float b, float c, float d)
{
if ((t/=d/2) < 1)
{
return (c / 2 * t * t * t + b);
}
return (c / 2 * ((t -= 2)* t * t + 2) + b);
}
// Quadratic Easing functions
public static float EaseQuadIn(float t, float b, float c, float d)
{
return (c * (t /= d) * t + b);
}
public static float EaseQuadOut(float t, float b, float c, float d)
{
return (-c * (t /= d) * (t - 2) + b);
}
public static float EaseQuadInOut(float t, float b, float c, float d)
{
if ((t /= d / 2) < 1)
{
return (((c / 2) * (t * t)) + b);
}
return (-c / 2 * (((t - 2) * (--t)) - 1) + b);
}
// Exponential Easing functions
public static float EaseExpoIn(float t, float b, float c, float d)
{
return (t == 0) ? b : (c * (float)Math.Pow(2, 10 * (t / d - 1)) + b);
}
public static float EaseExpoOut(float t, float b, float c, float d)
{
return (t == d) ? (b + c) : (c * (-(float)Math.Pow(2, -10 * t / d) + 1) + b);
}
public static float EaseExpoInOut(float t, float b, float c, float d)
{
if (t == 0)
{
return b;
}
if (t == d)
{
return (b + c);
}
if ((t /= d / 2) < 1)
{
return (c / 2 * (float)Math.Pow(2, 10 * (t - 1)) + b);
}
return (c / 2 * (-(float)Math.Pow(2, -10 * --t) + 2) + b);
}
// Back Easing functions
public static float EaseBackIn(float t, float b, float c, float d)
{
float s = 1.70158f;
float postFix = t /= d;
return (c * (postFix) * t *((s + 1) * t - s) + b);
}
public static float EaseBackOut(float t, float b, float c, float d)
{
float s = 1.70158f;
return (c * ((t = t / d - 1) * t * ((s + 1) * t + s) + 1) + b);
}
public static float EaseBackInOut(float t, float b, float c, float d)
{
float s = 1.70158f;
if ((t/=d/2) < 1)
{
return (c/2*(t*t*(((s*=(1.525f)) + 1)*t - s)) + b);
}
float postFix = t-=2;
return (c/2*((postFix)*t*(((s*=(1.525f)) + 1)*t + s) + 2) + b);
}
// Bounce Easing functions
public static float EaseBounceOut(float t, float b, float c, float d)
{
if ((t /= d) < (1/2.75f))
{
return (c * (7.5625f * t * t) + b);
}
else if (t < (2/2.75f))
{
float postFix = t -= (1.5f/2.75f);
return (c * (7.5625f * (postFix) * t + 0.75f) + b);
}
else if (t < (2.5/2.75))
{
float postFix = t -= (2.25f/2.75f);
return (c * (7.5625f * (postFix)*t + 0.9375f) + b);
}
else
{
float postFix = t -= (2.625f / 2.75f);
return (c * (7.5625f * (postFix) * t + 0.984375f) + b);
}
}
public static float EaseBounceIn(float t, float b, float c, float d)
{
return (c - EaseBounceOut(d - t, 0, c, d) + b);
}
public static float EaseBounceInOut(float t, float b, float c, float d)
{
if (t < d / 2)
{
return (EaseBounceIn(t * 2, 0, c, d) * 0.5f + b);
}
else
{
return (EaseBounceOut(t * 2 - d, 0, c, d) * 0.5f + c * 0.5f + b);
}
}
// Elastic Easing functions
public static float EaseElasticIn(float t, float b, float c, float d)
{
if (t == 0)
{
return b;
}
if ((t /= d) == 1)
{
return (b + c);
}
float p = d * 0.3f;
float a = c;
float s = p / 4;
float postFix = a * (float)Math.Pow(2, 10 * (t -= 1));
return (-(postFix * (float)Math.Sin((t * d - s)*(2 * (float)Math.PI) /p )) + b);
}
public static float EaseElasticOut(float t, float b, float c, float d)
{
if (t == 0)
{
return b;
}
if ((t /= d) == 1)
{
return (b + c);
}
float p = d * 0.3f;
float a = c;
float s = p / 4;
return (a * (float)Math.Pow(2,-10 * t) * (float)Math.Sin((t * d - s) * (2 * (float)Math.PI) / p) + c + b);
}
public static float EaseElasticInOut(float t, float b, float c, float d)
{
if (t == 0)
{
return b;
}
if ((t /= d / 2) == 2)
{
return (b + c);
}
float p = d * (0.3f * 1.5f);
float a = c;
float s = p / 4;
float postFix = 0f;
if (t < 1)
{
postFix = a * (float)Math.Pow(2, 10 * (t -= 1));
return -0.5f * (postFix * (float)Math.Sin((t * d - s) * (2 * (float)Math.PI) / p)) + b;
}
postFix = a * (float)Math.Pow(2, -10 * (t -= 1));
return (postFix * (float)Math.Sin((t * d -s)*(2 * (float)Math.PI)/p) * 0.5f + c + b);
}
}
}
/* Raylib-cs
* Easings.cs - Useful easing functions for values animation
* Copyright 2019 Chris Dill
*
* Release under zLib License.
* See LICENSE for details.
*/
using System;
namespace Raylib
{
public static partial class Raylib
{
// Linear Easing functions
public static float EaseLinearNone(float t, float b, float c, float d)
{
return (c * t / d + b);
}
public static float EaseLinearIn(float t, float b, float c, float d)
{
return (c * t / d + b);
}
public static float EaseLinearOut(float t, float b, float c, float d)
{
return (c * t / d + b);
}
public static float EaseLinearInOut(float t, float b, float c, float d)
{
return (c * t / d + b);
}
// Sine Easing functions
public static float EaseSineIn(float t, float b, float c, float d)
{
return (-c * (float)Math.Cos(t / d * ((float)Math.PI / 2)) + c + b);
}
public static float EaseSineOut(float t, float b, float c, float d)
{
return (c * (float)Math.Sin(t / d * ((float)Math.PI / 2)) + b);
}
public static float EaseSineInOut(float t, float b, float c, float d)
{
return (-c / 2 * ((float)Math.Cos((float)Math.PI * t / d) - 1) + b);
}
// Circular Easing functions
public static float EaseCircIn(float t, float b, float c, float d)
{
return (-c * ((float)Math.Sqrt(1 - (t /= d) * t) - 1) + b);
}
public static float EaseCircOut(float t, float b, float c, float d)
{
return (c * (float)Math.Sqrt(1 - (t = t / d - 1) * t) + b);
}
public static float EaseCircInOut(float t, float b, float c, float d)
{
if ((t /= d / 2) < 1)
{
return (-c / 2 * ((float)Math.Sqrt(1 - t * t) - 1) + b);
}
return (c / 2 * ((float)Math.Sqrt(1 - t * (t -= 2)) + 1) + b);
}
// Cubic Easing functions
public static float EaseCubicIn(float t, float b, float c, float d)
{
return (c * (t /= d) * t * t + b);
}
public static float EaseCubicOut(float t, float b, float c, float d)
{
return (c * ((t = t / d - 1) * t * t + 1) + b);
}
public static float EaseCubicInOut(float t, float b, float c, float d)
{
if ((t /= d / 2) < 1)
{
return (c / 2 * t * t * t + b);
}
return (c / 2 * ((t -= 2) * t * t + 2) + b);
}
// Quadratic Easing functions
public static float EaseQuadIn(float t, float b, float c, float d)
{
return (c * (t /= d) * t + b);
}
public static float EaseQuadOut(float t, float b, float c, float d)
{
return (-c * (t /= d) * (t - 2) + b);
}
public static float EaseQuadInOut(float t, float b, float c, float d)
{
if ((t /= d / 2) < 1)
{
return (((c / 2) * (t * t)) + b);
}
return (-c / 2 * (((t - 2) * (--t)) - 1) + b);
}
// Exponential Easing functions
public static float EaseExpoIn(float t, float b, float c, float d)
{
return (t == 0) ? b : (c * (float)Math.Pow(2, 10 * (t / d - 1)) + b);
}
public static float EaseExpoOut(float t, float b, float c, float d)
{
return (t == d) ? (b + c) : (c * (-(float)Math.Pow(2, -10 * t / d) + 1) + b);
}
public static float EaseExpoInOut(float t, float b, float c, float d)
{
if (t == 0)
{
return b;
}
if (t == d)
{
return (b + c);
}
if ((t /= d / 2) < 1)
{
return (c / 2 * (float)Math.Pow(2, 10 * (t - 1)) + b);
}
return (c / 2 * (-(float)Math.Pow(2, -10 * --t) + 2) + b);
}
// Back Easing functions
public static float EaseBackIn(float t, float b, float c, float d)
{
float s = 1.70158f;
float postFix = t /= d;
return (c * (postFix) * t * ((s + 1) * t - s) + b);
}
public static float EaseBackOut(float t, float b, float c, float d)
{
float s = 1.70158f;
return (c * ((t = t / d - 1) * t * ((s + 1) * t + s) + 1) + b);
}
public static float EaseBackInOut(float t, float b, float c, float d)
{
float s = 1.70158f;
if ((t /= d / 2) < 1)
{
return (c / 2 * (t * t * (((s *= (1.525f)) + 1) * t - s)) + b);
}
float postFix = t -= 2;
return (c / 2 * ((postFix) * t * (((s *= (1.525f)) + 1) * t + s) + 2) + b);
}
// Bounce Easing functions
public static float EaseBounceOut(float t, float b, float c, float d)
{
if ((t /= d) < (1 / 2.75f))
{
return (c * (7.5625f * t * t) + b);
}
else if (t < (2 / 2.75f))
{
float postFix = t -= (1.5f / 2.75f);
return (c * (7.5625f * (postFix) * t + 0.75f) + b);
}
else if (t < (2.5 / 2.75))
{
float postFix = t -= (2.25f / 2.75f);
return (c * (7.5625f * (postFix) * t + 0.9375f) + b);
}
else
{
float postFix = t -= (2.625f / 2.75f);
return (c * (7.5625f * (postFix) * t + 0.984375f) + b);
}
}
public static float EaseBounceIn(float t, float b, float c, float d)
{
return (c - EaseBounceOut(d - t, 0, c, d) + b);
}
public static float EaseBounceInOut(float t, float b, float c, float d)
{
if (t < d / 2)
{
return (EaseBounceIn(t * 2, 0, c, d) * 0.5f + b);
}
else
{
return (EaseBounceOut(t * 2 - d, 0, c, d) * 0.5f + c * 0.5f + b);
}
}
// Elastic Easing functions
public static float EaseElasticIn(float t, float b, float c, float d)
{
if (t == 0)
{
return b;
}
if ((t /= d) == 1)
{
return (b + c);
}
float p = d * 0.3f;
float a = c;
float s = p / 4;
float postFix = a * (float)Math.Pow(2, 10 * (t -= 1));
return (-(postFix * (float)Math.Sin((t * d - s) * (2 * (float)Math.PI) / p)) + b);
}
public static float EaseElasticOut(float t, float b, float c, float d)
{
if (t == 0)
{
return b;
}
if ((t /= d) == 1)
{
return (b + c);
}
float p = d * 0.3f;
float a = c;
float s = p / 4;
return (a * (float)Math.Pow(2, -10 * t) * (float)Math.Sin((t * d - s) * (2 * (float)Math.PI) / p) + c + b);
}
public static float EaseElasticInOut(float t, float b, float c, float d)
{
if (t == 0)
{
return b;
}
if ((t /= d / 2) == 2)
{
return (b + c);
}
float p = d * (0.3f * 1.5f);
float a = c;
float s = p / 4;
float postFix = 0f;
if (t < 1)
{
postFix = a * (float)Math.Pow(2, 10 * (t -= 1));
return -0.5f * (postFix * (float)Math.Sin((t * d - s) * (2 * (float)Math.PI) / p)) + b;
}
postFix = a * (float)Math.Pow(2, -10 * (t -= 1));
return (postFix * (float)Math.Sin((t * d - s) * (2 * (float)Math.PI) / p) * 0.5f + c + b);
}
}
}

View File

@ -1,344 +1,526 @@
/* Raylib-cs
* Extensions.cs - Extra features
* Copyright 2019 Chris Dill
*
* Release under zLib License.
* See LICENSE for details.
*/
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;
}
}
/* Raylib-cs
* Extensions.cs - Higher level features over bindings. This file is not automatically generated.
* Copyright 2019 Chris Dill
*
* Release under zLib License.
* See LICENSE for details.
*/
using System;
using System.Text;
using System.Numerics;
namespace Raylib
{
// Extensions to the raylib bindings.
// Seperate for easier code generation.
public partial class Raylib
{
// 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;
}
}
// Small utility for tweening values
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
{
// 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);
}
internal string DebugDisplayString
{
get
{
return string.Concat(
r.ToString(), " ",
g.ToString(), " ",
b.ToString(), " ",
a.ToString()
);
}
}
// Performs linear interpolation of <see cref="Color"/>.
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)
);
}
}
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 BoundingBox
{
public BoundingBox(Vector3 min, Vector3 max)
{
this.min = min;
this.max = max;
}
}
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;
}
}
public partial struct RayHitInfo
{
public RayHitInfo(bool hit, float distance, Vector3 position, Vector3 normal)
{
this.hit = hit;
this.distance = distance;
this.position = position;
this.normal = normal;
}
}
// 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) => (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)
{
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 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
{
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)
{
x = value;
y = value;
z = value;
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,258 +1,258 @@
using System;
using System.Runtime.InteropServices;
namespace Raylib
{
#region Raylib-cs Enums
public enum PhysicsShapeType
{
PHYSICS_CIRCLE,
PHYSICS_POLYGON
}
#endregion
#region Raylib-cs Types
// Mat2 type (used for polygon shape rotation matrix)
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Ansi)]
public struct Mat2
{
public float m00;
public float m01;
public float m10;
public float m11;
}
// @TODO Custom array marshall issue https://github.com/ChrisDill/Raylib-cs/issues/9
// hack same as raylib.cs _MaterialMap_e_FixedBuffer
// 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
{
public Vector2 v0;
public Vector2 v1;
public Vector2 v2;
public Vector2 v3;
public Vector2 v4;
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)]
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 PhysicsShapeType type; // Physics shape type (circle or polygon)
public IntPtr body; // Shape physics body reference
public float radius; // Circle shape radius (used for circle shapes)
public Mat2 transform; // Vertices transform matrix 2x2
public PolygonData vertexData; // Polygon shape vertices position and normals data (just used for polygon shapes)
}
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Ansi)]
public partial struct PhysicsBodyData
{
public uint id;
[MarshalAs(UnmanagedType.Bool)]
public bool enabled;
public Vector2 position;
public Vector2 velocity;
public Vector2 force;
public float angularVelocity;
public float torque;
public float orient;
public float inertia;
public float inverseInertia;
public float mass;
public float inverseMass;
public float staticFriction;
public float dynamicFriction;
public float restitution;
[MarshalAs(UnmanagedType.Bool)]
public bool useGravity;
[MarshalAs(UnmanagedType.Bool)]
public bool isGrounded;
[MarshalAs(UnmanagedType.Bool)]
public bool freezeOrient;
public PhysicsShape shape;
}
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Ansi)]
public struct PhysicsManifoldData
{
public uint id; // Reference unique identifier
public IntPtr bodyA; // Manifold first physics body reference
public IntPtr bodyB; // Manifold second physics body reference
public float penetration; // Depth of penetration from collision
public Vector2 normal; // Normal direction vector from 'a' to 'b'
public Vector2 contactsA; // Points of contact during collision
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 dynamicFriction; // Mixed dynamic friction during collision
public float staticFriction; // Mixed static friction during collision
}
#endregion
public static partial class Raylib
{
#region Raylib-cs Variables
public const int PHYSAC_MAX_BODIES = 64;
public const int PHYSAC_MAX_MANIFOLDS = 4096;
public const int PHYSAC_MAX_VERTICES = 24;
public const int PHYSAC_CIRCLE_VERTICES = 24;
public const float PHYSAC_DESIRED_DELTATIME = 1.0f / 60.0f;
public const float PHYSAC_MAX_TIMESTEP = 0.02f;
public const int PHYSAC_COLLISION_ITERATIONS = 100;
public const float PHYSAC_PENETRATION_ALLOWANCE = 0.05f;
public const float PHYSAC_PENETRATION_CORRECTION = 0.4f;
public const float PHYSAC_PI = 3.14159265358979323846f;
public const float PHYSAC_DEG2RAD = (PHYSAC_PI / 180.0f);
#endregion
#region Raylib-cs Functions
// Initializes physics values, pointers and creates physics loop thread
[DllImport(nativeLibName,CallingConvention = CallingConvention.Cdecl)]
public static extern void InitPhysics();
// Run physics step, to be used if PHYSICS_NO_THREADS is set in your main loop
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
public static extern void RunPhysicsStep();
// Returns true if physics thread is currently enabled
[DllImport(nativeLibName,CallingConvention = CallingConvention.Cdecl)]
public static extern bool IsPhysicsEnabled();
// Sets physics global gravity force
[DllImport(nativeLibName,CallingConvention = CallingConvention.Cdecl)]
public static extern void SetPhysicsGravity(float x, float y);
// Creates a new circle physics body with generic parameters
[DllImport(nativeLibName, EntryPoint = "CreatePhysicsBodyCircle")]
private static extern IntPtr CreatePhysicsBodyCircleImport(Vector2 pos, float radius, float density);
public static PhysicsBodyData CreatePhysicsBodyCircle(Vector2 pos, float radius, float density)
{
var body = CreatePhysicsBodyCircleImport(pos, radius, density);
var data = (PhysicsBodyData)Marshal.PtrToStructure(body, typeof(PhysicsBodyData));
return data;
}
// Creates a new rectangle physics body with generic parameters
[DllImport(nativeLibName, EntryPoint = "CreatePhysicsBodyRectangle")]
private static extern IntPtr CreatePhysicsBodyRectangleImport(Vector2 pos, float width, float height, float density);
public static PhysicsBodyData CreatePhysicsBodyRectangle(Vector2 pos, float width, float height, float density)
{
var body = CreatePhysicsBodyRectangleImport(pos, width, height, density);
var data = (PhysicsBodyData)Marshal.PtrToStructure(body, typeof(PhysicsBodyData));
return data;
}
// Creates a new polygon physics body with generic parameters
[DllImport(nativeLibName, EntryPoint = "CreatePhysicsBodyPolygon")]
private static extern IntPtr CreatePhysicsBodyPolygonImport(Vector2 pos, float radius, int sides, float density);
public static PhysicsBodyData CreatePhysicsBodyPolygon(Vector2 pos, float radius, int sides, float density)
{
var body = CreatePhysicsBodyPolygonImport(pos, radius, sides, density);
var data = (PhysicsBodyData)Marshal.PtrToStructure(body, typeof(PhysicsBodyData));
return data;
}
// Adds a force to a physics body
[DllImport(nativeLibName,CallingConvention = CallingConvention.Cdecl)]
public static extern void PhysicsAddForce(PhysicsBodyData body, Vector2 force);
// Adds an angular force to a physics body
[DllImport(nativeLibName,CallingConvention = CallingConvention.Cdecl)]
public static extern void PhysicsAddTorque(PhysicsBodyData body, float amount);
// Shatters a polygon shape physics body to little physics bodies with explosion force
[DllImport(nativeLibName,CallingConvention = CallingConvention.Cdecl)]
public static extern void PhysicsShatter(PhysicsBodyData body, Vector2 position, float force);
// Returns the current amount of created physics bodies
[DllImport(nativeLibName,CallingConvention = CallingConvention.Cdecl)]
public static extern int GetPhysicsBodiesCount();
// Returns a physics body of the bodies pool at a specific index
[DllImport(nativeLibName, EntryPoint = "GetPhysicsBody")]
public static extern IntPtr GetPhysicsBodyImport(int index);
public static PhysicsBodyData GetPhysicsBody(int index)
{
var body = GetPhysicsBodyImport(index);
var data = (PhysicsBodyData)Marshal.PtrToStructure(body, typeof(PhysicsBodyData));
return data;
}
// Returns the physics body shape type (PHYSICS_CIRCLE or PHYSICS_POLYGON)
[DllImport(nativeLibName,CallingConvention = CallingConvention.Cdecl)]
public static extern int GetPhysicsShapeType(int index);
// Returns the amount of vertices of a physics body shape
[DllImport(nativeLibName,CallingConvention = CallingConvention.Cdecl)]
public static extern int GetPhysicsShapeVerticesCount(int index);
// Returns transformed position of a body shape (body position + vertex transformed position)
[DllImport(nativeLibName,CallingConvention = CallingConvention.Cdecl)]
public static extern Vector2 GetPhysicsShapeVertex(PhysicsBodyData body, int vertex);
// Sets physics body shape transform based on radians parameter
[DllImport(nativeLibName,CallingConvention = CallingConvention.Cdecl)]
public static extern void SetPhysicsBodyRotation(PhysicsBodyData body, float radians);
// Unitializes and destroy a physics body
[DllImport(nativeLibName,CallingConvention = CallingConvention.Cdecl)]
public static extern void DestroyPhysicsBody(PhysicsBodyData body);
// Destroys created physics bodies and manifolds and resets global values
[DllImport(nativeLibName,CallingConvention = CallingConvention.Cdecl)]
public static extern void ResetPhysics();
// Unitializes physics pointers and closes physics loop thread
[DllImport(nativeLibName,CallingConvention = CallingConvention.Cdecl)]
public static extern void ClosePhysics();
#endregion
}
}
using System;
using System.Runtime.InteropServices;
namespace Raylib
{
#region Raylib-cs Enums
public enum PhysicsShapeType
{
PHYSICS_CIRCLE,
PHYSICS_POLYGON
}
#endregion
#region Raylib-cs Types
// Mat2 type (used for polygon shape rotation matrix)
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Ansi)]
public struct Mat2
{
public float m00;
public float m01;
public float m10;
public float m11;
}
// @TODO Custom array marshall issue https://github.com/ChrisDill/Raylib-cs/issues/9
// hack same as raylib.cs _MaterialMap_e_FixedBuffer
// 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
{
public Vector2 v0;
public Vector2 v1;
public Vector2 v2;
public Vector2 v3;
public Vector2 v4;
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)]
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 PhysicsShapeType type; // Physics shape type (circle or polygon)
public IntPtr body; // Shape physics body reference
public float radius; // Circle shape radius (used for circle shapes)
public Mat2 transform; // Vertices transform matrix 2x2
public PolygonData vertexData; // Polygon shape vertices position and normals data (just used for polygon shapes)
}
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Ansi)]
public partial struct PhysicsBodyData
{
public uint id;
[MarshalAs(UnmanagedType.Bool)]
public bool enabled;
public Vector2 position;
public Vector2 velocity;
public Vector2 force;
public float angularVelocity;
public float torque;
public float orient;
public float inertia;
public float inverseInertia;
public float mass;
public float inverseMass;
public float staticFriction;
public float dynamicFriction;
public float restitution;
[MarshalAs(UnmanagedType.Bool)]
public bool useGravity;
[MarshalAs(UnmanagedType.Bool)]
public bool isGrounded;
[MarshalAs(UnmanagedType.Bool)]
public bool freezeOrient;
public PhysicsShape shape;
}
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Ansi)]
public struct PhysicsManifoldData
{
public uint id; // Reference unique identifier
public IntPtr bodyA; // Manifold first physics body reference
public IntPtr bodyB; // Manifold second physics body reference
public float penetration; // Depth of penetration from collision
public Vector2 normal; // Normal direction vector from 'a' to 'b'
public Vector2 contactsA; // Points of contact during collision
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 dynamicFriction; // Mixed dynamic friction during collision
public float staticFriction; // Mixed static friction during collision
}
#endregion
public static partial class Raylib
{
#region Raylib-cs Variables
public const int PHYSAC_MAX_BODIES = 64;
public const int PHYSAC_MAX_MANIFOLDS = 4096;
public const int PHYSAC_MAX_VERTICES = 24;
public const int PHYSAC_CIRCLE_VERTICES = 24;
public const float PHYSAC_DESIRED_DELTATIME = 1.0f / 60.0f;
public const float PHYSAC_MAX_TIMESTEP = 0.02f;
public const int PHYSAC_COLLISION_ITERATIONS = 100;
public const float PHYSAC_PENETRATION_ALLOWANCE = 0.05f;
public const float PHYSAC_PENETRATION_CORRECTION = 0.4f;
public const float PHYSAC_PI = 3.14159265358979323846f;
public const float PHYSAC_DEG2RAD = (PHYSAC_PI / 180.0f);
#endregion
#region Raylib-cs Functions
// Initializes physics values, pointers and creates physics loop thread
[DllImport(nativeLibName,CallingConvention = CallingConvention.Cdecl)]
public static extern void InitPhysics();
// Run physics step, to be used if PHYSICS_NO_THREADS is set in your main loop
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
public static extern void RunPhysicsStep();
// Returns true if physics thread is currently enabled
[DllImport(nativeLibName,CallingConvention = CallingConvention.Cdecl)]
public static extern bool IsPhysicsEnabled();
// Sets physics global gravity force
[DllImport(nativeLibName,CallingConvention = CallingConvention.Cdecl)]
public static extern void SetPhysicsGravity(float x, float y);
// Creates a new circle physics body with generic parameters
[DllImport(nativeLibName, EntryPoint = "CreatePhysicsBodyCircle")]
private static extern IntPtr CreatePhysicsBodyCircleImport(Vector2 pos, float radius, float density);
public static PhysicsBodyData CreatePhysicsBodyCircle(Vector2 pos, float radius, float density)
{
var body = CreatePhysicsBodyCircleImport(pos, radius, density);
var data = (PhysicsBodyData)Marshal.PtrToStructure(body, typeof(PhysicsBodyData));
return data;
}
// Creates a new rectangle physics body with generic parameters
[DllImport(nativeLibName, EntryPoint = "CreatePhysicsBodyRectangle")]
private static extern IntPtr CreatePhysicsBodyRectangleImport(Vector2 pos, float width, float height, float density);
public static PhysicsBodyData CreatePhysicsBodyRectangle(Vector2 pos, float width, float height, float density)
{
var body = CreatePhysicsBodyRectangleImport(pos, width, height, density);
var data = (PhysicsBodyData)Marshal.PtrToStructure(body, typeof(PhysicsBodyData));
return data;
}
// Creates a new polygon physics body with generic parameters
[DllImport(nativeLibName, EntryPoint = "CreatePhysicsBodyPolygon")]
private static extern IntPtr CreatePhysicsBodyPolygonImport(Vector2 pos, float radius, int sides, float density);
public static PhysicsBodyData CreatePhysicsBodyPolygon(Vector2 pos, float radius, int sides, float density)
{
var body = CreatePhysicsBodyPolygonImport(pos, radius, sides, density);
var data = (PhysicsBodyData)Marshal.PtrToStructure(body, typeof(PhysicsBodyData));
return data;
}
// Adds a force to a physics body
[DllImport(nativeLibName,CallingConvention = CallingConvention.Cdecl)]
public static extern void PhysicsAddForce(PhysicsBodyData body, Vector2 force);
// Adds an angular force to a physics body
[DllImport(nativeLibName,CallingConvention = CallingConvention.Cdecl)]
public static extern void PhysicsAddTorque(PhysicsBodyData body, float amount);
// Shatters a polygon shape physics body to little physics bodies with explosion force
[DllImport(nativeLibName,CallingConvention = CallingConvention.Cdecl)]
public static extern void PhysicsShatter(PhysicsBodyData body, Vector2 position, float force);
// Returns the current amount of created physics bodies
[DllImport(nativeLibName,CallingConvention = CallingConvention.Cdecl)]
public static extern int GetPhysicsBodiesCount();
// Returns a physics body of the bodies pool at a specific index
[DllImport(nativeLibName, EntryPoint = "GetPhysicsBody")]
public static extern IntPtr GetPhysicsBodyImport(int index);
public static PhysicsBodyData GetPhysicsBody(int index)
{
var body = GetPhysicsBodyImport(index);
var data = (PhysicsBodyData)Marshal.PtrToStructure(body, typeof(PhysicsBodyData));
return data;
}
// Returns the physics body shape type (PHYSICS_CIRCLE or PHYSICS_POLYGON)
[DllImport(nativeLibName,CallingConvention = CallingConvention.Cdecl)]
public static extern int GetPhysicsShapeType(int index);
// Returns the amount of vertices of a physics body shape
[DllImport(nativeLibName,CallingConvention = CallingConvention.Cdecl)]
public static extern int GetPhysicsShapeVerticesCount(int index);
// Returns transformed position of a body shape (body position + vertex transformed position)
[DllImport(nativeLibName,CallingConvention = CallingConvention.Cdecl)]
public static extern Vector2 GetPhysicsShapeVertex(PhysicsBodyData body, int vertex);
// Sets physics body shape transform based on radians parameter
[DllImport(nativeLibName,CallingConvention = CallingConvention.Cdecl)]
public static extern void SetPhysicsBodyRotation(PhysicsBodyData body, float radians);
// Unitializes and destroy a physics body
[DllImport(nativeLibName,CallingConvention = CallingConvention.Cdecl)]
public static extern void DestroyPhysicsBody(PhysicsBodyData body);
// Destroys created physics bodies and manifolds and resets global values
[DllImport(nativeLibName,CallingConvention = CallingConvention.Cdecl)]
public static extern void ResetPhysics();
// Unitializes physics pointers and closes physics loop thread
[DllImport(nativeLibName,CallingConvention = CallingConvention.Cdecl)]
public static extern void ClosePhysics();
#endregion
}
}

View File

@ -1,292 +1,292 @@
using System;
using System.Runtime.InteropServices;
using System.Text;
namespace Raylib
{
// Gui global state enum
enum GuiControlState
{
GUI_STATE_NORMAL = 0,
GUI_STATE_FOCUSED,
GUI_STATE_PRESSED,
GUI_STATE_DISABLED,
}
// Gui standard controls
enum GuiControlStandard
{
DEFAULT = 0,
LABEL, // LABELBUTTON
BUTTON, // IMAGEBUTTON
TOGGLE, // TOGGLEGROUP
SLIDER, // SLIDERBAR
PROGRESSBAR,
CHECKBOX,
COMBOBOX,
DROPDOWNBOX,
TEXTBOX, // VALUEBOX, SPINNER
LISTVIEW,
COLORPICKER
}
// 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
{
// Global gui modification functions
// Enable gui controls (global state)
[DllImport(nativeLibName,CallingConvention = CallingConvention.Cdecl)]
public static extern void GuiEnable();
// Disable gui controls (global state)
[DllImport(nativeLibName,CallingConvention = CallingConvention.Cdecl)]
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
[DllImport(nativeLibName,CallingConvention = CallingConvention.Cdecl)]
public static extern void GuiFade(float alpha);
// Style set/get functions
// Set one style property
[DllImport(nativeLibName,CallingConvention = CallingConvention.Cdecl)]
public static extern void GuiSetStyle(int control, int property, int value);
// Get one style property
[DllImport(nativeLibName,CallingConvention = CallingConvention.Cdecl)]
public static extern int GuiGetStyle(int control, int property);
// Container/separator controls, useful for controls organization
// Window Box control, shows a window that can be closed
[DllImport(nativeLibName,CallingConvention = CallingConvention.Cdecl)]
public static extern bool GuiWindowBox(Rectangle bounds, string text);
// Group Box control with title name
[DllImport(nativeLibName,CallingConvention = CallingConvention.Cdecl)]
public static extern void GuiGroupBox(Rectangle bounds, string text);
// Line separator control
[DllImport(nativeLibName,CallingConvention = CallingConvention.Cdecl)]
public static extern void GuiLine(Rectangle bounds, int thick);
// Panel control, useful to group controls
[DllImport(nativeLibName,CallingConvention = CallingConvention.Cdecl)]
public static extern void GuiPanel(Rectangle bounds);
// Scroll Panel control
[DllImport(nativeLibName,CallingConvention = CallingConvention.Cdecl)]
public static extern Vector2 GuiScrollPanel(Rectangle bounds, Rectangle content, Vector2 viewScroll);
// Basic controls set
// Label control, shows text
[DllImport(nativeLibName,CallingConvention = CallingConvention.Cdecl)]
public static extern void GuiLabel(Rectangle bounds, string text);
// Button control, returns true when clicked
[DllImport(nativeLibName,CallingConvention = CallingConvention.Cdecl)]
public static extern bool GuiButton(Rectangle bounds, string text);
// Label button control, show true when clicked
[DllImport(nativeLibName,CallingConvention = CallingConvention.Cdecl)]
public static extern bool GuiLabelButton(Rectangle bounds, string text);
// Image button control, returns true when clicked
[DllImport(nativeLibName,CallingConvention = CallingConvention.Cdecl)]
public static extern bool GuiImageButton(Rectangle bounds, Texture2D texture);
// Image button extended control, returns true when clicked
[DllImport(nativeLibName,CallingConvention = CallingConvention.Cdecl)]
public static extern bool GuiImageButtonEx(Rectangle bounds, Texture2D texture, Rectangle texSource, string text);
// Toggle Button control, returns true when active
[DllImport(nativeLibName,CallingConvention = CallingConvention.Cdecl)]
public static extern bool GuiToggleButton(Rectangle bounds, string text, bool toggle);
// Toggle Group control, returns toggled button index
[DllImport(nativeLibName,CallingConvention = CallingConvention.Cdecl)]
public static extern int GuiToggleGroup(Rectangle bounds, string text, int count, int active);
// Check Box control, returns true when active
[DllImport(nativeLibName,CallingConvention = CallingConvention.Cdecl)]
public static extern bool GuiCheckBox(Rectangle bounds, bool isChecked);
// Check Box control with text, returns true when active
[DllImport(nativeLibName,CallingConvention = CallingConvention.Cdecl)]
public static extern bool GuiCheckBoxEx(Rectangle bounds, bool isChecked, string text);
// Combo Box control, returns selected item index
[DllImport(nativeLibName,CallingConvention = CallingConvention.Cdecl)]
public static extern int GuiComboBox(Rectangle bounds, string text, int count, int active);
// Dropdown Box control, returns selected item
[DllImport(nativeLibName,CallingConvention = CallingConvention.Cdecl)]
public static extern int GuiDropdownBox(Rectangle bounds, string[] text, int count, int active);
// Spinner control, returns selected value
[DllImport(nativeLibName,CallingConvention = CallingConvention.Cdecl)]
public static extern int GuiSpinner(Rectangle bounds, int value, int maxValue, int btnWidth);
// Value Box control, updates input text with numbers
[DllImport(nativeLibName,CallingConvention = CallingConvention.Cdecl)]
public static extern int GuiValueBox(Rectangle bounds, int value, int maxValue);
// Text Box control, updates input text
[DllImport(nativeLibName,CallingConvention = CallingConvention.Cdecl)]
public static extern bool GuiTextBox(Rectangle bounds, StringBuilder text, int textSize, bool freeEdit);
// Text Box control with multiple lines
[DllImport(nativeLibName,CallingConvention = CallingConvention.Cdecl)]
public static extern bool GuiTextBoxMulti(Rectangle bounds, StringBuilder text, int textSize, bool editMode);
// Slider control, returns selected value
[DllImport(nativeLibName,CallingConvention = CallingConvention.Cdecl)]
public static extern float GuiSlider(Rectangle bounds, float value, float minValue, float maxValue);
// Slider control, returns selected value
[DllImport(nativeLibName,CallingConvention = CallingConvention.Cdecl)]
public static extern float GuiSliderEx(Rectangle bounds, float value, float minValue, float maxValue, string text, bool showValue);
// Slider Bar control, returns selected value
[DllImport(nativeLibName,CallingConvention = CallingConvention.Cdecl)]
public static extern float GuiSliderBar(Rectangle bounds, float value, float minValue, float maxValue);
// Slider Bar control, returns selected value
[DllImport(nativeLibName,CallingConvention = CallingConvention.Cdecl)]
public static extern float GuiSliderBarEx(Rectangle bounds, float value, float minValue, float maxValue, string text, bool showValue);
// Progress Bar control, shows current progress value
[DllImport(nativeLibName,CallingConvention = CallingConvention.Cdecl)]
public static extern float GuiProgressBar(Rectangle bounds, float value, float minValue, float maxValue);
// Progress Bar control, shows current progress value
[DllImport(nativeLibName,CallingConvention = CallingConvention.Cdecl)]
public static extern float GuiProgressBarEx(Rectangle bounds, float value, float minValue, float maxValue, bool showValue);
// Status Bar control, shows info text
[DllImport(nativeLibName,CallingConvention = CallingConvention.Cdecl)]
public static extern void GuiStatusBar(Rectangle bounds, string text, int offsetX);
// Dummy control for placeholders
[DllImport(nativeLibName,CallingConvention = CallingConvention.Cdecl)]
public static extern void GuiDummyRec(Rectangle bounds, string text);
// Advance controls set
// List View control, returns selected list element index
[DllImport(nativeLibName,CallingConvention = CallingConvention.Cdecl)]
public static extern int GuiListView(Rectangle bounds, string text, int count, int active);
// Color Picker control
[DllImport(nativeLibName,CallingConvention = CallingConvention.Cdecl)]
public static extern Color GuiColorPicker(Rectangle bounds, Color color);
// Message Box control, displays a message
[DllImport(nativeLibName,CallingConvention = CallingConvention.Cdecl)]
public static extern bool GuiMessageBox(Rectangle bounds, string windowTitle, string message);
}
}
using System;
using System.Runtime.InteropServices;
using System.Text;
namespace Raylib
{
// Gui global state enum
enum GuiControlState
{
GUI_STATE_NORMAL = 0,
GUI_STATE_FOCUSED,
GUI_STATE_PRESSED,
GUI_STATE_DISABLED,
}
// Gui standard controls
enum GuiControlStandard
{
DEFAULT = 0,
LABEL, // LABELBUTTON
BUTTON, // IMAGEBUTTON
TOGGLE, // TOGGLEGROUP
SLIDER, // SLIDERBAR
PROGRESSBAR,
CHECKBOX,
COMBOBOX,
DROPDOWNBOX,
TEXTBOX, // VALUEBOX, SPINNER
LISTVIEW,
COLORPICKER
}
// 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
{
// Global gui modification functions
// Enable gui controls (global state)
[DllImport(nativeLibName,CallingConvention = CallingConvention.Cdecl)]
public static extern void GuiEnable();
// Disable gui controls (global state)
[DllImport(nativeLibName,CallingConvention = CallingConvention.Cdecl)]
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
[DllImport(nativeLibName,CallingConvention = CallingConvention.Cdecl)]
public static extern void GuiFade(float alpha);
// Style set/get functions
// Set one style property
[DllImport(nativeLibName,CallingConvention = CallingConvention.Cdecl)]
public static extern void GuiSetStyle(int control, int property, int value);
// Get one style property
[DllImport(nativeLibName,CallingConvention = CallingConvention.Cdecl)]
public static extern int GuiGetStyle(int control, int property);
// Container/separator controls, useful for controls organization
// Window Box control, shows a window that can be closed
[DllImport(nativeLibName,CallingConvention = CallingConvention.Cdecl)]
public static extern bool GuiWindowBox(Rectangle bounds, string text);
// Group Box control with title name
[DllImport(nativeLibName,CallingConvention = CallingConvention.Cdecl)]
public static extern void GuiGroupBox(Rectangle bounds, string text);
// Line separator control
[DllImport(nativeLibName,CallingConvention = CallingConvention.Cdecl)]
public static extern void GuiLine(Rectangle bounds, int thick);
// Panel control, useful to group controls
[DllImport(nativeLibName,CallingConvention = CallingConvention.Cdecl)]
public static extern void GuiPanel(Rectangle bounds);
// Scroll Panel control
[DllImport(nativeLibName,CallingConvention = CallingConvention.Cdecl)]
public static extern Vector2 GuiScrollPanel(Rectangle bounds, Rectangle content, Vector2 viewScroll);
// Basic controls set
// Label control, shows text
[DllImport(nativeLibName,CallingConvention = CallingConvention.Cdecl)]
public static extern void GuiLabel(Rectangle bounds, string text);
// Button control, returns true when clicked
[DllImport(nativeLibName,CallingConvention = CallingConvention.Cdecl)]
public static extern bool GuiButton(Rectangle bounds, string text);
// Label button control, show true when clicked
[DllImport(nativeLibName,CallingConvention = CallingConvention.Cdecl)]
public static extern bool GuiLabelButton(Rectangle bounds, string text);
// Image button control, returns true when clicked
[DllImport(nativeLibName,CallingConvention = CallingConvention.Cdecl)]
public static extern bool GuiImageButton(Rectangle bounds, Texture2D texture);
// Image button extended control, returns true when clicked
[DllImport(nativeLibName,CallingConvention = CallingConvention.Cdecl)]
public static extern bool GuiImageButtonEx(Rectangle bounds, Texture2D texture, Rectangle texSource, string text);
// Toggle Button control, returns true when active
[DllImport(nativeLibName,CallingConvention = CallingConvention.Cdecl)]
public static extern bool GuiToggleButton(Rectangle bounds, string text, bool toggle);
// Toggle Group control, returns toggled button index
[DllImport(nativeLibName,CallingConvention = CallingConvention.Cdecl)]
public static extern int GuiToggleGroup(Rectangle bounds, string text, int count, int active);
// Check Box control, returns true when active
[DllImport(nativeLibName,CallingConvention = CallingConvention.Cdecl)]
public static extern bool GuiCheckBox(Rectangle bounds, bool isChecked);
// Check Box control with text, returns true when active
[DllImport(nativeLibName,CallingConvention = CallingConvention.Cdecl)]
public static extern bool GuiCheckBoxEx(Rectangle bounds, bool isChecked, string text);
// Combo Box control, returns selected item index
[DllImport(nativeLibName,CallingConvention = CallingConvention.Cdecl)]
public static extern int GuiComboBox(Rectangle bounds, string text, int count, int active);
// Dropdown Box control, returns selected item
[DllImport(nativeLibName,CallingConvention = CallingConvention.Cdecl)]
public static extern int GuiDropdownBox(Rectangle bounds, string[] text, int count, int active);
// Spinner control, returns selected value
[DllImport(nativeLibName,CallingConvention = CallingConvention.Cdecl)]
public static extern int GuiSpinner(Rectangle bounds, int value, int maxValue, int btnWidth);
// Value Box control, updates input text with numbers
[DllImport(nativeLibName,CallingConvention = CallingConvention.Cdecl)]
public static extern int GuiValueBox(Rectangle bounds, int value, int maxValue);
// Text Box control, updates input text
[DllImport(nativeLibName,CallingConvention = CallingConvention.Cdecl)]
public static extern bool GuiTextBox(Rectangle bounds, StringBuilder text, int textSize, bool freeEdit);
// Text Box control with multiple lines
[DllImport(nativeLibName,CallingConvention = CallingConvention.Cdecl)]
public static extern bool GuiTextBoxMulti(Rectangle bounds, StringBuilder text, int textSize, bool editMode);
// Slider control, returns selected value
[DllImport(nativeLibName,CallingConvention = CallingConvention.Cdecl)]
public static extern float GuiSlider(Rectangle bounds, float value, float minValue, float maxValue);
// Slider control, returns selected value
[DllImport(nativeLibName,CallingConvention = CallingConvention.Cdecl)]
public static extern float GuiSliderEx(Rectangle bounds, float value, float minValue, float maxValue, string text, bool showValue);
// Slider Bar control, returns selected value
[DllImport(nativeLibName,CallingConvention = CallingConvention.Cdecl)]
public static extern float GuiSliderBar(Rectangle bounds, float value, float minValue, float maxValue);
// Slider Bar control, returns selected value
[DllImport(nativeLibName,CallingConvention = CallingConvention.Cdecl)]
public static extern float GuiSliderBarEx(Rectangle bounds, float value, float minValue, float maxValue, string text, bool showValue);
// Progress Bar control, shows current progress value
[DllImport(nativeLibName,CallingConvention = CallingConvention.Cdecl)]
public static extern float GuiProgressBar(Rectangle bounds, float value, float minValue, float maxValue);
// Progress Bar control, shows current progress value
[DllImport(nativeLibName,CallingConvention = CallingConvention.Cdecl)]
public static extern float GuiProgressBarEx(Rectangle bounds, float value, float minValue, float maxValue, bool showValue);
// Status Bar control, shows info text
[DllImport(nativeLibName,CallingConvention = CallingConvention.Cdecl)]
public static extern void GuiStatusBar(Rectangle bounds, string text, int offsetX);
// Dummy control for placeholders
[DllImport(nativeLibName,CallingConvention = CallingConvention.Cdecl)]
public static extern void GuiDummyRec(Rectangle bounds, string text);
// Advance controls set
// List View control, returns selected list element index
[DllImport(nativeLibName,CallingConvention = CallingConvention.Cdecl)]
public static extern int GuiListView(Rectangle bounds, string text, int count, int active);
// Color Picker control
[DllImport(nativeLibName,CallingConvention = CallingConvention.Cdecl)]
public static extern Color GuiColorPicker(Rectangle bounds, Color color);
// Message Box control, displays a message
[DllImport(nativeLibName,CallingConvention = CallingConvention.Cdecl)]
public static extern bool GuiMessageBox(Rectangle bounds, string windowTitle, string message);
}
}

View File

@ -1,27 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<package>
<metadata minClientVersion="3.3.0">
<id>Raylib-cs</id>
<version>1.4</version>
<authors>mysterious_space</authors>
<owners>mysterious_space</owners>
<licenseUrl>https://github.com/ChrisDill/Raylib-cs/blob/master/LICENSE</licenseUrl>
<projectUrl>https://github.com/ChrisDill/Raylib-cs</projectUrl>
<iconUrl>https://github.com/ChrisDill/Raylib-cs/blob/master/Logo/raylib-cs.ico</iconUrl>
<requireLicenseAcceptance>false</requireLicenseAcceptance>
<description>C# bindings for raylib, a simple and easy-to-use library to learn videogames programming.</description>
<copyright>Copyright 2018</copyright>
<tags>raylib csharp binding opengl gamedev</tags>
<contentFiles>
<files include="Easings.cs" buildAction="Content" />
<files include="Raygui.cs" buildAction="Content" />
<files include="Raymath.cs" buildAction="Content" />
<files include="Raylib.cs" buildAction="Content" />
</contentFiles>
</metadata>
<files>
<!-- <file src="Raylib.cs" target="contentFiles" /> -->
<file src="Raylib.cs" target="contentFiles" />
</files>
</package>

View File

@ -1,17 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup Condition=" '$(Platform)' == 'x64' ">
<Content Include="$(MSBuildThisFileDirectory)..\native\x64\raylib.dll">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
<Link>raylib.dll</Link>
</Content>
</ItemGroup>
<ItemGroup Condition=" '$(Platform)' == 'x86' OR '$(Platform)' == 'AnyCPU' ">
<Content Include="$(MSBuildThisFileDirectory)..\native\x86\raylib.dll">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
<Link>raylib.dll</Link>
</Content>
</ItemGroup>
</Project>

File diff suppressed because it is too large Load Diff

View File

@ -1,19 +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>
<?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>

View File

@ -1,13 +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>
<?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,405 +1,405 @@
/* Raylib-cs
* Raymath.cs - Core bindings to raymth
* Copyright 2019 Chris Dill
*
* Release under zLib License.
* See LICENSE for details.
*/
using System;
using System.Runtime.InteropServices;
namespace Raylib
{
// Vector2 type
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Ansi)]
public partial struct Vector2
{
public float x;
public float y;
}
// Vector3 type
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Ansi)]
public partial struct Vector3
{
public float x;
public float y;
public float z;
}
// Vector4 type
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Ansi)]
public partial struct Vector4
{
public float x;
public float y;
public float z;
public float w;
}
// Matrix type (OpenGL style 4x4 - right handed, column major)
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Ansi)]
public struct Matrix
{
public float m0, m4, m8, m12;
public float m1, m5, m9, m13;
public float m2, m6, m10, m14;
public float m3, m7, m11, m15;
public override string ToString()
{
return $"Matrix({m0}, {m4}, {m8}, {m12}\n {m1}, {m5}, {m9}, {m13}\n {m2}, {m6}, {m10}, {m14}\n {m3}, {m7}, {m11}, {m15})";
}
}
// Quaternion type
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Ansi)]
public struct Quaternion
{
public float x;
public float y;
public float z;
public float w;
public override string ToString()
{
return "Quaternion(" + x + " " + y + " " + z + " " + w + ")";
}
}
public static partial class Raylib
{
// Clamp float value
[DllImport(nativeLibName,CallingConvention = CallingConvention.Cdecl)]
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
[DllImport(nativeLibName,CallingConvention = CallingConvention.Cdecl)]
public static extern Vector2 Vector2Zero();
// Vector with components value 1.0f
[DllImport(nativeLibName,CallingConvention = CallingConvention.Cdecl)]
public static extern Vector2 Vector2One();
// Add two vectors (v1 + v2)
[DllImport(nativeLibName,CallingConvention = CallingConvention.Cdecl)]
public static extern Vector2 Vector2Add(Vector2 v1, Vector2 v2);
// Subtract two vectors (v1 - v2)
[DllImport(nativeLibName,CallingConvention = CallingConvention.Cdecl)]
public static extern Vector2 Vector2Subtract(Vector2 v1, Vector2 v2);
// Calculate vector length
[DllImport(nativeLibName,CallingConvention = CallingConvention.Cdecl)]
public static extern float Vector2Length(Vector2 v);
// Calculate two vectors dot product
[DllImport(nativeLibName,CallingConvention = CallingConvention.Cdecl)]
public static extern float Vector2DotProduct(Vector2 v1, Vector2 v2);
// Calculate distance between two vectors
[DllImport(nativeLibName,CallingConvention = CallingConvention.Cdecl)]
public static extern float Vector2Distance(Vector2 v1, Vector2 v2);
// Calculate angle from two vectors in X-axis
[DllImport(nativeLibName,CallingConvention = CallingConvention.Cdecl)]
public static extern float Vector2Angle(Vector2 v1, Vector2 v2);
// Scale vector (multiply by value)
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
public static extern Vector2 Vector2Scale(Vector2 v, float scale);
// Multiply vector by a vector
[DllImport(nativeLibName,CallingConvention = CallingConvention.Cdecl)]
public static extern Vector2 Vector2Multiplyv(Vector2 v1, Vector2 v2);
// Negate vector
[DllImport(nativeLibName,CallingConvention = CallingConvention.Cdecl)]
public static extern Vector2 Vector2Negate(Vector2 v);
// Divide vector by a float value
[DllImport(nativeLibName,CallingConvention = CallingConvention.Cdecl)]
public static extern Vector2 Vector2Divide(Vector2 v, float div);
// Divide vector by a vector
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
public static extern Vector2 Vector2DivideV(Vector2 v1, Vector2 v2);
// Normalize provided vector
[DllImport(nativeLibName,CallingConvention = CallingConvention.Cdecl)]
public static extern Vector2 Vector2Normalize(Vector2 v);
// Vector with components value 0.0f
[DllImport(nativeLibName,CallingConvention = CallingConvention.Cdecl)]
public static extern Vector3 Vector3Zero();
// Vector with components value 1.0f
[DllImport(nativeLibName,CallingConvention = CallingConvention.Cdecl)]
public static extern Vector3 Vector3One();
// Add two vectors
[DllImport(nativeLibName,CallingConvention = CallingConvention.Cdecl)]
public static extern Vector3 Vector3Add(Vector3 v1, Vector3 v2);
// Substract two vectors
[DllImport(nativeLibName,CallingConvention = CallingConvention.Cdecl)]
public static extern Vector3 Vector3Subtract(Vector3 v1, Vector3 v2);
// Multiply vector by scalar
[DllImport(nativeLibName,CallingConvention = CallingConvention.Cdecl)]
public static extern Vector3 Vector3Multiply(Vector3 v, float scalar);
// Multiply vector by vector
[DllImport(nativeLibName,CallingConvention = CallingConvention.Cdecl)]
public static extern Vector3 Vector3MultiplyV(Vector3 v1, Vector3 v2);
// Calculate two vectors cross product
[DllImport(nativeLibName,CallingConvention = CallingConvention.Cdecl)]
public static extern Vector3 Vector3CrossProduct(Vector3 v1, Vector3 v2);
// Calculate one vector perpendicular vector
[DllImport(nativeLibName,CallingConvention = CallingConvention.Cdecl)]
public static extern Vector3 Vector3Perpendicular(Vector3 v);
// Calculate vector length
[DllImport(nativeLibName,CallingConvention = CallingConvention.Cdecl)]
public static extern float Vector3Length(Vector3 v);
// Calculate two vectors dot product
[DllImport(nativeLibName,CallingConvention = CallingConvention.Cdecl)]
public static extern float Vector3DotProduct(Vector3 v1, Vector3 v2);
// Calculate distance between two vectors
[DllImport(nativeLibName,CallingConvention = CallingConvention.Cdecl)]
public static extern float Vector3Distance(Vector3 v1, Vector3 v2);
// Scale provided vector
[DllImport(nativeLibName,CallingConvention = CallingConvention.Cdecl)]
public static extern Vector3 Vector3Scale(Vector3 v, float scale);
// Negate provided vector (invert direction)
[DllImport(nativeLibName,CallingConvention = CallingConvention.Cdecl)]
public static extern Vector3 Vector3Negate(Vector3 v);
// Divide vector by a float value
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
public static extern Vector3 Vector3Divide(Vector3 v, float div);
// Divide vector by a vector
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
public static extern Vector3 Vector3DivideV(Vector3 v1, Vector3 v2);
// Normalize provided vector
[DllImport(nativeLibName,CallingConvention = CallingConvention.Cdecl)]
public static extern Vector3 Vector3Normalize(Vector3 v);
// Orthonormalize provided vectors
// Makes vectors normalized and orthogonal to each other
// Gram-Schmidt function implementation
[DllImport(nativeLibName,CallingConvention = CallingConvention.Cdecl)]
public static extern void Vector3OrthoNormalize(out Vector3 v1, out Vector3 v2);
// Transforms a Vector3 by a given Matrix
[DllImport(nativeLibName,CallingConvention = CallingConvention.Cdecl)]
public static extern Vector3 Vector3Transform(Vector3 v, Matrix mat);
// Transform a vector by quaternion rotation
[DllImport(nativeLibName,CallingConvention = CallingConvention.Cdecl)]
public static extern Vector3 Vector3RotateByQuaternion(Vector3 v, Quaternion q);
// Calculate linear interpolation between two vectors
[DllImport(nativeLibName,CallingConvention = CallingConvention.Cdecl)]
public static extern Vector3 Vector3Lerp(Vector3 v1, Vector3 v2, float amount);
// Calculate reflected vector to normal
[DllImport(nativeLibName,CallingConvention = CallingConvention.Cdecl)]
public static extern Vector3 Vector3Reflect(Vector3 v, Vector3 normal);
// Return min value for each pair of components
[DllImport(nativeLibName,CallingConvention = CallingConvention.Cdecl)]
public static extern Vector3 Vector3Min(Vector3 v1, Vector3 v2);
// Return max value for each pair of components
[DllImport(nativeLibName,CallingConvention = CallingConvention.Cdecl)]
public static extern Vector3 Vector3Max(Vector3 v1, Vector3 v2);
// Compute barycenter coordinates (u, v, w) for point p with respect to triangle (a, b, c)
// NOTE: Assumes P is on the plane of the triangle
[DllImport(nativeLibName,CallingConvention = CallingConvention.Cdecl)]
public static extern Vector3 Vector3Barycenter(Vector3 p, Vector3 a, Vector3 b, Vector3 c);
// Returns Vector3 as float array
[DllImport(nativeLibName,CallingConvention = CallingConvention.Cdecl)]
public static extern float[] Vector3ToFloatV(Vector3 v);
// Compute matrix determinant
[DllImport(nativeLibName,CallingConvention = CallingConvention.Cdecl)]
public static extern float MatrixDeterminant(Matrix mat);
// Returns the trace of the matrix (sum of the values along the diagonal)
[DllImport(nativeLibName,CallingConvention = CallingConvention.Cdecl)]
public static extern float MatrixTrace(Matrix mat);
// Transposes provided matrix
[DllImport(nativeLibName,CallingConvention = CallingConvention.Cdecl)]
public static extern Matrix MatrixTranspose(Matrix mat);
// Invert provided matrix
[DllImport(nativeLibName,CallingConvention = CallingConvention.Cdecl)]
public static extern Matrix MatrixInvert(Matrix mat);
// Normalize provided matrix
[DllImport(nativeLibName,CallingConvention = CallingConvention.Cdecl)]
public static extern Matrix MatrixNormalize(Matrix mat);
// Returns identity matrix
[DllImport(nativeLibName,CallingConvention = CallingConvention.Cdecl)]
public static extern Matrix MatrixIdentity();
// Add two matrices
[DllImport(nativeLibName,CallingConvention = CallingConvention.Cdecl)]
public static extern Matrix MatrixAdd(Matrix left, Matrix right);
// Substract two matrices (left - right)
[DllImport(nativeLibName,CallingConvention = CallingConvention.Cdecl)]
public static extern Matrix MatrixSubstract(Matrix left, Matrix right);
// Create rotation matrix from axis and angle
// NOTE: Angle should be provided in radians
[DllImport(nativeLibName,CallingConvention = CallingConvention.Cdecl)]
public static extern Matrix MatrixTranslate(float x, float y, float z);
// Returns x-rotation matrix (angle in radians)
[DllImport(nativeLibName,CallingConvention = CallingConvention.Cdecl)]
public static extern Matrix MatrixRotate(Vector3 axis, float angle);
// Returns x-rotation matrix (angle in radians)
[DllImport(nativeLibName,CallingConvention = CallingConvention.Cdecl)]
public static extern Matrix MatrixRotateX(float angle);
// Returns y-rotation matrix (angle in radians)
[DllImport(nativeLibName,CallingConvention = CallingConvention.Cdecl)]
public static extern Matrix MatrixRotateY(float angle);
// Returns z-rotation matrix (angle in radians)
[DllImport(nativeLibName,CallingConvention = CallingConvention.Cdecl)]
public static extern Matrix MatrixRotateZ(float angle);
// Returns scaling matrix
[DllImport(nativeLibName,CallingConvention = CallingConvention.Cdecl)]
public static extern Matrix MatrixScale(float x, float y, float z);
// Returns two matrix multiplication
// NOTE: When multiplying matrices... the order matters!
[DllImport(nativeLibName,CallingConvention = CallingConvention.Cdecl)]
public static extern Matrix MatrixMultiply(Matrix left, Matrix right);
// Returns perspective projection matrix
[DllImport(nativeLibName,CallingConvention = CallingConvention.Cdecl)]
public static extern Matrix MatrixFrustum(double left, double right, double bottom, double top, double near, double far);
// Returns perspective projection matrix
// NOTE: Angle should be provided in radians
[DllImport(nativeLibName,CallingConvention = CallingConvention.Cdecl)]
public static extern Matrix MatrixPerspective(double fovy, double aspect, double near, double far);
// Returns orthographic projection matrix
[DllImport(nativeLibName,CallingConvention = CallingConvention.Cdecl)]
public static extern Matrix MatrixOrtho(double left, double right, double bottom, double top, double near, double far);
// Returns camera look-at matrix (view matrix)
[DllImport(nativeLibName,CallingConvention = CallingConvention.Cdecl)]
public static extern Matrix MatrixLookAt(Vector3 eye, Vector3 target, Vector3 up);
// Returns float array of matrix data
[DllImport(nativeLibName,CallingConvention = CallingConvention.Cdecl)]
public static extern float[] MatrixToFloatV(Matrix mat);
// Returns identity quaternion
[DllImport(nativeLibName,CallingConvention = CallingConvention.Cdecl)]
public static extern Quaternion QuaternionIdentity();
// Computes the length of a quaternion
[DllImport(nativeLibName,CallingConvention = CallingConvention.Cdecl)]
public static extern float QuaternionLength(Quaternion q);
// Normalize provided quaternion
[DllImport(nativeLibName,CallingConvention = CallingConvention.Cdecl)]
public static extern Quaternion QuaternionNormalize(Quaternion q);
// Invert provided quaternion
[DllImport(nativeLibName,CallingConvention = CallingConvention.Cdecl)]
public static extern Quaternion QuaternionInvert(Quaternion q);
// Calculate two quaternion multiplication
[DllImport(nativeLibName,CallingConvention = CallingConvention.Cdecl)]
public static extern Quaternion QuaternionMultiply(Quaternion q1, Quaternion q2);
// Calculate linear interpolation between two quaternions
[DllImport(nativeLibName,CallingConvention = CallingConvention.Cdecl)]
public static extern Quaternion QuaternionLerp(Quaternion q1, Quaternion q2, float amount);
// Calculate slerp-optimized interpolation between two quaternions
[DllImport(nativeLibName,CallingConvention = CallingConvention.Cdecl)]
public static extern Quaternion QuaternionNlerp(Quaternion q1, Quaternion q2, float amount);
// Calculates spherical linear interpolation between two quaternions
[DllImport(nativeLibName,CallingConvention = CallingConvention.Cdecl)]
public static extern Quaternion QuaternionSlerp(Quaternion q1, Quaternion q2, float amount);
// Calculate quaternion based on the rotation from one vector to another
[DllImport(nativeLibName,CallingConvention = CallingConvention.Cdecl)]
public static extern Quaternion QuaternionFromVector3ToVector3(Vector3 from, Vector3 to);
// Returns a quaternion for a given rotation matrix
[DllImport(nativeLibName,CallingConvention = CallingConvention.Cdecl)]
public static extern Quaternion QuaternionFromMatrix(Matrix mat);
// Returns a matrix for a given quaternion
[DllImport(nativeLibName,CallingConvention = CallingConvention.Cdecl)]
public static extern Matrix QuaternionToMatrix(Quaternion q);
// Returns rotation quaternion for an angle and axis
// NOTE: angle must be provided in radians
[DllImport(nativeLibName,CallingConvention = CallingConvention.Cdecl)]
public static extern Quaternion QuaternionFromAxisAngle(Vector3 axis, float angle);
// Returns the rotation angle and axis for a given quaternion
[DllImport(nativeLibName,CallingConvention = CallingConvention.Cdecl)]
public static extern void QuaternionToAxisAngle(Quaternion q, out Vector3 outAxis, float[] outAngle);
// Returns he quaternion equivalent to Euler angles
[DllImport(nativeLibName,CallingConvention = CallingConvention.Cdecl)]
public static extern Quaternion QuaternionFromEuler(float roll, float pitch, float yaw);
// Return the Euler angles equivalent to quaternion (roll, pitch, yaw)
// NOTE: Angles are returned in a Vector3 struct in degrees
[DllImport(nativeLibName,CallingConvention = CallingConvention.Cdecl)]
public static extern Vector3 QuaternionToEuler(Quaternion q);
// Transform a quaternion given a transformation matrix
[DllImport(nativeLibName,CallingConvention = CallingConvention.Cdecl)]
public static extern Quaternion QuaternionTransform(Quaternion q, Matrix mat);
}
}
/* Raylib-cs
* Raymath.cs - Core bindings to raymth
* Copyright 2019 Chris Dill
*
* Release under zLib License.
* See LICENSE for details.
*/
using System;
using System.Runtime.InteropServices;
namespace Raylib
{
// Vector2 type
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Ansi)]
public partial struct Vector2
{
public float x;
public float y;
}
// Vector3 type
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Ansi)]
public partial struct Vector3
{
public float x;
public float y;
public float z;
}
// Vector4 type
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Ansi)]
public partial struct Vector4
{
public float x;
public float y;
public float z;
public float w;
}
// Matrix type (OpenGL style 4x4 - right handed, column major)
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Ansi)]
public struct Matrix
{
public float m0, m4, m8, m12;
public float m1, m5, m9, m13;
public float m2, m6, m10, m14;
public float m3, m7, m11, m15;
public override string ToString()
{
return $"Matrix({m0}, {m4}, {m8}, {m12}\n {m1}, {m5}, {m9}, {m13}\n {m2}, {m6}, {m10}, {m14}\n {m3}, {m7}, {m11}, {m15})";
}
}
// Quaternion type
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Ansi)]
public struct Quaternion
{
public float x;
public float y;
public float z;
public float w;
public override string ToString()
{
return "Quaternion(" + x + " " + y + " " + z + " " + w + ")";
}
}
public static partial class Raylib
{
// Clamp float value
[DllImport(nativeLibName,CallingConvention = CallingConvention.Cdecl)]
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
[DllImport(nativeLibName,CallingConvention = CallingConvention.Cdecl)]
public static extern Vector2 Vector2Zero();
// Vector with components value 1.0f
[DllImport(nativeLibName,CallingConvention = CallingConvention.Cdecl)]
public static extern Vector2 Vector2One();
// Add two vectors (v1 + v2)
[DllImport(nativeLibName,CallingConvention = CallingConvention.Cdecl)]
public static extern Vector2 Vector2Add(Vector2 v1, Vector2 v2);
// Subtract two vectors (v1 - v2)
[DllImport(nativeLibName,CallingConvention = CallingConvention.Cdecl)]
public static extern Vector2 Vector2Subtract(Vector2 v1, Vector2 v2);
// Calculate vector length
[DllImport(nativeLibName,CallingConvention = CallingConvention.Cdecl)]
public static extern float Vector2Length(Vector2 v);
// Calculate two vectors dot product
[DllImport(nativeLibName,CallingConvention = CallingConvention.Cdecl)]
public static extern float Vector2DotProduct(Vector2 v1, Vector2 v2);
// Calculate distance between two vectors
[DllImport(nativeLibName,CallingConvention = CallingConvention.Cdecl)]
public static extern float Vector2Distance(Vector2 v1, Vector2 v2);
// Calculate angle from two vectors in X-axis
[DllImport(nativeLibName,CallingConvention = CallingConvention.Cdecl)]
public static extern float Vector2Angle(Vector2 v1, Vector2 v2);
// Scale vector (multiply by value)
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
public static extern Vector2 Vector2Scale(Vector2 v, float scale);
// Multiply vector by a vector
[DllImport(nativeLibName,CallingConvention = CallingConvention.Cdecl)]
public static extern Vector2 Vector2Multiplyv(Vector2 v1, Vector2 v2);
// Negate vector
[DllImport(nativeLibName,CallingConvention = CallingConvention.Cdecl)]
public static extern Vector2 Vector2Negate(Vector2 v);
// Divide vector by a float value
[DllImport(nativeLibName,CallingConvention = CallingConvention.Cdecl)]
public static extern Vector2 Vector2Divide(Vector2 v, float div);
// Divide vector by a vector
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
public static extern Vector2 Vector2DivideV(Vector2 v1, Vector2 v2);
// Normalize provided vector
[DllImport(nativeLibName,CallingConvention = CallingConvention.Cdecl)]
public static extern Vector2 Vector2Normalize(Vector2 v);
// Vector with components value 0.0f
[DllImport(nativeLibName,CallingConvention = CallingConvention.Cdecl)]
public static extern Vector3 Vector3Zero();
// Vector with components value 1.0f
[DllImport(nativeLibName,CallingConvention = CallingConvention.Cdecl)]
public static extern Vector3 Vector3One();
// Add two vectors
[DllImport(nativeLibName,CallingConvention = CallingConvention.Cdecl)]
public static extern Vector3 Vector3Add(Vector3 v1, Vector3 v2);
// Substract two vectors
[DllImport(nativeLibName,CallingConvention = CallingConvention.Cdecl)]
public static extern Vector3 Vector3Subtract(Vector3 v1, Vector3 v2);
// Multiply vector by scalar
[DllImport(nativeLibName,CallingConvention = CallingConvention.Cdecl)]
public static extern Vector3 Vector3Multiply(Vector3 v, float scalar);
// Multiply vector by vector
[DllImport(nativeLibName,CallingConvention = CallingConvention.Cdecl)]
public static extern Vector3 Vector3MultiplyV(Vector3 v1, Vector3 v2);
// Calculate two vectors cross product
[DllImport(nativeLibName,CallingConvention = CallingConvention.Cdecl)]
public static extern Vector3 Vector3CrossProduct(Vector3 v1, Vector3 v2);
// Calculate one vector perpendicular vector
[DllImport(nativeLibName,CallingConvention = CallingConvention.Cdecl)]
public static extern Vector3 Vector3Perpendicular(Vector3 v);
// Calculate vector length
[DllImport(nativeLibName,CallingConvention = CallingConvention.Cdecl)]
public static extern float Vector3Length(Vector3 v);
// Calculate two vectors dot product
[DllImport(nativeLibName,CallingConvention = CallingConvention.Cdecl)]
public static extern float Vector3DotProduct(Vector3 v1, Vector3 v2);
// Calculate distance between two vectors
[DllImport(nativeLibName,CallingConvention = CallingConvention.Cdecl)]
public static extern float Vector3Distance(Vector3 v1, Vector3 v2);
// Scale provided vector
[DllImport(nativeLibName,CallingConvention = CallingConvention.Cdecl)]
public static extern Vector3 Vector3Scale(Vector3 v, float scale);
// Negate provided vector (invert direction)
[DllImport(nativeLibName,CallingConvention = CallingConvention.Cdecl)]
public static extern Vector3 Vector3Negate(Vector3 v);
// Divide vector by a float value
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
public static extern Vector3 Vector3Divide(Vector3 v, float div);
// Divide vector by a vector
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
public static extern Vector3 Vector3DivideV(Vector3 v1, Vector3 v2);
// Normalize provided vector
[DllImport(nativeLibName,CallingConvention = CallingConvention.Cdecl)]
public static extern Vector3 Vector3Normalize(Vector3 v);
// Orthonormalize provided vectors
// Makes vectors normalized and orthogonal to each other
// Gram-Schmidt function implementation
[DllImport(nativeLibName,CallingConvention = CallingConvention.Cdecl)]
public static extern void Vector3OrthoNormalize(out Vector3 v1, out Vector3 v2);
// Transforms a Vector3 by a given Matrix
[DllImport(nativeLibName,CallingConvention = CallingConvention.Cdecl)]
public static extern Vector3 Vector3Transform(Vector3 v, Matrix mat);
// Transform a vector by quaternion rotation
[DllImport(nativeLibName,CallingConvention = CallingConvention.Cdecl)]
public static extern Vector3 Vector3RotateByQuaternion(Vector3 v, Quaternion q);
// Calculate linear interpolation between two vectors
[DllImport(nativeLibName,CallingConvention = CallingConvention.Cdecl)]
public static extern Vector3 Vector3Lerp(Vector3 v1, Vector3 v2, float amount);
// Calculate reflected vector to normal
[DllImport(nativeLibName,CallingConvention = CallingConvention.Cdecl)]
public static extern Vector3 Vector3Reflect(Vector3 v, Vector3 normal);
// Return min value for each pair of components
[DllImport(nativeLibName,CallingConvention = CallingConvention.Cdecl)]
public static extern Vector3 Vector3Min(Vector3 v1, Vector3 v2);
// Return max value for each pair of components
[DllImport(nativeLibName,CallingConvention = CallingConvention.Cdecl)]
public static extern Vector3 Vector3Max(Vector3 v1, Vector3 v2);
// Compute barycenter coordinates (u, v, w) for point p with respect to triangle (a, b, c)
// NOTE: Assumes P is on the plane of the triangle
[DllImport(nativeLibName,CallingConvention = CallingConvention.Cdecl)]
public static extern Vector3 Vector3Barycenter(Vector3 p, Vector3 a, Vector3 b, Vector3 c);
// Returns Vector3 as float array
[DllImport(nativeLibName,CallingConvention = CallingConvention.Cdecl)]
public static extern float[] Vector3ToFloatV(Vector3 v);
// Compute matrix determinant
[DllImport(nativeLibName,CallingConvention = CallingConvention.Cdecl)]
public static extern float MatrixDeterminant(Matrix mat);
// Returns the trace of the matrix (sum of the values along the diagonal)
[DllImport(nativeLibName,CallingConvention = CallingConvention.Cdecl)]
public static extern float MatrixTrace(Matrix mat);
// Transposes provided matrix
[DllImport(nativeLibName,CallingConvention = CallingConvention.Cdecl)]
public static extern Matrix MatrixTranspose(Matrix mat);
// Invert provided matrix
[DllImport(nativeLibName,CallingConvention = CallingConvention.Cdecl)]
public static extern Matrix MatrixInvert(Matrix mat);
// Normalize provided matrix
[DllImport(nativeLibName,CallingConvention = CallingConvention.Cdecl)]
public static extern Matrix MatrixNormalize(Matrix mat);
// Returns identity matrix
[DllImport(nativeLibName,CallingConvention = CallingConvention.Cdecl)]
public static extern Matrix MatrixIdentity();
// Add two matrices
[DllImport(nativeLibName,CallingConvention = CallingConvention.Cdecl)]
public static extern Matrix MatrixAdd(Matrix left, Matrix right);
// Substract two matrices (left - right)
[DllImport(nativeLibName,CallingConvention = CallingConvention.Cdecl)]
public static extern Matrix MatrixSubstract(Matrix left, Matrix right);
// Create rotation matrix from axis and angle
// NOTE: Angle should be provided in radians
[DllImport(nativeLibName,CallingConvention = CallingConvention.Cdecl)]
public static extern Matrix MatrixTranslate(float x, float y, float z);
// Returns x-rotation matrix (angle in radians)
[DllImport(nativeLibName,CallingConvention = CallingConvention.Cdecl)]
public static extern Matrix MatrixRotate(Vector3 axis, float angle);
// Returns x-rotation matrix (angle in radians)
[DllImport(nativeLibName,CallingConvention = CallingConvention.Cdecl)]
public static extern Matrix MatrixRotateX(float angle);
// Returns y-rotation matrix (angle in radians)
[DllImport(nativeLibName,CallingConvention = CallingConvention.Cdecl)]
public static extern Matrix MatrixRotateY(float angle);
// Returns z-rotation matrix (angle in radians)
[DllImport(nativeLibName,CallingConvention = CallingConvention.Cdecl)]
public static extern Matrix MatrixRotateZ(float angle);
// Returns scaling matrix
[DllImport(nativeLibName,CallingConvention = CallingConvention.Cdecl)]
public static extern Matrix MatrixScale(float x, float y, float z);
// Returns two matrix multiplication
// NOTE: When multiplying matrices... the order matters!
[DllImport(nativeLibName,CallingConvention = CallingConvention.Cdecl)]
public static extern Matrix MatrixMultiply(Matrix left, Matrix right);
// Returns perspective projection matrix
[DllImport(nativeLibName,CallingConvention = CallingConvention.Cdecl)]
public static extern Matrix MatrixFrustum(double left, double right, double bottom, double top, double near, double far);
// Returns perspective projection matrix
// NOTE: Angle should be provided in radians
[DllImport(nativeLibName,CallingConvention = CallingConvention.Cdecl)]
public static extern Matrix MatrixPerspective(double fovy, double aspect, double near, double far);
// Returns orthographic projection matrix
[DllImport(nativeLibName,CallingConvention = CallingConvention.Cdecl)]
public static extern Matrix MatrixOrtho(double left, double right, double bottom, double top, double near, double far);
// Returns camera look-at matrix (view matrix)
[DllImport(nativeLibName,CallingConvention = CallingConvention.Cdecl)]
public static extern Matrix MatrixLookAt(Vector3 eye, Vector3 target, Vector3 up);
// Returns float array of matrix data
[DllImport(nativeLibName,CallingConvention = CallingConvention.Cdecl)]
public static extern float[] MatrixToFloatV(Matrix mat);
// Returns identity quaternion
[DllImport(nativeLibName,CallingConvention = CallingConvention.Cdecl)]
public static extern Quaternion QuaternionIdentity();
// Computes the length of a quaternion
[DllImport(nativeLibName,CallingConvention = CallingConvention.Cdecl)]
public static extern float QuaternionLength(Quaternion q);
// Normalize provided quaternion
[DllImport(nativeLibName,CallingConvention = CallingConvention.Cdecl)]
public static extern Quaternion QuaternionNormalize(Quaternion q);
// Invert provided quaternion
[DllImport(nativeLibName,CallingConvention = CallingConvention.Cdecl)]
public static extern Quaternion QuaternionInvert(Quaternion q);
// Calculate two quaternion multiplication
[DllImport(nativeLibName,CallingConvention = CallingConvention.Cdecl)]
public static extern Quaternion QuaternionMultiply(Quaternion q1, Quaternion q2);
// Calculate linear interpolation between two quaternions
[DllImport(nativeLibName,CallingConvention = CallingConvention.Cdecl)]
public static extern Quaternion QuaternionLerp(Quaternion q1, Quaternion q2, float amount);
// Calculate slerp-optimized interpolation between two quaternions
[DllImport(nativeLibName,CallingConvention = CallingConvention.Cdecl)]
public static extern Quaternion QuaternionNlerp(Quaternion q1, Quaternion q2, float amount);
// Calculates spherical linear interpolation between two quaternions
[DllImport(nativeLibName,CallingConvention = CallingConvention.Cdecl)]
public static extern Quaternion QuaternionSlerp(Quaternion q1, Quaternion q2, float amount);
// Calculate quaternion based on the rotation from one vector to another
[DllImport(nativeLibName,CallingConvention = CallingConvention.Cdecl)]
public static extern Quaternion QuaternionFromVector3ToVector3(Vector3 from, Vector3 to);
// Returns a quaternion for a given rotation matrix
[DllImport(nativeLibName,CallingConvention = CallingConvention.Cdecl)]
public static extern Quaternion QuaternionFromMatrix(Matrix mat);
// Returns a matrix for a given quaternion
[DllImport(nativeLibName,CallingConvention = CallingConvention.Cdecl)]
public static extern Matrix QuaternionToMatrix(Quaternion q);
// Returns rotation quaternion for an angle and axis
// NOTE: angle must be provided in radians
[DllImport(nativeLibName,CallingConvention = CallingConvention.Cdecl)]
public static extern Quaternion QuaternionFromAxisAngle(Vector3 axis, float angle);
// Returns the rotation angle and axis for a given quaternion
[DllImport(nativeLibName,CallingConvention = CallingConvention.Cdecl)]
public static extern void QuaternionToAxisAngle(Quaternion q, out Vector3 outAxis, float[] outAngle);
// Returns he quaternion equivalent to Euler angles
[DllImport(nativeLibName,CallingConvention = CallingConvention.Cdecl)]
public static extern Quaternion QuaternionFromEuler(float roll, float pitch, float yaw);
// Return the Euler angles equivalent to quaternion (roll, pitch, yaw)
// NOTE: Angles are returned in a Vector3 struct in degrees
[DllImport(nativeLibName,CallingConvention = CallingConvention.Cdecl)]
public static extern Vector3 QuaternionToEuler(Quaternion q);
// Transform a quaternion given a transformation matrix
[DllImport(nativeLibName,CallingConvention = CallingConvention.Cdecl)]
public static extern Quaternion QuaternionTransform(Quaternion q, Matrix mat);
}
}