Code from the demo. Tree collision and perspective correction.