Quaternion.Slerp
2015-11-06 18:38
363 查看
Quaternion.Slerp
static Quaternion Slerp(Quaternion from, Quaternion to,float t);
Description
Spherically interpolates between fromand
toby t.从from到to在t位置的球状插值
using UnityEngine; using System.Collections; public class ExampleClass : MonoBehaviour { public Transform from; public Transform to; public float speed = 0.1F; void Update() { transform.rotation = Quaternion.Slerp(from.rotation, to.rotation, Time.time * speed); } }
这是untiy3d官方文档的介绍。我有不明白的地方,1是t的范围;2是例子t的赋值是Time.time * speed,Time.time是系统启动到现在的时间,可以很大。3是Slerp与Lerp的区别。
参考Vector.Slerp。1、t的范围 [0...1]。2、t的赋值应该与Time.deltaTime相关,才能达到平滑的过度。andVector3.Slerp
static Vector3 Slerp(Vector3 from, Vector3 to, float t);Description
Spherically interpolates between two vectors.两个向量的球状插值。Interpolates between [code]from
toby amount
t. The difference between this and linear interpolation (aka, "lerp") is that the vectors are treated as directions rather than points in space. The direction of the returned vector is interpolated by the angle and its magnitude is interpolated between the magnitudes of
fromand
to.从from到to在t位置的球状插值。于线性插值lerp不同的是向量被当做方向而不是空间中的点。返回的插值方向是在from和to间通过角度和幅度插值得到的。/t/ is clamped between [0...1]. See Also: Lerp function.using UnityEngine;
using System.Collections;
public class ExampleClass : MonoBehaviour {
public Transform sunrise;
public Transform sunset;
public float journeyTime = 1.0F;
private float startTime;
void Start() {
startTime = Time.time;
}
void Update() {
Vector3 center = (sunrise.position + sunset.position) * 0.5F;
center -= new Vector3(0, 1, 0);
Vector3 riseRelCenter = sunrise.position - center;
Vector3 setRelCenter = sunset.position - center;
float fracComplete = (Time.time - startTime) / journeyTime;
transform.position = Vector3.Slerp(riseRelCenter, setRelCenter, fracComplete);
transform.position += center;
}
}[/code]
3、参考andQuaternion.Lerp
static Quaternion Lerp(Quaternion from, Quaternion to, float t);Description
Interpolates between [code]from
toby
tand normalizes the result afterwards.从from到to在t位置的插值,然后标准化结果。This is faster than Slerp but looks worse if the rotations are far apart.这个比Slerp快,但是旋转很远的话很糟糕。using UnityEngine;
using System.Collections;
public class ExampleClass : MonoBehaviour {
public Transform from;
public Transform to;
public float speed = 0.1F;
void Update() {
transform.rotation = Quaternion.Lerp(from.rotation, to.rotation, Time.time * speed);
}
}[/code]
在网上查到的不同点:
Slerp:在from和to间通过角度和幅度插值得到的。Lerp:是线性插值。
相关文章推荐
- SlidingMenu
- 迷茫且鉴定——《不要等到毕业以后》读后感(1)
- VS-Visual Studio-IIS Express 支持局域网访问
- centos7 安装hadoop-cdh-2.6
- Android实战技巧之四十六:用patch更新Android Studio
- 《第一行代码Android》学习日记12
- final关键字
- git分支管理和stash
- Activity启动模式
- iOS本地通知
- tif转jpg
- 文章标题
- C语言文法推导
- 1106-冒泡算法程序分析树
- [LeetCode] Perfect Squares
- [翻译] [RabbitMQ+Python入门经典] 兔子和兔子窝
- Android5.1 -Recents分析
- iOS获取应用程序信息,版本号,程序名等
- nginx [warn]: conflicting server name on 0.0.0.0:80 ignored
- linux vim .bashrc 配置以及一些常用的linux 命令解析