【问题标题】:Node not rotating?节点不旋转?
【发布时间】:2017-05-08 16:08:27
【问题描述】:

运行应用程序时节点不旋转。无论我将旋转更改为什么,节点都将保持在“0,0,0,0”处。

class CustomSCNNode: SCNNode {



var positionToSlideFrom = SCNVector3Zero

convenience init(geometry: SCNGeometry, initialPosition: SCNVector3, rotation: Float) {
    self.init()
    self.geometry = geometry
    self.position = initialPosition
    self.positionToSlideFrom = initialPosition
    self.rotation.y = rotation


}

}

//传递给GeometryNodes的节点由用户移动。这是什么都没有发生的地方!

class GeometryNodes {


let sphere = CustomSCNNode(geometry: SCNSphere(radius: 0.05), initialPosition: SCNVector3(0,1.3,0), rotation: -45)

func addNodesTo(_ parentNode: SCNNode) {
    sphere.rotation.y = -45
    parentNode.addChildNode(sphere)

}

func slideFunction(_ node: CustomSCNNode, translation: Float) {
    //Can't add anything yet due to rotation not working

  }
func slideFunction2(_ node: SCNNode, translation: Float) {

    node.position.z =  translation
    //node.position.x =  translation

}

func slide(xTranslation: Float) {

    slideFunction(sphere, translation: xTranslation)
}
func slide2(zTranslation: Float) {
    //let gameScene = BallScene()
    slideFunction2(sphere, translation: zTranslation)

}

}

【问题讨论】:

    标签: swift rotation scenekit


    【解决方案1】:

    要绕 Y 轴旋转 45 度,您需要将旋转指定为:

    self.rotation = SCNVector4Make(0, 1, 0, 45 * M_PI / 180.0)
    

    如果您围绕 X 或 Z 轴旋转,同样确保正确表达 XYZ 轴。

    或者,您也可以使用eulerAngles 属性来指定旋转:

    self.euelerAngles = SCNVector3Make(0, 45 * M_PI / 180.0, 0)
    

    【讨论】:

      猜你喜欢
      • 2018-12-17
      • 2018-01-31
      • 1970-01-01
      • 2015-07-10
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多