简体   繁体   中英

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.

The camera has the default configuration, and is positioned at 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:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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