mirror of
https://github.com/ctruLua/ctruLua.git
synced 2025-10-27 16:39:29 +00:00
Added hotspot arguments when drawing rotated textures
Did related changes to sprite.lua and cleaned stuff. I had to add a function to sf2dlib to make this work, so a make build-sf2dlib is required. Also, we should probably send this change to the original sf2dlib repository...
This commit is contained in:
parent
4d1e3ec455
commit
d0fb704205
4 changed files with 103 additions and 49 deletions
|
|
@ -588,6 +588,24 @@ void sf2d_draw_texture_part_rotate_scale(const sf2d_texture *texture, int x, int
|
|||
*/
|
||||
void sf2d_draw_texture_part_rotate_scale_blend(const sf2d_texture *texture, int x, int y, float rad, int tex_x, int tex_y, int tex_w, int tex_h, float x_scale, float y_scale, u32 color);
|
||||
|
||||
/**
|
||||
* @brief Draws a part of a texture, with rotation, scaling, color and hotspot
|
||||
* @param texture the texture to draw
|
||||
* @param x the x coordinate to draw the texture to
|
||||
* @param y the y coordinate to draw the texture to
|
||||
* @param rad rotation (in radians) to draw the texture
|
||||
* @param tex_x the starting point (x coordinate) where to start drawing
|
||||
* @param tex_y the starting point (y coordinate) where to start drawing
|
||||
* @param tex_w the width to draw from the starting point
|
||||
* @param tex_h the height to draw from the starting point
|
||||
* @param x_scale the x scale
|
||||
* @param y_scale the y scale
|
||||
* @param center_x the x position of the hotspot
|
||||
* @param center_y the y position of the hotspot
|
||||
* @param color the color to blend with the texture
|
||||
*/
|
||||
void sf2d_draw_texture_part_rotate_scale_hotspot_blend(const sf2d_texture *texture, int x, int y, float rad, int tex_x, int tex_y, int tex_w, int tex_h, float x_scale, float y_scale, float center_x, float center_y, u32 color);
|
||||
|
||||
/**
|
||||
* @brief Draws a texture blended in a certain depth
|
||||
* @param texture the texture to draw
|
||||
|
|
|
|||
|
|
@ -599,18 +599,18 @@ void sf2d_draw_texture_part_scale_blend(const sf2d_texture *texture, float x, fl
|
|||
sf2d_draw_texture_part_scale_generic(texture, x, y, tex_x, tex_y, tex_w, tex_h, x_scale, y_scale);
|
||||
}
|
||||
|
||||
static inline void sf2d_draw_texture_part_rotate_scale_generic(const sf2d_texture *texture, int x, int y, float rad, int tex_x, int tex_y, int tex_w, int tex_h, float x_scale, float y_scale)
|
||||
static inline void sf2d_draw_texture_part_rotate_scale_hotspot_generic(const sf2d_texture *texture, int x, int y, float rad, int tex_x, int tex_y, int tex_w, int tex_h, float x_scale, float y_scale, float center_x, float center_y)
|
||||
{
|
||||
sf2d_vertex_pos_tex *vertices = sf2d_pool_memalign(4 * sizeof(sf2d_vertex_pos_tex), 8);
|
||||
if (!vertices) return;
|
||||
|
||||
int w2 = (tex_w * x_scale)/2.0f;
|
||||
int h2 = (tex_h * y_scale)/2.0f;
|
||||
int w = tex_w;
|
||||
int h = tex_h;
|
||||
|
||||
vertices[0].position = (sf2d_vector_3f){(float)-w2, (float)-h2, SF2D_DEFAULT_DEPTH};
|
||||
vertices[1].position = (sf2d_vector_3f){(float) w2, (float)-h2, SF2D_DEFAULT_DEPTH};
|
||||
vertices[2].position = (sf2d_vector_3f){(float)-w2, (float) h2, SF2D_DEFAULT_DEPTH};
|
||||
vertices[3].position = (sf2d_vector_3f){(float) w2, (float) h2, SF2D_DEFAULT_DEPTH};
|
||||
vertices[0].position = (sf2d_vector_3f){(float)-center_x * x_scale, (float)-center_y * y_scale, SF2D_DEFAULT_DEPTH};
|
||||
vertices[1].position = (sf2d_vector_3f){(float) (w - center_x) * x_scale, (float)-center_y * y_scale, SF2D_DEFAULT_DEPTH};
|
||||
vertices[2].position = (sf2d_vector_3f){(float)-center_x * x_scale, (float) (h - center_y) * y_scale, SF2D_DEFAULT_DEPTH};
|
||||
vertices[3].position = (sf2d_vector_3f){(float) (w - center_x) * x_scale, (float) h - center_y * y_scale, SF2D_DEFAULT_DEPTH};
|
||||
|
||||
float u0 = tex_x/(float)texture->pow2_w;
|
||||
float v0 = tex_y/(float)texture->pow2_h;
|
||||
|
|
@ -650,13 +650,19 @@ static inline void sf2d_draw_texture_part_rotate_scale_generic(const sf2d_textur
|
|||
void sf2d_draw_texture_part_rotate_scale(const sf2d_texture *texture, int x, int y, float rad, int tex_x, int tex_y, int tex_w, int tex_h, float x_scale, float y_scale)
|
||||
{
|
||||
sf2d_bind_texture(texture, GPU_TEXUNIT0);
|
||||
sf2d_draw_texture_part_rotate_scale_generic(texture, x, y, rad, tex_x, tex_y, tex_w, tex_h, x_scale, y_scale);
|
||||
sf2d_draw_texture_part_rotate_scale_hotspot_generic(texture, x, y, rad, tex_x, tex_y, tex_w, tex_h, x_scale, y_scale, tex_w/2.0f, tex_h/2.0f);
|
||||
}
|
||||
|
||||
void sf2d_draw_texture_part_rotate_scale_blend(const sf2d_texture *texture, int x, int y, float rad, int tex_x, int tex_y, int tex_w, int tex_h, float x_scale, float y_scale, u32 color)
|
||||
{
|
||||
sf2d_bind_texture_color(texture, GPU_TEXUNIT0, color);
|
||||
sf2d_draw_texture_part_rotate_scale_generic(texture, x, y, rad, tex_x, tex_y, tex_w, tex_h, x_scale, y_scale);
|
||||
sf2d_draw_texture_part_rotate_scale_hotspot_generic(texture, x, y, rad, tex_x, tex_y, tex_w, tex_h, x_scale, y_scale, tex_w/2.0f, tex_h/2.0f);
|
||||
}
|
||||
|
||||
void sf2d_draw_texture_part_rotate_scale_hotspot_blend(const sf2d_texture *texture, int x, int y, float rad, int tex_x, int tex_y, int tex_w, int tex_h, float x_scale, float y_scale, float center_x, float center_y, u32 color)
|
||||
{
|
||||
sf2d_bind_texture_color(texture, GPU_TEXUNIT0, color);
|
||||
sf2d_draw_texture_part_rotate_scale_hotspot_generic(texture, x, y, rad, tex_x, tex_y, tex_w, tex_h, x_scale, y_scale, center_x, center_y);
|
||||
}
|
||||
|
||||
static inline void sf2d_draw_texture_depth_generic(const sf2d_texture *texture, int x, int y, signed short z)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue