/CameraManager.cs Secret
Last active
August 7, 2017 17:32
CameraManager - 3
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
void Refresh() { | |
float t = interpolationTimeAccum / interpolationTime; | |
cachedCamera.fieldOfView = Mathf.Lerp(fromFov, toCamera.fieldOfView, t); | |
//Rotate | |
transform.rotation = toCamera.transform.rotation * Quaternion.Lerp(fromRotation, Quaternion.identity, t); | |
//Translate | |
transform.position = target.position;//Place in target position | |
Vector3 p0 = fromPosition; | |
Vector3 p1 = -toCamera.transform.worldToLocalMatrix.MultiplyPoint(target.position); | |
Vector3 p2 = Vector3.Lerp(p0, p1, t); | |
//Fix Z based on fov changes so height interpolates linearly (better interpolation on fov changes) | |
float h0 = Mathf.Tan(fromFov * Mathf.Deg2Rad * 0.5f) * p0.z; | |
float h1 = Mathf.Tan(toCamera.fieldOfView * Mathf.Deg2Rad * 0.5f) * p1.z; | |
float h2 = Mathf.Lerp(h0, h1, t); | |
p2.z = h2 / Mathf.Tan(cachedCamera.fieldOfView * Mathf.Deg2Rad * 0.5f); | |
transform.Translate(p2); | |
float tZ = (p1.z == p2.z) ? t : (p2.z - p0.z) / (p1.z - p0.z) ; | |
cachedCamera.nearClipPlane = Mathf.Lerp(fromNear, toCamera.nearClipPlane, t); | |
cachedCamera.farClipPlane = Mathf.Lerp(fromFar, toCamera.farClipPlane, t); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment