aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--dc/dc.c3
-rw-r--r--teensy/teensy_renderer.c25
2 files changed, 14 insertions, 14 deletions
diff --git a/dc/dc.c b/dc/dc.c
index fb640bb..a654fbe 100644
--- a/dc/dc.c
+++ b/dc/dc.c
@@ -37,8 +37,7 @@ void tick(void)
img,
ty_vec2i(SCREEN_WIDTH/2, SCREEN_HEIGHT/2),
ty_vec2i(-img.width/2, -img.height/2),
- TY_PI / 4
- //ty_get_time()
+ ty_get_time() * TY_PI / 2
);
ty_draw_text(&font, ty_vec2i(5, SCREEN_HEIGHT - 5 - 8), "hello, world!");
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;