that's simple vector math. there's a sample doing just that in the manual afaik.