首页 > 代码库 > Quaternion

Quaternion

        /*Quaternion.Euler 欧拉角转换为四元数,以目标物体为原点,以自身X,Y旋转,并更新位置
        var temp = Quaternion.Euler(xAngle, yAngle, zAngle);
        var Pos = temp * distance + target.position;
        transform.rotation = temp;
        transform.position = Pos;
        */


        /*Quaternion.RotateTowards 由currentQuater-->targeQuater旋转,但是旋转的最大角度不能超过maxDegreesDelta
        targeQuater = Quaternion.Euler(xAngle, yAngle, zAngle);
        var temp= Quaternion.RotateTowards(currentQuater, targeQuater, 100);
        var Pos = temp * distance + target.position;
        transform.rotation = temp;
        transform.position = Pos;
        */


        /*Quaternion.AngleAxis 围绕某个轴旋转一定角度。缺点是只能以一个轴来旋转
        var temp = Quaternion.AngleAxis(30, target.up);
        transform.rotation = temp;
        transform.position = temp * distance + target.position;
        */


        /*Quaternion.FromToRotation 从一个向量到一个向量,问题是到了那个向量后,又会恢复到原向量
        var temp = Quaternion.FromToRotation(transform.forward, target.up);
        transform.rotation = temp;
        transform.position = temp * distance + target.position;
        */


        /*Quaternion.LerpUnclamped 对两个四元数线性插值 不过限制了只能取到整数 如果t以秒计算 会出现抖动现象
        targeQuater = Quaternion.Euler(xAngle, yAngle, zAngle);
        var temp = Quaternion.LerpUnclamped(currentQuater, targeQuater, 2);
        var Pos = temp * distance + target.position;
        transform.rotation = temp;
        transform.position = Pos;
        */


        /*Quaternion.LookRotation 看向一个向量 并且自身的Up方向始终和两者父向量的Up方向一致
        var temp= Quaternion.LookRotation(target.position, target.up);
        var Pos = temp * distance + target.position;
        transform.rotation = temp;
        transform.position = Pos;
        */

 四元数 复杂 却并不需要咱们去搞清楚它对每一个参数是如何变换的,仅仅根据需求给予相应的参数便可

 


 

 

Quaternion