diff --git a/include/glez/draw.hpp b/include/glez/draw.hpp index c6be95e..33f43ec 100644 --- a/include/glez/draw.hpp +++ b/include/glez/draw.hpp @@ -16,7 +16,7 @@ namespace glez::draw void line(int x, int y, int dx, int dy, rgba color, int thickness); void rect(int x, int y, int w, int h, rgba color); void rect_outline(int x, int y, int w, int h, rgba color, int thickness); -void rect_textured(int x, int y, int w, int h, rgba color, texture& texture, int tx, int ty, int tw, int th); +void rect_textured(int x, int y, int w, int h, rgba color, texture& texture, int tx, int ty, int tw, int th, float angle); void circle(int x, int y, int radius, rgba color, int thickness, int steps); void string(int x, int y, const std::string& string, font& font, rgba color, int *width, int *height); diff --git a/src/draw.cpp b/src/draw.cpp index 0b9a3e8..7b3e50c 100644 --- a/src/draw.cpp +++ b/src/draw.cpp @@ -11,6 +11,7 @@ #include #include #include +#include namespace indices { @@ -169,7 +170,7 @@ void outlined_string(int x, int y, const std::string &string, } void -rect_textured(int x, int y, int w, int h, rgba color, texture &texture, int tx, int ty, int tw, int th) +rect_textured(int x, int y, int w, int h, rgba color, texture &texture, int tx, int ty, int tw, int th, float angle) { if (!texture.isLoaded()) texture.load(); @@ -190,6 +191,21 @@ rect_textured(int x, int y, int w, int h, rgba color, texture &texture, int tx, vertices[2].position = { x + w, y + h }; vertices[3].position = { x + w, y }; + if (angle != 0.0f) + { + float cx = x + float(w) / 2.0f; + float cy = y + float(h) / 2.0f; + + for (auto& v: vertices) + { + float ox = v.position.x; + float oy = v.position.y; + + v.position.x = cx + cosf(angle) * (ox - cx) - sinf(angle) * (oy - cy); + v.position.y = cy + sinf(angle) * (ox - cx) + cosf(angle) * (oy - cy); + } + } + float s0 = float(tx) / texture.getWidth(); float s1 = float(tx + tw) / texture.getWidth(); float t0 = float(ty) / texture.getHeight();