static public void Lerp(ref BlendedCameraOutput result, ref BlendedCameraOutput from, ref BlendedCameraOutput to, CameraLerp.LerpStyle style, float interpolatePos, float interpolatePitch, float interpolateYaw) { if (interpolatePos >= 1f && interpolatePitch >= 1.0f && interpolateYaw >= 1.0f) { result = to; return; } switch (style) { case CameraLerp.LerpStyle.positionToPosition: Vector3 fromPosition = from.CalculatePosition(); Vector3 toPosition = to.CalculatePosition(); Vector3 resultPosition = fromPosition + ((toPosition - fromPosition) * interpolatePos); result.distFromLookAt = from.distFromLookAt + ((to.distFromLookAt - from.distFromLookAt) * interpolatePos); Vector3 toEuler = to.rotation.eulerAngles; Vector3 fromEuler = from.rotation.eulerAngles; Vector3 lerpEuler = Vector3.zero; lerpEuler.x = Mathf.LerpAngle(fromEuler.x, toEuler.x, interpolatePitch); lerpEuler.y = Mathf.LerpAngle(fromEuler.y, toEuler.y, interpolateYaw); //result.rotation = Quaternion.Slerp(from.rotation, to.rotation, interpolate); result.rotation = Quaternion.Euler(lerpEuler); result.lookAt = resultPosition + GameUtils.CalculateForward(result.rotation) * result.distFromLookAt; break; case CameraLerp.LerpStyle.keepTargetOnScreen: result.distFromLookAt = from.distFromLookAt + ((to.distFromLookAt - from.distFromLookAt) * interpolatePos); //result.rotation = Quaternion.Slerp(from.rotation, to.rotation, interpolatePos); Vector3 toEulerK = to.rotation.eulerAngles; Vector3 fromEulerK = from.rotation.eulerAngles; Vector3 lerpEulerK = Vector3.zero; lerpEulerK.x = Mathf.LerpAngle(fromEulerK.x, toEulerK.x, interpolatePitch); lerpEulerK.y = Mathf.LerpAngle(fromEulerK.y, toEulerK.y, interpolateYaw); //result.rotation = Quaternion.Slerp(from.rotation, to.rotation, interpolate); result.rotation = Quaternion.Euler(lerpEulerK); result.lookAt = from.lookAt + ((to.lookAt - from.lookAt) * interpolatePos); break; default: result = to; break; } }
// calculate what the look at point is based on the inputs public Vector3 CalculateLookAt(Vector3 targetPosition, Vector3 camPos, Quaternion camRotation) { Vector3 planeNormal = targetPosition - camPos; if (GameUtils.NormalizeXZ(ref planeNormal)) { _plane.SetNormalAndPosition(planeNormal, targetPosition); Vector3 forward = GameUtils.CalculateForward(camRotation); _ray.origin = camPos; _ray.direction = forward; float dist = 0f; if (_plane.Raycast(_ray, out dist)) { return(camPos + forward * dist); } } return(targetPosition); }
public void SetPosition(Vector3 position) { _gameCameraLookAt = position + (GameUtils.CalculateForward(_gameCameraRotation) * _gameCameraDistanceFromLookat); }
public void GetPosition(ref Vector3 position) { position = _gameCameraLookAt - (GameUtils.CalculateForward(_gameCameraRotation) * _gameCameraDistanceFromLookat); }
public Vector3 CalculatePosition() { return(lookAt - GameUtils.CalculateForward(rotation) * distFromLookAt); }