11

Couple people asked about how I did sprite rotation for josefnpat's collab cart https://www.lexaloffle.com/bbs/?tid=27582
Included is a sprite rotation function, and a way of layering them on top of each other to create an illusion of a 3d sprite.
Everything is commented, hopefully it's clear.
Enjoy, hope this is helpful for someone!

Cart #28035 | 2016-09-05 | Code ▽ | License: CC4-BY-NC-SA
11

(the effect isn't perfect and can be a little unclear if you don't consider it when drawing sprites, if anyone has any more accurate examples of rotation functions I'd like to see!)

P#28036 2016-09-05 08:53 ( Edited 2016-10-15 21:22)

Very cool effect. Thanks!

P#28045 2016-09-05 14:19 ( Edited 2016-09-05 18:19)

neat! and as good as you can get imho.

tried optimizing/rewriting rotsprite, stat(1) went from 0.36 to 0.30 on your cart:

 ```function rotsprite(sprite, posx, posy, angle) local scx = sprite%16*8 local scy = flr(sprite/16)*8 local cs = cos(angle) local sn = sin(angle) local cpx=-5*(cs-sn) +4 local cpy=-5*(sn+cs) +4 for x=-5,5 do local px=cpx local py=cpy for y=-5,5 do if (px>=0 and px<8 and py>=0 and py<8) then local col = sget(scx+px, scy+py) if (col ~= 0) pset(posx+x, posy+y, col) end px-=sn py+=cs end cpx+=cs cpy+=sn end end ```

P#28086 2016-09-06 09:30 ( Edited 2016-09-06 13:30)

Oh, good to see, cheers!

P#28106 2016-09-06 17:31 ( Edited 2016-09-06 21:31)

just found out I had this optimized further but didn't update here:

 ```function layeredsprite(sprite, posx, posy, angle, layers) local cs,sn = cos(angle),sin(angle) local osx,osy = -5*(cs-sn)+4,-5*(sn+cs)+4 local spx,spy = 8*(sprite%16),8*flr(sprite/16) for layer=1, layers do local csx,csy = osx,osy for x=-5,5 do local sx,sy = csx,csy for y=-5,5 do if (sx>=0 and sx<8 and sy>=0 and sy<8) then local col = sget(spx+sx, spy+sy) if (col~=0) pset(posx+x, posy+y, col) end sx-=sn sy+=cs end csx+=cs csy+=sn end spx+=8 --layers on same row pls posy-=1 end end ```

merged rotsprite() in layeredsprite(), demo runs at 0.24

P#30981 2016-10-15 11:50 ( Edited 2016-10-15 16:01)
:: dw817

Is there a way to zoom these sprites, UB ?

P#30982 2016-10-15 12:08 ( Edited 2016-10-15 16:08)

not out of the box dw, also this works on single sprites (8x8).
sizes are hardcoded, but should be 'easily' adapted.
if somebody needs help about that, I can have a look, but I won't right now ;)

P#30988 2016-10-15 17:22 ( Edited 2016-10-15 21:22)