modifed to use Codea's vec3, look at old version for a version that works outside of Codea