Watch
2
0
Fork
You've already forked raylib-cs
0
Added new extension "byte.Lerp".
Added new extension "Log" for "TraceLogLevel".
Constructors on Color no longer just truncate the float value, but also round it (+ 0.5f).
New static method on Color, "Color.Lerp".
Added static method "FromHSV" to Color.
Added new getter method "GetHSV" on Color.
Added index security on the FilePathList indexer.
Merged Rectangle extensions with the type itself as read-only methods.
Merged Image extensions with the type itself.
Merged Texture2D extensions with the type itself.
New file "Raymath.Utils" with some useful methods taken from Unity.
Added "MoveTowards" extensions to RaylibExtensions.
Added "TranslateLocal" and "TranslateGlobal" to Transform.
Added "Load", "Export", "ExportAsCode", "Format", "Crop", and "Unload" shortcut methods to Wave.
Added "IsValid" property to Wave, Texture2D, Sound, Shader, RenderTexture2D, Music, Image, Model, Material, Font, and AudioStream.
Added "IsPlaying" and "IsProcessed" properties to AudioStream.
Added "Load", "Play", "Stop", "Pause", "Resume", "SetBufferSizeDefault", "SetPan", "SetPitch", "SetVolume", and "Unload" shortcut methods to AudioStream.
Added "Load", "Export", and "Unload" methods to AutomationEventList.
Added "Default" property to Font.
Added "Load", "GetMaterial", "GetTexture", "SetTexture", "SetShader", and "Unload" methods to material.
Added "Draw", "DrawInstanced", "Export", "ExportAsCode", "Upload", and "Unload" methods to Mesh.
Added "Load", "LoadFromMesh", "Unload", and a lot of "Draw" overloads.
Added "Load", "Play", "Pause", "Stop", "SetPan", "SetPitch", "SetVolume", "Seek", and "Unload" methods to Music.
Added "Load" and "Unload" methods to RenderTexture2D.
Added "Load", "LoadFromMemory", "GetLocationAttrib", "SetValue", "SetTexture", "SetMatrix", and "Unload" methods to Shader.
Removed unnecessary "partial" declarations.
This commit is contained in:
Matorio 2025-07-17 03:14:57 -05:00
commit b84a0d4f12
31 changed files with 1090 additions and 395 deletions

View file

