Projection Mapping in Processing

Projection mapping is something I've been waning to play with for a while now.  The biggest hurdle I've run into so far is compensating for distortion caused by surfaces that aren't perpendicular to the projector.  You can pre-render the video to counteract this effect, but for content generated in real-time (something needed for most interactive projects) you have to deal with this problem on the fly. After looking around I came across a library for Processing called keystone which sounded like exactly what I needed.  However, when I tried it out I noticed a critical flaw.  The library doesn't compensate for real perspective.  If you look at the image here, you can see that the vertical lines don't get closer together as they move further away.


Since I want to project images that line up with real world objects, the keystone library won't work so I decided to try solving the problem myself.  After lots of reading and poking around on the internet, I've built the beginnings of my own projection mapping library.  Here's a shot of the same setup using my code instead of the keystone library.  You can see the difference immediately.


My plan is to release this as a processing library once it's in a state that is easy to consume; right now it's just a handful of java classes in a processing sketch..