drawRotatedBitmap not respecting negative unit scales at small angles

How to reproduce:

  1. Use drawRotatedBitmap with the C API to draw a sprite with a very small angle. I put in on a sine wave with a tiny amplitude to see the effect.
  2. Have some arbitrary centre like 0.25,0.25
  3. The scales must be unit magnitude but at least one of them negative
    The rasterisation algorithm is clearly reverting to non rotated algorithm for small angles for speed, but it's not respecting the pivot * negative scale.
    Funnily, it doesn't happen if the scale is negative but not 1.0. Another optimisation I assume.

I'm not clear how you're using drawRotatedBitmap along with sprites here. Are you doing that in a sprite draw callback? Or outside the sprite, then setting that image on the sprite? A code example would be really useful here.

I do have the rotated drawing function clamping to 90 degree increments if the offset is less than 0.01 degrees, so that tiny rounding errors don't keep if from using the optimized rotation algorithm. It sounds like some case isn't handled correctly in there but I don't see anything obvious yet. :thinking:

Sorry, my fault, I shouldn't have used the word "sprite." I meant it in a general sense, not the PD API struct.
I am just drawing a bitmap by itself. Like I say, the issue comes with have -1 as one of the scales and setting the angle very near zero.
I'm busy at the moment, but when I have time, I'll do another experiment and post some code.

1 Like

Oh, here you go:

LCDBitmap* bm = /* load a bitmap */
static float t=0.f; t += 0.1f;
g_playdate->graphics->drawRotatedBitmap(bm, 100, 100, sinf(t)*0.01f, 0.25f, 0.25f, -1.f, -1.f);
1 Like

Great, thanks! I don't see it flipping but there's definitely something wrong with the placement, looks like it isn't calculating the center point correctly.


Thanks for catching this! I'll get a fix in today and mark it high priority, hopefully get it into a release soon.

Yeah, it was tricky to figure out what's going on. But glad you got to see it too, so I'm not going insane :smiley:

1 Like