mirror of
https://git.coom.tech/drummyfish/small3dlib.git
synced 2024-11-20 20:29:58 +01:00
Add lookAt horizontal
This commit is contained in:
parent
417092f579
commit
79dd3c6284
2 changed files with 9 additions and 11 deletions
|
@ -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);
|
||||
|
|
11
small3dlib.h
11
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
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue