私はあなたが正確に何をしたいのかわからないんだけど、基本的に何をやっていることは(遊び場にコードを置く)です:
import UIKit
import SceneKit
import PlaygroundSupport
let scnView = SCNView(frame: CGRect(x: 0, y: 0, width: 500, height: 500))
scnView.autoenablesDefaultLighting = true
let scene = SCNScene()
scnView.scene = scene
let light = SCNLight()
light.type = .directional
let lightNode = SCNNode()
lightNode.light = light
scene.rootNode.addChildNode(lightNode)
let camera = SCNCamera()
let cameraNode = SCNNode()
cameraNode.camera = camera
cameraNode.position = SCNVector3(0,0,10)
scene.rootNode.addChildNode(cameraNode)
let box = SCNBox(width: 1, height: 1, length: 1, chamferRadius: 0)
let boxNode = SCNNode(geometry: box)
boxNode.geometry?.firstMaterial?.diffuse.contents = UIColor.red
scene.rootNode.addChildNode(boxNode)
let rotateAction = SCNAction.rotateBy(x: 0, y: -1, z: 5, duration: 1)
let repeatAction = SCNAction.repeatForever(rotateAction)
SCNTransaction.begin()
SCNTransaction.animationDuration = 1
boxNode.runAction(repeatAction)
SCNTransaction.commit()
PlaygroundPage.current.liveView = scnView
これが要件を満たしていません。 'rotateBy'は、ラジアン単位の角度だけ回転します。したがって、もしあなたがベクトル '(1 0 0)'を持っていて、それをy軸上に-1ラジアン、z軸上に5ラジアンだけ回転させると、 '(1 -1 5)'は得られませんが、 。 –
別の言い方をすると:元の質問に与えられた位置に2つのノードがあり、各ノードに球が含まれている場合、元の質問から望む場所に終わるように、 'rootNode'をどのように回転させる必要がありますか? –
空のノードに子ノードとして追加するだけで、空ノードをシーンrootNodeに追加します。その空のノードを回転させると、childNodesは同じ位置にとどまります。これがシーングラフの基本的な考え方です。詳細はこちらをご覧ください:https://en.wikipedia.org/wiki/Scene_graph –