fixed coordinate transformation function to scale properly to window width and height