From f0b17d67ba21376d2fc3921dd32298583d4ed758 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miloslav=20=C4=8C=C3=AD=C5=BE?= Date: Wed, 5 Jun 2019 22:18:01 +0200 Subject: [PATCH] Finish lookAt --- small3dlib.h | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/small3dlib.h b/small3dlib.h index 49d0784..3f2cb91 100644 --- a/small3dlib.h +++ b/small3dlib.h @@ -1096,16 +1096,22 @@ void S3L_lookAt(S3L_Vec4 pointFrom, S3L_Vec4 pointTo, S3L_Transform3D *t) v.x = pointTo.x - pointFrom.x; v.y = pointTo.z - pointFrom.z; + S3L_Unit dx = v.x; S3L_Unit l = S3L_vec2Length(v); - - v.x = (v.x * S3L_FRACTIONS_PER_UNIT) / l; - t->rotation.y = S3L_asin(v.x); + dx = (v.x * S3L_FRACTIONS_PER_UNIT) / l; // normalize + + t->rotation.y = S3L_asin(dx); if (v.y < 0) t->rotation.y = S3L_FRACTIONS_PER_UNIT / 2 - t->rotation.y; - // TODO + v.x = pointTo.y - pointFrom.y; + v.y = l; + + dx = (v.x * S3L_FRACTIONS_PER_UNIT) / S3L_vec2Length(v); + + t->rotation.x = S3L_asin(dx); } void S3L_setTransform3D(