首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Matrix.RotateAt in Unity3d

Matrix.RotateAt in Unity3d
EN

Stack Overflow用户
提问于 2018-12-26 18:09:59
回答 1查看 553关注 0票数 3

我一直试图围绕Unity3d中指定的中心创建一个旋转矩阵,但是Matrix4x4类没有提供任何允许我这样做的函数,尽管C#确实提供了一个名为:

public void RotateAt(双角度,双centerX,双centerY);

它位于System.Windows.Media名称空间中,但在Unity3d中不可访问,有什么方法可以在Unity3d中创建相同的旋转矩阵吗?谢谢。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2018-12-26 18:40:45

围绕一个点创建一个旋转矩阵可以按照以下步骤进行:

  • 把这个矩阵转到你想让它旋转的地方。
  • 旋转矩阵。
  • 将矩阵转换回原点。

这大致是指:

代码语言:javascript
复制
// 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;
票数 3
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/53935540

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档