From cd7137af60ba2c3f1d95ae77d59e6663412eab4a Mon Sep 17 00:00:00 2001 From: gingerBill Date: Tue, 19 Mar 2024 21:16:04 +0000 Subject: [PATCH] Update raylib to use `#row_major` matrices --- vendor/raylib/raylib.odin | 12 ++++++------ vendor/raylib/raymath.odin | 31 ++++++++++++++++++------------- 2 files changed, 24 insertions(+), 19 deletions(-) diff --git a/vendor/raylib/raylib.odin b/vendor/raylib/raylib.odin index 0e4bf60dc..b98770271 100644 --- a/vendor/raylib/raylib.odin +++ b/vendor/raylib/raylib.odin @@ -213,17 +213,17 @@ MAGENTA :: Color{ 255, 0, 255, 255 } // Magenta RAYWHITE :: Color{ 245, 245, 245, 255 } // My own White (raylib logo) // Vector2 type -Vector2 :: linalg.Vector2f32 +Vector2 :: [2]f32 // Vector3 type -Vector3 :: linalg.Vector3f32 +Vector3 :: [3]f32 // Vector4 type -Vector4 :: linalg.Vector4f32 +Vector4 :: [4]f32 // Quaternion type -Quaternion :: linalg.Quaternionf32 +Quaternion :: quaternion128 -// Matrix type (OpenGL style 4x4 - right handed, stored column major) -Matrix :: linalg.Matrix4x4f32 +// Matrix type (right handed, stored row major) +Matrix :: #row_major matrix[4, 4]f32 // Color, 4 components, R8G8B8A8 (32bit) diff --git a/vendor/raylib/raymath.odin b/vendor/raylib/raymath.odin index c657152c1..beeda7989 100644 --- a/vendor/raylib/raymath.odin +++ b/vendor/raylib/raymath.odin @@ -590,74 +590,79 @@ MatrixMultiply :: proc "c" (left, right: Matrix) -> Matrix { // Get translation matrix @(require_results) MatrixTranslate :: proc "c" (x, y, z: f32) -> Matrix { - return linalg.matrix4_translate(Vector3{x, y, z}) + return { + 1, 0, 0, x, + 0, 1, 0, y, + 0, 0, 1, z, + 0, 0, 0, 1, + } } // Create rotation matrix from axis and angle // NOTE: Angle should be provided in radians @(require_results) MatrixRotate :: proc "c" (axis: Vector3, angle: f32) -> Matrix { - return linalg.matrix4_rotate(angle, axis) + return auto_cast linalg.matrix4_rotate(angle, axis) } // Get x-rotation matrix // NOTE: Angle must be provided in radians @(require_results) MatrixRotateX :: proc "c" (angle: f32) -> Matrix { - return linalg.matrix4_rotate(angle, Vector3{1, 0, 0}) + return auto_cast linalg.matrix4_rotate(angle, Vector3{1, 0, 0}) } // Get y-rotation matrix // NOTE: Angle must be provided in radians @(require_results) MatrixRotateY :: proc "c" (angle: f32) -> Matrix { - return linalg.matrix4_rotate(angle, Vector3{0, 1, 0}) + return auto_cast linalg.matrix4_rotate(angle, Vector3{0, 1, 0}) } // Get z-rotation matrix // NOTE: Angle must be provided in radians @(require_results) MatrixRotateZ :: proc "c" (angle: f32) -> Matrix { - return linalg.matrix4_rotate(angle, Vector3{0, 0, 1}) + return auto_cast linalg.matrix4_rotate(angle, Vector3{0, 0, 1}) } // Get xyz-rotation matrix // NOTE: Angle must be provided in radians @(require_results) MatrixRotateXYZ :: proc "c" (angle: Vector3) -> Matrix { - return linalg.matrix4_from_euler_angles_xyz(angle.x, angle.y, angle.z) + return auto_cast linalg.matrix4_from_euler_angles_xyz(angle.x, angle.y, angle.z) } // Get zyx-rotation matrix // NOTE: Angle must be provided in radians @(require_results) MatrixRotateZYX :: proc "c" (angle: Vector3) -> Matrix { - return linalg.matrix4_from_euler_angles_zyx(angle.x, angle.y, angle.z) + return auto_cast linalg.matrix4_from_euler_angles_zyx(angle.x, angle.y, angle.z) } // Get scaling matrix @(require_results) MatrixScale :: proc "c" (x, y, z: f32) -> Matrix { - return linalg.matrix4_scale(Vector3{x, y, z}) + return auto_cast linalg.matrix4_scale(Vector3{x, y, z}) } // Get orthographic projection matrix @(require_results) MatrixOrtho :: proc "c" (left, right, bottom, top, near, far: f32) -> Matrix { - return linalg.matrix_ortho3d(left, right, bottom, top, near, far) + return auto_cast linalg.matrix_ortho3d(left, right, bottom, top, near, far) } // Get perspective projection matrix // NOTE: Fovy angle must be provided in radians @(require_results) MatrixPerspective :: proc "c" (fovY, aspect, nearPlane, farPlane: f32) -> Matrix { - return linalg.matrix4_perspective(fovY, aspect, nearPlane, farPlane) + return auto_cast linalg.matrix4_perspective(fovY, aspect, nearPlane, farPlane) } // Get camera look-at matrix (view matrix) @(require_results) MatrixLookAt :: proc "c" (eye, target, up: Vector3) -> Matrix { - return linalg.matrix4_look_at(eye, target, up) + return auto_cast linalg.matrix4_look_at(eye, target, up) } // Get float array of matrix data @@ -755,12 +760,12 @@ QuaternionFromVector3ToVector3 :: proc "c" (from, to: Vector3) -> Quaternion { // Get a quaternion for a given rotation matrix @(require_results) QuaternionFromMatrix :: proc "c" (mat: Matrix) -> Quaternion { - return linalg.quaternion_from_matrix4(mat) + return linalg.quaternion_from_matrix4(linalg.Matrix4f32(mat)) } // Get a matrix for a given quaternion @(require_results) QuaternionToMatrix :: proc "c" (q: Quaternion) -> Matrix { - return linalg.matrix4_from_quaternion(q) + return auto_cast linalg.matrix4_from_quaternion(q) } // Get rotation quaternion for an angle and axis NOTE: Angle must be provided in radians @(require_results)