My orthogonal camera has rotation values (30, 12, 6)
, and the map also has rotation values (90, 0, 0)
. When the game is initialized, I make the bottom left corner of the camera’s field of view coincide with the bottom left corner of the map, so that at the beginning of the game, the camera shines on the bottom left corner of the map. Afterwards, players can drag the map and move the camera.
I need to calculate the projection coordinates of my orthogonal camera on the map. How do I need to calculate it?
This code is always incorrect.
cameraDistance = Mathf.Max(mapInfo.mapSize.x / (2f * Mathf.Tan(Mathf.Deg2Rad * mainCamera.fieldOfView / 2f)) , mapInfo.mapSize.y / (2f * Mathf.Tan(Mathf.Deg2Rad * mainCamera.fieldOfView / 2f)));
Vector3 cameraDirection = transform.rotation * Vector3.forward;
Vector3 centerProjector = cameraCenter + cameraDirection * cameraInfo.cameraDistance;
Vector3 cameraCenterMapSpace = Quaternion.Inverse(mapInfo.map.transform.rotation) * (centerProjector - new Vector3(0f, 0f, 0f));
Vector3 projectedCenter = new Vector3(cameraCenterMapSpace.x, mapInfo.map.transform.position.y, cameraCenterMapSpace.z);