Christian Kreiter
Christian Kreiter

Reputation: 620

SceneKit – How to set the zoom on the default SCNCamera?

Basically put, my problem:

I have searched the Apple Docs for some form of "zoom" applied to the default camera, but I can't find one. I have also tried creating my own camera (instead of using the default one) but for other reasons, this will not work. I need to use the default camera, but I need to figure out how to remove this property of initial "zoom." Is it even possible to change certain values of the default camera without creating my own camera?


What do I mean by "zoom?":

When I say zoom, I'm referring to the fact that when I open the scene, I can't see very much. When I pinch my fingers inward, I "zoom out" of the scene so that I can see more (and the stuff in the distance gets smaller). See this image to further understand what I mean:

enter image description here

As you can see in this image, the left is what the default camera gives me every time I open the scene. What I instead want is on the right. It is "zoomed out."


What I have tried:

I have tried several things. Some of these are already explained above.

• First off, I have already tried to make my own camera instead of changing the values on the default camera. However, creating my own camera changes some other things in my app that I can't have. So what I really need is to change this "zoom" value on the default camera.

• I have also tried searching the Apple Docs for this variable/property. I cannot find anything that I need. Unless I am wrong. If it seems pretty obvious what the solution is, just tell it to me! Nothing is working for me (partly because I don't 100% know how to use all the SCNCamera settings).

• I have also tried offsetting everything backwards (-z) from the camera. "If I can't zoom out, then I'll just push everything farther away!" But no, this does not work. Again, it has to do with some of the other features in my app. I can't have it conflict with the other necessities of the game.


What do I need from you?:

I don't necessarily need some code. Code would, of course, be great! But it's not necessary. I just can't figure out how to access this property.

Also, if I am wrong in my reasoning at all, let me know. That way, I can more-easily figure out the solution on my own. For example, is it actually a "zoom" property, or is it merely the position of the camera changing when I pinch my fingers. What does pinching my fingers do, anyway? Can I mirror the pinching with a few lines of code, before the scene even displays? Etc etc.

Upvotes: 1

Views: 3154

Answers (1)

Sergiy Shilingov
Sergiy Shilingov

Reputation: 125

Try adding a Camera Node, and then add it to your SceneView:

//add Camera Node
let cameraNode = SCNNode()
cameraNode.camera = SCNCamera()

// Add Camera Node Position
cameraNode.position = SCNVector3(x: 0, y: 0, z: 50)

//add Camera Node to SceneView
scene.rootNode.addChildNode(cameraNode)
sceneView.scene = scene

Upvotes: 3

Related Questions