From da346a5426c74a0ddb62913ad3a708418c8b8e46 Mon Sep 17 00:00:00 2001 From: BenCat07 Date: Sun, 4 Mar 2018 10:47:00 +0100 Subject: [PATCH 1/5] Update glez.h --- include/glez.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/glez.h b/include/glez.h index fb60432..01c160b 100644 --- a/include/glez.h +++ b/include/glez.h @@ -93,7 +93,7 @@ void glez_rect_outline(float x, float y, float w, float h, glez_rgba_t color, void glez_rect_textured(float x, float y, float w, float h, glez_rgba_t color, glez_texture_t texture, float tx, float ty, float tw, - float th); + float th, float angle); void glez_string(float x, float y, const char *string, glez_font_t font, glez_rgba_t color, float *out_x, float *out_y); From 24e1b9da324413b63f2e0376a6c66397f8951015 Mon Sep 17 00:00:00 2001 From: BenCat07 Date: Sun, 4 Mar 2018 10:47:17 +0100 Subject: [PATCH 2/5] Update glez.c --- src/glez.c | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/src/glez.c b/src/glez.c index d6432ca..36918c1 100644 --- a/src/glez.c +++ b/src/glez.c @@ -142,7 +142,7 @@ void glez_rect_outline(float x, float y, float w, float h, glez_rgba_t color, void glez_rect_textured(float x, float y, float w, float h, glez_rgba_t color, glez_texture_t texture, float tx, float ty, float tw, - float th) + float th, float angle) { internal_texture_t *tex = internal_texture_get(texture); internal_texture_bind(texture); @@ -162,29 +162,29 @@ void glez_rect_textured(float x, float y, float w, float h, glez_rgba_t color, float t0 = ty / tex->height; float t1 = (ty + th) / tex->height; - vertices[0].position.x = x; - vertices[0].position.y = y; + vertices[0].position.x = x * cos(angle) - y * sin(angle); + vertices[0].position.y = y * sin(angle) + y * cos(angle); vertices[0].tex_coords.x = s0; vertices[0].tex_coords.y = t1; vertices[0].color = color; vertices[0].mode = DRAW_MODE_TEXTURED; - vertices[1].position.x = x; - vertices[1].position.y = y + h; + vertices[1].position.x = x * cos(angle) - y * sin(angle); + vertices[1].position.y = (y + h) * sin(angle) + y * cos(angle); vertices[1].tex_coords.x = s0; vertices[1].tex_coords.y = t0; vertices[1].color = color; vertices[1].mode = DRAW_MODE_TEXTURED; - vertices[2].position.x = x + w; - vertices[2].position.y = y + h; + vertices[2].position.x = (x + w) * cos(angle) - y * sin(angle); + vertices[2].position.y = (y + h) * sin(angle) + y * cos(angle); vertices[2].tex_coords.x = s1; vertices[2].tex_coords.y = t0; vertices[2].color = color; vertices[2].mode = DRAW_MODE_TEXTURED; - vertices[3].position.x = x + w; - vertices[3].position.y = y; + vertices[3].position.x = (x + w) * cos(angle) - y * sin(angle); + vertices[3].position.y = y * sin(angle) + y * cos(angle); vertices[3].tex_coords.x = s1; vertices[3].tex_coords.y = t1; vertices[3].color = color; From 216bdf9fd079a58e74731034ab1f49b76f537dcb Mon Sep 17 00:00:00 2001 From: BenCat07 Date: Sun, 1 Apr 2018 14:39:12 +0200 Subject: [PATCH 3/5] fix --- .settings/language.settings.xml | 2 +- src/glez.c | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/.settings/language.settings.xml b/.settings/language.settings.xml index aaa2b7b..8bbf096 100644 --- a/.settings/language.settings.xml +++ b/.settings/language.settings.xml @@ -5,7 +5,7 @@ - + diff --git a/src/glez.c b/src/glez.c index 36918c1..8bc357d 100644 --- a/src/glez.c +++ b/src/glez.c @@ -170,20 +170,20 @@ void glez_rect_textured(float x, float y, float w, float h, glez_rgba_t color, vertices[0].mode = DRAW_MODE_TEXTURED; vertices[1].position.x = x * cos(angle) - y * sin(angle); - vertices[1].position.y = (y + h) * sin(angle) + y * cos(angle); + vertices[1].position.y = (y * sin(angle) + y * cos(angle)) + h; vertices[1].tex_coords.x = s0; vertices[1].tex_coords.y = t0; vertices[1].color = color; vertices[1].mode = DRAW_MODE_TEXTURED; - vertices[2].position.x = (x + w) * cos(angle) - y * sin(angle); - vertices[2].position.y = (y + h) * sin(angle) + y * cos(angle); + vertices[2].position.x = (x * cos(angle) - y * sin(angle)) + w; + vertices[2].position.y = (y * sin(angle) + y * cos(angle)) + h; vertices[2].tex_coords.x = s1; vertices[2].tex_coords.y = t0; vertices[2].color = color; vertices[2].mode = DRAW_MODE_TEXTURED; - vertices[3].position.x = (x + w) * cos(angle) - y * sin(angle); + vertices[3].position.x = (x * cos(angle) - y * sin(angle)) + w; vertices[3].position.y = y * sin(angle) + y * cos(angle); vertices[3].tex_coords.x = s1; vertices[3].tex_coords.y = t1; From 0eb53f0d4d54b9e7e69c5b56baa3c8b767f35a56 Mon Sep 17 00:00:00 2001 From: BenCat07 Date: Sun, 1 Apr 2018 14:45:54 +0200 Subject: [PATCH 4/5] tf is math --- src/glez.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/glez.c b/src/glez.c index 8bc357d..dbc6fd4 100644 --- a/src/glez.c +++ b/src/glez.c @@ -163,28 +163,28 @@ void glez_rect_textured(float x, float y, float w, float h, glez_rgba_t color, float t1 = (ty + th) / tex->height; vertices[0].position.x = x * cos(angle) - y * sin(angle); - vertices[0].position.y = y * sin(angle) + y * cos(angle); + vertices[0].position.y = x * sin(angle) + y * cos(angle); vertices[0].tex_coords.x = s0; vertices[0].tex_coords.y = t1; vertices[0].color = color; vertices[0].mode = DRAW_MODE_TEXTURED; vertices[1].position.x = x * cos(angle) - y * sin(angle); - vertices[1].position.y = (y * sin(angle) + y * cos(angle)) + h; + vertices[1].position.y = (x * sin(angle) + y * cos(angle)) + h; vertices[1].tex_coords.x = s0; vertices[1].tex_coords.y = t0; vertices[1].color = color; vertices[1].mode = DRAW_MODE_TEXTURED; vertices[2].position.x = (x * cos(angle) - y * sin(angle)) + w; - vertices[2].position.y = (y * sin(angle) + y * cos(angle)) + h; + vertices[2].position.y = (x * sin(angle) + y * cos(angle)) + h; vertices[2].tex_coords.x = s1; vertices[2].tex_coords.y = t0; vertices[2].color = color; vertices[2].mode = DRAW_MODE_TEXTURED; vertices[3].position.x = (x * cos(angle) - y * sin(angle)) + w; - vertices[3].position.y = y * sin(angle) + y * cos(angle); + vertices[3].position.y = x * sin(angle) + y * cos(angle); vertices[3].tex_coords.x = s1; vertices[3].tex_coords.y = t1; vertices[3].color = color; From e3bdf1c994da95544b84896efe8de0099dffe023 Mon Sep 17 00:00:00 2001 From: BenCat07 Date: Mon, 2 Apr 2018 09:51:11 +0200 Subject: [PATCH 5/5] Fix rotation --- src/glez.c | 48 +++++++++++++++++++++++++++++++++++++++--------- 1 file changed, 39 insertions(+), 9 deletions(-) diff --git a/src/glez.c b/src/glez.c index dbc6fd4..ec6750e 100644 --- a/src/glez.c +++ b/src/glez.c @@ -11,6 +11,7 @@ #include "internal/draw.h" #include "internal/fonts.h" #include "internal/textures.h" +#include #include @@ -139,7 +140,6 @@ void glez_rect_outline(float x, float y, float w, float h, glez_rgba_t color, glez_line(x + w, y + h, -w, 0, color, thickness); glez_line(x, y + h, 0, -h, color, thickness); } - void glez_rect_textured(float x, float y, float w, float h, glez_rgba_t color, glez_texture_t texture, float tx, float ty, float tw, float th, float angle) @@ -162,34 +162,64 @@ void glez_rect_textured(float x, float y, float w, float h, glez_rgba_t color, float t0 = ty / tex->height; float t1 = (ty + th) / tex->height; - vertices[0].position.x = x * cos(angle) - y * sin(angle); - vertices[0].position.y = x * sin(angle) + y * cos(angle); + vertices[0].position.x = x; + vertices[0].position.y = y; vertices[0].tex_coords.x = s0; vertices[0].tex_coords.y = t1; vertices[0].color = color; vertices[0].mode = DRAW_MODE_TEXTURED; - vertices[1].position.x = x * cos(angle) - y * sin(angle); - vertices[1].position.y = (x * sin(angle) + y * cos(angle)) + h; + vertices[1].position.x = x; + vertices[1].position.y = y + h; vertices[1].tex_coords.x = s0; vertices[1].tex_coords.y = t0; vertices[1].color = color; vertices[1].mode = DRAW_MODE_TEXTURED; - vertices[2].position.x = (x * cos(angle) - y * sin(angle)) + w; - vertices[2].position.y = (x * sin(angle) + y * cos(angle)) + h; + vertices[2].position.x = x + w; + vertices[2].position.y = y + h; vertices[2].tex_coords.x = s1; vertices[2].tex_coords.y = t0; vertices[2].color = color; vertices[2].mode = DRAW_MODE_TEXTURED; - vertices[3].position.x = (x * cos(angle) - y * sin(angle)) + w; - vertices[3].position.y = x * sin(angle) + y * cos(angle); + vertices[3].position.x = x + w; + vertices[3].position.y = y; vertices[3].tex_coords.x = s1; vertices[3].tex_coords.y = t1; vertices[3].color = color; vertices[3].mode = DRAW_MODE_TEXTURED; + if (angle) { + float v1[2] = {vertices[0].position.x, vertices[0].position.y}; + float v2[2] = {vertices[1].position.x, vertices[1].position.y}; + float v3[2] = {vertices[2].position.x, vertices[2].position.y}; + float v4[2] = {vertices[3].position.x, vertices[3].position.y}; + vertices[0].position.x = -tw; + vertices[1].position.x = -tw; + vertices[2].position.x = tw; + vertices[3].position.x = tw; + + vertices[0].position.y = -th; + vertices[1].position.y = th; + vertices[2].position.y = th; + vertices[3].position.y = -th; + for (int i = 0; i < 4; i++) { + float x = vertices[i].position.x; + float y = vertices[i].position.y; + vertices[i].position.x = x *cos(angle) - y *sin(angle); + vertices[i].position.y = x *sin(angle) + y *cos(angle); + } + vertices[0].position.x += v1[0]; + vertices[0].position.y += v1[1]; + vertices[1].position.x += v2[0]; + vertices[1].position.y += v2[1]; + vertices[2].position.x += v3[0]; + vertices[2].position.y += v3[1]; + vertices[3].position.x += v4[0]; + vertices[3].position.y += v4[1]; + } + vertex_buffer_push_back(program.buffer, vertices, 4, indices, 6); }