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(