Quaternion.Slerp

Quaternion.Slerp

static  Quaternion  Slerp( Quaternion  fromQuaternion  to, float  t);

Description

Spherically interpolates between from and to by 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相关,才能达到平滑的过度。
  
  

Vector3.Slerp

static  Vector3  Slerp( Vector3  fromVector3  to, float  t);

Description

Spherically interpolates between two vectors.两个向量的球状插值。

Interpolates between from and to by 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 from and 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;
    }
}
3、参考
    
    

Quaternion.Lerp

static  Quaternion  Lerp( Quaternion  fromQuaternion  to, float  t);

Description

Interpolates between from and to by t and 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);
    }
}
在网上查到的不同点:
Slerp:在from和to间通过角度和幅度插值得到的。Lerp:是线性插值。
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值