The author attached a magnet to a reflective encoding disk. Using four infrared photoreflectors he was able to read the position of the disk and thefore the magnet.
For those that aren't so clever as to create your own electric compass, the popular Devantech compass works.