unity3d 四元数最直观的用法(旋转)
2017-04-21 16:50
218 查看
本文通过网上查阅资料,通过自己的理解。把四元数最直接的用法记录下来
Vector3.right(right可以改为left,up,down,fwd,forward)具体向什么方向旋转,自己去测试
下面是一个左右摆动的例子:
gameObject.transform.rotation = Quaternion.Euler(30, 0, 0);//旋转x轴角度 gameObject.transform.rotation = Quaternion.EulerAngles(π/n, 0, 0); //π/n(n是整数,得到角度 1=57.3度 gameObject.transform.rotation = Quaternion.AngleAxis(30, Vector3.right);//旋转x角度
Vector3.right(right可以改为left,up,down,fwd,forward)具体向什么方向旋转,自己去测试
下面是一个左右摆动的例子:
private float time0 = 0; private float change; void Update () { time0 += Time.deltaTime; //左右摆动 change = Mathf.Repeat(time0 * 0.4f, 2);//从0数到2,循环,比下面的时间慢一倍 if (change >= 1) { gameObject.transform.rotation = Quaternion.EulerAngles(Mathf.PingPong(time0 * 0.8f, 1), 0, 0); } else { gameObject.transform.rotation = Quaternion.EulerAngles(-1 * Mathf.PingPong(time0 * 0.8f, 1), 0, 0); } }
相关文章推荐
- unity3d 相机围绕某个物体旋转,四元数*位置
- Unity3D 四元数旋转使用 Quaternion
- unity3d四元数和旋转矩阵
- unity3d中用四元数 Quaternion来对一个坐标点进行旋转的初步体会
- [unity3D基础知识]之Quaternion(四元数)和旋转
- Unity的旋转-四元数,欧拉角用法简介
- unity3d中Find的用法
- 旋转与四元数
- UIDeviceOrientation 和 UIInterfaceOrientation 设备旋转的用法 (实例)
- Unity3D地形建模插件World Composer用法(大范围地形建模)
- 008-实现Unity3d中使用LeanTouch插件进行触屏控制(拖拽、移动、缩放旋转...)
- 四元数与旋转
- 【Unity3D】设置自动旋转屏幕默认旋转方向
- unity3d Lerp 用法
- 【Unity技巧】四元数(Quaternion)和旋转
- unity3d 状态存储 PlayerPrefs高级用法
- Unity3D-VR人物瞬移、脚丫旋转判定、高光、开关灯、门、电视
- 四元数旋转公式的证明
- Unity3D中Ragdoll的用法
- Unity3d控制物体的旋转以及缩放