ios - 尽管相机和节点共享原点,但 SceneKit 相机旋转错误

标签 ios swift scenekit

我正在玩 SceneKit 试图制作星空。以下是一些带有坐标的样本星:

Name: Alpheratz, X: 25.9746 Y: 0.951042 Z: 14.4613
Name: Caph, X: 8.60001 Y: 0.344589 Z: 14.4095
Name: Algenib, X: 115.664 Y: 6.68732 Z: 31.4421
Name: Ankaa, X: 19.0837 Y: 2.19828 Z: -17.4833
Name: Shedir, X: 37.9848 Y: 6.78448 Z: 58.3796
Name: Diphda, X: 27.5836 Y: 5.31046 Z: -9.11979
Name: 96 G. Psc, X: 7.25837 Y: 1.5555 Z: 0.686093
Name: Van Maanen's Star, X: 4.14696 Y: 0.903519 Z: 0.400348
Name: Cih, X: 79.8367 Y: 20.168 Z: 146.837

(坐标来自HYG Database.)

SceneView 只是添加到 Storyboard中的全窗口 View 。场景、相机等的设置是这样的:

let scene = SCNScene()
sceneView.scene = scene
let camera = SCNCamera()
camera.usesOrthographicProjection = true
let cameraNode = SCNNode()
cameraNode.camera = camera
cameraNode.position = SCNVector3Make(0.0, 0.0, 0.0)
scene.rootNode.addChildNode(cameraNode)

然后我为每颗星做:

        let starGeometry = SCNSphere(radius: CGFloat(1.0))
        let starNode = SCNNode(geometry: starGeometry)
        starNode.transform = SCNMatrix4MakeTranslation(star.cartesianX.floatValue, star.cartesianY.floatValue, star.cartesianZ.floatValue)
        scene.rootNode.addChildNode(starNode)

这会在 View 中产生一些带阴影的球体,但它们似乎在错误的位置,并且它们围绕屏幕右侧某处的一个点旋转。

我希望看到的是所有围绕相机旋转的球体。当他们移动时,他们不应该改变外观大小或摆动离开相机,这是他们所做的。随着绘制的星星越来越多,即使在完全缩小时也很难找到任何东西,一旦应用平移,一切都会消失。

如何将相机固定在原点,所有物体都围绕原点定位,以便它们围绕该点旋转?

最佳答案

What I expect to see is all the spheres rotating around the camera. As they move they should not change apparent size or swing away from the camera which is what they do. As more stars are plotted it gets harder to find anything to see even when fully zoomed out and as soon as a pan is applied everything disappears.

相机行为是如何实现的? 您绝对不应该依赖 allowsCameraControl,这有助于快速入门。

关于ios - 尽管相机和节点共享原点,但 SceneKit 相机旋转错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29909338/

相关文章:

swift - 从字典数组中删除重复值

string - Swift REPL 意外行为

ios - 如何创建逼真的 .scn 文件?

ios - 为什么 UITableView 和 UIScrollView 的 bounds 属性中的 "Y"值最初是 "-64"?

ios - NSMutableDictionary 键值打乱

javascript - iOS:如何以编程方式触发 web View 中文本字段的输入

swift - 在 SceneKit 中绘制 3D 圆弧和螺旋线

ios - Scene Kit节点不旋转

iphone - 如何使用 Graph API 在 iphone 中获取 Facebook 好友的在线状态。?

ios - 缺少 64 位支持。应用商店提交错误