fix the bugs in generateRay