简体   繁体   English

SCNNode 根据位置显示更多/更少扭曲(SceneKit)

[英]SCNNode appears more/less warped depending on position (SceneKit)

I have a SceneKit scene in which the camera looks down at a single sphere that rolls around atop a flat plane.我有一个 SceneKit 场景,其中相机俯视一个在平面上滚动的单个球体。

The camera has the default configuration, and is positioned at SCNVector3(0.0, 0.0, 100.0) .相机具有默认配置,位于SCNVector3(0.0, 0.0, 100.0)

The sphere starts out in the center of the screen.球体从屏幕中心开始。 At this point, the sphere looks normal, as seen in this screenshot.此时,球体看起来很正常,如此屏幕截图所示。 在此处输入图像描述

But the farther away from the center it moves, the more warped/stretched it appears.但是它移动的离中心越远,它看起来越扭曲/拉伸。 As seen in this screenshot, the sphere appears warped (it looks like an egg) when it's near the edge of the screen.如此屏幕截图所示,当球体靠近屏幕边缘时,它会出现扭曲(看起来像鸡蛋)。 在此处输入图像描述

The sphere is configured like this:球体配置如下:

let ballNode = SCNNode()
let sphereGeometry = SCNSphere(radius: MainData.screenWidth*0.005)
let targetMaterial = SCNMaterial()

targetMaterial.diffuse.contents = UIColor.red
sphereGeometry.materials = [targetMaterial]
sphereGeometry.firstMaterial?.diffuse.contents = targetMaterial
ballNode.geometry = sphereGeometry
ballNode.geometry?.firstMaterial?.lightingModel = .phong
ballNode.position = SCNVector3(0.0,0.0,20.0)
        
ballNode.physicsBody = SCNPhysicsBody(type: SCNPhysicsBodyType.dynamic, shape: SCNPhysicsShape.init(node: ballNode))
ballNode.physicsBody?.categoryBitMask = CollisionTypes.dynamicObjects
ballNode.physicsBody?.collisionBitMask = CollisionTypes.staticObjects
ballNode.physicsBody?.contactTestBitMask = CollisionTypes.nothing
ballNode.physicsBody?.isAffectedByGravity = true
ballNode.physicsBody?.allowsResting = false
        
scnView.scene?.rootNode.addChildNode(ballNode)

The "plane" is actually just an SCNBox node, and is configured like this: “平面”实际上只是一个SCNBox节点,配置如下:

let platform = SCNNode()
let platformGeometry = SCNBox(width: MainData.screenWidth, height: MainData.screenHeight, length: 2.0, chamferRadius: 0.0)

platform.geometry = platformGeometry

 platform.physicsBody = SCNPhysicsBody(type: SCNPhysicsBodyType.static, shape: SCNPhysicsShape.init(node: platform))
platform.physicsBody?.categoryBitMask = CollisionTypes.staticObjects
platform.physicsBody?.collisionBitMask = CollisionTypes.dynamicObjects
platform.physicsBody?.contactTestBitMask = CollisionTypes.nothing
platform.physicsBody?.isAffectedByGravity = false
platform.physicsBody?.allowsResting = true

scnView.scene?.rootNode.addChildNode(platform)

Question: Why does the sphere appear warped (like an egg) the farther it travels from the center of the scene/screen?问题:为什么球体离场景/屏幕中心越远,就会出现扭曲(像鸡蛋一样)?

Thanks for your help!谢谢你的帮助!

我真的不明白为什么,但添加以下解决了这个问题:

cameraNode.camera?.fieldOfView = 20.0

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM