From 81d3264dfd6013b29ae3fa09ebb8eedd1793878a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miloslav=20=C4=8C=C3=AD=C5=BE?= Date: Tue, 18 Jun 2019 23:07:00 +0200 Subject: [PATCH] Fix lookAt --- programs/city.c | 2 +- programs/testSDL.c | 5 ++++- small3dlib.h | 11 +++++------ 3 files changed, 10 insertions(+), 8 deletions(-) diff --git a/programs/city.c b/programs/city.c index c887d19..4518953 100644 --- a/programs/city.c +++ b/programs/city.c @@ -227,7 +227,7 @@ int main() scene.camera.transform.translation.y = S3L_FRACTIONS_PER_UNIT; scene.camera.transform.translation.z = scene.models[1].transform.translation.z - carDirection.z; - scene.camera.transform.rotation.y = -1 * scene.models[1].transform.rotation.y; + scene.camera.transform.rotation.y = scene.models[1].transform.rotation.y; SDL_RenderClear(renderer); SDL_RenderCopy(renderer,textureSDL,NULL,NULL); diff --git a/programs/testSDL.c b/programs/testSDL.c index 960be1c..c8192e4 100644 --- a/programs/testSDL.c +++ b/programs/testSDL.c @@ -328,6 +328,8 @@ int main() S3L_initCamera(&scene.camera); + houseModelInit(); + // scene.camera.transform.translation.z = -S3L_FRACTIONS_PER_UNIT * 2; scene.camera.transform.translation.x = 105; @@ -456,7 +458,8 @@ S3L_setTransform3D(-2039,173,6096,-2,-296,0,512,512,512,&(scene.camera.transform scene.camera.transform.rotation.z += 1; if (keys['p']) - S3L_lookAt(scene.camera.transform.translation,scene.models[0].transform.translation,&(scene.camera.transform)); +// S3L_lookAt(scene.models[0].transform.translation,&(scene.camera.transform)); + S3L_lookAt(scene.camera.transform.translation,&(scene.models[1].transform)); SDL_RenderClear(renderer); SDL_RenderCopy(renderer,texture,NULL,NULL); diff --git a/small3dlib.h b/small3dlib.h index 9d4547e..663ce2a 100644 --- a/small3dlib.h +++ b/small3dlib.h @@ -1364,7 +1364,7 @@ void S3L_lookAt(S3L_Vec4 pointTo, S3L_Transform3D *t) dx = (v.x * S3L_FRACTIONS_PER_UNIT) / S3L_nonZero(l); // normalize - t->rotation.y = S3L_asin(dx); + t->rotation.y = -1 * S3L_asin(dx); if (v.y < 0) t->rotation.y = S3L_FRACTIONS_PER_UNIT / 2 - t->rotation.y; @@ -1376,8 +1376,7 @@ void S3L_lookAt(S3L_Vec4 pointTo, S3L_Transform3D *t) dx = (v.x * S3L_FRACTIONS_PER_UNIT) / S3L_nonZero(l); - t->rotation.x = -1 * S3L_asin(dx); - + t->rotation.x = S3L_asin(dx); } void S3L_setTransform3D( @@ -2220,9 +2219,9 @@ void S3L_makeCameraMatrix(S3L_Transform3D cameraTransform, S3L_Mat4 *m) S3L_Mat4 r; S3L_makeRotationMatrixZXY( - -1 * cameraTransform.rotation.x, - -1 * cameraTransform.rotation.y, - -1 * cameraTransform.rotation.z, + cameraTransform.rotation.x, + cameraTransform.rotation.y, + cameraTransform.rotation.z, &r); S3L_transposeMat4(&r); // transposing creates an inverse transform