raycasting refactored into class