Jo Engine Forum

Sega Saturn Development => Jo Engine Wish List => Topic started by: null1024 on August 03, 2017, 04:15:26 am

Title: Drawing "billboard" sprites in 3D, sprite pre-scaling
Post by: null1024 on August 03, 2017, 04:15:26 am
One thing I was looking for how to do was to use two-point scaled sprites in 3D for effects that always face the screen. Eg., it's positioned and sorted in 3D, but it's just a plain 2D sprite rather than a quad (so camera rotation doesn't immediately out it as being flat as a pancake).
This sort of thing is used pretty often in Saturn and PS1 games (the example that immediately comes to mind are point items and bullets in Bulk Slash, or literally every object in After Burner 8))
This would be both faster (fewer points needed to be transformed) and convenient for things like particle effects and the lot.

also, having a function to pre-scale those sprites (billboards or 3d) before the 3D transform would be convenient as a built-in part of the library (a new user to the library might attempt to do jo_3d_set_scale before jo_3d_draw_sprite_at, which would result in the scale affecting the translation jo_3d_draw_sprite_at does and everything would be positioned wrong, and jo_3d_set_scale's name/description in the docs doesn't actually tell the user that it affects the matrix :P)

here's an implementation for that for 3D quad sprites I'd come up with (feel free to use this if you want)
Code: [Select]
void jo_3d_draw_sprite_at_scaled(int texture, int x, int y, int z, int xscale, int yscale) {
    jo_3d_push_matrix();
    {
        jo_3d_translate_matrix(x,y,z);
        jo_3d_set_scale(xscale,yscale,1);
        jo_3d_draw_sprite(texture);
    }
    jo_3d_pop_matrix();
}
Title: Re: Drawing "billboard" sprites in 3D, sprite pre-scaling
Post by: mindslight on August 03, 2017, 09:13:11 am
Hi,

Wish accepted :)
Title: Re: Drawing "billboard" sprites in 3D, sprite pre-scaling
Post by: mindslight on August 12, 2017, 03:18:06 pm
Hi Null1024,

You will find below, the prototype of the function I have added on the next release:

Code: [Select]
/** @brief Draw billboard with a specific scale
 *  @param sprite_id Sprite Id returned by jo_sprite_add(), jo_sprite_add_tga() or jo_sprite_add_image_pack()
 *  @param x X coordinate
 *  @param y Y coordinate
 *  @param z Z coordinate
 *  @param scale_x X scale
 *  @param scale_y Y scale
 */
void      jo_3d_draw_billboard(const int sprite_id, const int x, const int y, const int z, const int scale_x, const int scale_y);