Files
prosperon/sprite.c
2025-11-26 12:52:56 -06:00

30 lines
673 B
C
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#include "sprite.h"
sprite *make_sprite(void)
{
sprite *sprite = calloc(sizeof(*sprite),1);
sprite->image = JS_NULL;
return sprite;
}
void sprite_free(JSRuntime *rt, sprite *sprite)
{
JS_FreeValueRT(rt,sprite->image);
free(sprite);
}
void sprite_apply(sprite *sp)
{
/* -------- rotation + skew → 2×2 affine matrix -------- */
float rot = sp->rotation;
HMM_Vec2 k = sp->skew;
float c = cosf(rot), s = sinf(rot);
sp->affine.Columns[0] = (HMM_Vec2){ .x = c + k.x * s,
.y = k.y * c + s };
sp->affine.Columns[1] = (HMM_Vec2){ .x = -s + k.x * c,
.y = -k.y * s + c };
}