@ -1,367 +1,26 @@
using System.Collections.Generic; using System.Collections.Generic;
using static Raylib_cs.Raylib;
using System.Numerics; using System.Numerics;
namespace Raylib_cs; namespace Raylib_cs;
public static class RaylibExtensions public static class RaylibExtensions
{ {
#region Rectangle
public static void Draw(this Rectangle rectangle, Color color)
{
DrawRectangleRec(rectangle, color);
}
public static void Draw(this Rectangle rec, Vector2 origin, Color color)
{
rec.Draw(origin, 0.0f, color);
}
public static void Draw(this Rectangle rec, Vector2 origin, float rotation, Color color)
{
DrawRectanglePro(rec, origin, rotation, color);
}
public static void GetIntegerPosition(this Rectangle rec, out int x, out int y)
{
x = (int)rec.X;
y = (int)rec.Y;
}
public static void GetIntegerDimentions(this Rectangle rec, out int width, out int height)
{
width = (int)rec.Width;
height = (int)rec.Height;
}
public static void GetIntegerValues(this Rectangle rec, out int x, out int y, out int width, out int height)
{
x = (int)rec.X;
y = (int)rec.Y;
width = (int)rec.Width;
height = (int)rec.Height;
}
public static void DrawLines(this Rectangle rectangle, Color color)
{
rectangle.GetIntegerValues(out int x, out int y, out int w, out int h);
DrawRectangleLines(x, y, w, h, color);
}
public static void DrawLines(this Rectangle rectangle, float thickness, Color color)
{
DrawRectangleLinesEx(rectangle, thickness, color);
}
public static void DrawGradient(this Rectangle rec, Color topLeft, Color bottomLeft, Color topRight, Color bottomRight)
{
DrawRectangleGradientEx(rec, topLeft, bottomLeft, topRight, bottomRight);
}
public static void DrawGradientV(this Rectangle rectangle, Color top, Color bottom)
{
rectangle.GetIntegerValues(out int x, out int y, out int w, out int h);
DrawRectangleGradientV(x, y, w, h, top, bottom);
}
public static void DrawGradientH(this Rectangle rec, Color left, Color right)
{
rec.GetIntegerValues(out int x, out int y, out int w, out int h);
DrawRectangleGradientH(x, y, w, h, left, right);
}
public static void DrawRounded(this Rectangle rec, float roundness, Color color)
{
DrawRectangleRounded(rec, roundness, 10, color);
}
public static void DrawRounded(this Rectangle rec, float roundness, int segments, Color color)
{
DrawRectangleRounded(rec, roundness, segments, color);
}
public static void DrawRoundedLines(this Rectangle rec, float roundness, Color color)
{
DrawRectangleRoundedLines(rec, roundness, 10, color);
}
public static void DrawRoundedLines(this Rectangle rec, float roundness, int segments, Color color)
{
DrawRectangleRoundedLines(rec, roundness, segments, color);
}
public static void DrawRoundedLines(this Rectangle rec, float roundness, float thickness, Color color)
{
DrawRectangleRoundedLinesEx(rec, roundness, 10, thickness, color);
}
public static void DrawRoundedLines(this Rectangle rec, float roundness, int segments, float thickness, Color color)
{
DrawRectangleRoundedLinesEx(rec, roundness, segments, thickness, color);
}
public static CBool CheckCollision(this Rectangle rec, Rectangle rectangle)
{
return CheckCollisionRecs(rec, rectangle);
}
public static CBool CheckCollision(this Rectangle rec, Vector2 point)
{
return CheckCollisionPointRec(point, rec);
}
public static CBool CheckCircleCollision(this Rectangle rec, Vector2 center, float radius)
{
return CheckCollisionCircleRec(center, radius, rec);
}
public static CBool CheckColllisionCircle(this Rectangle rec, Vector2 position, float radius)
{
return CheckCollisionCircleRec(position, radius, rec);
}
public static Rectangle GetCollisionRectangle(this Rectangle rectangle, Rectangle rectangle2)
{
return GetCollisionRec(rectangle, rectangle2);
}
#endregion
public static void DrawLines(this IEnumerable<Vector2> points, Color color) public static void DrawLines(this IEnumerable<Vector2> points, Color color)
{ {
Vector2[] pointArray = System.Linq.Enumerable.ToArray<Vector2>(points); Vector2[] pointArray = System.Linq.Enumerable.ToArray<Vector2>(points);
DrawLineStrip(pointArray, pointArray.Length, color); Raylib.DrawLineStrip(pointArray, pointArray.Length, color);
} }
#region Image public static void Log(this TraceLogLevel logLevel, string message)
public static void Load(this ref Image image, string fileName)
{ {
image = LoadImage(fileName); Raylib.TraceLog(logLevel, message);
} }
public static void Load(this ref Image image, string fileType, byte[] data) public static byte Lerp(this byte a, byte b, float t)
{ {
image = LoadImageFromMemory(fileType, data); return (byte)(a + (b - a) * t);
} }
public static void Load(this ref Image image, Texture2D texture)
{
image = LoadImageFromTexture(texture);
}
public static void Load(this ref Image image, string fileName, int width, int height, PixelFormat format, int headerSize)
{
image = LoadImageRaw(fileName, width, height, format, headerSize);
}
public static void Unload(this Image image)
{
UnloadImage(image);
}
public static unsafe Color[] GetPalette(this Image image, int maxPaletteSize)
{
int colorCount = 0;
Color* colors = LoadImagePalette(image, maxPaletteSize, &colorCount);
Color[] palette = new Color[colorCount];
for (int i = 0; i < colorCount; i++)
{
palette[i] = colors[i];
}
UnloadImagePalette(colors);
return palette;
}
public static void LoadFromScreen(this ref Image image)
{
image = LoadImageFromScreen();
}
public static void DrawLine(this ref Image image, Vector2 start, Vector2 end, Color color)
{
ImageDrawLineV(ref image, start, end, color);
}
public static void DrawLine(this ref Image image, Vector2 start, Vector2 end, int thickness, Color color)
{
ImageDrawLineEx(ref image, start, end, thickness, color);
}
public static void DrawCircle(this ref Image image, Vector2 position, float radius, Color color)
{
ImageDrawCircle(ref image, (int)position.X, (int)position.Y, (int)radius, color);
}
public static void Draw(this ref Image image, Rectangle rectangle, Color color)
{
ImageDrawRectangleRec(ref image, rectangle, color);
}
public static void Draw(this ref Image image, string text, Vector2 position, int fontSize, Color color)
{
ImageDrawText(ref image, text, (int)position.X, (int)position.Y, fontSize, color);
}
public static void Draw(this ref Image image, Font font, string text, Vector2 position, int fontSize, float spacing, Color color)
{
ImageDrawTextEx(ref image, font, text, position, fontSize, spacing, color);
}
public static unsafe void DrawCircleLines(this ref Image image, Vector2 position, float radius, Color color)
{
ImageDrawCircleLinesV(ref image, position, (int)radius, color);
}
public static void DrawTriangle(this ref Image image, Vector2 p1, Vector2 p2, Vector2 p3, Color color)
{
ImageDrawTriangle(ref image, p1, p2, p3, color);
}
public static void DrawTriangle(this ref Image image, Vector2 p1, Vector2 p2, Vector2 p3, Color c1, Color c2, Color c3)
{
ImageDrawTriangleEx(ref image, p1, p2, p3, c1, c2, c3);
}
public static void DrawLines(this ref Image image, Rectangle rectangle, Color color)
{
ImageDrawRectangleLines(ref image, rectangle, 1, color);
}
public static void DrawLines(this ref Image image, Rectangle rectangle, int thickness, Color color)
{
ImageDrawRectangleLines(ref image, rectangle, thickness, color);
}
#endregion
#region Texture2D
public static void Load(this ref Texture2D texture, string fileName)
{
texture = LoadTexture(fileName);
}
public static void Load(this ref Texture2D texture, Image image)
{
texture = LoadTextureFromImage(image);
}
public static void Load(this ref Texture2D texture, string fileType, byte[] fileData)
{
Image img = LoadImageFromMemory(fileType, fileData);
texture.Load(img);
UnloadImage(img);
}
public static void Unload(this Texture2D texture)
{
UnloadTexture(texture);
}
public static void SetFilter(this Texture2D texture, TextureFilter filter)
{
SetTextureFilter(texture, filter);
}
public static void SetWrap(this Texture2D texture, TextureWrap wrap)
{
SetTextureWrap(texture, wrap);
}
public static void Update<T>(this Texture2D texture, T[] pixels) where T : unmanaged
{
UpdateTexture(texture, pixels);
}
public static Rectangle GetSourceRectangle(this Texture2D texture)
{
return new Rectangle(Vector2.Zero, texture.Width, texture.Height);
}
public static void Draw(this Texture2D texture, int x, int y)
{
DrawTexture(texture, x, y, Color.White);
}
public static void Draw(this Texture2D texture, int x, int y, Color color)
{
DrawTexture(texture, x, y, color);
}
public static void Draw(this Texture2D texture, Vector2 position)
{
DrawTexture(texture, (int)position.X, (int)position.Y, Color.White);
}
public static void Draw(this Texture2D texture, Vector2 position, Vector2 origin)
{
Vector2 size = texture.Dimensions;
Rectangle source = new Rectangle(Vector2.Zero, size);
Rectangle target = new Rectangle(position, size);
DrawTexturePro(texture, source, target, origin, 0, Color.White);
}
public static void Draw(this Texture2D texture, Vector2 position, Vector2 origin, Color color)
{
Vector2 size = texture.Dimensions;
Rectangle source = new Rectangle(Vector2.Zero, size);
Rectangle target = new Rectangle(position, size);
DrawTexturePro(texture, source, target, origin, 0, color);
}
public static void Draw(this Texture2D texture, Vector2 position, Color color)
{
DrawTexture(texture, (int)position.X, (int)position.Y, color);
}
public static void Draw(this Texture2D texture, Vector2 position, float rotation, float scale)
{
DrawTextureEx(texture, position, rotation, scale, Color.White);
}
public static void Draw(this Texture2D texture, Vector2 position, float rotation, float scale, Color color)
{
DrawTextureEx(texture, position, rotation, scale, color);
}
public static void Draw(this Texture2D texture, Vector2 position, float rotation, Vector2 scale)
{
Draw(texture, position, rotation, scale, Color.White);
}
public static void Draw(this Texture2D texture, Vector2 position, float rotation, Vector2 scale, Color color)
{
Vector2 size = new Vector2(texture.Width, texture.Height);
Rectangle source = new Rectangle(Vector2.Zero, size);
Rectangle target = new Rectangle(position, size);
target.Size *= scale;
DrawTexturePro(texture, source, target, Vector2.Zero, rotation, color);
}
public static void Draw(this Texture2D texture, Rectangle source, Rectangle dest)
{
DrawTexturePro(texture, source, dest, Vector2.Zero, 0, Color.White);
}
public static void Draw(this Texture2D texture, Rectangle source, Rectangle dest, Vector2 origin)
{
DrawTexturePro(texture, source, dest, origin, 0, Color.White);
}
public static void Draw(this Texture2D texture, Rectangle source, Rectangle dest, Vector2 origin, float rotation)
{
DrawTexturePro(texture, source, dest, origin, rotation, Color.White);
}
public static void Draw(this Texture2D texture, Rectangle source, Rectangle dest, Vector2 origin, float rotation, Color color)
{
DrawTexturePro(texture, source, dest, origin, rotation, color);
}
#endregion
#region Vector #region Vector
public static void Normalize(this ref Vector2 vector) public static void Normalize(this ref Vector2 vector)
@ -414,5 +73,15 @@ public static class RaylibExtensions
return Raymath.Vector3Lerp(v1, v2, amount); return Raymath.Vector3Lerp(v1, v2, amount);
} }
public static Vector2 MoveTowards(this Vector2 v1, Vector2 v2, float t)
{
return Raymath.Vector2MoveTowards(v1, v2, t);
}
public static Vector3 MoveTowards(this Vector3 v1, Vector3 v2, float t)
{
return Raymath.Vector3MoveTowards(v1, v2, t);
}
#endregion #endregion
} }

View file

@ -37,12 +37,9 @@ public static unsafe partial class Raymath
/// <summary>Remap input value within input range to output range</summary> /// <summary>Remap input value within input range to output range</summary>
[DllImport(NativeLibName, CallingConvention = CallingConvention.Cdecl)] [DllImport(NativeLibName, CallingConvention = CallingConvention.Cdecl)]
public static extern float Remap( public static extern float Remap(float value,
float value, float inputStart, float inputEnd,
float inputStart, float outputStart, float outputEnd
float inputEnd,
float outputStart,
float outputEnd
); );
/// <summary>Wrap input value from min to max</summary> /// <summary>Wrap input value from min to max</summary>

View file

@ -0,0 +1 @@

View file

