rotation
This commit is contained in:
parent
ecb7f5b345
commit
d8de409ddd
@ -16,7 +16,7 @@ namespace glez::draw
|
|||||||
void line(int x, int y, int dx, int dy, rgba color, int thickness);
|
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(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_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 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);
|
void string(int x, int y, const std::string& string, font& font, rgba color, int *width, int *height);
|
||||||
|
18
src/draw.cpp
18
src/draw.cpp
@ -11,6 +11,7 @@
|
|||||||
#include <glez/detail/font.hpp>
|
#include <glez/detail/font.hpp>
|
||||||
#include <cstring>
|
#include <cstring>
|
||||||
#include <glez/detail/texture.hpp>
|
#include <glez/detail/texture.hpp>
|
||||||
|
#include <cmath>
|
||||||
|
|
||||||
namespace indices
|
namespace indices
|
||||||
{
|
{
|
||||||
@ -169,7 +170,7 @@ void outlined_string(int x, int y, const std::string &string,
|
|||||||
}
|
}
|
||||||
|
|
||||||
void
|
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())
|
if (!texture.isLoaded())
|
||||||
texture.load();
|
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[2].position = { x + w, y + h };
|
||||||
vertices[3].position = { x + w, y };
|
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 s0 = float(tx) / texture.getWidth();
|
||||||
float s1 = float(tx + tw) / texture.getWidth();
|
float s1 = float(tx + tw) / texture.getWidth();
|
||||||
float t0 = float(ty) / texture.getHeight();
|
float t0 = float(ty) / texture.getHeight();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user