我想从SCNNode中检索屏幕坐标,这样我就可以在SpriteKit-overlay中使用这些坐标。 该节点是子节点。 当我旋转父节点的pivot时,projectPoint返回乱码结果。
SCNScene:
class ScenekitScene:SCNScene {
override init() {
super.init()
let nodeCamera = SCNNode()
nodeCamera.camera = SCNCamera()
rootNode.addChildNode(nodeCamera)
let geoPyramid = SCNPyramid(width: 0.2, height: 0.5, length: 0.2)
let nodeCenterOfUniverse = SCNNode(geometry: geoPyramid)
nodeCenterOfUniverse.position = SCNVector3(0, 0, -5)
nodeCenterOfUniverse.pivot = SCNMatrix4MakeRotation(CGFloat.pi/4, 0.0, 0.0, 1.0)
rootNode.addChildNode(nodeCenterOfUniverse)
let geoSphere = SCNSphere(radius: 0.3)
let nodePlanet = SCNNode(geometry: geoSphere)
nodePlanet.name = "planet"
nodePlanet.position = SCNVector3(2, 0, 0)
nodeCenterOfUniverse.addChildNode(nodePlanet)
}
required init?(coder aDecoder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
}
SCNSceneRenderDelegate:
extension ViewController:SCNSceneRendererDelegate {
func renderer(_ renderer: SCNSceneRenderer, didRenderScene scene: SCNScene, atTime time: TimeInterval) {
if let planet = scene.rootNode.childNode(withName: "planet", recursively: true) {
let position = planet.convertPosition(planet.position, to: scene.rootNode)
let screencoords = renderer.projectPoint(position)
print (screencoords)
# result:
# SCNVector3(x: 461.913848876953, y: 2.58612823486328, z: 0.808080852031708)
# y should clearly be more to the center of the screen somewhere between 100-200
}
}
}
有谁知道如何获得正确的屏幕坐标?
答案 0 :(得分:0)
看起来世界坐标中的行星位置不正确。 当我手动计算行星位置时,我会得到不同的结果,而projectPoints的工作方式与宣传的一样。 [我可能会发布一个关于worldTransform的不同问题]。
static class starton implements ActionListener {
//...
public void actionPerformed(ActionEvent e) {
button.setText("Press A Button");
button.setSize(button.getPreferredSize());
button.addKeyListener(...);
button.removeActionListener(this);
}
}