diff --git a/programs/testSDL.c b/programs/testSDL.c index 4349c71..8569827 100644 --- a/programs/testSDL.c +++ b/programs/testSDL.c @@ -309,13 +309,6 @@ void draw() int main() { - - -for (int i = -512; i < 513; ++i) - printf("%d: %d (%d)\n",i,S3L_asin(i),S3L_sin(S3L_asin(i))); - -return 0; - SDL_Window *window = SDL_CreateWindow("test", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, S3L_RESOLUTION_X, S3L_RESOLUTION_Y, SDL_WINDOW_SHOWN); SDL_Renderer *renderer = SDL_CreateRenderer(window,-1,0); SDL_Texture *texture = SDL_CreateTexture(renderer,SDL_PIXELFORMAT_RGBX8888, SDL_TEXTUREACCESS_STATIC, S3L_RESOLUTION_X, S3L_RESOLUTION_Y); @@ -454,7 +447,7 @@ S3L_setTransform3D(3196,1814,5958,-18,300,0,512,512,512,&(scene.camera.transform scene.camera.transform.rotation.z += 1; if (keys['p']) - S3L_lookAt(scene.camera.transform.translation,scene.models[1].transform.translation,&(scene.camera.transform)); + S3L_lookAt(scene.camera.transform.translation,scene.models[0].transform.translation,&(scene.camera.transform)); SDL_RenderClear(renderer); SDL_RenderCopy(renderer,texture,NULL,NULL); diff --git a/small3dlib.h b/small3dlib.h index f4f9c03..49d0784 100644 --- a/small3dlib.h +++ b/small3dlib.h @@ -1095,10 +1095,15 @@ 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_normalizeVec2(&v); - t->rotation.y = (v.y + S3L_FRACTIONS_PER_UNIT) / 2 ; + S3L_Unit l = S3L_vec2Length(v); + + v.x = (v.x * S3L_FRACTIONS_PER_UNIT) / l; + + t->rotation.y = S3L_asin(v.x); + + if (v.y < 0) + t->rotation.y = S3L_FRACTIONS_PER_UNIT / 2 - t->rotation.y; // TODO }