From f87fed4fb8dbaba2406143168de6629d3d0a5a00 Mon Sep 17 00:00:00 2001 From: skal Date: Fri, 6 Feb 2026 09:42:30 +0100 Subject: fix(math): Normalize axis in quat::from_axis to prevent scaling artifacts MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Fixed critical bug causing mesh and bounding box stretching during rotation. ROOT CAUSE: quat::from_axis() did not normalize the input axis vector. When called with non-unit vectors (e.g., {0.5, 1.0, 0.0}), it created invalid quaternions that encoded scaling transformations instead of pure rotations. SYMPTOMS: - Mesh vertices stretched during rotation (non-uniform scaling) - Bounding boxes deformed and stretched - Transform matrices became non-orthogonal ISSUE LOCATIONS: - src/tests/test_mesh.cc:309 - axis {0.5, 1.0, 0.0} (length ≈1.118) - src/gpu/effects/flash_cube_effect.cc:79 - axis {0.3, 1, 0.2} (length ≈1.044) FIX: Added automatic normalization in quat::from_axis(): a = a.normalize(); // Ensure axis is unit vector RESULT: - All quaternions now represent pure rotations - No scaling artifacts during rotation - Bounding boxes remain orthogonal - Fixes Task A (test_mesh stretching bug) SAFETY: This change is backward compatible. Code that already passed normalized axes will work identically (normalizing a unit vector = identity). handoff(Claude): Rotation stretching bug fixed. Both shader normal transformation (previous commit) and quaternion creation (this commit) now work correctly. test_mesh should display properly rotated meshes without distortion. --- src/util/mini_math.h | 1 + 1 file changed, 1 insertion(+) diff --git a/src/util/mini_math.h b/src/util/mini_math.h index 2307087..f847cc1 100644 --- a/src/util/mini_math.h +++ b/src/util/mini_math.h @@ -350,6 +350,7 @@ struct quat { } static quat from_axis(vec3 a, float ang) { + a = a.normalize(); // Normalize axis to prevent scaling artifacts float s = std::sin(ang * 0.5f); return {a.x * s, a.y * s, a.z * s, std::cos(ang * 0.5f)}; } -- cgit v1.2.3