From 6fbecb411a212ef493d9384d23d62edc64283e3a Mon Sep 17 00:00:00 2001 From: ChrisDill Date: Thu, 22 Sep 2022 08:16:11 +0100 Subject: [PATCH] Cleanup/review Raymath.cs --- Raylib-cs/interop/Raymath.cs | 131 ++++++++++++++++++++++++++++++----- 1 file changed, 112 insertions(+), 19 deletions(-) diff --git a/Raylib-cs/interop/Raymath.cs b/Raylib-cs/interop/Raymath.cs index e53dce6..e61634e 100644 --- a/Raylib-cs/interop/Raymath.cs +++ b/Raylib-cs/interop/Raymath.cs @@ -39,6 +39,13 @@ namespace Raylib_cs [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern float Remap(float value, float inputStart, float inputEnd, float outputStart, float outputEnd); + /// Wrap input value from min to max + [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] + public static extern float Wrap(float value, float min, float max); + + /// Check whether two given floats are almost equal + [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] + public static extern int FloatEquals(float x, float y); /// Vector with components value 0.0f [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] @@ -76,11 +83,15 @@ namespace Raylib_cs [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern float Vector2DotProduct(Vector2 v1, Vector2 v2); + /// Calculate distance between two vectors + [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] + public static extern float Vector2Distance(Vector2 v1, Vector2 v2); + /// Calculate square distance between two vectors [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern float Vector2DistanceSqr(Vector2 v1, Vector2 v2); - /// Calculate angle from two vectors in X-axis + /// Calculate angle from two vectors [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern float Vector2Angle(Vector2 v1, Vector2 v2); @@ -112,10 +123,36 @@ namespace Raylib_cs [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern Vector2 Vector2Lerp(Vector2 v1, Vector2 v2, float amount); + /// Calculate reflected vector to normal + [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] + public static extern Vector2 Vector2Reflect(Vector2 v, Vector2 normal); + /// Rotate vector by angle [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern Vector2 Vector2Rotate(Vector2 v, float angle); + /// Move Vector towards target + [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] + public static extern Vector2 Vector2MoveTowards(Vector2 v, Vector2 target, float maxDistance); + + /// Invert the given vector + [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] + public static extern Vector2 Vector2Invert(Vector2 v); + + /// + /// Clamp the components of the vector between min and max values specified by the given vectors + /// + [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] + public static extern Vector2 Vector2Clamp(Vector2 v); + + /// Clamp the magnitude of the vector between two min and max values + [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] + public static extern Vector2 Vector2ClampValue(Vector2 v, float min, float max); + + /// Check whether two given vectors are almost equal + [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] + public static extern int Vector2Equals(Vector2 p, Vector2 q); + /// Vector with components value 0.0f [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] @@ -193,9 +230,11 @@ namespace Raylib_cs [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern Vector3 Vector3Normalize(Vector3 v); - /// Orthonormalize provided vectors
+ /// + /// Orthonormalize provided vectors
/// Makes vectors normalized and orthogonal to each other
- /// Gram-Schmidt function implementation
+ /// Gram-Schmidt function implementation + ///
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern void Vector3OrthoNormalize(Vector3* v1, Vector3* v2); @@ -207,6 +246,10 @@ namespace Raylib_cs [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern Vector3 Vector3RotateByQuaternion(Vector3 v, Quaternion q); + /// Rotates a vector around an axis + [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] + public static extern Vector3 Vector3RotateByAxisAngle(Vector3 v, Vector3 axis, float angle); + /// Calculate linear interpolation between two vectors [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern Vector3 Vector3Lerp(Vector3 v1, Vector3 v2, float amount); @@ -223,13 +266,17 @@ namespace Raylib_cs [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); - /// Projects a Vector3 from screen space into object space
- /// NOTE: We are avoiding calling other raymath functions despite available
+ /// + /// 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 Vector3 Vector3Unproject(Vector3 source, Matrix4x4 projection, Matrix4x4 view); @@ -237,6 +284,36 @@ namespace Raylib_cs [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern float3 Vector3ToFloatV(Vector3 v); + /// Invert the given vector + [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] + public static extern Vector3 Vector3Invert(Vector3 v); + + /// + /// Clamp the components of the vector between + /// min and max values specified by the given vectors + /// + [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] + public static extern Vector3 Vector3Clamp(Vector3 v, Vector3 min, Vector3 max); + + /// Clamp the magnitude of the vector between two values + [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] + public static extern Vector3 Vector3ClampValue(Vector3 v, float min, float max); + + /// Check whether two given vectors are almost equal + [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] + public static extern int Vector3Equals(Vector3 p, Vector3 q); + + /// + /// Compute the direction of a refracted ray where v specifies the + /// normalized direction of the incoming ray, n specifies the + /// normalized normal vector of the interface of two optical media, + /// and r specifies the ratio of the refractive index of the medium + /// from where the ray comes to the refractive index of the medium + /// on the other side of the surface + /// + [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] + public static extern Vector3 Vector3Refract(Vector3 v, Vector3 n, float r); + /// Compute matrix determinant [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] @@ -270,8 +347,10 @@ namespace Raylib_cs [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern Matrix4x4 MatrixSubtract(Matrix4x4 left, Matrix4x4 right); - /// Get 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); @@ -279,8 +358,10 @@ namespace Raylib_cs [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
+ /// + /// 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); @@ -312,8 +393,10 @@ namespace Raylib_cs [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern Matrix4x4 MatrixFrustum(double left, double right, double bottom, double top, double near, double far); - /// Get 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); @@ -398,8 +481,10 @@ namespace Raylib_cs [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern Matrix4x4 QuaternionToMatrix(Quaternion q); - /// Get 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); @@ -407,18 +492,26 @@ namespace Raylib_cs [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern void QuaternionToAxisAngle(Quaternion q, Vector3* outAxis, float* outAngle); - /// Get the quaternion equivalent to Euler angles
- /// NOTE: Rotation order is ZYX
+ /// + /// Get the quaternion equivalent to Euler angles
+ /// NOTE: Rotation order is ZYX + ///
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern Quaternion QuaternionFromEuler(float pitch, float yaw, float roll); - /// Get the Euler angles equivalent to quaternion (roll, pitch, yaw)
- /// NOTE: Angles are returned in a Vector3 struct in radians
+ /// + /// 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 [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern Quaternion QuaternionTransform(Quaternion q, Matrix4x4 mat); + + /// Check whether two given quaternions are almost equal + [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] + public static extern Quaternion QuaternionEquals(Quaternion p, Quaternion q); } }