lhs | 左侧四元数。 |
rhs | 右侧四元数。 |
组合旋转 lhs
和 rhs
。
通过乘积 lhs
* rhs
进行旋转等同于按顺序应用两个旋转:先应用 lhs
,然后应用 rhs
,相对于由 lhs
旋转产生的参考系。请注意,这意味着旋转不是可交换的,因此 lhs
* rhs
与 rhs
* lhs
产生的旋转不同。
using UnityEngine; using System.Collections;
public class Example2 : MonoBehaviour { float rotateSpeed = 90;
// Applies a rotation of 90 degrees per second around the local Y axis void Update() { float angle = rotateSpeed * Time.deltaTime; transform.rotation *= Quaternion.AngleAxis(angle, Vector3.up); } }
使用 rotation
旋转点 point
。
using UnityEngine; using System.Collections;
public class Example2 : MonoBehaviour { private void Start() { //Creates an array of three points forming a triangle Vector3[] points = new Vector3[] { new Vector3(-1, -1, 0), new Vector3(1, -1, 0), new Vector3(0, 1, 0) };
//Creates a Quaternion rotation of 5 degrees around the Z axis Quaternion rotation = Quaternion.AngleAxis(5, Vector3.forward);
//Loop through the array of Vector3s and apply the rotation for (int n = 0; n < points.Length; n++) { Vector3 rotatedPoint = rotation * points[n]; //Output the new rotation values Debug.Log("Point " + n + " rotated: " + rotatedPoint); } } }