【问题标题】:How do I rotate a SCNNode around a point?如何围绕一个点旋转 SCNNode?
【发布时间】:2018-02-27 12:52:01
【问题描述】:

我有一个 SCNNode - sceneNode - 它是 rootNode 的子节点,包含我所有的子节点。用户点击按钮后,我想围绕 y 轴上的某个点旋转场景。例如,相机的视角是已知的,我想将所有东西围绕相机旋转 90º。相机不再位于 0, 0, 0。

我尝试过使用 SCNMatrix4MakeTranslation 函数,然后更改欧拉角上的 y 值,但我无法让它按预期工作。

【问题讨论】:

  • 试试SKAction.rotateToAngle方法
  • 你的意思是像行星围绕太阳旋转的方式吗?

标签: ios rotation scenekit euler-angles


【解决方案1】:

您的问题相当模棱两可,如果您将整个场景“围绕相机”旋转 90 度,场景最终会靠近相机而您将看不到它。

要围绕一个点而不是它自己的枢轴旋转 SCNNode,如标题中的问题,创建一个将其移动到该点的平移矩阵,与 SCNNode 的旋转矩阵相乘,然后乘以平移矩阵。

但是,您可能想要做的是使用相机节点而不是场景节点执行基本相同的过程。这将使相机在场景节点周围移动,呈现场景在原地旋转的外观。

例如:

//get the current camera's transform and store it in cammat
GLKMatrix4 cammat = SCNMatrix4ToGLKMatrix4(self.myView.pointOfView.transform);

//create a rotation matrix of 90 degrees over axis Y
GLKQuaternion quaty = GLKQuaternionMakeWithAngleAndAxis(M_PI/2, 0, 1, 0);
GLKMatrix4 rotMat = GLKMatrix4MakeWithQuaternion(quaty);

//set the camera transform to rotMat * cammat, which basically rotates the camera first, and then moves it back to the same offset it was. 
self.myView.pointOfView.transform = SCNMatrix4FromGLKMatrix4(GLKMatrix4Multiply(rotMat, cammat));

【讨论】:

    猜你喜欢
    • 2020-04-07
    • 1970-01-01
    • 1970-01-01
    • 2023-04-03
    • 2017-03-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多