Bump raylib/zig versions
This commit is contained in:
parent
aa9ee05f22
commit
8e04b7098a
20 changed files with 1383 additions and 1027 deletions
236
lib/raymath.h
vendored
236
lib/raymath.h
vendored
|
|
@ -19,20 +19,25 @@
|
|||
*
|
||||
* CONFIGURATION:
|
||||
* #define RAYMATH_IMPLEMENTATION
|
||||
* Generates the implementation of the library into the included file.
|
||||
* Generates the implementation of the library into the included file
|
||||
* If not defined, the library is in header only mode and can be included in other headers
|
||||
* or source files without problems. But only ONE file should hold the implementation.
|
||||
* or source files without problems. But only ONE file should hold the implementation
|
||||
*
|
||||
* #define RAYMATH_STATIC_INLINE
|
||||
* Define static inline functions code, so #include header suffices for use.
|
||||
* This may use up lots of memory.
|
||||
* Define static inline functions code, so #include header suffices for use
|
||||
* This may use up lots of memory
|
||||
*
|
||||
* #define RAYMATH_DISABLE_CPP_OPERATORS
|
||||
* Disables C++ operator overloads for raymath types.
|
||||
*
|
||||
* #define RAYMATH_USE_SIMD_INTRINSICS 1
|
||||
* Try to enable SIMD intrinsics for MatrixMultiply()
|
||||
* Note that users enabling it must be aware of the target platform where application will
|
||||
* run to support the selected SIMD intrinsic, for now, only SSE is supported
|
||||
*
|
||||
* LICENSE: zlib/libpng
|
||||
*
|
||||
* Copyright (c) 2015-2025 Ramon Santamaria (@raysan5)
|
||||
* Copyright (c) 2015-2026 Ramon Santamaria (@raysan5)
|
||||
*
|
||||
* This software is provided "as-is", without any express or implied warranty. In no event
|
||||
* will the authors be held liable for any damages arising from the use of this software.
|
||||
|
|
@ -61,11 +66,11 @@
|
|||
// Function specifiers definition
|
||||
#if defined(RAYMATH_IMPLEMENTATION)
|
||||
#if defined(_WIN32) && defined(BUILD_LIBTYPE_SHARED)
|
||||
#define RMAPI __declspec(dllexport) extern inline // We are building raylib as a Win32 shared library (.dll)
|
||||
#define RMAPI __declspec(dllexport) extern inline // Building raylib as a Win32 shared library (.dll)
|
||||
#elif defined(BUILD_LIBTYPE_SHARED)
|
||||
#define RMAPI __attribute__((visibility("default"))) // We are building raylib as a Unix shared library (.so/.dylib)
|
||||
#define RMAPI __attribute__((visibility("default"))) // Building raylib as a Unix shared library (.so/.dylib)
|
||||
#elif defined(_WIN32) && defined(USE_LIBTYPE_SHARED)
|
||||
#define RMAPI __declspec(dllimport) // We are using raylib as a Win32 shared library (.dll)
|
||||
#define RMAPI __declspec(dllimport) // Using raylib as a Win32 shared library (.dll)
|
||||
#else
|
||||
#define RMAPI extern inline // Provide external definition
|
||||
#endif
|
||||
|
|
@ -79,7 +84,6 @@
|
|||
#endif
|
||||
#endif
|
||||
|
||||
|
||||
//----------------------------------------------------------------------------------
|
||||
// Defines and Macros
|
||||
//----------------------------------------------------------------------------------
|
||||
|
|
@ -160,16 +164,51 @@ typedef struct Matrix {
|
|||
#endif
|
||||
|
||||
// NOTE: Helper types to be used instead of array return types for *ToFloat functions
|
||||
#if !defined(RL_FLOAT3_TYPE)
|
||||
typedef struct float3 {
|
||||
float v[3];
|
||||
} float3;
|
||||
#define RL_FLOAT3_TYPE
|
||||
#endif
|
||||
|
||||
#if !defined(RL_FLOAT16_TYPE)
|
||||
typedef struct float16 {
|
||||
float v[16];
|
||||
} float16;
|
||||
#define RL_FLOAT16_TYPE
|
||||
#endif
|
||||
|
||||
#include <math.h> // Required for: sinf(), cosf(), tan(), atan2f(), sqrtf(), floor(), fminf(), fmaxf(), fabsf()
|
||||
|
||||
#if RAYMATH_USE_SIMD_INTRINSICS
|
||||
// SIMD is used on the most costly raymath function MatrixMultiply()
|
||||
// NOTE: Only SSE intrinsics support implemented
|
||||
// TODO: Consider support for other SIMD instrinsics:
|
||||
// - SSEx, AVX, AVX2, FMA, NEON, RVV
|
||||
/*
|
||||
#if defined(__SSE4_2__)
|
||||
#include <nmmintrin.h>
|
||||
#define RAYMATH_SSE42_ENABLED
|
||||
#elif defined(__SSE4_1__)
|
||||
#include <smmintrin.h>
|
||||
#define RAYMATH_SSE41_ENABLED
|
||||
#elif defined(__SSSE3__)
|
||||
#include <tmmintrin.h>
|
||||
#define RAYMATH_SSSE3_ENABLED
|
||||
#elif defined(__SSE3__)
|
||||
#include <pmmintrin.h>
|
||||
#define RAYMATH_SSE3_ENABLED
|
||||
#elif defined(__SSE2__) || (defined(_M_AMD64) || defined(_M_X64)) // SSE2 x64
|
||||
#include <emmintrin.h>
|
||||
#define RAYMATH_SSE2_ENABLED
|
||||
#endif
|
||||
*/
|
||||
#if defined(__SSE__) || defined(_M_X64) || (defined(_M_IX86_FP) && (_M_IX86_FP >= 1))
|
||||
#include <xmmintrin.h>
|
||||
#define RAYMATH_SSE_ENABLED
|
||||
#endif
|
||||
#endif
|
||||
|
||||
//----------------------------------------------------------------------------------
|
||||
// Module Functions Definition - Utils math
|
||||
//----------------------------------------------------------------------------------
|
||||
|
|
@ -528,15 +567,9 @@ RMAPI Vector2 Vector2ClampValue(Vector2 v, float min, float max)
|
|||
{
|
||||
length = sqrtf(length);
|
||||
|
||||
float scale = 1; // By default, 1 as the neutral element.
|
||||
if (length < min)
|
||||
{
|
||||
scale = min/length;
|
||||
}
|
||||
else if (length > max)
|
||||
{
|
||||
scale = max/length;
|
||||
}
|
||||
float scale = 1; // By default, 1 as the neutral element
|
||||
if (length < min) scale = min/length;
|
||||
else if (length > max) scale = max/length;
|
||||
|
||||
result.x = v.x*scale;
|
||||
result.y = v.y*scale;
|
||||
|
|
@ -562,7 +595,7 @@ RMAPI int Vector2Equals(Vector2 p, Vector2 q)
|
|||
// v: normalized direction of the incoming ray
|
||||
// n: normalized normal vector of the interface of two optical media
|
||||
// r: 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
|
||||
// to the refractive index of the medium on the other side of the surface
|
||||
RMAPI Vector2 Vector2Refract(Vector2 v, Vector2 n, float r)
|
||||
{
|
||||
Vector2 result = { 0 };
|
||||
|
|
@ -1050,7 +1083,7 @@ RMAPI 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
|
||||
// NOTE: Self-contained function, no other raymath functions are called
|
||||
RMAPI Vector3 Vector3Unproject(Vector3 source, Matrix projection, Matrix view)
|
||||
{
|
||||
Vector3 result = { 0 };
|
||||
|
|
@ -1176,15 +1209,9 @@ RMAPI Vector3 Vector3ClampValue(Vector3 v, float min, float max)
|
|||
{
|
||||
length = sqrtf(length);
|
||||
|
||||
float scale = 1; // By default, 1 as the neutral element.
|
||||
if (length < min)
|
||||
{
|
||||
scale = min/length;
|
||||
}
|
||||
else if (length > max)
|
||||
{
|
||||
scale = max/length;
|
||||
}
|
||||
float scale = 1; // By default, 1 as the neutral element
|
||||
if (length < min) scale = min/length;
|
||||
else if (length > max) scale = max/length;
|
||||
|
||||
result.x = v.x*scale;
|
||||
result.y = v.y*scale;
|
||||
|
|
@ -1212,7 +1239,7 @@ RMAPI int Vector3Equals(Vector3 p, Vector3 q)
|
|||
// v: normalized direction of the incoming ray
|
||||
// n: normalized normal vector of the interface of two optical media
|
||||
// r: 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
|
||||
// to the refractive index of the medium on the other side of the surface
|
||||
RMAPI Vector3 Vector3Refract(Vector3 v, Vector3 n, float r)
|
||||
{
|
||||
Vector3 result = { 0 };
|
||||
|
|
@ -1484,7 +1511,7 @@ RMAPI float MatrixDeterminant(Matrix mat)
|
|||
a20*a01*a12*a33 - a00*a21*a12*a33 - a10*a01*a22*a33 + a00*a11*a22*a33;
|
||||
*/
|
||||
// Using Laplace expansion (https://en.wikipedia.org/wiki/Laplace_expansion),
|
||||
// previous operation can be simplified to 40 multiplications, decreasing matrix
|
||||
// previous operation can be simplified to 40 multiplications, decreasing matrix
|
||||
// size from 4x4 to 2x2 using minors
|
||||
|
||||
// Cache the matrix values (speed optimization)
|
||||
|
|
@ -1648,6 +1675,63 @@ RMAPI Matrix MatrixMultiply(Matrix left, Matrix right)
|
|||
{
|
||||
Matrix result = { 0 };
|
||||
|
||||
#if defined(RAYMATH_SSE_ENABLED)
|
||||
// Load left side and right side
|
||||
__m128 c0 = _mm_set_ps(right.m12, right.m8, right.m4, right.m0);
|
||||
__m128 c1 = _mm_set_ps(right.m13, right.m9, right.m5, right.m1);
|
||||
__m128 c2 = _mm_set_ps(right.m14, right.m10, right.m6, right.m2);
|
||||
__m128 c3 = _mm_set_ps(right.m15, right.m11, right.m7, right.m3);
|
||||
|
||||
// Transpose so c0..c3 become *rows* of the right matrix in semantic order
|
||||
_MM_TRANSPOSE4_PS(c0, c1, c2, c3);
|
||||
|
||||
float tmp[4] = { 0 };
|
||||
__m128 row;
|
||||
|
||||
// Row 0 of result: [m0, m1, m2, m3]
|
||||
row = _mm_mul_ps(_mm_set1_ps(left.m0), c0);
|
||||
row = _mm_add_ps(row, _mm_mul_ps(_mm_set1_ps(left.m1), c1));
|
||||
row = _mm_add_ps(row, _mm_mul_ps(_mm_set1_ps(left.m2), c2));
|
||||
row = _mm_add_ps(row, _mm_mul_ps(_mm_set1_ps(left.m3), c3));
|
||||
_mm_storeu_ps(tmp, row);
|
||||
result.m0 = tmp[0];
|
||||
result.m1 = tmp[1];
|
||||
result.m2 = tmp[2];
|
||||
result.m3 = tmp[3];
|
||||
|
||||
// Row 1 of result: [m4, m5, m6, m7]
|
||||
row = _mm_mul_ps(_mm_set1_ps(left.m4), c0);
|
||||
row = _mm_add_ps(row, _mm_mul_ps(_mm_set1_ps(left.m5), c1));
|
||||
row = _mm_add_ps(row, _mm_mul_ps(_mm_set1_ps(left.m6), c2));
|
||||
row = _mm_add_ps(row, _mm_mul_ps(_mm_set1_ps(left.m7), c3));
|
||||
_mm_storeu_ps(tmp, row);
|
||||
result.m4 = tmp[0];
|
||||
result.m5 = tmp[1];
|
||||
result.m6 = tmp[2];
|
||||
result.m7 = tmp[3];
|
||||
|
||||
// Row 2 of result: [m8, m9, m10, m11]
|
||||
row = _mm_mul_ps(_mm_set1_ps(left.m8), c0);
|
||||
row = _mm_add_ps(row, _mm_mul_ps(_mm_set1_ps(left.m9), c1));
|
||||
row = _mm_add_ps(row, _mm_mul_ps(_mm_set1_ps(left.m10), c2));
|
||||
row = _mm_add_ps(row, _mm_mul_ps(_mm_set1_ps(left.m11), c3));
|
||||
_mm_storeu_ps(tmp, row);
|
||||
result.m8 = tmp[0];
|
||||
result.m9 = tmp[1];
|
||||
result.m10 = tmp[2];
|
||||
result.m11 = tmp[3];
|
||||
|
||||
// Row 3 of result: [m12, m13, m14, m15]
|
||||
row = _mm_mul_ps(_mm_set1_ps(left.m12), c0);
|
||||
row = _mm_add_ps(row, _mm_mul_ps(_mm_set1_ps(left.m13), c1));
|
||||
row = _mm_add_ps(row, _mm_mul_ps(_mm_set1_ps(left.m14), c2));
|
||||
row = _mm_add_ps(row, _mm_mul_ps(_mm_set1_ps(left.m15), c3));
|
||||
_mm_storeu_ps(tmp, row);
|
||||
result.m12 = tmp[0];
|
||||
result.m13 = tmp[1];
|
||||
result.m14 = tmp[2];
|
||||
result.m15 = tmp[3];
|
||||
#else
|
||||
result.m0 = left.m0*right.m0 + left.m1*right.m4 + left.m2*right.m8 + left.m3*right.m12;
|
||||
result.m1 = left.m0*right.m1 + left.m1*right.m5 + left.m2*right.m9 + left.m3*right.m13;
|
||||
result.m2 = left.m0*right.m2 + left.m1*right.m6 + left.m2*right.m10 + left.m3*right.m14;
|
||||
|
|
@ -1664,6 +1748,19 @@ RMAPI Matrix MatrixMultiply(Matrix left, Matrix right)
|
|||
result.m13 = left.m12*right.m1 + left.m13*right.m5 + left.m14*right.m9 + left.m15*right.m13;
|
||||
result.m14 = left.m12*right.m2 + left.m13*right.m6 + left.m14*right.m10 + left.m15*right.m14;
|
||||
result.m15 = left.m12*right.m3 + left.m13*right.m7 + left.m14*right.m11 + left.m15*right.m15;
|
||||
#endif
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
RMAPI Matrix MatrixMultiplyValue(Matrix left, float value)
|
||||
{
|
||||
Matrix result = {
|
||||
left.m0 * value, left.m4 * value, left.m8 * value, left.m12 * value,
|
||||
left.m1 * value, left.m5 * value, left.m9 * value, left.m13 * value,
|
||||
left.m2 * value, left.m6 * value, left.m10 * value, left.m14 * value,
|
||||
left.m3 * value, left.m7 * value, left.m11 * value, left.m15 * value
|
||||
};
|
||||
|
||||
return result;
|
||||
}
|
||||
|
|
@ -2272,13 +2369,13 @@ RMAPI Quaternion QuaternionFromVector3ToVector3(Vector3 from, Vector3 to)
|
|||
{
|
||||
Quaternion result = { 0 };
|
||||
|
||||
float cos2Theta = (from.x*to.x + from.y*to.y + from.z*to.z); // Vector3DotProduct(from, to)
|
||||
float cos2Theta = (from.x*to.x + from.y*to.y + from.z*to.z); // Vector3DotProduct(from, to)
|
||||
Vector3 cross = { from.y*to.z - from.z*to.y, from.z*to.x - from.x*to.z, from.x*to.y - from.y*to.x }; // Vector3CrossProduct(from, to)
|
||||
|
||||
result.x = cross.x;
|
||||
result.y = cross.y;
|
||||
result.z = cross.z;
|
||||
result.w = 1.0f + cos2Theta;
|
||||
result.w = sqrtf(cross.x*cross.x + cross.y*cross.y + cross.z*cross.z + cos2Theta*cos2Theta) + cos2Theta;
|
||||
|
||||
// QuaternionNormalize(q);
|
||||
// NOTE: Normalize to essentially nlerp the original and identity to 0.5
|
||||
|
|
@ -2465,8 +2562,8 @@ RMAPI void QuaternionToAxisAngle(Quaternion q, Vector3 *outAxis, float *outAngle
|
|||
}
|
||||
else
|
||||
{
|
||||
// This occurs when the angle is zero.
|
||||
// Not a problem: just set an arbitrary normalized axis.
|
||||
// This occurs when the angle is zero
|
||||
// Not a problem, set an arbitrary normalized axis
|
||||
resAxis.x = 1.0f;
|
||||
}
|
||||
|
||||
|
|
@ -2552,7 +2649,38 @@ RMAPI int QuaternionEquals(Quaternion p, Quaternion q)
|
|||
return result;
|
||||
}
|
||||
|
||||
// Compose a transformation matrix from rotational, translational and scaling components
|
||||
// TODO: This function is not following raymath conventions defined in header: NOT self-contained
|
||||
RMAPI Matrix MatrixCompose(Vector3 translation, Quaternion rotation, Vector3 scale)
|
||||
{
|
||||
// Initialize vectors
|
||||
Vector3 right = { 1.0f, 0.0f, 0.0f };
|
||||
Vector3 up = { 0.0f, 1.0f, 0.0f };
|
||||
Vector3 forward = { 0.0f, 0.0f, 1.0f };
|
||||
|
||||
// Scale vectors
|
||||
right = Vector3Scale(right, scale.x);
|
||||
up = Vector3Scale(up, scale.y);
|
||||
forward = Vector3Scale(forward , scale.z);
|
||||
|
||||
// Rotate vectors
|
||||
right = Vector3RotateByQuaternion(right, rotation);
|
||||
up = Vector3RotateByQuaternion(up, rotation);
|
||||
forward = Vector3RotateByQuaternion(forward, rotation);
|
||||
|
||||
// Set result matrix output
|
||||
Matrix result = {
|
||||
right.x, up.x, forward.x, translation.x,
|
||||
right.y, up.y, forward.y, translation.y,
|
||||
right.z, up.z, forward.z, translation.z,
|
||||
0.0f, 0.0f, 0.0f, 1.0f
|
||||
};
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
// Decompose a transformation matrix into its rotational, translational and scaling components and remove shear
|
||||
// TODO: This function is not following raymath conventions defined in header: NOT self-contained
|
||||
RMAPI void MatrixDecompose(Matrix mat, Vector3 *translation, Quaternion *rotation, Vector3 *scale)
|
||||
{
|
||||
float eps = (float)1e-9;
|
||||
|
|
@ -2562,10 +2690,10 @@ RMAPI void MatrixDecompose(Matrix mat, Vector3 *translation, Quaternion *rotatio
|
|||
translation->y = mat.m13;
|
||||
translation->z = mat.m14;
|
||||
|
||||
// Matrix Columns - Rotation will be extracted into here.
|
||||
Vector3 matColumns[3] = { { mat.m0, mat.m4, mat.m8 },
|
||||
// Matrix Columns - Rotation will be extracted into here
|
||||
Vector3 matColumns[3] = {{ mat.m0, mat.m4, mat.m8 },
|
||||
{ mat.m1, mat.m5, mat.m9 },
|
||||
{ mat.m2, mat.m6, mat.m10 } };
|
||||
{ mat.m2, mat.m6, mat.m10 }};
|
||||
|
||||
// Shear Parameters XY, XZ, and YZ (extract and ignored)
|
||||
float shear[3] = { 0 };
|
||||
|
|
@ -2580,17 +2708,14 @@ RMAPI void MatrixDecompose(Matrix mat, Vector3 *translation, Quaternion *rotatio
|
|||
stabilizer = fmaxf(stabilizer, fabsf(matColumns[i].x));
|
||||
stabilizer = fmaxf(stabilizer, fabsf(matColumns[i].y));
|
||||
stabilizer = fmaxf(stabilizer, fabsf(matColumns[i].z));
|
||||
};
|
||||
}
|
||||
matColumns[0] = Vector3Scale(matColumns[0], 1.0f / stabilizer);
|
||||
matColumns[1] = Vector3Scale(matColumns[1], 1.0f / stabilizer);
|
||||
matColumns[2] = Vector3Scale(matColumns[2], 1.0f / stabilizer);
|
||||
|
||||
// X Scale
|
||||
scl.x = Vector3Length(matColumns[0]);
|
||||
if (scl.x > eps)
|
||||
{
|
||||
matColumns[0] = Vector3Scale(matColumns[0], 1.0f / scl.x);
|
||||
}
|
||||
if (scl.x > eps) matColumns[0] = Vector3Scale(matColumns[0], 1.0f / scl.x);
|
||||
|
||||
// Compute XY shear and make col2 orthogonal
|
||||
shear[0] = Vector3DotProduct(matColumns[0], matColumns[1]);
|
||||
|
|
@ -2619,7 +2744,7 @@ RMAPI void MatrixDecompose(Matrix mat, Vector3 *translation, Quaternion *rotatio
|
|||
shear[2] /= scl.z; // Correct YZ shear
|
||||
}
|
||||
|
||||
// matColumns are now orthonormal in O(3). Now ensure its in SO(3) by enforcing det = 1.
|
||||
// matColumns are now orthonormal in O(3). Now ensure its in SO(3) by enforcing det = 1
|
||||
if (Vector3DotProduct(matColumns[0], Vector3CrossProduct(matColumns[1], matColumns[2])) < 0)
|
||||
{
|
||||
scl = Vector3Negate(scl);
|
||||
|
|
@ -2954,6 +3079,11 @@ inline const Quaternion& operator *= (Quaternion& lhs, const Matrix& rhs)
|
|||
}
|
||||
|
||||
// Matrix operators
|
||||
static constexpr Matrix MatrixUnit = { 1, 0, 0, 0,
|
||||
0, 1, 0, 0,
|
||||
0, 0, 1, 0,
|
||||
0, 0, 0, 1 };
|
||||
|
||||
inline Matrix operator + (const Matrix& lhs, const Matrix& rhs)
|
||||
{
|
||||
return MatrixAdd(lhs, rhs);
|
||||
|
|
@ -2986,7 +3116,19 @@ inline const Matrix& operator *= (Matrix& lhs, const Matrix& rhs)
|
|||
lhs = MatrixMultiply(lhs, rhs);
|
||||
return lhs;
|
||||
}
|
||||
//-------------------------------------------------------------------------------
|
||||
#endif // C++ operators
|
||||
|
||||
#endif // RAYMATH_H
|
||||
inline Matrix operator * (const Matrix& lhs, const float value)
|
||||
{
|
||||
return MatrixMultiplyValue(lhs, value);
|
||||
}
|
||||
|
||||
inline const Matrix& operator *= (Matrix& lhs, const float value)
|
||||
{
|
||||
lhs = MatrixMultiplyValue(lhs, value);
|
||||
return lhs;
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------------------
|
||||
#endif // C++ operators
|
||||
|
||||
#endif // RAYMATH_H
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue