Search code examples
iosscenekitscnnodescncamera

Change "field of view" in SceneKit


I have some camera with perspective projection and object in the (0,0,0). I computed "bounding frame"(size in pixels on screen) of this object according to this camera and scaled it to fit the screen size. And now it in the middle of screen.

Frame of the scnView is equal to the screen size and I have some UI components above this view(e.g. navigation bar and some big transparent view in the bottom of view). The scnView has some fullscreen background and this object can be scaled/moved/... therefore I need scnview to be fullscreen.

smth like that

Then I move this object in the middle of "clear area" (the area with absence of UIComponents) and see the bottom of this object (as if it's above me), because my projection is perspective.

I want to move this object in the center of clear area and see like it's in front of me without any distortion. How can I achieve that?

enter image description here

I see 2 solutions. 1) Draw my object offscreen in texture and after that draw this texture on screen in required position. 2) create scnView a bit taller. For example set frame size to = (0, (bottomHeight - topHeight) / 2, width, height + (bottomHeight - topHeight) / 2) to move the center of scnView in required position.

But I don't like first solution due to addition draw call and second solution even sounds crappy.

P.S. sorry for that pictures

Update: Basically I want to use perspective projection and move 3D object like a 2D image in SceneKit.


Solution

  • Solved it by changing camera projectionTransform. Smth like:

    let newMatrix = SCNMatrix4Mult(initialProjectionCameraMatrix, translationMatrix)