aboutsummaryrefslogtreecommitdiff
path: root/teensy
diff options
context:
space:
mode:
authoriamcheeseman <[email protected]>2026-05-14 21:11:21 -0400
committeriamcheeseman <[email protected]>2026-05-14 21:11:21 -0400
commit27202a3c293f4b4d5a2cd88171c7e00860c4b1d1 (patch)
tree180d507643a1d3bfe4764b5bb34b560a57bd60b0 /teensy
parented4f96cc6df493480596074dcc18043fe7b35d38 (diff)
fix rotated sprites
Diffstat (limited to 'teensy')
-rw-r--r--teensy/teensy_renderer.c25
1 files changed, 13 insertions, 12 deletions
diff --git a/teensy/teensy_renderer.c b/teensy/teensy_renderer.c
index 61710a2..ea61163 100644
--- a/teensy/teensy_renderer.c
+++ b/teensy/teensy_renderer.c
@@ -202,20 +202,21 @@ void ty_draw_image_rot(
ty_Vec2i offset,
double rot
) {
- double s = sin(rot);
- double c = cos(rot);
-
- // x1 = c*x - s*y
- // y1 = s*x + c*y
+ double s = sin(-rot);
+ double c = cos(-rot);
- // FIXME: the corners of the rotated image get cut off.
- for (int img_y = 0; img_y < img.height; img_y++) {
- for (int img_x = 0; img_x < img.width; img_x++) {
- double pixel_x = img_x + offset.x;
- double pixel_y = img_y + offset.y;
+ int blit_width = ceil(img.width * fabs(c) + img.height * fabs(s));
+ int blit_height = ceil(img.width * fabs(s) + img.height * fabs(c));
- int dx = floor(pixel_x * c - pixel_y * s - offset.x);
- int dy = floor(pixel_x * s + pixel_y * c - offset.y);
+ int startx = -blit_width / 2;
+ int starty = -blit_height / 2;
+ int endx = (blit_width + 1) / 2;
+ int endy = (blit_height + 1) / 2;
+
+ for (int img_y = starty; img_y < endy; img_y++) {
+ for (int img_x = startx; img_x < endx; img_x++) {
+ int dx = floor(img_x * c - img_y * s - offset.x);
+ int dy = floor(img_x * s + img_y * c - offset.y);
if (dx < 0 || dx >= img.width || dy < 0 || dy >= img.height)
continue;