Files
cell/source/sprite.c
John Alanbrook f1b3e5eddc
Some checks failed
Build and Deploy / build-macos (push) Failing after 5s
Build and Deploy / build-windows (CLANG64) (push) Has been cancelled
Build and Deploy / package-dist (push) Has been cancelled
Build and Deploy / deploy-itch (push) Has been cancelled
Build and Deploy / deploy-gitea (push) Has been cancelled
Build and Deploy / build-linux (push) Has been cancelled
Merge branch 'master' into box2d
2025-05-24 22:45:52 -05:00

32 lines
699 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"
#include <stdlib.h>
sprite *make_sprite(void)
{
sprite *sprite = calloc(sizeof(*sprite),1);
sprite->image = JS_UNDEFINED;
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 };
}