public static void CalcDistance(float deltaTime, CamAdjustStock origin, CamAdjustStock prev, ref CameraUpdateInfo updateInfo, ref SmoothStock smooth) { if (prev.Stock.Distance == origin.Stock.Distance) { smooth.LifeTime = 0; return; } smooth.LifeTime += deltaTime; float elapsed = (float)smooth.LifeTime / smooth.PeriodTime; float difference = Mathf.Abs(prev.Stock.Distance - origin.Stock.Distance) / smooth.Value; float smoothDiff = GetSmoothValue(elapsed, difference, smooth.Power) * smooth.Value; if (smoothDiff == 0) { return; } if (prev.Stock.Distance > origin.Stock.Distance) { updateInfo.Distance = origin.Stock.Distance + smoothDiff; } else { updateInfo.Distance = origin.Stock.Distance - smoothDiff; } }
public static void CalcDirection(float deltaTime, CamAdjustStock origin, CamAdjustStock prev, ref CameraUpdateInfo updateInfo, ref SmoothStock smooth) { Vector2 v2Difference = Vector2.zero; v2Difference.x = LEMath.RadianDistance(origin.Stock.Horizon, prev.Stock.Horizon); v2Difference.y = LEMath.RadianDistance(origin.Stock.Vertical, prev.Stock.Vertical); float difference = v2Difference.magnitude; if (difference == 0) { smooth.LifeTime = 0; return; } smooth.LifeTime += deltaTime; float elapsed = (float)smooth.LifeTime / smooth.PeriodTime; difference = difference / smooth.Value; float smoothDiff = GetSmoothValue(elapsed, difference, smooth.Power) * smooth.Value; if (smoothDiff == 0) { return; } Vector2 v2Result = v2Difference.normalized; v2Result = v2Result * (smoothDiff); updateInfo.Horizon = origin.Stock.Horizon + v2Result.x; updateInfo.Vertical = origin.Stock.Vertical + v2Result.y; }
public static void CalcTarget(float deltaTime, CamAdjustStock origin, CamAdjustStock prev, ref CameraUpdateInfo updateInfo, ref SmoothStock smooth) { float difference = Vector3.Distance(prev.Target, origin.Target); if (difference == 0.0f) { return; } if (difference - smooth.Value > 0) { smooth.LifeTime = 0; } smooth.LifeTime += deltaTime; float elapsed = 0.1f; float smoothDiff = GetSmoothValue(elapsed, difference, smooth.Power) * 2.0f; if (smoothDiff == 0) { return; } updateInfo.Distance += smoothDiff + 0.01f; Vector3 dir = prev.Target - origin.Target; dir.Normalize(); updateInfo.Target = origin.Target + dir * smoothDiff; }