diff options
author | mattkae <mattkae@protonmail.com> | 2022-05-07 12:17:36 -0400 |
---|---|---|
committer | mattkae <mattkae@protonmail.com> | 2022-05-07 12:17:36 -0400 |
commit | 0b8596a5ebec39f797fe8a14eed1bda3c2e3a93d (patch) | |
tree | ea248ce7d55046d578f5ad371f4083405a4f7892 /themes/mathlib.cpp | |
parent | 1c051dffdb27ff6ebaa96802b021e99e49afb861 (diff) |
Working bunny render
Diffstat (limited to 'themes/mathlib.cpp')
-rw-r--r-- | themes/mathlib.cpp | 14 |
1 files changed, 14 insertions, 0 deletions
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() { }; |