From d6fbb1563c6158e089653aba834a963e384c9fb3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=91=D1=80=D0=B0=D0=BD=D0=B8=D0=BC=D0=B8=D1=80=20=D0=9A?= =?UTF-8?q?=D0=B0=D1=80=D0=B0=D1=9F=D0=B8=D1=9B?= Date: Sat, 10 Jun 2023 10:20:00 -0700 Subject: [PATCH] Fixed mtxLookAt when eye looks straight up or down. --- src/math.cpp | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/src/math.cpp b/src/math.cpp index f45dfac..dd2a38c 100644 --- a/src/math.cpp +++ b/src/math.cpp @@ -248,9 +248,20 @@ namespace bx ? sub(_eye, _at) : sub(_at, _eye) ); - const Vec3 uxv = cross(_up, view); - const Vec3 right = normalize(uxv); - const Vec3 up = cross(view, right); + + const Vec3 uxv = cross(_up, view); + Vec3 right = bx::InitNone; + + if (0.0f == dot(uxv, uxv) ) + { + right = { -1.0f, 0.0f, 0.0f }; + } + else + { + right = normalize(uxv); + } + + const Vec3 up = cross(view, right); memSet(_result, 0, sizeof(float)*16); _result[ 0] = right.x;