Is it possible to rotate text in increments of 90 degrees? My DIY Arduboy supports vertical screen orientation.
Possible but not without effort.
Note that you could also implement your own font rendering if it’s just font that needs to be on its side.
The crux of the matter is that it’s possible but there’s no pre-made solution.
Could this be implemented into the sprite base file http://www.drdobbs.com/architecture-and-design/fast-bitmap-rotation-and-scaling/184416337
It could but it wouldn’t be very fast or efficient, especially if it’s only 90, 180 and 270 degree rotations that are required.
AVR chips like the Arduboy’s ATmega32u4 don’t have built in floating point support, they rely on a software implementation.
cos are well known to be slow as it is, but they’d be even slower on a software-only implementation.
For something grid-based like a bitmap, rotations that are multiples of 90 degrees can completely avoid
cos with clever manipulation of pixel coordinates (which is what filmote’s code does).
If anyone wants to try the Dr Dobbs approach using fixed points though, I know of this handy little library (which may or may not be written by myself) that would make it easier.
Sine can be approximated using a radian conversion
It would probably be cheaper to switch to brads and use a 64 element look-up table (which would be enough to cover the full range of sin and cos for brads).
Even after that though there’s the issue of calculating how many pixels you’d need to encompass the rotated version of the whole image (I think 45 degrees/32 brads produces the worst case scenario though I’ve never checked), and the issue of how to allocate those pixels (static vs dynamic).
It’s doable, but for something like the Arduboy it would be eating a heck of a lot of resources.
For something like font it would be easier to just write a new font library with all the font character already rotated.
For game graphics it would be easier to either limit to 90/18/270 degree rotations or to go for a 2D vector-based approach.
If the rotation is just intented for a portrait view of the display instead of landscape. It might be simp[er and faster to ‘rotate’ the display buffer content while sending it to the display. like load 8 bytes of display data into 8 registers then bitload and bitstore to a temp register and send that to the display. The display initialisation should also be configured to use vertical addressing.
It should be doable with a small effort with Tinyfont by modifying drawByte.
Every symbol is a 4x4 bit bitmap, so you could swap the loops/coords.
The following github submissions containing rotated text for a vertical display:
A version of THAT game
My version of 1943 just had some graphics of rotated text, not a full library.
In our ‘Dark & Under’ game (still a work in progress but soooo close to being done), I hacked the Arduboy2 font library to have a 5x3 font. The core Arduboy library is quite simple and I would suggest that you look to creating your own version.
I had a fast bitmap rotation function but I can’t seem to find it now. Forget which sprite format it supported though. I think just simple unmasked.
Though I wouldn’t call it finished or polished or anything, but in my testing it worked just fine. Note: It remaps pixels though… so if you’re rotating and don’t want “holes” (rotation glitches) you may need a sprite 2x bigger or so and then scale it down as you do the rotation (which is supported). This is still going to be a zillion times slower than drawing in general… but I think in my testing I was getting like 20 FPS for full screen rotation if I remember correctly, which i thought wasn’t terrible.