gpt4 book ai didi

swift - 节点不旋转?

转载 作者:行者123 更新时间:2023-11-30 12:48:45 24 4
gpt4 key购买 nike

当我运行应用程序时,节点不旋转。无论我将旋转更改为什么,节点都将保持在“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)

}

}

最佳答案

要绕 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)

关于swift - 节点不旋转?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41293196/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com