Explorar o código

Fixed mtxLookAt when eye looks straight up or down.

Бранимир Караџић %!s(int64=2) %!d(string=hai) anos
pai
achega
d6fbb1563c
Modificáronse 1 ficheiros con 14 adicións e 3 borrados
  1. 14 3
      src/math.cpp

+ 14 - 3
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;