Commit 9c5f974a authored by Tommé Nöll's avatar Tommé Nöll
Browse files

made corruption camera scaling for zone visibility work with perspective camera

parent f4eb9b16
using System.Collections;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
......@@ -54,8 +54,7 @@ public class CameraZone : MonoBehaviour
{
if (apply)
{
//if (!playerWasInZone)
CalculateBounds();
if (!playerWasInZone)
{
if (camera.GetOrthographic())
{
......@@ -64,7 +63,7 @@ public class CameraZone : MonoBehaviour
}
else
{
camera.targetPos = VecZ(transform.position, -(CalculateCameraSize(bounds, fitMode) / 2) / Mathf.Tan(camera.GetFov() / 2 * Mathf.PI / 180));
camera.targetPos = CalculatePerpectiveCameraPosition(transform.position, bounds, fitMode); //calculate camera z to effectively change its size
}
}
}
......@@ -79,6 +78,11 @@ public class CameraZone : MonoBehaviour
playerWasInZone = apply;
}
public static Vector3 CalculatePerpectiveCameraPosition(Vector3 position, Bounds bounds, FitMode fitMode)
{
return VecZ(position, -(CalculateCameraSize(bounds, fitMode) / 2) / Mathf.Tan(camera.GetFov() / 2 * Mathf.PI / 180));
}
public static float CalculateCameraSize(Bounds bounds, FitMode fitMode)
{
float aspect = camera.GetAspectRatio(); // width / height
......
using System.Collections;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
[ExecuteInEditMode]
public class CorruptionCamera : MonoBehaviour
{
......@@ -27,7 +29,14 @@ public class CorruptionCamera : MonoBehaviour
if (!Application.IsPlaying(gameObject))
{
ScaleZonesVisible();
if (camera.orthographic)
{
camera.orthographicSize *= editorCorruptionCameraScaleFactor;
}
else
{
camera.transform.position = new Vector3(camera.transform.position.x, camera.transform.position.y, mainCamera.transform.position.z * editorCorruptionCameraScaleFactor);
}
corruptionMap.plantSurfaceMaterial.SetFloat("_CorruptionCameraScaleFactor", editorCorruptionCameraScaleFactor);
}
#endif
......@@ -37,6 +46,12 @@ public class CorruptionCamera : MonoBehaviour
//by checking if they are visible to the corruption camera
private void ScaleZonesVisible()
{
/*if (!camera.orthographic)
{
editorCorruptionCameraScaleFactor = 1;
return;
}*/
Bounds bounds = new Bounds(transform.position, new Vector3(0, 0, 0));
foreach (Transform zoneTransform in corruptionMap.transform)
{
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment