Log In  

Cart #rspr_greygraphics-3 | 2019-05-05 | Code ▽ | Embed ▽ | License: CC4-BY-NC-SA
9

Hi,

I made a small demo of a function I have been working on. It is called rspr and can draw sprites with any rotation.
It has the following signature:

rspr(sx,sy,sw,sh,a,dx,dy,dw,dh)
--  sx,sy,sw,sh - pos,dimensions in spritesheet
--  a - angle
--  dx,dy,dw,dh - pos,dimensions on screen

It takes the angle in the same format as sin and cos and draws the sprite rotated around dx,dy.
You can scale the drawn sprite with dw,dh and it can draw sprites of any size.
However, large values for dw and dh cause some serious performance losses, so you should avoid scaling up sprites to unreasonable sizes.

Due to this slowdown, I would really like to have this function implemented natively in pico-8. What do you think, @zep?

Thank you, @freds72, for the suggestion of inlining the function calls. It does speed up the function remarkably.

P#64178 2019-05-04 22:55 ( Edited 2019-05-05 17:52)

The scaling is a nice touch - that said you can do a lot faster by inlining most of the function calls.

For scaling, suggest to use sspr for that (e.g write rotated sprite back to sprite sheet and then scale - mucho faster)

See my port of an old Dr Dobbs article: https://www.lexaloffle.com/bbs/?tid=3593 (scroll down the thread)

And @zep said api was complete - if you go this way, a trifill function would be handy...

P#64182 2019-05-05 07:29 ( Edited 2019-05-05 07:30)

@greygraphics better but still way too many sin/cos calls!

P#64186 2019-05-05 15:09

@freds72 Thank you again for your suggestions. I am also reusing sin/cos values now. I don't think I can get this to run any faster now, without using your sspr trick.

P#64190 2019-05-05 17:54
3

Cart #kopemumajo-0 | 2019-05-05 | Code ▽ | Embed ▽ | No License
3

@greygraphics: using DDA "classic" trick, you can get cpu down to 14% (from 22%) :]

P#64192 2019-05-05 19:53 ( Edited 2019-05-05 19:54)

[Please log in to post a comment]

Follow Lexaloffle:          
Generated 2024-03-29 09:14:23 | 0.027s | Q:28