From d243a8dbfb96fdffc447ada0a518f692928daf3f Mon Sep 17 00:00:00 2001 From: TommiTheFirst Date: Fri, 19 Sep 2025 12:18:06 +0000 Subject: [PATCH] replaced applicable fm_sinf() and fm_cosf() calls with fm_sincosf() --- src/t3d/t3dmath.c | 16 +++++----------- src/t3d/t3dmath.h | 14 ++++++-------- 2 files changed, 11 insertions(+), 19 deletions(-) diff --git a/src/t3d/t3dmath.c b/src/t3d/t3dmath.c index b0ab0f76..972914fa 100644 --- a/src/t3d/t3dmath.c +++ b/src/t3d/t3dmath.c @@ -240,13 +240,10 @@ void t3d_mat4_from_srt(T3DMat4 *mat, const float scale[3], const float quat[4], void t3d_mat4_from_srt_euler(T3DMat4 *mat, const float scale[3], const float rot[3], const float translate[3]) { - float cosR0 = fm_cosf(rot[0]); - float cosR2 = fm_cosf(rot[2]); - float cosR1 = fm_cosf(rot[1]); - - float sinR0 = fm_sinf(rot[0]); - float sinR1 = fm_sinf(rot[1]); - float sinR2 = fm_sinf(rot[2]); + float sinR0, sinR1, sinR2, cosR0, cosR1, cosR2; + fm_sincosf(rot[0], &sinR0, &cosR0); + fm_sincosf(rot[1], &sinR1, &cosR1); + fm_sincosf(rot[2], &sinR2, &cosR2); *mat = (T3DMat4){{ {scale[0] * cosR2 * cosR1, scale[0] * (cosR2 * sinR1 * sinR0 - sinR2 * cosR0), scale[0] * (cosR2 * sinR1 * cosR0 + sinR2 * sinR0), 0.0f}, @@ -290,10 +287,7 @@ void t3d_mat4fp_from_srt(T3DMat4FP *mat, const float scale[3], const float rotQu void t3d_mat4_rotate(T3DMat4 *mat, const T3DVec3* axis, float angleRad) { float s, c; - // @TODO: currently buggy in libdragon, use once fixed - // fm_sincosf(angleRad, &s, &c); - s = fm_sinf(angleRad); - c = fm_cosf(angleRad); + fm_sincosf(angleRad, &s, &c); float t = 1.0f - c; diff --git a/src/t3d/t3dmath.h b/src/t3d/t3dmath.h index 2086b526..285c2824 100644 --- a/src/t3d/t3dmath.h +++ b/src/t3d/t3dmath.h @@ -153,12 +153,10 @@ inline static void t3d_quat_identity(T3DQuat *quat) { */ inline static void t3d_quat_from_euler(T3DQuat *quat, const float rotEuler[3]) { - float c1 = fm_cosf(rotEuler[0] / 2.0f); - float s1 = fm_sinf(rotEuler[0] / 2.0f); - float c2 = fm_cosf(rotEuler[1] / 2.0f); - float s2 = fm_sinf(rotEuler[1] / 2.0f); - float c3 = fm_cosf(rotEuler[2] / 2.0f); - float s3 = fm_sinf(rotEuler[2] / 2.0f); + float c1, c2, c3, s1, s2, s3; + fm_sincosf(rotEuler[0] / 2.0f, &s1, &c1); + fm_sincosf(rotEuler[1] / 2.0f, &s2, &c2); + fm_sincosf(rotEuler[2] / 2.0f, &s3, &c3); quat->v[0] = c1 * c2 * s3 - s1 * s2 * c3; quat->v[1] = s1 * c2 * c3 - c1 * s2 * s3; @@ -174,8 +172,8 @@ inline static void t3d_quat_from_euler(T3DQuat *quat, const float rotEuler[3]) */ inline static void t3d_quat_from_rotation(T3DQuat *quat, float axis[3], float angleRad) { - float s = fm_sinf(angleRad / 2.0f); - float c = fm_cosf(angleRad / 2.0f); + float s, c; + fm_sincosf(angleRad / 2.0f, &s, &c); *quat = (T3DQuat){{axis[0] * s, axis[1] * s, axis[2] * s, c}}; }