Source code from my 2007 book, updated for XNA 4.x