using System.Numerics; using System.Runtime.CompilerServices; using System.Runtime.InteropServices; using System.Security; namespace Raylib_cs; // NOTE: Helper types to be used instead of array return types for *ToFloat functions public unsafe struct Float3 { public fixed float v[3]; } public unsafe struct Float16 { public fixed float v[16]; } [SuppressUnmanagedCodeSecurity] public static unsafe partial class Raymath { /// /// Used by LibraryImport to load the native library /// public const string NativeLibName = Raylib.NativeLibName; /// Clamp float value [LibraryImport(NativeLibName)] [UnmanagedCallConv(CallConvs = [typeof(CallConvCdecl)])] public static partial float Clamp(float value, float min, float max); /// Calculate linear interpolation between two vectors [LibraryImport(NativeLibName)] [UnmanagedCallConv(CallConvs = [typeof(CallConvCdecl)])] public static partial float Lerp(float start, float end, float amount); /// Normalize input value within input range [LibraryImport(NativeLibName)] [UnmanagedCallConv(CallConvs = [typeof(CallConvCdecl)])] public static partial float Normalize(float value, float start, float end); /// Remap input value within input range to output range [LibraryImport(NativeLibName)] [UnmanagedCallConv(CallConvs = [typeof(CallConvCdecl)])] public static partial float Remap(float value, float inputStart, float inputEnd, float outputStart, float outputEnd ); /// Wrap input value from min to max [LibraryImport(NativeLibName)] [UnmanagedCallConv(CallConvs = [typeof(CallConvCdecl)])] public static partial float Wrap(float value, float min, float max); /// Check whether two given floats are almost equal [LibraryImport(NativeLibName)] [UnmanagedCallConv(CallConvs = [typeof(CallConvCdecl)])] public static partial int FloatEquals(float x, float y); /// Vector with components value 0.0f [LibraryImport(NativeLibName)] [UnmanagedCallConv(CallConvs = [typeof(CallConvCdecl)])] public static partial Vector2 Vector2Zero(); /// Vector with components value 1.0f [LibraryImport(NativeLibName)] [UnmanagedCallConv(CallConvs = [typeof(CallConvCdecl)])] public static partial Vector2 Vector2One(); /// Add two vectors (v1 + v2) [LibraryImport(NativeLibName)] [UnmanagedCallConv(CallConvs = [typeof(CallConvCdecl)])] public static partial Vector2 Vector2Add(Vector2 v1, Vector2 v2); /// Add vector and float value [LibraryImport(NativeLibName)] [UnmanagedCallConv(CallConvs = [typeof(CallConvCdecl)])] public static partial Vector2 Vector2AddValue(Vector2 v, float add); /// Subtract two vectors (v1 - v2) [LibraryImport(NativeLibName)] [UnmanagedCallConv(CallConvs = [typeof(CallConvCdecl)])] public static partial Vector2 Vector2Subtract(Vector2 v1, Vector2 v2); /// Subtract vector by float value [LibraryImport(NativeLibName)] [UnmanagedCallConv(CallConvs = [typeof(CallConvCdecl)])] public static partial Vector2 Vector2SubtractValue(Vector2 v, float sub); /// Calculate vector length [LibraryImport(NativeLibName)] [UnmanagedCallConv(CallConvs = [typeof(CallConvCdecl)])] public static partial float Vector2Length(Vector2 v); /// Calculate vector square length [LibraryImport(NativeLibName)] [UnmanagedCallConv(CallConvs = [typeof(CallConvCdecl)])] public static partial float Vector2LengthSqr(Vector2 v); /// Calculate two vectors dot product [LibraryImport(NativeLibName)] [UnmanagedCallConv(CallConvs = [typeof(CallConvCdecl)])] public static partial float Vector2DotProduct(Vector2 v1, Vector2 v2); /// Calculate two vectors cross product [LibraryImport(NativeLibName)] [UnmanagedCallConv(CallConvs = [typeof(CallConvCdecl)])] public static partial float Vector2CrossProduct(Vector2 v1, Vector2 v2); /// Calculate distance between two vectors [LibraryImport(NativeLibName)] [UnmanagedCallConv(CallConvs = [typeof(CallConvCdecl)])] public static partial float Vector2Distance(Vector2 v1, Vector2 v2); /// Calculate square distance between two vectors [LibraryImport(NativeLibName)] [UnmanagedCallConv(CallConvs = [typeof(CallConvCdecl)])] public static partial float Vector2DistanceSqr(Vector2 v1, Vector2 v2); /// /// Calculate the signed angle from v1 to v2, relative to the origin (0, 0) /// NOTE: Coordinate system convention: positive X right, positive Y down /// positive angles appear clockwise, and negative angles appear counterclockwise /// [LibraryImport(NativeLibName)] [UnmanagedCallConv(CallConvs = [typeof(CallConvCdecl)])] public static partial float Vector2Angle(Vector2 v1, Vector2 v2); /// /// Calculate angle defined by a two vectors line /// NOTE: Parameters need to be normalized /// Current implementation should be aligned with glm::angle /// [LibraryImport(NativeLibName)] [UnmanagedCallConv(CallConvs = [typeof(CallConvCdecl)])] public static partial float Vector2LineAngle(Vector2 start, Vector2 end); /// Scale vector (multiply by value) [LibraryImport(NativeLibName)] [UnmanagedCallConv(CallConvs = [typeof(CallConvCdecl)])] public static partial Vector2 Vector2Scale(Vector2 v, float scale); /// Multiply vector by vector [LibraryImport(NativeLibName)] [UnmanagedCallConv(CallConvs = [typeof(CallConvCdecl)])] public static partial Vector2 Vector2Multiply(Vector2 v1, Vector2 v2); /// Negate vector [LibraryImport(NativeLibName)] [UnmanagedCallConv(CallConvs = [typeof(CallConvCdecl)])] public static partial Vector2 Vector2Negate(Vector2 v); /// Divide vector by vector [LibraryImport(NativeLibName)] [UnmanagedCallConv(CallConvs = [typeof(CallConvCdecl)])] public static partial Vector2 Vector2Divide(Vector2 v1, Vector2 v2); /// Normalize provided vector [LibraryImport(NativeLibName)] [UnmanagedCallConv(CallConvs = [typeof(CallConvCdecl)])] public static partial Vector2 Vector2Normalize(Vector2 v); /// Transforms a Vector2 by a given Matrix [LibraryImport(NativeLibName)] [UnmanagedCallConv(CallConvs = [typeof(CallConvCdecl)])] public static partial Vector2 Vector2Transform(Vector2 v, Matrix4x4 mat); /// Calculate linear interpolation between two vectors [LibraryImport(NativeLibName)] [UnmanagedCallConv(CallConvs = [typeof(CallConvCdecl)])] public static partial Vector2 Vector2Lerp(Vector2 v1, Vector2 v2, float amount); /// Calculate reflected vector to normal [LibraryImport(NativeLibName)] [UnmanagedCallConv(CallConvs = [typeof(CallConvCdecl)])] public static partial Vector2 Vector2Reflect(Vector2 v, Vector2 normal); /// Rotate vector by angle [LibraryImport(NativeLibName)] [UnmanagedCallConv(CallConvs = [typeof(CallConvCdecl)])] public static partial Vector2 Vector2Rotate(Vector2 v, float angle); /// Move Vector towards target [LibraryImport(NativeLibName)] [UnmanagedCallConv(CallConvs = [typeof(CallConvCdecl)])] public static partial Vector2 Vector2MoveTowards(Vector2 v, Vector2 target, float maxDistance); /// Invert the given vector [LibraryImport(NativeLibName)] [UnmanagedCallConv(CallConvs = [typeof(CallConvCdecl)])] public static partial Vector2 Vector2Invert(Vector2 v); /// /// Clamp the components of the vector between min and max values specified by the given vectors /// [LibraryImport(NativeLibName)] [UnmanagedCallConv(CallConvs = [typeof(CallConvCdecl)])] public static partial Vector2 Vector2Clamp(Vector2 v, Vector2 min, Vector2 max); /// Clamp the magnitude of the vector between two min and max values [LibraryImport(NativeLibName)] [UnmanagedCallConv(CallConvs = [typeof(CallConvCdecl)])] public static partial Vector2 Vector2ClampValue(Vector2 v, float min, float max); /// Check whether two given vectors are almost equal [LibraryImport(NativeLibName)] [UnmanagedCallConv(CallConvs = [typeof(CallConvCdecl)])] public static partial int Vector2Equals(Vector2 p, Vector2 q); /// Compute the direction of a refracted ray /// normalized direction of the incoming ray /// normalized normal vector of the interface of two optical media /// /// 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 /// [LibraryImport(NativeLibName)] [UnmanagedCallConv(CallConvs = [typeof(CallConvCdecl)])] public static partial Vector2 Vector2Refract(Vector2 v, Vector2 n, float r); /// Vector with components value 0.0f [LibraryImport(NativeLibName)] [UnmanagedCallConv(CallConvs = [typeof(CallConvCdecl)])] public static partial Vector3 Vector3Zero(); /// Vector with components value 1.0f [LibraryImport(NativeLibName)] [UnmanagedCallConv(CallConvs = [typeof(CallConvCdecl)])] public static partial Vector3 Vector3One(); /// Add two vectors [LibraryImport(NativeLibName)] [UnmanagedCallConv(CallConvs = [typeof(CallConvCdecl)])] public static partial Vector3 Vector3Add(Vector3 v1, Vector3 v2); /// Add vector and float value [LibraryImport(NativeLibName)] [UnmanagedCallConv(CallConvs = [typeof(CallConvCdecl)])] public static partial Vector3 Vector3AddValue(Vector3 v, float add); /// Subtract two vectors [LibraryImport(NativeLibName)] [UnmanagedCallConv(CallConvs = [typeof(CallConvCdecl)])] public static partial Vector3 Vector3Subtract(Vector3 v1, Vector3 v2); /// Subtract vector and float value [LibraryImport(NativeLibName)] [UnmanagedCallConv(CallConvs = [typeof(CallConvCdecl)])] public static partial Vector3 Vector3SubtractValue(Vector3 v, float sub); /// Multiply vector by scalar [LibraryImport(NativeLibName)] [UnmanagedCallConv(CallConvs = [typeof(CallConvCdecl)])] public static partial Vector3 Vector3Scale(Vector3 v, float scalar); /// Multiply vector by vector [LibraryImport(NativeLibName)] [UnmanagedCallConv(CallConvs = [typeof(CallConvCdecl)])] public static partial Vector3 Vector3Multiply(Vector3 v1, Vector3 v2); /// Calculate two vectors cross product [LibraryImport(NativeLibName)] [UnmanagedCallConv(CallConvs = [typeof(CallConvCdecl)])] public static partial Vector3 Vector3CrossProduct(Vector3 v1, Vector3 v2); /// Calculate one vector perpendicular vector [LibraryImport(NativeLibName)] [UnmanagedCallConv(CallConvs = [typeof(CallConvCdecl)])] public static partial Vector3 Vector3Perpendicular(Vector3 v); /// Calculate vector length [LibraryImport(NativeLibName)] [UnmanagedCallConv(CallConvs = [typeof(CallConvCdecl)])] public static partial float Vector3Length(Vector3 v); /// Calculate vector square length [LibraryImport(NativeLibName)] [UnmanagedCallConv(CallConvs = [typeof(CallConvCdecl)])] public static partial float Vector3LengthSqr(Vector3 v); /// Calculate two vectors dot product [LibraryImport(NativeLibName)] [UnmanagedCallConv(CallConvs = [typeof(CallConvCdecl)])] public static partial float Vector3DotProduct(Vector3 v1, Vector3 v2); /// Calculate distance between two vectors [LibraryImport(NativeLibName)] [UnmanagedCallConv(CallConvs = [typeof(CallConvCdecl)])] public static partial float Vector3Distance(Vector3 v1, Vector3 v2); /// Calculate square distance between two vectors [LibraryImport(NativeLibName)] [UnmanagedCallConv(CallConvs = [typeof(CallConvCdecl)])] public static partial float Vector3DistanceSqr(Vector3 v1, Vector3 v2); /// Calculate angle between two vectors in XY and XZ [LibraryImport(NativeLibName)] [UnmanagedCallConv(CallConvs = [typeof(CallConvCdecl)])] public static partial float Vector3Angle(Vector3 v1, Vector3 v2); /// Negate provided vector (invert direction) [LibraryImport(NativeLibName)] [UnmanagedCallConv(CallConvs = [typeof(CallConvCdecl)])] public static partial Vector3 Vector3Negate(Vector3 v); /// Divide vector by vector [LibraryImport(NativeLibName)] [UnmanagedCallConv(CallConvs = [typeof(CallConvCdecl)])] public static partial Vector3 Vector3Divide(Vector3 v1, Vector3 v2); /// Normalize provided vector [LibraryImport(NativeLibName)] [UnmanagedCallConv(CallConvs = [typeof(CallConvCdecl)])] public static partial Vector3 Vector3Normalize(Vector3 v); /// Calculate the projection of the vector v1 on to v2 [LibraryImport(NativeLibName)] [UnmanagedCallConv(CallConvs = [typeof(CallConvCdecl)])] public static partial Vector3 Vector3Project(Vector3 v1, Vector3 v2); /// Calculate the rejection of the vector v1 on to v2 [LibraryImport(NativeLibName)] [UnmanagedCallConv(CallConvs = [typeof(CallConvCdecl)])] public static partial Vector3 Vector3Reject(Vector3 v1, Vector3 v2); /// /// Orthonormalize provided vectors
/// Makes vectors normalized and orthogonal to each other
/// Gram-Schmidt function implementation ///
[LibraryImport(NativeLibName)] [UnmanagedCallConv(CallConvs = [typeof(CallConvCdecl)])] public static partial void Vector3OrthoNormalize(Vector3* v1, Vector3* v2); /// Transforms a Vector3 by a given Matrix [LibraryImport(NativeLibName)] [UnmanagedCallConv(CallConvs = [typeof(CallConvCdecl)])] public static partial Vector3 Vector3Transform(Vector3 v, Matrix4x4 mat); /// Transform a vector by quaternion rotation [LibraryImport(NativeLibName)] [UnmanagedCallConv(CallConvs = [typeof(CallConvCdecl)])] public static partial Vector3 Vector3RotateByQuaternion(Vector3 v, Quaternion q); /// Rotates a vector around an axis [LibraryImport(NativeLibName)] [UnmanagedCallConv(CallConvs = [typeof(CallConvCdecl)])] public static partial Vector3 Vector3RotateByAxisAngle(Vector3 v, Vector3 axis, float angle); /// Move Vector towards target [LibraryImport(NativeLibName)] [UnmanagedCallConv(CallConvs = [typeof(CallConvCdecl)])] public static partial Vector3 Vector3MoveTowards(Vector3 v, Vector3 target, float maxDistance); /// Calculate linear interpolation between two vectors [LibraryImport(NativeLibName)] [UnmanagedCallConv(CallConvs = [typeof(CallConvCdecl)])] public static partial Vector3 Vector3Lerp(Vector3 v1, Vector3 v2, float amount); /// /// Calculate cubic hermite interpolation between two vectors and their tangents /// as described in the GLTF 2.0 specification: https://registry.khronos.org/glTF/specs/2.0/glTF-2.0.html#interpolation-cubic /// [LibraryImport(NativeLibName)] [UnmanagedCallConv(CallConvs = [typeof(CallConvCdecl)])] public static partial Vector3 Vector3CubicHermite(Vector3 v1, Vector3 tangent1, Vector3 v2, Vector3 tangent2, float amount); /// Calculate reflected vector to normal [LibraryImport(NativeLibName)] [UnmanagedCallConv(CallConvs = [typeof(CallConvCdecl)])] public static partial Vector3 Vector3Reflect(Vector3 v, Vector3 normal); /// Get min value for each pair of components [LibraryImport(NativeLibName)] [UnmanagedCallConv(CallConvs = [typeof(CallConvCdecl)])] public static partial Vector3 Vector3Min(Vector3 v1, Vector3 v2); /// Get max value for each pair of components [LibraryImport(NativeLibName)] [UnmanagedCallConv(CallConvs = [typeof(CallConvCdecl)])] public static partial 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 ///
[LibraryImport(NativeLibName)] [UnmanagedCallConv(CallConvs = [typeof(CallConvCdecl)])] public static partial 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 ///
[LibraryImport(NativeLibName)] [UnmanagedCallConv(CallConvs = [typeof(CallConvCdecl)])] public static partial Vector3 Vector3Unproject(Vector3 source, Matrix4x4 projection, Matrix4x4 view); /// Get Vector3 as float array [LibraryImport(NativeLibName)] [UnmanagedCallConv(CallConvs = [typeof(CallConvCdecl)])] public static partial Float3 Vector3ToFloatV(Vector3 v); /// Invert the given vector [LibraryImport(NativeLibName)] [UnmanagedCallConv(CallConvs = [typeof(CallConvCdecl)])] public static partial Vector3 Vector3Invert(Vector3 v); /// /// Clamp the components of the vector between /// min and max values specified by the given vectors /// [LibraryImport(NativeLibName)] [UnmanagedCallConv(CallConvs = [typeof(CallConvCdecl)])] public static partial Vector3 Vector3Clamp(Vector3 v, Vector3 min, Vector3 max); /// Clamp the magnitude of the vector between two values [LibraryImport(NativeLibName)] [UnmanagedCallConv(CallConvs = [typeof(CallConvCdecl)])] public static partial Vector3 Vector3ClampValue(Vector3 v, float min, float max); /// Check whether two given vectors are almost equal [LibraryImport(NativeLibName)] [UnmanagedCallConv(CallConvs = [typeof(CallConvCdecl)])] public static partial 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 /// [LibraryImport(NativeLibName)] [UnmanagedCallConv(CallConvs = [typeof(CallConvCdecl)])] public static partial Vector3 Vector3Refract(Vector3 v, Vector3 n, float r); /// Compute matrix determinant [LibraryImport(NativeLibName)] [UnmanagedCallConv(CallConvs = [typeof(CallConvCdecl)])] public static partial float MatrixDeterminant(Matrix4x4 mat); /// Get the trace of the matrix (sum of the values along the diagonal) [LibraryImport(NativeLibName)] [UnmanagedCallConv(CallConvs = [typeof(CallConvCdecl)])] public static partial float MatrixTrace(Matrix4x4 mat); /// Transposes provided matrix [LibraryImport(NativeLibName)] [UnmanagedCallConv(CallConvs = [typeof(CallConvCdecl)])] public static partial Matrix4x4 MatrixTranspose(Matrix4x4 mat); /// Invert provided matrix [LibraryImport(NativeLibName)] [UnmanagedCallConv(CallConvs = [typeof(CallConvCdecl)])] public static partial Matrix4x4 MatrixInvert(Matrix4x4 mat); /// Get identity matrix [LibraryImport(NativeLibName)] [UnmanagedCallConv(CallConvs = [typeof(CallConvCdecl)])] public static partial Matrix4x4 MatrixIdentity(); /// Add two matrices [LibraryImport(NativeLibName)] [UnmanagedCallConv(CallConvs = [typeof(CallConvCdecl)])] public static partial Matrix4x4 MatrixAdd(Matrix4x4 left, Matrix4x4 right); /// Subtract two matrices (left - right) [LibraryImport(NativeLibName)] [UnmanagedCallConv(CallConvs = [typeof(CallConvCdecl)])] public static partial Matrix4x4 MatrixSubtract(Matrix4x4 left, Matrix4x4 right); /// /// Get two matrix multiplication
/// NOTE: When multiplying matrices... the order matters! ///
[LibraryImport(NativeLibName)] [UnmanagedCallConv(CallConvs = [typeof(CallConvCdecl)])] public static partial Matrix4x4 MatrixMultiply(Matrix4x4 left, Matrix4x4 right); /// /// Multiply matrix components by value /// [LibraryImport(NativeLibName)] [UnmanagedCallConv(CallConvs = [typeof(CallConvCdecl)])] public static partial Matrix4x4 MatrixMultiplyValue(Matrix4x4 left, float value); /// Get translation matrix [LibraryImport(NativeLibName)] [UnmanagedCallConv(CallConvs = [typeof(CallConvCdecl)])] public static partial Matrix4x4 MatrixTranslate(float x, float y, float z); /// /// Create rotation matrix from axis and angle
/// NOTE: Angle should be provided in radians ///
[LibraryImport(NativeLibName)] [UnmanagedCallConv(CallConvs = [typeof(CallConvCdecl)])] public static partial Matrix4x4 MatrixRotate(Vector3 axis, float angle); /// Get x-rotation matrix (angle in radians) [LibraryImport(NativeLibName)] [UnmanagedCallConv(CallConvs = [typeof(CallConvCdecl)])] public static partial Matrix4x4 MatrixRotateX(float angle); /// Get y-rotation matrix (angle in radians) [LibraryImport(NativeLibName)] [UnmanagedCallConv(CallConvs = [typeof(CallConvCdecl)])] public static partial Matrix4x4 MatrixRotateY(float angle); /// Get z-rotation matrix (angle in radians) [LibraryImport(NativeLibName)] [UnmanagedCallConv(CallConvs = [typeof(CallConvCdecl)])] public static partial Matrix4x4 MatrixRotateZ(float angle); /// Get xyz-rotation matrix (angles in radians) [LibraryImport(NativeLibName)] [UnmanagedCallConv(CallConvs = [typeof(CallConvCdecl)])] public static partial Matrix4x4 MatrixRotateXYZ(Vector3 ang); /// Get zyx-rotation matrix (angles in radians) [LibraryImport(NativeLibName)] [UnmanagedCallConv(CallConvs = [typeof(CallConvCdecl)])] public static partial Matrix4x4 MatrixRotateZYX(Vector3 ang); /// Get scaling matrix [LibraryImport(NativeLibName)] [UnmanagedCallConv(CallConvs = [typeof(CallConvCdecl)])] public static partial Matrix4x4 MatrixScale(float x, float y, float z); /// Get perspective projection matrix [LibraryImport(NativeLibName)] [UnmanagedCallConv(CallConvs = [typeof(CallConvCdecl)])] public static partial Matrix4x4 MatrixFrustum( double left, double right, double bottom, double top, double nearPlane, double farPlane ); /// /// Get perspective projection matrix
/// NOTE: Angle should be provided in radians ///
[LibraryImport(NativeLibName)] [UnmanagedCallConv(CallConvs = [typeof(CallConvCdecl)])] public static partial Matrix4x4 MatrixPerspective(double fovy, double aspect, double near, double far); /// Get orthographic projection matrix [LibraryImport(NativeLibName)] [UnmanagedCallConv(CallConvs = [typeof(CallConvCdecl)])] public static partial Matrix4x4 MatrixOrtho( double left, double right, double bottom, double top, double near, double far ); /// Get camera look-at matrix (view matrix) [LibraryImport(NativeLibName)] [UnmanagedCallConv(CallConvs = [typeof(CallConvCdecl)])] public static partial Matrix4x4 MatrixLookAt(Vector3 eye, Vector3 target, Vector3 up); /// Get float array of matrix data [LibraryImport(Raylib.NativeLibName)] [UnmanagedCallConv(CallConvs = [typeof(CallConvCdecl)])] public static partial Float16 MatrixToFloatV(Matrix4x4 m); /// Add 2 quaternions [LibraryImport(NativeLibName)] [UnmanagedCallConv(CallConvs = [typeof(CallConvCdecl)])] public static partial Quaternion QuaternionAdd(Quaternion q1, Quaternion q2); /// Add quaternion and float value [LibraryImport(NativeLibName)] [UnmanagedCallConv(CallConvs = [typeof(CallConvCdecl)])] public static partial Quaternion QuaternionAddValue(Quaternion q, float add); /// Subtract 2 quaternions [LibraryImport(NativeLibName)] [UnmanagedCallConv(CallConvs = [typeof(CallConvCdecl)])] public static partial Quaternion QuaternionSubtract(Quaternion q1, Quaternion q2); /// Subtract quaternion and float value [LibraryImport(NativeLibName)] [UnmanagedCallConv(CallConvs = [typeof(CallConvCdecl)])] public static partial Quaternion QuaternionSubtractValue(Quaternion q, float add); /// Get identity quaternion [LibraryImport(NativeLibName)] [UnmanagedCallConv(CallConvs = [typeof(CallConvCdecl)])] public static partial Quaternion QuaternionIdentity(); /// Computes the length of a quaternion [LibraryImport(NativeLibName)] [UnmanagedCallConv(CallConvs = [typeof(CallConvCdecl)])] public static partial float QuaternionLength(Quaternion q); /// Normalize provided quaternion [LibraryImport(NativeLibName)] [UnmanagedCallConv(CallConvs = [typeof(CallConvCdecl)])] public static partial Quaternion QuaternionNormalize(Quaternion q); /// Invert provided quaternion [LibraryImport(NativeLibName)] [UnmanagedCallConv(CallConvs = [typeof(CallConvCdecl)])] public static partial Quaternion QuaternionInvert(Quaternion q); /// Calculate two quaternion multiplication [LibraryImport(NativeLibName)] [UnmanagedCallConv(CallConvs = [typeof(CallConvCdecl)])] public static partial Quaternion QuaternionMultiply(Quaternion q1, Quaternion q2); /// Scale quaternion by float value [LibraryImport(NativeLibName)] [UnmanagedCallConv(CallConvs = [typeof(CallConvCdecl)])] public static partial Quaternion QuaternionScale(Quaternion q, float mul); /// Divide two quaternions [LibraryImport(NativeLibName)] [UnmanagedCallConv(CallConvs = [typeof(CallConvCdecl)])] public static partial Quaternion QuaternionDivide(Quaternion q1, Quaternion q2); /// Calculate linear interpolation between two quaternions [LibraryImport(NativeLibName)] [UnmanagedCallConv(CallConvs = [typeof(CallConvCdecl)])] public static partial Quaternion QuaternionLerp(Quaternion q1, Quaternion q2, float amount); /// Calculate slerp-optimized interpolation between two quaternions [LibraryImport(NativeLibName)] [UnmanagedCallConv(CallConvs = [typeof(CallConvCdecl)])] public static partial Quaternion QuaternionNlerp(Quaternion q1, Quaternion q2, float amount); /// Calculates spherical linear interpolation between two quaternions [LibraryImport(NativeLibName)] [UnmanagedCallConv(CallConvs = [typeof(CallConvCdecl)])] public static partial Quaternion QuaternionSlerp(Quaternion q1, Quaternion q2, float amount); /// /// Calculate quaternion cubic spline interpolation using Cubic Hermite Spline algorithm /// as described in the GLTF 2.0 specification: https://registry.khronos.org/glTF/specs/2.0/glTF-2.0.html#interpolation-cubic /// [LibraryImport(NativeLibName)] [UnmanagedCallConv(CallConvs = [typeof(CallConvCdecl)])] public static partial Quaternion QuaternionCubicHermiteSpline( Quaternion q1, Quaternion outTangent1, Quaternion q2, Quaternion inTangent2, float t ); /// Calculate quaternion based on the rotation from one vector to another [LibraryImport(NativeLibName)] [UnmanagedCallConv(CallConvs = [typeof(CallConvCdecl)])] public static partial Quaternion QuaternionFromVector3ToVector3(Vector3 from, Vector3 to); /// Get a quaternion for a given rotation matrix [LibraryImport(NativeLibName)] [UnmanagedCallConv(CallConvs = [typeof(CallConvCdecl)])] public static partial Quaternion QuaternionFromMatrix(Matrix4x4 mat); /// Get a matrix for a given quaternion [LibraryImport(NativeLibName)] [UnmanagedCallConv(CallConvs = [typeof(CallConvCdecl)])] public static partial Matrix4x4 QuaternionToMatrix(Quaternion q); /// /// Get rotation quaternion for an angle and axis
/// NOTE: angle must be provided in radians ///
[LibraryImport(NativeLibName)] [UnmanagedCallConv(CallConvs = [typeof(CallConvCdecl)])] public static partial Quaternion QuaternionFromAxisAngle(Vector3 axis, float angle); /// Get the rotation angle and axis for a given quaternion [LibraryImport(NativeLibName)] [UnmanagedCallConv(CallConvs = [typeof(CallConvCdecl)])] public static partial void QuaternionToAxisAngle(Quaternion q, Vector3* outAxis, float* outAngle); /// /// Get the quaternion equivalent to Euler angles
/// NOTE: Rotation order is ZYX ///
[LibraryImport(NativeLibName)] [UnmanagedCallConv(CallConvs = [typeof(CallConvCdecl)])] public static partial 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 ///
[LibraryImport(NativeLibName)] [UnmanagedCallConv(CallConvs = [typeof(CallConvCdecl)])] public static partial Vector3 QuaternionToEuler(Quaternion q); /// Transform a quaternion given a transformation matrix [LibraryImport(NativeLibName)] [UnmanagedCallConv(CallConvs = [typeof(CallConvCdecl)])] public static partial Quaternion QuaternionTransform(Quaternion q, Matrix4x4 mat); /// Check whether two given quaternions are almost equal [LibraryImport(NativeLibName)] [UnmanagedCallConv(CallConvs = [typeof(CallConvCdecl)])] public static partial int QuaternionEquals(Quaternion p, Quaternion q); /// /// Compose a transformation matrix from rotational, translational and scaling components /// TODO: This function is not following raymath conventions defined in header: NOT self-contained /// [LibraryImport(NativeLibName)] [UnmanagedCallConv(CallConvs = [typeof(CallConvCdecl)])] public static partial Matrix4x4 MatrixCompose(Vector3 translation, Quaternion rotation, Vector3 scale); /// Decompose a transformation matrix into its rotational, translational and scaling components [LibraryImport(NativeLibName)] [UnmanagedCallConv(CallConvs = [typeof(CallConvCdecl)])] public static partial void MatrixDecompose( Matrix4x4 mat, Vector3* translation, Quaternion* rotation, Vector3* scale ); }