rendering.c: non-square rotating sprites

This commit is contained in:
veclav talica 2024-07-29 12:43:46 +03:00
parent 8a0f767002
commit e8ff04b3e6
2 changed files with 14 additions and 1 deletions

View File

@ -37,6 +37,11 @@ static void ingame_tick(struct state *state) {
.path = "/assets/player/baron-walk.png",
.color = (t_color){255, 255, 255, 255}, });
push_sprite_ex((t_frect){ .x = 128, .y = 32, .w = 128, .h = 64 }, (t_push_sprite_args){
.path = "/assets/player/baron-walk.png",
.color = (t_color){255, 255, 255, 255},
.rotation = (float)M_PI * 2 * (float)(ctx.tick_count % 64) / 64, });
unfurl_triangle("/assets/big-violet.png",
(t_fvec3){ -1, -1, 0 },
(t_fvec3){ 1, -1, 0 },

View File

@ -241,7 +241,15 @@ static void render_sprites(const struct primitive_2d primitives[],
} else {
/* rotated non-square case*/
CRY("Rotation", "Unimplemented");
const t_fvec2 c = frect_center(sprite.rect);
const t_fvec2 t = fast_cossine(sprite.rotation);
const t_fvec2 h = { sprite.rect.w / 2, sprite.rect.h / 2 };
v0 = (t_fvec2){ c.x + t.x * -h.x - t.y * -h.y, c.y + t.y * -h.x + t.x * -h.y };
v1 = (t_fvec2){ c.x + t.x * -h.x - t.y * +h.y, c.y + t.y * -h.x + t.x * +h.y };
v2 = (t_fvec2){ c.x + t.x * +h.x - t.y * +h.y, c.y + t.y * +h.x + t.x * +h.y };
v3 = (t_fvec2){ c.x + t.x * +h.x - t.y * -h.y, c.y + t.y * +h.x + t.x * -h.y };
}
if (!batch.constant_colored)