1
0
Fork 0
mirror of https://git.coom.tech/drummyfish/small3dlib.git synced 2024-11-21 20:39:57 +01:00

Fix lookAt

This commit is contained in:
Miloslav Číž 2019-06-18 23:07:00 +02:00
parent 3e5094db87
commit 81d3264dfd
3 changed files with 10 additions and 8 deletions

View file

@ -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);

View file

@ -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);

View file

@ -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