/// <summary> /// Converts the world position to screen space coordinates relative to camera. /// </summary> /// <param name="cameraComponent"></param> /// <param name="position"></param> /// <returns> /// The screen position in normalized X, Y coordinates. Top-left is (0,0), bottom-right is (1,1). /// </returns> /// <exception cref="ArgumentNullException">If the cameraComponent argument is null.</exception> public static Vector2 WorldToScreen(this CameraComponent cameraComponent, Vector3 position) { var clipSpace = cameraComponent.WorldToClip(position); var screenSpace = new Vector2 { X = (clipSpace.X + 1f) / 2f, Y = 1f - (clipSpace.Y + 1f) / 2f }; return(screenSpace); }