Vector3.Slerp
Declaration
public static Vector3 Slerp(Vector3 a, Vector3 b, float t);Параметры
| Параметр | Описание |
|---|---|
| a | Первое направление Vector3 для интерполяции. |
| b | Второе направление Vector3 для интерполяции. |
| t | Параметр интерполяции с ожидаемым значением в диапазоне [0,1]. |
Возвращаемое значение
Vector3 Полученное сферически интерполированное направление Vector3.
Описание
Сферически интерполирует между двумя трехмерными векторами.
Интерполирует между a и b на величину t. Разница между этой интерполяцией и линейной интерполяцией (также известной как "lerp") заключается в том, что векторы рассматриваются как направления, а не точки в пространстве. Направление возвращаемого вектора интерполируется по углу и его magnitude линейно интерполируется между величинами a и b.
Параметр t закреплен в диапазоне [0, 1]. Установка t==0 возвращает a, а установка t==1 возвращает b.
// Animates the position in an arc between sunrise and sunset.
using UnityEngine; using System.Collections;
public class Vector3SlerpExample : MonoBehaviour { public Transform sunrise; public Transform sunset;
// Time to move from sunrise to sunset position, in seconds. public float journeyTime = 1.0f;
// The time at which the animation started. private float startTime;
void Start() { // Note the time at the start of the animation. startTime = Time.time; }
void Update() { // The center of the arc Vector3 center = (sunrise.position + sunset.position) * 0.5F;
// move the center a bit downwards to make the arc vertical center -= new Vector3(0, 1, 0);
// Interpolate over the arc relative to center Vector3 riseRelCenter = sunrise.position - center; Vector3 setRelCenter = sunset.position - center;
// The fraction of the animation that has happened so far is // equal to the elapsed time divided by the desired time for // the total journey. float fracComplete = (Time.time - startTime) / journeyTime;
transform.position = Vector3.Slerp(riseRelCenter, setRelCenter, fracComplete); transform.position += center; } }
Дополнительные ресурсы: ,Lerp,, ,SlerpUnclamped,.