我一直试图围绕Unity3d中指定的中心创建一个旋转矩阵,但是Matrix4x4类没有提供任何允许我这样做的函数,尽管C#确实提供了一个名为:
public void RotateAt(双角度,双centerX,双centerY);
它位于System.Windows.Media名称空间中,但在Unity3d中不可访问,有什么方法可以在Unity3d中创建相同的旋转矩阵吗?谢谢。
发布于 2018-12-26 18:40:45
围绕一个点创建一个旋转矩阵可以按照以下步骤进行:
这大致是指:
// Set the following variables according to your setup
Vector3 centerOfRotation = ...;
float angleOfRotation = ...;
Vector3 rotationAxis = ...;
// This should calculate the resulting matrix, as described in the answer
Matrix4x4 translationToCenterPoint = Matrix4x4.Translate(centerOfRotation);
Matrix4x4 rotation = Matrix4x4.Rotate(Quaternion.AngleAxis(angleOfRotation, rotationAxis));
Matrix4x4 translationBackToOrigin = Matrix4x4.Translate(-centerOfRotation);
Matrix4x4 resultMatrix = translationToCenterPoint * rotation * translationBackToOrigin;https://stackoverflow.com/questions/53935540
复制相似问题