diff options
Diffstat (limited to 'src/rotrect.c')
-rw-r--r-- | src/rotrect.c | 43 |
1 files changed, 43 insertions, 0 deletions
diff --git a/src/rotrect.c b/src/rotrect.c new file mode 100644 index 0000000..5abae13 --- /dev/null +++ b/src/rotrect.c @@ -0,0 +1,43 @@ +#include "rotrect.h" +#include "cfg.h" +#include "lzy.h" +#include <math.h> + +static void +rotate(double *x, double *y, double angle) +{ + const double s = sin(angle); + const double c = cos(angle); + const double ox = *x; + const double oy = *y; + + *x = ox * c - oy * s; + *y = ox * s + oy * c; +} + +void +rotrect(double x, double y, double width, double height, double angle) +{ + double xs[4] = { + width / 2.0, + width / 2.0, + -width / 2.0, + -width / 2.0, + }; + double ys[4] = { + -height / 2.0, + height / 2.0, + height / 2.0, + -height / 2.0, + }; + for (int i = 0; i < 4; i++) { + rotate(&xs[i], &ys[i], angle); + xs[i] = round(xs[i] + x); + ys[i] = round(ys[i] + y); + } + LZY_DrawLine(xs[0], ys[0], xs[1], ys[1]); + LZY_DrawLine(xs[1], ys[1], xs[2], ys[2]); + LZY_DrawLine(xs[2], ys[2], xs[3], ys[3]); + LZY_DrawLine(xs[3], ys[3], xs[0], ys[0]); +} + |