@ -0,0 +1 @@

View file

View file

View file

@ -0,0 +1 @@

View file

@ -35,4 +35,68 @@ public partial struct AudioStream
/// Number of channels (1-mono, 2-stereo) /// Number of channels (1-mono, 2-stereo)
/// </summary> /// </summary>
public uint Channels; public uint Channels;
public readonly CBool IsValid => Raylib.IsAudioStreamValid(this);
public readonly CBool IsPlaying => Raylib.IsAudioStreamPlaying(this);
public readonly CBool IsProcessed => Raylib.IsAudioStreamProcessed(this);
public static AudioStream Load(uint sampleRate, uint sampleSize, uint channels)
{
return Raylib.LoadAudioStream(sampleRate, sampleSize, channels);
}
public readonly void Play()
{
Raylib.PlayAudioStream(this);
}
public readonly void Pause()
{
Raylib.PauseAudioStream(this);
}
public readonly void Resume()
{
Raylib.ResumeAudioStream(this);
}
public readonly void Stop()
{
Raylib.StopAudioStream(this);
}
public static void SetBufferSizeDefault(int size)
{
Raylib.SetAudioStreamBufferSizeDefault(size);
}
/// <summary>
/// Set pan for this audio stream where 0.5 is centered
/// </summary>
/// <param name="pan"></param>
public void SetPan(float pan)
{
Raylib.SetAudioStreamPan(this, pan);
}
/// <summary>
/// Set pitch for this audio stream where 1.0 si base level
/// </summary>
public void SetPitch(float pitch)
{
Raylib.SetAudioStreamPitch(this, pitch);
}
/// <summary>
/// Set the volume from 0.0 to 1.0
/// </summary>
public void SetVolume(float volume)
{
Raylib.SetAudioStreamVolume(this, volume);
}
public void Unload()
{
Raylib.UnloadAudioStream(this);
}
} }

View file

@ -15,6 +15,11 @@ public unsafe struct AutomationEvent
/// <summary>Event parameters (if required)</summary> /// <summary>Event parameters (if required)</summary>
public fixed int Params[4]; public fixed int Params[4];
public readonly void Play()
{
Raylib.PlayAutomationEvent(this);
}
} }
/// <summary>Automation event list</summary> /// <summary>Automation event list</summary>
@ -31,5 +36,21 @@ public unsafe struct AutomationEventList
public AutomationEvent* Events; public AutomationEvent* Events;
/// <inheritdoc cref="Events"/> /// <inheritdoc cref="Events"/>
public ReadOnlySpan<AutomationEvent> EventsAsSpan => new(Events, (int)Count); public readonly ReadOnlySpan<AutomationEvent> EventsAsSpan => new ReadOnlySpan<AutomationEvent>(Events, (int)Count);
public static AutomationEventList Load(string fileName)
{
return Raylib.LoadAutomationEventList(fileName);
}
public readonly CBool Export(string fileName)
{
return Raylib.ExportAutomationEventList(this, fileName);
}
public void Unload()
{
Raylib.UnloadAutomationEventList(this);
}
} }

View file

