This commit is contained in:
Jenny White 2018-04-30 17:07:38 +03:00
parent ecb7f5b345
commit d8de409ddd
2 changed files with 18 additions and 2 deletions

View File

@ -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);

View File

@ -11,6 +11,7 @@
#include <glez/detail/font.hpp>
#include <cstring>
#include <glez/detail/texture.hpp>
#include <cmath>
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();