123
-=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- (c) WidthPadding Industries 1987 0|557|0 -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=-
Socoder -> C/C++/C#/Other -> image rotation?

Sun, 08 Apr 2018, 02:47
spinal

image rotation?


I'm working on a little but of code to rotate an image in real time. I'm currently doing it a slow way -



However, apparently it's much faster to shear+skew the image and only calculate the angle once per render instead of once per pixel...

But I can't get my head around it. Has anyone doe this before?
www.drdobbs.com/architecture-and-design/fast-bitmap-rotation-and-scaling/184416337

-=-=-
Check out my excellent homepage!
Sun, 08 Apr 2018, 03:36
Jayenkai
Yeah, code-based rotation's never been a good thing. If you have the memory, pre-rotate your sprites whilst loading, to (360/(16 or 32)) degree rotations, and use those.. It's not perfect, but it's better than nothing.

I've never attempted to rotate using skews, and although it sounds like it might work, I imagine the fake-rotate might look a little warped by the end of it.
But then, given the small resolution, you'll probably be able to get away with it..?

-=-=-
''Load, Next List!''
Sun, 08 Apr 2018, 04:15
spinal
Yeah, no RAM, slow processor etc.
Thu, 12 Apr 2018, 09:50
spinal
OK, apparently this is supposed to be really fast as it removes almost all of the math from inside the double loop...

link


However, the output is completely wonky and wrong, perhaps the sin/cos bit is incorrect?

blitz...


-=-=-
Check out my excellent homepage!
Thu, 12 Apr 2018, 11:02
Jayenkai


I smudged together the code you posted, along with my tilemap rotation code from the other day.
Seems nice and fast, I think..

-=-=-
''Load, Next List!''
Thu, 12 Apr 2018, 14:00
spinal
Right, I won't claim to follow the math 100%, or even 70% but this is apparently the 'correct' way...

We assume that because were drawing a straight line on the screen, then the line we are copying from our source image is also straight. We then create a vector based on the angle we are rotating to outside of the loops so that it is done only once per render, then its a case of additions on the x and y going from that vector.




There's a lot of floats there, which slow everything down a lot, also its in basic, which is also slow

Just got to figure how to fixed-point the whole thing...

-=-=-
Check out my excellent homepage!