示例:变换旋转空间
//世界空间转摄像机空间
Quaternion rotationCameraSpace = Quaternion.Inverse(CameraCache.Main.transform.rotation) * transform.Rotation;
//保持与摄像机相对旋转角不变
transform.Rotation = CameraCache.Main.transform.rotation * rotationCameraSpace;
示例:旋转3D向量
/// <summary>
/// Transform中的RotateAround()方法源代码。
/// point: 绕此点公转
/// axis: 旋转轴
/// angle: 旋转角度
/// </summary>
public void RotateAround(Vector3 point, Vector3 axis, float angle)
{
//当前位置
Vector3 vector = position;
//创建旋转四元数
Quaternion quaternion = Quaternion.AngleAxis(angle, axis);
//待旋转的向量
Vector3 vector2 = vector - point;
//旋转向量
vector2 = quaternion * vector2;
//新位置
vector = point + vector2;
position = vector;
RotateAroundInternal(axis, angle * ((float)Math.PI / 180f));
}