From e1d5eba1f2cd21c04798192cdf8e0f1c91c6cfb0 Mon Sep 17 00:00:00 2001 From: kichikuou Date: Sun, 11 Jun 2023 13:37:09 +0900 Subject: [PATCH] Implement DrawGraph.CopyRotZoom2Bilinear Used in Daiteikoku. It's similar to DrawGraph.CopyRotZoom, but specifies source and destination center points. --- include/gfx/gfx.h | 1 + src/draw.c | 23 +++++++++++++++++++++++ src/hll/DrawGraph.c | 7 +++++-- 3 files changed, 29 insertions(+), 2 deletions(-) diff --git a/include/gfx/gfx.h b/include/gfx/gfx.h index 0c6c9c0..614e4a1 100644 --- a/include/gfx/gfx.h +++ b/include/gfx/gfx.h @@ -146,6 +146,7 @@ void gfx_copy_stretch_blend_amap_alpha(struct texture *dst, int dx, int dy, int void gfx_copy_rot_zoom(Texture *dst, Texture *src, int sx, int sy, int w, int h, float rotate, float mag); void gfx_copy_rot_zoom_amap(Texture *dst, Texture *src, int sx, int sy, int w, int h, float rotate, float mag); void gfx_copy_rot_zoom_use_amap(Texture *dst, Texture *src, int sx, int sy, int w, int h, float rotate, float mag); +void gfx_copy_root_zoom2(Texture *dst, float cx, float cy, Texture *src, float scx, float scy, float rot, float mag); void gfx_copy_reverse_LR(Texture *dst, int dx, int dy, Texture *src, int sx, int sy, int w, int h); void gfx_copy_reverse_amap_LR(Texture *dst, int dx, int dy, Texture *src, int sx, int sy, int w, int h); void gfx_copy_rotate_y(Texture *dst, Texture *front, Texture *back, int sx, int sy, int w, int h, float rot, float mag); diff --git a/src/draw.c b/src/draw.c index ec8caf9..23ac847 100644 --- a/src/draw.c +++ b/src/draw.c @@ -770,6 +770,29 @@ void gfx_copy_rot_zoom_use_amap(Texture *dst, Texture *src, int sx, int sy, int copy_rot_zoom(dst, src, sx, sy, w, h, rotate, mag, &hitbox_shader.s); } +void gfx_copy_root_zoom2(Texture *dst, float cx, float cy, Texture *src, float scx, float scy, float rot, float mag) +{ + gfx_fill_amap(dst, 0, 0, dst->w, dst->h, 0); + + // 1. scale src vertices to texture size + // 2. translate so that center point of copy region is at origin + // 3. rotate + // 4. scale + // 4. tranlate to center point of dst texture + // (applied in reverse order) + mat4 mw_transform = GLM_MAT4_IDENTITY_INIT; + glm_translate(mw_transform, (vec3){ cx, cy, 0 }); + glm_scale(mw_transform, (vec3){ mag, mag, 0 }); + glm_rotate_z(mw_transform, -rot * (M_PI/180.0), mw_transform); + glm_translate(mw_transform, (vec3){ -scx, -scy, 0 }); + glm_scale(mw_transform, (vec3){ src->w, src->h, 1 }); + + mat4 wv_transform = WV_TRANSFORM(dst->w, dst->h); + + struct copy_data data = ROTATE_DATA(dst, 0, 0, src->w, src->h); + run_draw_shader(&hitbox_noblend_shader.s, dst, src, mw_transform, wv_transform, &data); +} + static void copy_rotate_y(Texture *dst, Texture *front, Texture *back, int sx, int sy, int w, int h, float rot, float mag, Shader *shader) { Texture *src = front; diff --git a/src/hll/DrawGraph.c b/src/hll/DrawGraph.c index 729e83b..984181d 100644 --- a/src/hll/DrawGraph.c +++ b/src/hll/DrawGraph.c @@ -298,7 +298,10 @@ static void DrawGraph_CopyRotZoomUseAMap(int dst, int src, int sx, int sy, int w gfx_copy_rot_zoom_use_amap(DTEX(dst), STEX(src), sx, sy, w, h, rotate, mag); } -//void DrawGraph_CopyRotZoom2Bilinear(int dst, float cx, float cy, int src, float scx, float scy, float rot, float mag); +static void DrawGraph_CopyRotZoom2Bilinear(int dst, float cx, float cy, int src, float scx, float scy, float rot, float mag) +{ + gfx_copy_root_zoom2(DTEX(dst), cx, cy, STEX(src), scx, scy, rot, mag); +} static void DrawGraph_CopyRotateY(int write, int dst, int src, int sx, int sy, int w, int h, float rot, float mag) { @@ -469,7 +472,7 @@ HLL_LIBRARY(DrawGraph, HLL_EXPORT(CopyRotZoom, DrawGraph_CopyRotZoom), HLL_EXPORT(CopyRotZoomAMap, DrawGraph_CopyRotZoomAMap), HLL_EXPORT(CopyRotZoomUseAMap, DrawGraph_CopyRotZoomUseAMap), - //HLL_EXPORT(CopyRotZoom2Bilinear, DrawGraph_CopyRotZoom2Bilinear), + HLL_EXPORT(CopyRotZoom2Bilinear, DrawGraph_CopyRotZoom2Bilinear), HLL_EXPORT(CopyRotateY, DrawGraph_CopyRotateY), HLL_EXPORT(CopyRotateYUseAMap, DrawGraph_CopyRotateYUseAMap), //HLL_EXPORT(CopyRotateYFixL, DrawGraph_CopyRotateYFixL),