@ -7,7 +7,7 @@ namespace Raylib_cs;
/// Camera2D, defines position/orientation in 2d space /// Camera2D, defines position/orientation in 2d space
/// </summary> /// </summary>
[StructLayout(LayoutKind.Sequential)] [StructLayout(LayoutKind.Sequential)]
public partial struct Camera2D public struct Camera2D
{ {
/// <summary> /// <summary>
/// Camera offset (displacement from target) /// Camera offset (displacement from target)

View file

@ -28,7 +28,7 @@ public enum CameraProjection
/// Camera3D, defines position/orientation in 3d space /// Camera3D, defines position/orientation in 3d space
/// </summary> /// </summary>
[StructLayout(LayoutKind.Sequential)] [StructLayout(LayoutKind.Sequential)]
public partial struct Camera3D public struct Camera3D
{ {
/// <summary> /// <summary>
/// Camera position /// Camera position

View file

@ -7,7 +7,7 @@ namespace Raylib_cs;
/// Color type, RGBA (32bit) /// Color type, RGBA (32bit)
/// </summary> /// </summary>
[StructLayout(LayoutKind.Sequential)] [StructLayout(LayoutKind.Sequential)]
public partial struct Color public struct Color
{ {
public byte R; public byte R;
public byte G; public byte G;
@ -115,7 +115,108 @@ public partial struct Color
this.A = 255; this.A = 255;
} }
public override string ToString() public readonly void GetHSV(out float h, out float s, out float v)
{
float rf = this.R / 255f;
float gf = this.G / 255f;
float bf = this.B / 255f;
float max = MathF.Max(rf, MathF.Max(gf, bf));
float min = MathF.Min(rf, MathF.Min(gf, bf));
float delta = max - min;
// Value
v = max;
// Saturation
s = (max == 0f) ? 0f : delta / max;
// Hue
if (delta == 0f)
{
h = 0f;
}
else if (max == rf)
{
h = 60f * (((gf - bf) / delta) % 6f);
}
else if (max == gf)
{
h = 60f * (((bf - rf) / delta) + 2f);
}
else // max == bf
{
h = 60f * (((rf - gf) / delta) + 4f);
}
// Keep h inside 0 and 360
if (h < 0f)
{
h += 360f;
}
}
public static Color FromHSV(float h, float s, float v)
{
float c = v * s;
float x = c * (1f - MathF.Abs((h / 60f) % 2f - 1f));
float m = v - c;
float rf, gf, bf;
if (h < 60f)
{
rf = c;
gf = x;
bf = 0;
}
else if (h < 120f)
{
rf = x;
gf = c;
bf = 0;
}
else if (h < 180f)
{
rf = 0;
gf = c;
bf = x;
}
else if (h < 240f)
{
rf = 0;
gf = x;
bf = c;
}
else if (h < 300f)
{
rf = x;
gf = 0;
bf = c;
}
else
{
rf = c;
gf = 0;
bf = x;
}
byte r = (byte)((rf + m) * 255f + 0.5f);
byte g = (byte)((gf + m) * 255f + 0.5f);
byte b = (byte)((bf + m) * 255f + 0.5f);
return new Color(r, g, b, byte.MaxValue);
}
public static Color Lerp(Color origin, Color target, float t)
{
byte r = origin.R.Lerp(target.R, t);
byte g = origin.G.Lerp(target.G, t);
byte b = origin.B.Lerp(target.B, t);
byte a = origin.A.Lerp(target.A, t);
return new Color(r, g, b, a);
}
public readonly override string ToString()
{ {
return $"{{R:{R} G:{G} B:{B} A:{A}}}"; return $"{{R:{R} G:{G} B:{B} A:{A}}}";
} }

View file

@ -59,7 +59,7 @@ public partial struct GlyphInfo
/// Font, font texture and GlyphInfo array data /// Font, font texture and GlyphInfo array data
/// </summary> /// </summary>
[StructLayout(LayoutKind.Sequential)] [StructLayout(LayoutKind.Sequential)]
public unsafe partial struct Font public unsafe struct Font
{ {
/// <summary> /// <summary>
/// Base size (default chars height) /// Base size (default chars height)
@ -90,4 +90,8 @@ public unsafe partial struct Font
/// Glyphs info data /// Glyphs info data
/// </summary> /// </summary>
public GlyphInfo* Glyphs; public GlyphInfo* Glyphs;
public readonly CBool IsValid => Raylib.IsFontValid(this);
public static Font Default => Raylib.GetFontDefault();
} }

View file

@ -134,7 +134,7 @@ public enum PixelFormat
/// Image, pixel data stored in CPU memory (RAM) /// Image, pixel data stored in CPU memory (RAM)
/// </summary> /// </summary>
[StructLayout(LayoutKind.Sequential)] [StructLayout(LayoutKind.Sequential)]
public unsafe partial struct Image public unsafe struct Image
{ {
/// <summary> /// <summary>
/// Image raw data /// Image raw data
@ -164,11 +164,117 @@ public unsafe partial struct Image
/// <summary> /// <summary>
/// Get width and height packed in a Vector2 /// Get width and height packed in a Vector2
/// </summary> /// </summary>
public Vector2 Dimensions public readonly Vector2 Dimensions => new Vector2(Width, Height);
public readonly CBool IsValid => Raylib.IsImageValid(this);
public static Image Load(string fileName)
{ {
get return Raylib.LoadImage(fileName);
}
/// <summary>
/// Create an image from text using the default font
/// </summary>
public static Image CreateFromText(string text, int fontSize, Color color)
{
return Raylib.ImageText(text, fontSize, color);
}
public static Image CreateFromText(Font font, string text, int fontSize, float spacing, Color color)
{
return Raylib.ImageTextEx(font, text, fontSize, spacing, color);
}
public static Image LoadFromMemory(string fileType, byte[] data)
{
return Raylib.LoadImageFromMemory(fileType, data);
}
public static Image LoadFromTexture(Texture2D texture)
{
return Raylib.LoadImageFromTexture(texture);
}
public static Image LoadRaw(string fileName, int width, int height, PixelFormat format, int headerSize)
{
return Raylib.LoadImageRaw(fileName, width, height, format, headerSize);
}
public readonly void Unload()
{
Raylib.UnloadImage(this);
}
public readonly unsafe Color[] GetPalette(int maxPaletteSize)
{
int colorCount = 0;
Color* colors = Raylib.LoadImagePalette(this, maxPaletteSize, &colorCount);
Color[] palette = new Color[colorCount];
for (int i = 0; i < colorCount; i++)
{ {
return new Vector2(Width, Height); palette[i] = colors[i];
} }
Raylib.UnloadImagePalette(colors);
return palette;
}
public static Image LoadFromScreen()
{
return Raylib.LoadImageFromScreen();
}
public void DrawLine(Vector2 start, Vector2 end, Color color)
{
Raylib.ImageDrawLineV(ref this, start, end, color);
}
public void DrawLine(Vector2 start, Vector2 end, int thickness, Color color)
{
Raylib.ImageDrawLineEx(ref this, start, end, thickness, color);
}
public void DrawCircle(Vector2 position, float radius, Color color)
{
Raylib.ImageDrawCircle(ref this, (int)position.X, (int)position.Y, (int)radius, color);
}
public void DrawRectangle(Rectangle rectangle, Color color)
{
Raylib.ImageDrawRectangleRec(ref this, rectangle, color);
}
public void DrawText(string text, Vector2 position, int fontSize, Color color)
{
Raylib.ImageDrawText(ref this, text, (int)position.X, (int)position.Y, fontSize, color);
}
public void DrawText(Font font, string text, Vector2 position, int fontSize, float spacing, Color color)
{
Raylib.ImageDrawTextEx(ref this, font, text, position, fontSize, spacing, color);
}
public unsafe void DrawCircleLines(Vector2 position, float radius, Color color)
{
Raylib.ImageDrawCircleLinesV(ref this, position, (int)radius, color);
}
public void DrawTriangle(Vector2 p1, Vector2 p2, Vector2 p3, Color color)
{
Raylib.ImageDrawTriangle(ref this, p1, p2, p3, color);
}
public void DrawTriangle(Vector2 p1, Vector2 p2, Vector2 p3, Color c1, Color c2, Color c3)
{
Raylib.ImageDrawTriangleEx(ref this, p1, p2, p3, c1, c2, c3);
}
public void DrawRectangleLines(Rectangle rectangle, Color color)
{
Raylib.ImageDrawRectangleLines(ref this, rectangle, 1, color);
}
public void DrawRectangleLines(Rectangle rectangle, int thickness, Color color)
{
Raylib.ImageDrawRectangleLines(ref this, rectangle, thickness, color);
} }
} }

View file

@ -29,7 +29,7 @@ internal readonly struct Native
} }
[StructLayout(LayoutKind.Sequential, Pack = 4)] [StructLayout(LayoutKind.Sequential, Pack = 4)]
struct VaListLinuxX64 internal struct VaListLinuxX64
{ {
uint _gpOffset; uint _gpOffset;
uint _fpOffset; uint _fpOffset;
@ -95,7 +95,7 @@ public static unsafe class Logging
} }
} }
static string LinuxX64LogCallback(IntPtr format, IntPtr args) private static string LinuxX64LogCallback(IntPtr format, IntPtr args)
{ {
// The args pointer cannot be reused between two calls. We need to make a copy of the underlying structure. // The args pointer cannot be reused between two calls. We need to make a copy of the underlying structure.
VaListLinuxX64 listStructure = Marshal.PtrToStructure<VaListLinuxX64>(args); VaListLinuxX64 listStructure = Marshal.PtrToStructure<VaListLinuxX64>(args);
@ -125,7 +125,7 @@ public static unsafe class Logging
} }
// https://github.com/dotnet/runtime/issues/51052 // https://github.com/dotnet/runtime/issues/51052
static int VsnPrintf(IntPtr buffer, UIntPtr size, IntPtr format, IntPtr args) private static int VsnPrintf(IntPtr buffer, UIntPtr size, IntPtr format, IntPtr args)
{ {
OperatingSystem os = Environment.OSVersion; OperatingSystem os = Environment.OSVersion;
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
@ -144,7 +144,7 @@ public static unsafe class Logging
} }
// https://github.com/dotnet/runtime/issues/51052 // https://github.com/dotnet/runtime/issues/51052
static int VsPrintf(IntPtr buffer, IntPtr format, IntPtr args) private static int VsPrintf(IntPtr buffer, IntPtr format, IntPtr args)
{ {
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
{ {

View file

@ -48,7 +48,7 @@ public enum MaterialMapIndex
/// Material texture map /// Material texture map
/// </summary> /// </summary>
[StructLayout(LayoutKind.Sequential)] [StructLayout(LayoutKind.Sequential)]
public partial struct MaterialMap public struct MaterialMap
{ {
/// <summary> /// <summary>
/// Material map texture /// Material map texture
@ -70,7 +70,7 @@ public partial struct MaterialMap
/// Material type (generic) /// Material type (generic)
/// </summary> /// </summary>
[StructLayout(LayoutKind.Sequential)] [StructLayout(LayoutKind.Sequential)]
public unsafe partial struct Material public unsafe struct Material
{ {
/// <summary> /// <summary>
/// Material shader /// Material shader
@ -87,4 +87,55 @@ public unsafe partial struct Material
/// Material generic parameters (if required) /// Material generic parameters (if required)
/// </summary> /// </summary>
public fixed float Param[4]; public fixed float Param[4];
public readonly CBool IsValid => Raylib.IsMaterialValid(this);
/// <summary>
/// Load default material
/// </summary>
public static Material Load()
{
return Raylib.LoadMaterialDefault();
}
/// <summary>
/// Load materials from model file
/// </summary>
public static Material[] Load(string fileName)
{
using AnsiBuffer buffer = fileName.ToAnsiBuffer();
int count = 0;
Material* materials = Raylib.LoadMaterials(buffer.AsPointer(), &count);
Material[] output = new Material[count];
for (int i = 0; i < count; i++)
{
output[i] = materials[i];
}
return output;
}
public static Material GetMaterial(ref Model model, int materialIndex)
{
return Raylib.GetMaterial(ref model, materialIndex);
}
public static Texture2D GetTexture(ref Model model, int materialIndex, MaterialMapIndex mapIndex)
{
return Raylib.GetMaterialTexture(ref model, materialIndex, mapIndex);
}
public void SetTexture(MaterialMapIndex mapIndex, Texture2D texture)
{
Raylib.SetMaterialTexture(ref this, mapIndex, texture);
}
public static void SetShader(ref Model model, int materialIndex, ref Shader shader)
{
Raylib.SetMaterialShader(ref model, materialIndex, ref shader);
}
public void Unload()
{
Raylib.UnloadMaterial(this);
}
} }

View file

@ -9,7 +9,7 @@ namespace Raylib_cs;
/// NOTE: Data stored in CPU memory (and GPU) /// NOTE: Data stored in CPU memory (and GPU)
/// </summary> /// </summary>
[StructLayout(LayoutKind.Sequential)] [StructLayout(LayoutKind.Sequential)]
public unsafe partial struct Mesh public unsafe struct Mesh
{ {
/// <summary> /// <summary>
/// Creates a mesh ready for default vertex data allocation /// Creates a mesh ready for default vertex data allocation
@ -30,6 +30,36 @@ public unsafe partial struct Mesh
/// </summary> /// </summary>
public int TriangleCount; public int TriangleCount;
public readonly void Draw(Material material, Matrix4x4 transform)
{
Raylib.DrawMesh(this, material, transform);
}
public readonly void DrawInstanced(Material material, Matrix4x4[] transforms, int instances)
{
Raylib.DrawMeshInstanced(this, material, transforms, instances);
}
public readonly void Export(string fileName)
{
Raylib.ExportMesh(this, fileName);
}
public readonly void ExportAsCode(string fileName)
{
Raylib.ExportMeshAsCode(this, fileName);
}
public void Upload(CBool dynamic)
{
Raylib.UploadMesh(ref this, dynamic);
}
public void Unload()
{
Raylib.UnloadMesh(this);
}
#region Default vertex data #region Default vertex data
/// <summary> /// <summary>

View file

@ -8,7 +8,7 @@ namespace Raylib_cs;
/// Bone information /// Bone information
/// </summary> /// </summary>
[StructLayout(LayoutKind.Sequential)] [StructLayout(LayoutKind.Sequential)]
public unsafe partial struct BoneInfo public unsafe struct BoneInfo
{ {
/// <summary> /// <summary>
/// Bone name (char[32]) /// Bone name (char[32])
@ -25,7 +25,7 @@ public unsafe partial struct BoneInfo
/// Model type /// Model type
/// </summary> /// </summary>
[StructLayout(LayoutKind.Sequential)] [StructLayout(LayoutKind.Sequential)]
public unsafe partial struct Model public unsafe struct Model
{ {
/// <summary> /// <summary>
/// Local transform matrix /// Local transform matrix
@ -73,13 +73,105 @@ public unsafe partial struct Model
/// Bones base transformation (pose, Transform *) /// Bones base transformation (pose, Transform *)
/// </summary> /// </summary>
public Transform* BindPose; public Transform* BindPose;
public readonly CBool IsValid => Raylib.IsModelValid(this);
public static Model Load(string fileName)
{
return Raylib.LoadModel(fileName);
}
public static Model LoadFromMesh(Mesh mesh)
{
return Raylib.LoadModelFromMesh(mesh);
}
public readonly void Draw(Vector3 position)
{
Raylib.DrawModel(this, position, 1.0f, Color.White);
}
public readonly void Draw(Vector3 position, float scale)
{
Raylib.DrawModel(this, position, scale, Color.White);
}
public readonly void Draw(Vector3 position, float scale, Color color)
{
Raylib.DrawModel(this, position, scale, color);
}
public readonly void Draw(Vector3 position, Vector3 rotationAxis, float rotationAngle)
{
Raylib.DrawModelEx(this, position, rotationAxis, rotationAngle, Vector3.One, Color.White);
}
public readonly void Draw(Vector3 position, Vector3 rotationAxis, float rotationAngle, Vector3 scale)
{
Raylib.DrawModelEx(this, position, rotationAxis, rotationAngle, scale, Color.White);
}
public readonly void Draw(Vector3 position, Vector3 rotationAxis, float rotationAngle, Vector3 scale, Color color)
{
Raylib.DrawModelEx(this, position, rotationAxis, rotationAngle, scale, color);
}
public readonly void DrawWires(Vector3 position, Color color)
{
Raylib.DrawModelWires(this, position, 1.0f, color);
}
public readonly void DrawWires(Vector3 position, float scale)
{
Raylib.DrawModelWires(this, position, scale, Color.White);
}
public readonly void DrawWires(Vector3 position, float scale, Color color)
{
Raylib.DrawModelWires(this, position, scale, color);
}
public readonly void DrawWires(Vector3 position, Vector3 rotationAxis, float rotationAngle, Color color)
{
Raylib.DrawModelWiresEx(this, position, rotationAxis, rotationAngle, Vector3.One, color);
}
public readonly void DrawWires(Vector3 position, Vector3 rotationAxis, float rotationAngle, Vector3 scale, Color color)
{
Raylib.DrawModelWiresEx(this, position, rotationAxis, rotationAngle, scale, color);
}
public readonly void DrawPoints(Vector3 position, Color color)
{
Raylib.DrawModelPoints(this, position, 1.0f, color);
}
public readonly void DrawPoints(Vector3 position, float scale, Color color)
{
Raylib.DrawModelPoints(this, position, scale, color);
}
public readonly void DrawPoints(Vector3 position, Vector3 rotationAxis, float rotationAngle, Color color)
{
Raylib.DrawModelPointsEx(this, position, rotationAxis, rotationAngle, Vector3.One, color);
}
public readonly void DrawPoints(Vector3 position, Vector3 rotationAxis, float rotationAngle, Vector3 scale, Color color)
{
Raylib.DrawModelPointsEx(this, position, rotationAxis, rotationAngle, scale, color);
}
public void Unload()
{
Raylib.UnloadModel(this);
}
} }
/// <summary> /// <summary>
/// Model animation /// Model animation
/// </summary> /// </summary>
[StructLayout(LayoutKind.Sequential)] [StructLayout(LayoutKind.Sequential)]
public unsafe partial struct ModelAnimation public unsafe struct ModelAnimation
{ {
/// <summary> /// <summary>
/// Number of bones /// Number of bones
@ -110,7 +202,7 @@ public unsafe partial struct ModelAnimation
public fixed sbyte Name[32]; public fixed sbyte Name[32];
/// <inheritdoc cref="FramePoses"/> /// <inheritdoc cref="FramePoses"/>
public FramePosesCollection FramePosesColl => new(FramePoses, FrameCount, BoneCount); public readonly FramePosesCollection FramePosesColl => new FramePosesCollection(FramePoses, FrameCount, BoneCount);
public struct FramePosesCollection public struct FramePosesCollection
{ {
@ -120,9 +212,9 @@ public unsafe partial struct ModelAnimation
readonly int _boneCount; readonly int _boneCount;
public FramePoses this[int index] => new(_framePoses[index], _boneCount); public readonly FramePoses this[int index] => new FramePoses(_framePoses[index], _boneCount);
public Transform this[int index1, int index2] => new FramePoses(_framePoses[index1], _boneCount)[index2]; public readonly Transform this[int index1, int index2] => new FramePoses(_framePoses[index1], _boneCount)[index2];
internal FramePosesCollection(Transform** framePoses, int frameCount, int boneCount) internal FramePosesCollection(Transform** framePoses, int frameCount, int boneCount)
{ {
@ -131,6 +223,31 @@ public unsafe partial struct ModelAnimation
this._boneCount = boneCount; this._boneCount = boneCount;
} }
} }
public static ModelAnimation[] LoadAnimations(string fileName)
{
int count = 0;
ModelAnimation* animations = Raylib.LoadModelAnimations(fileName, ref count);
ModelAnimation[] output = new ModelAnimation[count];
for (int i = 0; i < count; i++)
{
output[i] = animations[i];
}
return output;
}
public static void UnloadAnimations(ModelAnimation[] modelAnimations)
{
fixed (ModelAnimation* ptr = modelAnimations)
{
Raylib.UnloadModelAnimations(ptr, modelAnimations.Length);
}
}
public void Unload()
{
Raylib.UnloadModelAnimation(this);
}
} }
public unsafe struct FramePoses public unsafe struct FramePoses

View file

@ -7,7 +7,7 @@ namespace Raylib_cs;
/// NOTE: Anything longer than ~10 seconds should be streamed /// NOTE: Anything longer than ~10 seconds should be streamed
/// </summary> /// </summary>
[StructLayout(LayoutKind.Sequential)] [StructLayout(LayoutKind.Sequential)]
public unsafe partial struct Music public unsafe struct Music
{ {
/// <summary> /// <summary>
/// Audio stream /// Audio stream
@ -34,4 +34,63 @@ public unsafe partial struct Music
/// Audio context data, depends on type /// Audio context data, depends on type
/// </summary> /// </summary>
public void* CtxData; public void* CtxData;
public readonly CBool IsValid => Raylib.IsMusicValid(this);
public static Music Load(string fileName)
{
return Raylib.LoadMusicStream(fileName);
}
public readonly void Play()
{
Raylib.PlayMusicStream(this);
}
public readonly void Pause()
{
Raylib.PauseMusicStream(this);
}
public readonly void Stop()
{
Raylib.StopMusicStream(this);
}
/// <summary>
/// Set pan of this music where 0.5 is centered
/// </summary>
public void SetPan(float pan)
{
Raylib.SetMusicPan(this, pan);
}
/// <summary>
/// Set pitch for this music where 1.0 is base level
/// </summary>}
public void SetPitch(float pitch)
{
Raylib.SetMusicPitch(this, pitch);
}
/// <summary>
/// Set music volume from 0.0 to 1.0
/// </summary>
public void SetVolume(float volume)
{
Raylib.SetMusicVolume(this, volume);
}
/// <summary>
/// Seek music to a position (in seconds)
/// </summary>
public void Seek(float position)
{
Raylib.SeekMusicStream(this, position);
}
public void Unload()
{
Raylib.UnloadMusicStream(this);
}
} }

View file

@ -27,7 +27,7 @@ public enum NPatchLayout
/// N-Patch layout info /// N-Patch layout info
/// </summary> /// </summary>
[StructLayout(LayoutKind.Sequential)] [StructLayout(LayoutKind.Sequential)]
public partial struct NPatchInfo public struct NPatchInfo
{ {
/// <summary> /// <summary>
/// Texture source rectangle /// Texture source rectangle

View file

@ -7,7 +7,7 @@ namespace Raylib_cs;
/// Ray, ray for raycasting /// Ray, ray for raycasting
/// </summary> /// </summary>
[StructLayout(LayoutKind.Sequential)] [StructLayout(LayoutKind.Sequential)]
public partial struct Ray public struct Ray
{ {
/// <summary> /// <summary>
/// Ray position (origin) /// Ray position (origin)
@ -30,7 +30,7 @@ public partial struct Ray
/// Raycast hit information /// Raycast hit information
/// </summary> /// </summary>
[StructLayout(LayoutKind.Sequential)] [StructLayout(LayoutKind.Sequential)]
public partial struct RayCollision public struct RayCollision
{ {
/// <summary> /// <summary>
/// Did the ray hit something? /// Did the ray hit something?

View file

@ -0,0 +1,98 @@
using System;
namespace Raylib_cs;
public static partial class Raymath
{
public static float Clamp01(float value) => Clamp(value, 0.0f, 1.0f);
/// <summary>
/// Loops the value, so that it is never larger than length and never smaller than 0
/// </summary>
public static float Repeat(float value, float length)
{
return Clamp(value - MathF.Floor(value / length) * length, 0f, length);
}
/// <summary>
/// Same as Lerp but makes sure the values interpolate correctly when they wrap around
/// 360 degrees.
/// </summary>
/// <param name="a">The start angle. A float expressed in degrees.</param>
/// <param name="b">The end angle. A float expressed in degrees.</param>
/// <param name="t">The interpolation value between the start and end angles.
/// This value is clamped to the range [0, 1].</param>
/// <returns>Returns the interpolated float result between angle a and angle b,
/// based on the interpolation value t.</returns>
public static float LerpAngle(float a, float b, float t)
{
float num = Repeat(b - a, 360f);
if (num > 180f)
{
num -= 360f;
}
return a + num * Clamp01(t);
}
public static int Sign(float value) => MathF.Sign(value);
/// <summary>
/// Returns a value that increments and decrements between zero and the
/// length. It follows the triangle wave formula where the bottom is set to zero
/// and the peak is set to length.
/// </summary>
public static float PingPong(float t, float length)
{
t = Repeat(t, length * 2f);
return length - MathF.Abs(t - length);
}
/// <summary>
/// Moves a value current towards target.
/// </summary>
/// <param name="current">The current value.</param>
/// <param name="target">The value to move towards.</param>
/// <param name="maxDelta">The maximum change applied to the current value.</param>
public static float MoveTowards(float current, float target, float maxDelta)
{
if (MathF.Abs(target - current) <= maxDelta)
{
return target;
}
return current + Sign(target - current) * maxDelta;
}
/// <summary>
/// Calculates the shortest difference between two angles.
/// </summary>
/// <param name="current">The current angle in degrees.</param>
/// <param name="target">The target angle in degrees.</param>
/// <returns>A value between -179 and 180, in degrees.</returns>
public static float DeltaAngle(float current, float target)
{
float num = Repeat(target - current, 360f);
if (num > 180f)
{
num -= 360f;
}
return num;
}
/// <summary>
/// Same as MoveTowards but makes sure the values interpolate correctly when they wrap around 360 degrees.
/// </summary>
public static float MoveTowardsAngle(float current, float target, float maxDelta)
{
float num = DeltaAngle(current, target);
if (0f - maxDelta < num && num < maxDelta)
{
return target;
}
target = current + num;
return MoveTowards(current, target, maxDelta);
}
}

View file

@ -7,7 +7,7 @@ namespace Raylib_cs;
/// Rectangle type /// Rectangle type
/// </summary> /// </summary>
[StructLayout(LayoutKind.Sequential)] [StructLayout(LayoutKind.Sequential)]
public partial struct Rectangle public struct Rectangle
{ {
public float X; public float X;
public float Y; public float Y;
@ -72,7 +72,108 @@ public partial struct Rectangle
} }
} }
public override string ToString() public readonly void Draw(Color color)
{
Raylib.DrawRectangleRec(this, color);
}
public readonly void Draw(Vector2 origin, Color color)
{
Draw(origin, 0.0f, color);
}
public readonly void Draw(Vector2 origin, float rotation, Color color)
{
Raylib.DrawRectanglePro(this, origin, rotation, color);
}
public readonly void GetIntegerValues(out int x, out int y, out int width, out int height)
{
x = (int)this.X;
y = (int)this.Y;
width = (int)this.Width;
height = (int)this.Height;
}
public readonly void DrawLines(Color color)
{
GetIntegerValues(out int x, out int y, out int w, out int h);
Raylib.DrawRectangleLines(x, y, w, h, color);
}
public readonly void DrawLines(float thickness, Color color)
{
Raylib.DrawRectangleLinesEx(this, thickness, color);
}
public readonly void DrawGradient(Color topLeft, Color bottomLeft, Color topRight, Color bottomRight)
{
Raylib.DrawRectangleGradientEx(this, topLeft, bottomLeft, topRight, bottomRight);
}
public readonly void DrawGradientV(Color top, Color bottom)
{
GetIntegerValues(out int x, out int y, out int w, out int h);
Raylib.DrawRectangleGradientV(x, y, w, h, top, bottom);
}
public readonly void DrawGradientH(Color left, Color right)
{
GetIntegerValues(out int x, out int y, out int w, out int h);
Raylib.DrawRectangleGradientH(x, y, w, h, left, right);
}
public readonly void DrawRounded(float roundness, Color color)
{
Raylib.DrawRectangleRounded(this, roundness, 10, color);
}
public readonly void DrawRounded(float roundness, int segments, Color color)
{
Raylib.DrawRectangleRounded(this, roundness, segments, color);
}
public readonly void DrawRoundedLines(float roundness, Color color)
{
Raylib.DrawRectangleRoundedLines(this, roundness, 10, color);
}
public readonly void DrawRoundedLines(float roundness, int segments, Color color)
{
Raylib.DrawRectangleRoundedLines(this, roundness, segments, color);
}
public readonly void DrawRoundedLines(float roundness, float thickness, Color color)
{
Raylib.DrawRectangleRoundedLinesEx(this, roundness, 10, thickness, color);
}
public readonly void DrawRoundedLines(float roundness, int segments, float thickness, Color color)
{
Raylib.DrawRectangleRoundedLinesEx(this, roundness, segments, thickness, color);
}
public readonly CBool CheckCollisionRec(Rectangle rectangle)
{
return Raylib.CheckCollisionRecs(this, rectangle);
}
public readonly CBool CheckCollisionPoint(Vector2 point)
{
return Raylib.CheckCollisionPointRec(point, this);
}
public readonly CBool CheckCollisionCircle(Vector2 center, float radius)
{
return Raylib.CheckCollisionCircleRec(center, radius, this);
}
public readonly Rectangle GetCollisionRectangle(Rectangle rectangle2)
{
return Raylib.GetCollisionRec(this, rectangle2);
}
public readonly override string ToString()
{ {
return $"{{X:{X} Y:{Y} Width:{Width} Height:{Height}}}"; return $"{{X:{X} Y:{Y} Width:{Width} Height:{Height}}}";
} }

View file

@ -7,7 +7,7 @@ namespace Raylib_cs;
/// RenderBatch type /// RenderBatch type
/// </summary> /// </summary>
[StructLayout(LayoutKind.Sequential)] [StructLayout(LayoutKind.Sequential)]
public unsafe partial struct RenderBatch public unsafe struct RenderBatch
{ {
/// <summary> /// <summary>
/// Number of vertex buffers (multi-buffering support) /// Number of vertex buffers (multi-buffering support)
@ -44,7 +44,7 @@ public unsafe partial struct RenderBatch
/// Dynamic vertex buffers (position + texcoords + colors + indices arrays) /// Dynamic vertex buffers (position + texcoords + colors + indices arrays)
/// </summary> /// </summary>
[StructLayout(LayoutKind.Sequential)] [StructLayout(LayoutKind.Sequential)]
public unsafe partial struct VertexBuffer public unsafe struct VertexBuffer
{ {
/// <summary> /// <summary>
/// Number of elements in the buffer (QUADS) /// Number of elements in the buffer (QUADS)

View file

@ -6,7 +6,7 @@ namespace Raylib_cs;
/// RenderTexture2D type, for texture rendering /// RenderTexture2D type, for texture rendering
/// </summary> /// </summary>
[StructLayout(LayoutKind.Sequential)] [StructLayout(LayoutKind.Sequential)]
public partial struct RenderTexture2D public struct RenderTexture2D
{ {
/// <summary> /// <summary>
/// OpenGL Framebuffer Object (FBO) id /// OpenGL Framebuffer Object (FBO) id
@ -22,4 +22,16 @@ public partial struct RenderTexture2D
/// Depth buffer attachment texture /// Depth buffer attachment texture
/// </summary> /// </summary>
public Texture2D Depth; public Texture2D Depth;
public readonly CBool IsValid => Raylib.IsRenderTextureValid(this);
public static RenderTexture2D Load(int width, int height)
{
return Raylib.LoadRenderTexture(width, height);
}
public void Unload()
{
Raylib.UnloadRenderTexture(this);
}
} }

View file

@ -76,7 +76,7 @@ public enum ShaderUniformDataType
/// Shader type (generic) /// Shader type (generic)
/// </summary> /// </summary>
[StructLayout(LayoutKind.Sequential)] [StructLayout(LayoutKind.Sequential)]
public unsafe partial struct Shader public unsafe struct Shader
{ {
/// <summary> /// <summary>
/// Shader program id /// Shader program id
@ -87,4 +87,47 @@ public unsafe partial struct Shader
/// Shader locations array (MAX_SHADER_LOCATIONS, int *) /// Shader locations array (MAX_SHADER_LOCATIONS, int *)
/// </summary> /// </summary>
public int* Locs; public int* Locs;
public readonly CBool IsValid => Raylib.IsShaderValid(this);
public static Shader Load(string vsFileName, string fsFileName)
{
return Raylib.LoadShader(vsFileName, fsFileName);
}
public static Shader LoadFromMemory(string vsCode, string fsCode)
{
return Raylib.LoadShaderFromMemory(vsCode, fsCode);
}
public void GetLocationAttrib(string attribName)
{
Raylib.GetShaderLocationAttrib(this, attribName);
}
public void SetValue<T>(int locationIndex, T value, ShaderUniformDataType uniformDataType) where T : unmanaged
{
void* val = &value;
Raylib.SetShaderValue(this, locationIndex, val, uniformDataType);
}
public void SetValues<T>(int locationIndex, T[] values, ShaderUniformDataType uniformDataType) where T : unmanaged
{
Raylib.SetShaderValueV(this, locationIndex, values, uniformDataType, values.Length);
}
public void SetTexture(int locationIndex, Texture2D texture)
{
Raylib.SetShaderValueTexture(this, locationIndex, texture);
}
public void SetMatrix(int locationIndex, System.Numerics.Matrix4x4 matrix)
{
Raylib.SetShaderValueMatrix(this, locationIndex, matrix);
}
public void Unload()
{
Raylib.UnloadShader(this);
}
} }

View file

@ -6,7 +6,7 @@ namespace Raylib_cs;
/// Sound source type /// Sound source type
/// </summary> /// </summary>
[StructLayout(LayoutKind.Sequential)] [StructLayout(LayoutKind.Sequential)]
public partial struct Sound public struct Sound
{ {
/// <summary> /// <summary>
/// Audio stream /// Audio stream
@ -17,4 +17,61 @@ public partial struct Sound
/// Total number of frames (considering channels) /// Total number of frames (considering channels)
/// </summary> /// </summary>
public uint FrameCount; public uint FrameCount;
public readonly CBool IsValid => Raylib.IsSoundValid(this);
public readonly CBool IsPlaying => Raylib.IsSoundPlaying(this);
public static Sound Load(string fileName)
{
return Raylib.LoadSound(fileName);
}
public static Sound LoadFromWave(Wave wave)
{
return Raylib.LoadSoundFromWave(wave);
}
public readonly void Play()
{
Raylib.PlaySound(this);
}
public readonly void Pause()
{
Raylib.PauseSound(this);
}
public readonly void Resume()
{
Raylib.ResumeSound(this);
}
/// <summary>
/// Set pan where 0.5 is center
/// </summary>
public void SetPan(float pan)
{
Raylib.SetSoundPan(this, pan);
}
/// <summary>
/// Set pitch where 1.0 is base level
/// </summary>
public void SetPitch(float pitch)
{
Raylib.SetSoundPitch(this, pitch);
}
/// <summary>
/// Set volume from 0.0 to 1.0
/// </summary>
public void SetVolume(float volume)
{
Raylib.SetSoundVolume(this, volume);
}
public void Unload()
{
Raylib.UnloadSound(this);
}
} }

View file

@ -103,7 +103,7 @@ public enum CubemapLayout
/// NOTE: Data stored in GPU memory /// NOTE: Data stored in GPU memory
/// </summary> /// </summary>
[StructLayout(LayoutKind.Sequential)] [StructLayout(LayoutKind.Sequential)]
public partial struct Texture2D public struct Texture2D
{ {
/// <summary> /// <summary>
/// OpenGL texture id /// OpenGL texture id
@ -133,11 +133,124 @@ public partial struct Texture2D
/// <summary> /// <summary>
/// Get width and height packed in a Vector2 /// Get width and height packed in a Vector2
/// </summary> /// </summary>
public Vector2 Dimensions public readonly Vector2 Dimensions => new Vector2(Width, Height);
public readonly CBool IsValid => Raylib.IsTextureValid(this);
public static Texture2D Load(string fileName)
{ {
get return Raylib.LoadTexture(fileName);
{ }
return new Vector2(Width, Height);
} public static Texture2D LoadFromImage(Image image)
{
return Raylib.LoadTextureFromImage(image);
}
public static Texture2D LoadFromMemory(string fileType, byte[] fileData)
{
Image img = Raylib.LoadImageFromMemory(fileType, fileData);
Texture2D texture = Raylib.LoadTextureFromImage(img);
Raylib.UnloadImage(img);
return texture;
}
public void Unload()
{
Raylib.UnloadTexture(this);
}
public void SetFilter(TextureFilter filter)
{
Raylib.SetTextureFilter(this, filter);
}
public void SetWrap(TextureWrap wrap)
{
Raylib.SetTextureWrap(this, wrap);
}
public void Update<T>(T[] pixels) where T : unmanaged
{
Raylib.UpdateTexture(this, pixels);
}
public readonly void Draw(int x, int y)
{
Raylib.DrawTexture(this, x, y, Color.White);
}
public readonly void Draw(int x, int y, Color color)
{
Raylib.DrawTexture(this, x, y, color);
}
public readonly void Draw(Vector2 position)
{
Raylib.DrawTexture(this, (int)position.X, (int)position.Y, Color.White);
}
public readonly void Draw(Vector2 position, Vector2 origin)
{
Vector2 size = this.Dimensions;
Rectangle source = new Rectangle(Vector2.Zero, size);
Rectangle target = new Rectangle(position, size);
Raylib.DrawTexturePro(this, source, target, origin, 0, Color.White);
}
public readonly void Draw(Vector2 position, Vector2 origin, Color color)
{
Vector2 size = this.Dimensions;
Rectangle source = new Rectangle(Vector2.Zero, size);
Rectangle target = new Rectangle(position, size);
Raylib.DrawTexturePro(this, source, target, origin, 0, color);
}
public readonly void Draw(Vector2 position, Color color)
{
Raylib.DrawTexture(this, (int)position.X, (int)position.Y, color);
}
public readonly void Draw(Vector2 position, float rotation, float scale)
{
Raylib.DrawTextureEx(this, position, rotation, scale, Color.White);
}
public readonly void Draw(Vector2 position, float rotation, float scale, Color color)
{
Raylib.DrawTextureEx(this, position, rotation, scale, color);
}
public readonly void Draw(Vector2 position, float rotation, Vector2 scale)
{
Draw(position, rotation, scale, Color.White);
}
public readonly void Draw(Vector2 position, float rotation, Vector2 scale, Color color)
{
Vector2 size = this.Dimensions;
Rectangle source = new Rectangle(Vector2.Zero, size);
Rectangle target = new Rectangle(position, size);
target.Size *= scale;
Raylib.DrawTexturePro(this, source, target, Vector2.Zero, rotation, color);
}
public readonly void Draw(Rectangle source, Rectangle dest)
{
Raylib.DrawTexturePro(this, source, dest, Vector2.Zero, 0, Color.White);
}
public readonly void Draw(Rectangle source, Rectangle dest, Vector2 origin)
{
Raylib.DrawTexturePro(this, source, dest, origin, 0, Color.White);
}
public readonly void Draw(Rectangle source, Rectangle dest, Vector2 origin, float rotation)
{
Raylib.DrawTexturePro(this, source, dest, origin, rotation, Color.White);
}
public readonly void Draw(Rectangle source, Rectangle dest, Vector2 origin, float rotation, Color color)
{
Raylib.DrawTexturePro(this, source, dest, origin, rotation, color);
} }
} }

View file

@ -7,7 +7,7 @@ namespace Raylib_cs;
/// Transform, vertex transformation data /// Transform, vertex transformation data
/// </summary> /// </summary>
[StructLayout(LayoutKind.Sequential)] [StructLayout(LayoutKind.Sequential)]
public partial struct Transform public struct Transform
{ {
/// <summary> /// <summary>
/// Translation /// Translation
@ -23,4 +23,14 @@ public partial struct Transform
/// Scale /// Scale
/// </summary> /// </summary>
public Vector3 Scale; public Vector3 Scale;
public void TranslateLocal(Vector3 translation)
{
Translation += Vector3.Transform(translation, Rotation);
}
public void TranslateGlobal(Vector3 translation)
{
Translation += translation;
}
} }

View file

@ -6,7 +6,7 @@ namespace Raylib_cs;
/// Wave type, defines audio wave data /// Wave type, defines audio wave data
/// </summary> /// </summary>
[StructLayout(LayoutKind.Sequential)] [StructLayout(LayoutKind.Sequential)]
public unsafe partial struct Wave public unsafe struct Wave
{ {
/// <summary> /// <summary>
/// Number of samples /// Number of samples
@ -33,4 +33,36 @@ public unsafe partial struct Wave
/// Buffer data pointer /// Buffer data pointer
/// </summary> /// </summary>
public void* Data; public void* Data;
public readonly CBool IsValid => Raylib.IsWaveValid(this);
public static Wave Load(string fileName)
{
return Raylib.LoadWave(fileName);
}
public CBool Export(string fileName)
{
return Raylib.ExportWave(this, fileName);
}
public CBool ExportAsCode(string fileName)
{
return Raylib.ExportWaveAsCode(this, fileName);
}
public void Format(int sampleRate, int sampleSize, int channels)
{
Raylib.WaveFormat(ref this, sampleRate, sampleSize, channels);
}
public void Crop(int initFrame, int finalFrame)
{
Raylib.WaveCrop(ref this, initFrame, finalFrame);
}
public void Unload()
{
Raylib.UnloadWave(this);
}
} }

View file

@ -27,7 +27,14 @@ public unsafe struct FilePathList
{ {
get get
{ {
return Marshal.PtrToStringUTF8((System.IntPtr)Paths[i]); if (i >= 0 && i < Count)
{
return Marshal.PtrToStringUTF8((System.IntPtr)Paths[i]);
}
else
{
throw new System.IndexOutOfRangeException();
}
} }
} }
} }