Is it possible to rotate text in increments of 90 degrees? My DIY Arduboy supports vertical screen orientation.
Possible but not without effort.
The only Arduboy-based rotation I know of is some experimental bitmap rotation code written by @filmote. Hopefully he wonât mind me pointing you to his work.
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. sin
and 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 sin
and 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:
Breakout-V
1943
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.
Found it: https://github.com/yyyc514/Arduboy2/tree/rotate
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.