summaryrefslogtreecommitdiffhomepage
path: root/src/gfx
diff options
context:
space:
mode:
authorrealtradam <[email protected]>2023-06-18 23:09:00 -0400
committerrealtradam <[email protected]>2023-06-18 23:09:00 -0400
commited248e655236699bdeae473a602b2c74b2f47fa7 (patch)
tree56c03da4655fc8f8c9f72afa39f74838df57de82 /src/gfx
parent77337049740437d1f707018c862fc2d891f29abf (diff)
downloadRodeoKit-ed248e655236699bdeae473a602b2c74b2f47fa7.tar.gz
RodeoKit-ed248e655236699bdeae473a602b2c74b2f47fa7.zip
implement drawing rotated sprites
Diffstat (limited to 'src/gfx')
-rw-r--r--src/gfx/rodeo_gfx.c112
1 files changed, 94 insertions, 18 deletions
diff --git a/src/gfx/rodeo_gfx.c b/src/gfx/rodeo_gfx.c
index 2c2cc33..52345dc 100644
--- a/src/gfx/rodeo_gfx.c
+++ b/src/gfx/rodeo_gfx.c
@@ -515,12 +515,15 @@ rodeo_gfx_texture_2d_destroy(rodeo_gfx_texture_2d_t texture)
void
rodeo_gfx_rectangle_draw(
const rodeo_rectangle_t rectangle,
+ const float turns,
const rodeo_color_RGBAFloat_t color
)
{
rodeo_gfx_texture_2d_draw(
rectangle,
(rodeo_rectangle_t){ 0, 0, (float)rodeo_gfx_texture_2d_default_get().width, (float)rodeo_gfx_texture_2d_default_get().height },
+ turns,
+ (rodeo_math_vec2_t){0},
color,
rodeo_gfx_texture_2d_default_get()
);
@@ -602,6 +605,8 @@ void
rodeo_gfx_texture_2d_draw(
const rodeo_rectangle_t destination,
const rodeo_rectangle_t source,
+ const float turns,
+ const rodeo_math_vec2_t origin,
const rodeo_color_RGBAFloat_t color,
const rodeo_gfx_texture_2d_t texture
)
@@ -629,10 +634,6 @@ rodeo_gfx_texture_2d_draw(
};
}
- // if not using texture: use default instead
- // otherwise check what current texture is active
- // if none or the same: set it
- // if different: flush and then set it
if(texture.data != NULL)
{
rodeo_gfx_texture_set(texture);
@@ -644,11 +645,87 @@ rodeo_gfx_texture_2d_draw(
{
rodeo_gfx_renderer_flush();
}
+
+ //rodeo_math_vec2_t origin = {0};
+ rodeo_math_vec2_t vertex_pos[4] = {
+ {
+ .val.x = destination.x,
+ .val.y = destination.y
+ },
+ {
+ .val.x = destination.x,
+ .val.y = destination.y
+ },
+ {
+ .val.x = destination.x,
+ .val.y = destination.y
+ },
+ {
+ .val.x = destination.x,
+ .val.y = destination.y
+ }
+ };
+
+ if(turns == 0.0f)
+ {
+ vertex_pos[0].val.x += destination.width - origin.val.x;
+ vertex_pos[0].val.y += destination.height - origin.val.y;
+
+ vertex_pos[1].val.x += destination.width - origin.val.x;
+ vertex_pos[1].val.y += -origin.val.y;
+
+ vertex_pos[2].val.x += -origin.val.x;
+ vertex_pos[2].val.y += -origin.val.y;
+
+ vertex_pos[3].val.x += -origin.val.x;
+ vertex_pos[3].val.y += destination.height - origin.val.y;
+ }
+ else
+ {
+ float sin_rotation = sinf(rodeo_math_turns_to_radians(turns));
+ float cos_rotation = cosf(rodeo_math_turns_to_radians(turns));
+
+ // bottom right
+ vertex_pos[0].val.x += (destination.width - origin.val.x) * cos_rotation - (destination.height -origin.val.y) * sin_rotation;
+ vertex_pos[0].val.y += (destination.width - origin.val.x) * sin_rotation + (destination.height - origin.val.y) * cos_rotation;
+
+ // top right
+ vertex_pos[1].val.x += (destination.width - origin.val.x) * cos_rotation - -origin.val.y * sin_rotation;
+ vertex_pos[1].val.y += (destination.width - origin.val.x) * sin_rotation + -origin.val.y * cos_rotation;
+
+ // top left
+ vertex_pos[2].val.x += -origin.val.x * cos_rotation - -origin.val.y * sin_rotation;
+ vertex_pos[2].val.y += -origin.val.x * sin_rotation + -origin.val.y * cos_rotation;
+
+ // bottom left
+ vertex_pos[3].val.x += -origin.val.x * cos_rotation - (destination.height - origin.val.y) * sin_rotation;
+ vertex_pos[3].val.y += -origin.val.y * sin_rotation + (destination.height - origin.val.y) * cos_rotation;
+
+ /*
+ vertex_pos[0] = (rodeo_math_vec2_t){
+ .val.x = -(destination.height * sin_rotation) + (destination.width * cos_rotation) + destination.x,
+ .val.y = (destination.height * cos_rotation) + (destination.width * sin_rotation) + destination.y
+ };
+ vertex_pos[1] = (rodeo_math_vec2_t){
+ .val.x = -(destination.width * cos_rotation) + destination.x,
+ .val.y = (destination.width * sin_rotation) + destination.y
+ };
+ vertex_pos[2] = (rodeo_math_vec2_t){
+ .val.x = destination.x,
+ .val.y = destination.y
+ };
+ vertex_pos[3] = (rodeo_math_vec2_t){
+ .val.x = -(destination.height * sin_rotation) + destination.x,
+ .val.y = (destination.height * cos_rotation) + destination.y
+ };
+ */
+ }
+
rodeo_gfx_vertex_add(
(rodeo_gfx_vertex_t)
{
- .x = destination.width + destination.x,
- .y = destination.height + destination.y,
+ .x = vertex_pos[0].val.x,
+ .y = vertex_pos[0].val.y,
//.z = 0.0f,
.color = color,
.texture_id = texture_uniform_slot,
@@ -656,12 +733,11 @@ rodeo_gfx_texture_2d_draw(
.texture_y = source_applied.height + source_applied.y,
}
);
-
rodeo_gfx_vertex_add(
(rodeo_gfx_vertex_t)
{
- .x = destination.width + destination.x,
- .y = destination.y,
+ .x = vertex_pos[1].val.x,
+ .y = vertex_pos[1].val.y,
//.z = 0.0f,
.color = color,
.texture_id = texture_uniform_slot,
@@ -672,8 +748,8 @@ rodeo_gfx_texture_2d_draw(
rodeo_gfx_vertex_add(
(rodeo_gfx_vertex_t)
{
- .x = destination.x,
- .y = destination.y,
+ .x = vertex_pos[2].val.x,
+ .y = vertex_pos[2].val.y,
//.z = 0.0f,
.color = color,
.texture_id = texture_uniform_slot,
@@ -684,13 +760,13 @@ rodeo_gfx_texture_2d_draw(
rodeo_gfx_vertex_add(
(rodeo_gfx_vertex_t)
{
- .x = destination.x,
- .y = destination.height + destination.y,
- //.z = 0.0f,
- .color = color,
- .texture_id = texture_uniform_slot,
- .texture_x = source_applied.x,
- .texture_y = source_applied.height + source_applied.y,
+ .x = vertex_pos[3].val.x,
+ .y = vertex_pos[3].val.y,
+ //.z = 0.0f,
+ .color = color,
+ .texture_id = texture_uniform_slot,
+ .texture_x = source_applied.x,
+ .texture_y = source_applied.height + source_applied.y,
}
);