On arctangent.

The arctangent is one of the more interesting trigonometry functions – and by “interesting” I of course mean a bitch to get right. I've been meaning to write something about the various methods of calculating it for a while now and finally got round to it recently.

I, ah, uhm, may have gotten a little carried away with it though ... but that's okay,! At least now I while one to recommend.

New doc: matrices from a geometry perspective

Matrices from a geometry perspective” is now out. Vector and matrix math is used heavily in computer graphics because it involved geometry and coordinate transformations. While this is widely known, I've seen many people struggle with the basic concepts of how it's supposed to work. this is especially true in the GBA/NDS community, where erroneous information about the affine matrix is still found in many demos and even library code even today. And that just kills me, because the fundamentals are really quite simple to grasp once you look at it from the right direction(1)

I've wanted to write something on the subject for quite some time. Yeah, there were a few sections in Tonc that covered it, but not in the amount of detail I wanted it. A recent email (thanks Ian) finally spurred me to write something down.

In the document, I describe what points, vectors and coordinates really are in geometrical terms. This may seem obvious, but it's always good to go over the basics again because overlooking those is often the reason for misunderstandings. Then it describes how coordinate transformations work and how matrices fit into the subject.

I've tried to keep the hardcore math to a minimum in order to keep it understandable. I'd really like to get some feedback on this to know if it is comprehensible to people who don't already know how all this stuff works. If there are other items that anyone feels I should add, I'll consider that as well. I should probably also note that many parts of it have already been rewritten three times already, so if sentences don't make sense, let me know so I can fix it.

linky: Matrices from a geometry perspective.

  1. I'm not saying it's not easy to make mistakes here (it's still math we're talking about), but the basic concepts are not that complex.

Fiddle to the bittle

I've added two new routines to the bit-trick page: 1→4 bit-unpack with reverse and bit reversals. This last one is elegant … except for one bit of C tomfoolery that is required to get GCC to produce the right ARM code. I hope to discuss this in more detail later.

I've also added a new document about dealing with bitfields. It explains what to do with them, gives a few useful functions to get and set bitfields, and demonstrates how to use the C construct for bitfields. It also touches briefly on a nasty detail in the way GCC implements bitfield that can cause them to fail in certain GBA/NDS memory sections. If you're using bitfields to map VRAM or OAM, please read.

The Docs

Bit late, yes, but now that I have my second document, I feel I should perhaps say something about the category. In broad lines, the site is divided into three sections. First there are ‘short bits’, which are, well, short pieces of text, from simple announcements and comments to maybe a few pages worth of functions on various subjects, like a fast memset for ARM systems. This basically corresponds to a WordPress ‘Post’. Then there are ‘collections’ – groups of pages on a subject which could serve as a standalone site. Tonc would be a good example of this. I suppose you could call these ‘books’. The ‘documents’ are somewhere in between – too long and relevant to be posts, but, being singular pages, too short to be books. A book is what a document wants to be when it grows up.

Anyway, right now I have two documents. The first is a collection of bit tricks: little snippets of code on bit-fiddling. No, they are not futile exercises, they're programming-puzzles and they're clever little hacks for extra speed. OK, maybe they're just a little futile >_>.

The second document is about 20 pages worth of Annotations to “Programming the Nintendo GameBoy Advance”, Mr Harbour's popular E-book on GBA programming. As slick as it looks, the book has some very serious flaws like incorrect information, non-functional code and teaches some bad programming habits. This document points them out.

I've actually been sitting on this one for quite a while now. I may have the social graces of a bent teaspoon, but even I know that pointing out errors in code written by a professional that beginner C courses warn about isn't a nice thing to do. Of course, that's just part of why I'm releasing this: the book certainly looks like a good resource for GBA programming if you're new to the GBA, especially if you're new to programming in general. It'd kinda suck if you had to unlearn large parts later because the information wasn't up to standards. These annotations should help you recognize most of its errors and steer around them.