This is probably the weirdest, stupidest self-own/bug I have managed to cause yet.
The first image, with the blue head, is not properly animating/interpolating between side facing and 3/4 facing. HOWEVER!, if I set the horizontal (x) scale to any value other than a round 1, IT WORKS! And by any other value, I mean that it fucking works when it is
1.001, but does NOT work when it's
1 or
1.0.
Of course, such discovery was completely accidental, because I was trying to figure what the fuck was going on that caused only that pair of animations to fail. For making the gifs, I was going to scale up the head, but when it worked I was... Don't even know the proper word here. Dumbfounded? Anyway, I couldn't believe that shit. Scale was fucking my animation? HOW!??
So, double checking my code, it led me to my
transformPolygon function, which I got tricksy in trying to avoid unnecessary math.
var vxy = rotatePoints(pol.rotation, pol.cppolygon[4])
if (pol.polygon[4].x == (vxy.x * pol.scalex) + pol.x):
return
else:
#do the actual scaling and rotation of every vertice
The idea here is solid, I don't need to recalculate *every single vertice's position* if they didn't change. Just because I'm unlikely to hit a number of vertices that might actually cause a significant impact on framerates isn't reason for me to be sloppy. With an uncapped framerate, not doing that check and only applying the math to around 40 vertices in total, drops the FPS from ~2700 to ~2500. Or, a better measure, this calculation adds 0,00003 seconds (0,03ms) to compute. Supposing a linear growth, 1k vertices would take 1 extra millisecond doing unnecessary compute. I doubt my game will even get that many vertices on screen, but I digress.
Back to the function, this was something I half expected to happen there, which is why I thought "eh, just checking the position [4]'s x ought to be enough". Well, guess fucking what, past me, it wasn't. Right now, I changed the if to the following:
if (pol.polygon[1].x == (vxy.x * pol.scalex) + pol.x) and (pol.polygon[1].y == (vxy.y * pol.scaley) + pol.y):Even that still has a chance to cause this problem again, although this time I'll know where to look. Maybe tomorrow I'll think of a better solution, maybe a flag variable somewhere.
#programming #gamedev #raylib #vectorgraphics #nim #naylib