diff --git a/Raylib-cs/Raylib.cs b/Raylib-cs/Raylib.cs index 14f0306..846a592 100644 --- a/Raylib-cs/Raylib.cs +++ b/Raylib-cs/Raylib.cs @@ -9,7 +9,7 @@ namespace Raylib_cs public static unsafe class Raylib { /// - /// Used by DllImport to load the native library. + /// Used by DllImport to load the native library /// public const string nativeLibName = "raylib"; @@ -163,10 +163,9 @@ namespace Raylib_cs [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern void SetWindowSize(int width, int height); - /// Get native window handle
- /// IntPtr refers to a void *
+ /// Get native window handle [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] - public static extern IntPtr GetWindowHandle(); + public static extern void* GetWindowHandle(); /// Get current screen width [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] @@ -483,15 +482,15 @@ namespace Raylib_cs /// Internal memory allocator [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] - public static extern IntPtr MemAlloc(int size); + public static extern void* MemAlloc(int size); /// Internal memory reallocator [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] - public static extern IntPtr MemRealloc(IntPtr ptr, int size); + public static extern void* MemRealloc(void* ptr, int size); /// Internal memory free [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] - public static extern void MemFree(IntPtr ptr); + public static extern void MemFree(void* ptr); // Set custom callbacks @@ -520,19 +519,17 @@ namespace Raylib_cs // Files management functions - /// Load file data as byte array (read)
- /// IntPtr refers to unsigned char *
+ /// Load file data as byte array (read) [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] - public static extern IntPtr LoadFileData(string fileName, ref int bytesRead); + public static extern byte* LoadFileData(string fileName, ref int bytesRead); - /// Unload file data allocated by LoadFileData()
- /// data refers to a unsigned char *
+ /// Unload file data allocated by LoadFileData() [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] - public static extern void UnloadFileData(IntPtr data); + public static extern void UnloadFileData(byte* data); /// Save data to file from byte array (write) [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] - public static extern CBool SaveFileData(string fileName, IntPtr data, int bytesToWrite); + public static extern CBool SaveFileData(string fileName, void* data, int bytesToWrite); /// Check file extension [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] @@ -556,11 +553,11 @@ namespace Raylib_cs /// Compress data (DEFLATE algorythm) [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] - public static extern IntPtr CompressData(byte[] data, int dataLength, ref int compDataLength); + public static extern byte* CompressData(byte[] data, int dataLength, ref int compDataLength); /// Decompress data (DEFLATE algorythm) [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] - public static extern IntPtr DecompressData(byte[] compData, int compDataLength, ref int dataLength); + public static extern byte* DecompressData(byte[] compData, int compDataLength, ref int dataLength); // Persistent storage management @@ -1025,10 +1022,9 @@ namespace Raylib_cs [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern Image LoadImageAnim(string fileName, ref int frames); - /// Load image from memory buffer, fileType refers to extension: i.e. "png"
- /// fileData refers to const unsigned char *
+ /// Load image from memory buffer, fileType refers to extension: i.e. "png" [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] - public static extern Image LoadImageFromMemory(string fileType, IntPtr fileData, int dataSize); + public static extern Image LoadImageFromMemory(string fileType, byte* fileData, int dataSize); /// Load image from GPU texture data [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] @@ -1188,25 +1184,21 @@ namespace Raylib_cs [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern void ImageColorReplace(ref Image image, Color color, Color replace); - /// Load color data from image as a Color array (RGBA - 32bit)
- /// IntPtr refers to Color *
+ /// Load color data from image as a Color array (RGBA - 32bit) [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] - public static extern IntPtr LoadImageColors(Image image); + public static extern Color* LoadImageColors(Image image); - /// Load colors palette from image as a Color array (RGBA - 32bit)
- /// IntPtr refers to Color *
+ /// Load colors palette from image as a Color array (RGBA - 32bit) [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] - public static extern IntPtr LoadImagePaletee(Image image, int maxPaletteSize, ref int colorsCount); + public static extern Color* LoadImagePalette(Image image, int maxPaletteSize, ref int colorsCount); - /// Unload color data loaded with LoadImageColors()
- /// colors refers to Color *
+ /// Unload color data loaded with LoadImageColors() [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] - public static extern void UnloadImageColors(IntPtr colors); + public static extern void UnloadImageColors(Color* colors); - /// Unload colors palette loaded with LoadImagePalette() - /// colors refers to Color * + /// Unload colors palette loaded with LoadImagePalette() [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] - public static extern void UnloadImagePaletee(IntPtr colors); + public static extern void UnloadImagePalette(Color* colors); /// Get image alpha border rectangle [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] @@ -1304,15 +1296,13 @@ namespace Raylib_cs [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern void UnloadRenderTexture(RenderTexture2D target); - /// Update GPU texture with new data
- /// pixels refers to a const void *
+ /// Update GPU texture with new data [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] - public static extern void UpdateTexture(Texture2D texture, IntPtr pixels); + public static extern void UpdateTexture(Texture2D texture, void* pixels); - /// Update GPU texture rectangle with new data - /// pixels refers to a const void * + /// Update GPU texture rectangle with new data [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] - public static extern void UpdateTextureRec(Texture2D texture, Rectangle rec, IntPtr pixels); + public static extern void UpdateTextureRec(Texture2D texture, Rectangle rec, void* pixels); // Texture configuration functions @@ -1405,11 +1395,11 @@ namespace Raylib_cs /// Get Color from a source pixel pointer of certain format [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] - public static extern Color GetPixelColor(IntPtr srcPtr, PixelFormat format); + public static extern Color GetPixelColor(void* srcPtr, PixelFormat format); /// Set color formatted into destination pixel pointer [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] - public static extern void SetPixelColor(IntPtr dstPtr, Color color, PixelFormat format); + public static extern void SetPixelColor(void* dstPtr, Color color, PixelFormat format); /// Get pixel data size in bytes for certain format [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] @@ -1441,22 +1431,19 @@ namespace Raylib_cs /// Load font from memory buffer, fileType refers to extension: i.e. "ttf"
/// fileData refers to const unsigned char *
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] - public static extern Font LoadFontFromMemory(string fileType, IntPtr fileData, int dataSize, int fontSize, int[] fontChars, int charsCount); + public static extern Font LoadFontFromMemory(string fileType, byte* fileData, int dataSize, int fontSize, int[] fontChars, int charsCount); - /// Load font data for further use
- /// fileData refers to const unsigned char *
- /// IntPtr refers to GlyphInfo *
+ /// Load font data for further use [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] - public static extern IntPtr LoadFontData(IntPtr fileData, int dataSize, int fontSize, int[] fontChars, int charsCount, FontType type); + public static extern GlyphInfo* LoadFontData(byte* fileData, int dataSize, int fontSize, int[] fontChars, int charsCount, FontType type); /// Generate image font atlas using chars info [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] - public static extern Image GenImageFontAtlas(IntPtr chars, ref IntPtr recs, int charsCount, int fontSize, int padding, int packMethod); + public static extern Image GenImageFontAtlas(GlyphInfo* chars, Rectangle** recs, int charsCount, int fontSize, int padding, int packMethod); - /// Unload font chars info data (RAM)
- /// chars refers to GlpyhInfo *
+ /// Unload font chars info data (RAM) [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] - public static extern void UnloadFontData(IntPtr chars, int charsCount); + public static extern void UnloadFontData(GlyphInfo* chars, int charsCount); /// Unload Font from GPU memory (VRAM) [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] @@ -1538,10 +1525,9 @@ namespace Raylib_cs // UTF8 text strings management functions - /// Get all codepoints in a string, codepoints count returned by parameters
- /// IntPtr refers to a int *
+ /// Get all codepoints in a string, codepoints count returned by parameters [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] - public static extern IntPtr GetCodepoints(string text, ref int count); + public static extern int* GetCodepoints(string text, ref int count); /// Get total number of characters (codepoints) in a UTF8 encoded string [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] @@ -1679,10 +1665,9 @@ namespace Raylib_cs [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern void UploadMesh(ref Mesh mesh, CBool dynamic); - /// Update mesh vertex data in GPU for a specific buffer index
- /// data refers to a void *
+ /// Update mesh vertex data in GPU for a specific buffer index [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] - public static extern void UpdateMeshBuffer(Mesh mesh, int index, IntPtr data, int dataSize, int offset); + public static extern void UpdateMeshBuffer(Mesh mesh, int index, void* data, int dataSize, int offset); /// Unload mesh from memory (RAM and/or VRAM) [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] @@ -1715,10 +1700,9 @@ namespace Raylib_cs // Material loading/unloading functions - /// Load materials from model file
- /// IntPtr refers to Material *
+ /// Load materials from model file [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] - public static extern IntPtr LoadMaterials(string fileName, ref int materialCount); + public static extern Material* LoadMaterials(string fileName, ref int materialCount); /// Load default material (Supports: DIFFUSE, SPECULAR, NORMAL maps) [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] @@ -1819,10 +1803,9 @@ namespace Raylib_cs // Model animations loading/unloading functions - /// Load model animations from file
- /// IntPtr refers to ModelAnimation *
+ /// Load model animations from file [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] - public static extern IntPtr LoadModelAnimations(string fileName, ref int animsCount); + public static extern ModelAnimation* LoadModelAnimations(string fileName, ref int animsCount); /// Update model animation pose [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] @@ -1911,7 +1894,7 @@ namespace Raylib_cs /// Load wave from memory buffer, fileType refers to extension: i.e. "wav"
/// fileData refers to a const unsigned char *
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] - public static extern Wave LoadWaveFromMemory(string fileType, IntPtr fileData, int dataSize); + public static extern Wave LoadWaveFromMemory(string fileType, byte* fileData, int dataSize); /// Load sound from file [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] @@ -1921,10 +1904,9 @@ namespace Raylib_cs [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern Sound LoadSoundFromWave(Wave wave); - /// Update sound buffer with new data
- /// refers to a const void *
+ /// Update sound buffer with new data [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] - public static extern void UpdateSound(Sound sound, IntPtr data, int samplesCount); + public static extern void UpdateSound(Sound sound, void* data, int samplesCount); /// Unload wave data [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] @@ -1997,15 +1979,13 @@ namespace Raylib_cs [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern void WaveCrop(ref Wave wave, int initSample, int finalSample); - /// Get samples data from wave as a floats array
- /// IntPtr refers to float *
+ /// Get samples data from wave as a floats array [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] - public static extern IntPtr LoadWaveSamples(Wave wave); + public static extern float* LoadWaveSamples(Wave wave); - /// Unload samples data loaded with LoadWaveSamples()
- /// samples refers to float *
+ /// Unload samples data loaded with LoadWaveSamples() [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] - public static extern void UnloadWaveSamples(IntPtr samples); + public static extern void UnloadWaveSamples(float* samples); // Music management functions @@ -2015,7 +1995,7 @@ namespace Raylib_cs /// Load music stream from data [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] - public static extern Music LoadMusicStreamFromMemory(string fileType, IntPtr data, int dataSize); + public static extern Music LoadMusicStreamFromMemory(string fileType, byte* data, int dataSize); /// Unload music stream [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] @@ -2076,10 +2056,9 @@ namespace Raylib_cs [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern void UnloadAudioStream(AudioStream stream); - /// Update audio stream buffers with data
- /// data refers to a const void *
+ /// Update audio stream buffers with data [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] - public static extern void UpdateAudioStream(AudioStream stream, IntPtr data, int samplesCount); + public static extern void UpdateAudioStream(AudioStream stream, void* data, int samplesCount); /// Check if any audio stream buffers requires refill [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] diff --git a/Raylib-cs/Raymath.cs b/Raylib-cs/Raymath.cs index b72ba71..d3c03ea 100644 --- a/Raylib-cs/Raymath.cs +++ b/Raylib-cs/Raymath.cs @@ -16,333 +16,392 @@ namespace Raylib_cs } [SuppressUnmanagedCodeSecurity] - public static class Raymath + public static unsafe class Raymath { - // Used by DllImport to load the native library. + /// + /// Used by DllImport to load the native library + /// public const string nativeLibName = "raylib"; - // Clamp float value + /// Clamp float value [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern float Clamp(float value, float min, float max); - // Calculate linear interpolation between two vectors + /// Calculate linear interpolation between two vectors [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern float Lerp(float start, float end, float amount); - // Vector with components value 0.0f + /// Normalize input value within input range + [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] + public static extern float Normalize(float value, float start, float end); + + /// Remap input value within input range to output range + [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] + public static extern float Remap(float value, float inputStart, float inputEnd, float outputStart, float outputEnd); + + + /// Vector with components value 0.0f [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern Vector2 Vector2Zero(); - // Vector with components value 1.0f + /// Vector with components value 1.0f [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern Vector2 Vector2One(); - // Add two vectors (v1 + v2) + /// Add two vectors (v1 + v2) [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern Vector2 Vector2Add(Vector2 v1, Vector2 v2); - // Subtract two vectors (v1 - v2) + /// Add vector and float value + [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] + public static extern Vector2 Vector2AddValue(Vector2 v, float add); + + /// Subtract two vectors (v1 - v2) [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern Vector2 Vector2Subtract(Vector2 v1, Vector2 v2); - // Calculate vector length + /// Subtract vector by float value + [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] + public static extern Vector2 Vector2SubtractValue(Vector2 v, float sub); + + /// Calculate vector length [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern float Vector2Length(Vector2 v); - // Calculate two vectors dot product + /// Calculate vector square length + [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] + public static extern float Vector2LengthSqr(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 + /// 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 + /// 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) + /// Scale vector (multiply by value) [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern Vector2 Vector2Scale(Vector2 v, float scale); - // Multiply vector by vector + /// Multiply vector by vector [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] - public static extern Vector2 Vector2MultiplyV(Vector2 v1, Vector2 v2); + public static extern Vector2 Vector2Multiply(Vector2 v1, Vector2 v2); - // Negate vector + /// Negate vector [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern Vector2 Vector2Negate(Vector2 v); - // Divide vector by a float value + /// Divide vector by vector [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] - public static extern Vector2 Vector2Divide(Vector2 v, float div); + public static extern Vector2 Vector2Divide(Vector2 v1, Vector2 v2); - // Divide vector by vector - [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] - public static extern Vector2 Vector2DivideV(Vector2 v1, Vector2 v2); - - // Normalize provided vector + /// Normalize provided vector [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern Vector2 Vector2Normalize(Vector2 v); - // Calculate linear interpolation between two vectors + /// Calculate linear interpolation between two vectors [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern Vector2 Vector2Lerp(Vector2 v1, Vector2 v2, float amount); - // Calculate linear interpolation between two vectors + /// Calculate linear interpolation between two vectors [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern Vector2 Vector2Rotate(Vector2 v, float degs); - // Vector with components value 0.0f + + /// Vector with components value 0.0f [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern Vector3 Vector3Zero(); - // Vector with components value 1.0f + /// Vector with components value 1.0f [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern Vector3 Vector3One(); - // Add two vectors + /// Add two vectors [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern Vector3 Vector3Add(Vector3 v1, Vector3 v2); - // Subtract two vectors + /// Add vector and float value + [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] + public static extern Vector3 Vector3AddValue(Vector3 v, float add); + + /// Subtract two vectors [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern Vector3 Vector3Subtract(Vector3 v1, Vector3 v2); - // Multiply vector by scalar + /// Subtract vector and float value + [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] + public static extern Vector3 Vector3SubtractValue(Vector3 v, float sub); + + /// Multiply vector by scalar [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern Vector3 Vector3Scale(Vector3 v, float scalar); - // Multiply vector by vector + /// Multiply vector by vector [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern Vector3 Vector3Multiply(Vector3 v1, Vector3 v2); - // Calculate two vectors cross product + /// Calculate two vectors cross product [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern Vector3 Vector3CrossProduct(Vector3 v1, Vector3 v2); - // Calculate one vector perpendicular vector + /// Calculate one vector perpendicular vector [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern Vector3 Vector3Perpendicular(Vector3 v); - // Calculate vector length + /// Calculate vector length [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern float Vector3Length(Vector3 v); - // Calculate two vectors dot product + /// Calculate vector square length + [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] + public static extern float Vector3LengthSqr(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 + /// Calculate distance between two vectors [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern float Vector3Distance(Vector3 v1, Vector3 v2); - // Negate provided vector (invert direction) + /// Calculate angle between two vectors in XY and XZ + [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] + public static extern Vector2 Vector3Angle(Vector3 v1, Vector3 v2); + + /// Negate provided vector (invert direction) [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern Vector3 Vector3Negate(Vector3 v); - // Divide vector by a float value + /// Divide vector by vector [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] - public static extern Vector3 Vector3Divide(Vector3 v, float div); + public static extern Vector3 Vector3Divide(Vector3 v1, Vector3 v2); - // Divide vector by vector - [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] - public static extern Vector3 Vector3DivideV(Vector3 v1, Vector3 v2); - - // Normalize provided vector + /// 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 + /// 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(ref Vector3 v1, ref Vector3 v2); + public static extern void Vector3OrthoNormalize(Vector3* v1, Vector3* v2); - // Transforms a Vector3 by a given Matrix + /// Transforms a Vector3 by a given Matrix [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern Vector3 Vector3Transform(Vector3 v, Matrix4x4 mat); - // Transform a vector by quaternion rotation + /// 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 + /// 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 + /// 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 + /// 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 + /// 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 + /// 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 + /// Projects a Vector3 from screen space into object space
+ /// NOTE: We are avoiding calling other raymath functions despite available
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] - public static extern float3 Vector3ToFloatV(Vector3 v); + public static extern Vector3 Vector3Unproject(Vector3 source, Matrix4x4 projection, Matrix4x4 view); - // Compute matrix determinant + + /// Compute matrix determinant [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern float MatrixDeterminant(Matrix4x4 mat); - // Returns the trace of the matrix (sum of the values along the diagonal) + /// Get the trace of the matrix (sum of the values along the diagonal) [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern float MatrixTrace(Matrix4x4 mat); - // Transposes provided matrix + /// Transposes provided matrix [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern Matrix4x4 MatrixTranspose(Matrix4x4 mat); - // Invert provided matrix + /// Invert provided matrix [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern Matrix4x4 MatrixInvert(Matrix4x4 mat); - // Normalize provided matrix + /// Normalize provided matrix [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern Matrix4x4 MatrixNormalize(Matrix4x4 mat); - // Returns identity matrix + /// Get identity matrix [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern Matrix4x4 MatrixIdentity(); - // Add two matrices + /// Add two matrices [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern Matrix4x4 MatrixAdd(Matrix4x4 left, Matrix4x4 right); - // Subtract two matrices (left - right) + /// Subtract two matrices (left - right) [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern Matrix4x4 MatrixSubtract(Matrix4x4 left, Matrix4x4 right); - // Returns translation matrix - [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] - public static extern Matrix4x4 MatrixTranslate(float x, float y, float z); - - // Create rotation matrix from axis and angle - // NOTE: Angle should be provided in radians - [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] - public static extern Matrix4x4 MatrixRotate(Vector3 axis, float angle); - - // Returns xyz-rotation matrix (angles in radians) - [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] - public static extern Matrix4x4 MatrixRotateXYZ(Vector3 ang); - - // Returns x-rotation matrix (angle in radians) - [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] - public static extern Matrix4x4 MatrixRotateX(float angle); - - // Returns y-rotation matrix (angle in radians) - [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] - public static extern Matrix4x4 MatrixRotateY(float angle); - - // Returns z-rotation matrix (angle in radians) - [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] - public static extern Matrix4x4 MatrixRotateZ(float angle); - - // Returns scaling matrix - [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] - public static extern Matrix4x4 MatrixScale(float x, float y, float z); - - // Returns two matrix multiplication - // NOTE: When multiplying matrices... the order matters! + /// Get two matrix multiplication
+ /// NOTE: When multiplying matrices... the order matters!
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern Matrix4x4 MatrixMultiply(Matrix4x4 left, Matrix4x4 right); - // Returns perspective projection matrix + /// Get translation matrix + [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] + public static extern Matrix4x4 MatrixTranslate(float x, float y, float z); + + /// Create rotation matrix from axis and angle
+ /// NOTE: Angle should be provided in radians
+ [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] + public static extern Matrix4x4 MatrixRotate(Vector3 axis, float angle); + + /// Get x-rotation matrix (angle in radians) + [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] + public static extern Matrix4x4 MatrixRotateX(float angle); + + /// Get y-rotation matrix (angle in radians) + [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] + public static extern Matrix4x4 MatrixRotateY(float angle); + + /// Get z-rotation matrix (angle in radians) + [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] + public static extern Matrix4x4 MatrixRotateZ(float angle); + + /// Get xyz-rotation matrix (angles in radians) + [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] + public static extern Matrix4x4 MatrixRotateXYZ(Vector3 ang); + + /// Get zyx-rotation matrix (angles in radians) + [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] + public static extern Matrix4x4 MatrixRotateZYX(Vector3 ang); + + /// Get scaling matrix + [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] + public static extern Matrix4x4 MatrixScale(float x, float y, float z); + + /// Get perspective projection matrix [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern Matrix4x4 MatrixFrustum(double left, double right, double bottom, double top, double near, double far); - // Returns perspective projection matrix - // NOTE: Angle should be provided in radians + /// Get perspective projection matrix
+ /// NOTE: Angle should be provided in radians
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern Matrix4x4 MatrixPerspective(double fovy, double aspect, double near, double far); - // Returns orthographic projection matrix + /// Get orthographic projection matrix [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern Matrix4x4 MatrixOrtho(double left, double right, double bottom, double top, double near, double far); - // Returns camera look-at matrix (view matrix) + /// Get camera look-at matrix (view matrix) [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern Matrix4x4 MatrixLookAt(Vector3 eye, Vector3 target, Vector3 up); - // Returns float array of matrix data - [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] - public static extern float16 MatrixToFloatV(Matrix4x4 mat); - // Returns identity quaternion + /// Add 2 quaternions + [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] + public static extern Quaternion QuaternionAdd(Quaternion q1, Quaternion q2); + + /// Add quaternion and float value + [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] + public static extern Quaternion QuaternionAddValue(Quaternion q, float add); + + /// Subtract 2 quaternions + [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] + public static extern Quaternion QuaternionSubtract(Quaternion q1, Quaternion q2); + + /// Subtract quaternion and float value + [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] + public static extern Quaternion QuaternionSubtractValue(Quaternion q, float add); + + /// Get identity quaternion [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern Quaternion QuaternionIdentity(); - // Computes the length of a quaternion + /// Computes the length of a quaternion [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern float QuaternionLength(Quaternion q); - // Normalize provided quaternion + /// Normalize provided quaternion [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern Quaternion QuaternionNormalize(Quaternion q); - // Invert provided quaternion + /// Invert provided quaternion [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern Quaternion QuaternionInvert(Quaternion q); - // Calculate two quaternion multiplication + /// Calculate two quaternion multiplication [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern Quaternion QuaternionMultiply(Quaternion q1, Quaternion q2); - // Calculate linear interpolation between two quaternions + /// Scale quaternion by float value + [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] + public static extern Quaternion QuaternionScale(Quaternion q, float mul); + + /// Divide two quaternions + [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] + public static extern Quaternion QuaternionDivide(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 + /// 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 + /// 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 + /// 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 + /// Get a quaternion for a given rotation matrix [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern Quaternion QuaternionFromMatrix(Matrix4x4 mat); - // Returns a matrix for a given quaternion + /// Get a matrix for a given quaternion [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern Matrix4x4 QuaternionToMatrix(Quaternion q); - // Returns rotation quaternion for an angle and axis - // NOTE: angle must be provided in radians + /// Get 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 + /// Get the rotation angle and axis for a given quaternion [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] - public static extern void QuaternionToAxisAngle(Quaternion q, ref Vector3 outAxis, ref float outAngle); + public static extern void QuaternionToAxisAngle(Quaternion q, Vector3* outAxis, float* outAngle); - // Returns he quaternion equivalent to Euler angles + /// Get the quaternion equivalent to Euler angles
+ /// NOTE: Rotation order is ZYX
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] - public static extern Quaternion QuaternionFromEuler(float roll, float pitch, float yaw); + public static extern Quaternion QuaternionFromEuler(float pitch, float yaw, float roll); - // Return the Euler angles equivalent to quaternion (roll, pitch, yaw) - // NOTE: Angles are returned in a Vector3 struct in degrees + /// Get the Euler angles equivalent to quaternion (roll, pitch, yaw)
+ /// NOTE: Angles are returned in a Vector3 struct in radians
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern Vector3 QuaternionToEuler(Quaternion q); - // Transform a quaternion given a transformation matrix + /// Transform a quaternion given a transformation matrix [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern Quaternion QuaternionTransform(Quaternion q, Matrix4x4 mat); } diff --git a/Raylib-cs/Rlgl.cs b/Raylib-cs/Rlgl.cs index dffbbcd..be4c78f 100644 --- a/Raylib-cs/Rlgl.cs +++ b/Raylib-cs/Rlgl.cs @@ -6,9 +6,11 @@ using System.Security; namespace Raylib_cs { [SuppressUnmanagedCodeSecurity] - public static class Rlgl + public static unsafe class Rlgl { - // Used by DllImport to load the native library. + /// + /// Used by DllImport to load the native library + /// public const string nativeLibName = "raylib"; public const int DEFAULT_BATCH_BUFFER_ELEMENTS = 8192; @@ -200,10 +202,9 @@ namespace Raylib_cs public static extern void rlDisableVertexAttribute(uint index); /// Enable attribute state pointer
- /// buffer refers to a void *
/// NOTE: Only available for GRAPHICS_API_OPENGL_11
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] - public static extern void rlEnableStatePointer(int vertexAttribType, IntPtr buffer); + public static extern void rlEnableStatePointer(int vertexAttribType, void* buffer); /// Disable attribute state pointer
/// NOTE: Only available for GRAPHICS_API_OPENGL_11
@@ -379,10 +380,9 @@ namespace Raylib_cs [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern void rlglClose(); - /// Load OpenGL extensions
- /// loader refers to a void *
+ /// Load OpenGL extensions [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] - public static extern void rlLoadExtensions(IntPtr loader); + public static extern void rlLoadExtensions(void* loader); /// Get current OpenGL version [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] @@ -406,7 +406,7 @@ namespace Raylib_cs /// Get default shader locations [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] - public static unsafe extern int* rlGetShaderLocsDefault(); + public static extern int* rlGetShaderLocsDefault(); // Render batch management @@ -449,15 +449,15 @@ namespace Raylib_cs /// Load a vertex buffer attribute [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] - public static extern uint rlLoadVertexBuffer(IntPtr buffer, int size, CBool dynamic); + public static extern uint rlLoadVertexBuffer(void* buffer, int size, CBool dynamic); /// Load a new attributes element buffer [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] - public static extern uint rlLoadVertexBufferElement(IntPtr buffer, int size, CBool dynamic); + public static extern uint rlLoadVertexBufferElement(void* buffer, int size, CBool dynamic); /// Update GPU buffer with new data [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] - public static extern void rlUpdateVertexBuffer(uint bufferId, IntPtr data, int dataSize, int offset); + public static extern void rlUpdateVertexBuffer(uint bufferId, void* data, int dataSize, int offset); [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern void rlUnloadVertexArray(uint vaoId); @@ -466,48 +466,45 @@ namespace Raylib_cs public static extern void rlUnloadVertexBuffer(uint vboId); [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] - public static extern void rlSetVertexAttribute(uint index, int compSize, int type, CBool normalized, int stride, IntPtr pointer); + public static extern void rlSetVertexAttribute(uint index, int compSize, int type, CBool normalized, int stride, void* pointer); [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern void rlSetVertexAttributeDivisor(uint index, int divisor); /// Set vertex attribute default value [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] - public static extern void rlSetVertexAttributeDefault(int locIndex, IntPtr value, int attribType, int count); + public static extern void rlSetVertexAttributeDefault(int locIndex, void* value, int attribType, int count); [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern void rlDrawVertexArray(int offset, int count); [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] - public static extern void rlDrawVertexArrayElements(int offset, int count, IntPtr buffer); + public static extern void rlDrawVertexArrayElements(int offset, int count, void* buffer); [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern void rlDrawVertexArrayInstanced(int offset, int count, int instances); [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] - public static extern void rlDrawVertexArrayElementsInstanced(int offset, int count, IntPtr buffer, int instances); + public static extern void rlDrawVertexArrayElementsInstanced(int offset, int count, void* buffer, int instances); // Textures data management - /// Load texture in GPU
- /// data refers to a void *
+ /// Load texture in GPU [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] - public static extern uint rlLoadTexture(IntPtr data, int width, int height, PixelFormat format, int mipmapCount); + public static extern uint rlLoadTexture(void* data, int width, int height, PixelFormat format, int mipmapCount); /// Load depth texture/renderbuffer (to be attached to fbo) [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern uint rlLoadTextureDepth(int width, int height, CBool useRenderBuffer); - /// Load texture cubemap
- /// data refers to a void *
+ /// Load texture cubemap [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] - public static extern uint rlLoadTextureCubemap(IntPtr data, int size, PixelFormat format); + public static extern uint rlLoadTextureCubemap(void* data, int size, PixelFormat format); - /// Update GPU texture with new data
- /// data refers to a const void *
+ /// Update GPU texture with new data [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] - public static extern void rlUpdateTexture(uint id, int width, int height, PixelFormat format, IntPtr data); + public static extern void rlUpdateTexture(uint id, int width, int height, PixelFormat format, void* data); /// Get OpenGL internal formats [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] @@ -515,7 +512,7 @@ namespace Raylib_cs /// Get OpenGL internal formats [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] - public static extern IntPtr rlGetPixelFormatName(PixelFormat format); + public static extern sbyte* rlGetPixelFormatName(PixelFormat format); /// Unload texture from GPU memory [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] @@ -525,15 +522,13 @@ namespace Raylib_cs [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern void rlGenTextureMipmaps(uint id, int width, int height, PixelFormat format, ref int[] mipmaps); - /// Read texture pixel data
- /// IntPtr refers to a void *
+ /// Read texture pixel data [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] - public static extern IntPtr rlReadTexturePixels(uint id, int width, int height, PixelFormat format); + public static extern void* rlReadTexturePixels(uint id, int width, int height, PixelFormat format); - /// Read screen pixel data (color buffer)
- /// IntPtr refers to a unsigned char *
+ /// Read screen pixel data (color buffer) [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] - public static extern IntPtr rlReadScreenPixels(int width, int height); + public static extern byte* rlReadScreenPixels(int width, int height); // Framebuffer management (fbo) @@ -584,7 +579,7 @@ namespace Raylib_cs /// Set shader value uniform [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] - public static extern void rlSetUniform(int locIndex, IntPtr value, int uniformType, int count); + public static extern void rlSetUniform(int locIndex, void* value, int uniformType, int count); /// Set shader value matrix [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] @@ -611,7 +606,7 @@ namespace Raylib_cs /// Load shader storage buffer object (SSBO) [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] - public static extern unsafe uint rlLoadShaderBuffer(ulong size, void* data, int usageHint); + public static extern uint rlLoadShaderBuffer(ulong size, void* data, int usageHint); /// Unload shader storage buffer object (SSBO) [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] @@ -623,11 +618,11 @@ namespace Raylib_cs /// Get SSBO buffer size [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] - public static extern unsafe ulong rlGetShaderBufferSize(uint id, void* dest, ulong count, ulong offset); + public static extern ulong rlGetShaderBufferSize(uint id, void* dest, ulong count, ulong offset); /// Bind SSBO buffer [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] - public static extern unsafe void rlReadShaderBufferElements(uint id, void* dest, ulong count, ulong offset); + public static extern void rlReadShaderBufferElements(uint id, void* dest, ulong count, ulong offset); /// Copy SSBO buffer data [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]