From 0b8596a5ebec39f797fe8a14eed1bda3c2e3a93d Mon Sep 17 00:00:00 2001 From: mattkae Date: Sat, 7 May 2022 12:17:36 -0400 Subject: Working bunny render --- themes/mathlib.cpp | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'themes/mathlib.cpp') diff --git a/themes/mathlib.cpp b/themes/mathlib.cpp index 2e92aa8..702d86c 100644 --- a/themes/mathlib.cpp +++ b/themes/mathlib.cpp @@ -572,6 +572,20 @@ void Mat4x4::print() { printf(" ]\n"); } +// See https://stackoverflow.com/questions/349050/calculating-a-lookat-matrix for why the dot product is in the bottom +Mat4x4 Mat4x4::getLookAt(Vector3 eye,Vector3 pointToLookAt, Vector3 up) { + Vector3 zAxis = (pointToLookAt - eye).normalize(); + Vector3 xAxis = zAxis.cross(up).normalize(); + Vector3 yAxis = xAxis.cross(zAxis).normalize(); + + return { + { xAxis.x, yAxis.x, -zAxis.x, 0, + xAxis.y, yAxis.y, -zAxis.y, 0, + xAxis.z, yAxis.z, -zAxis.z, 0, + -xAxis.dot(eye), -yAxis.dot(eye), zAxis.dot(eye), 1 } + }; +} + // *************************************** // Quaternion Quaternion::Quaternion() { }; -- cgit v1.2.1