0

I have an object on SCNScene and I want the user to zoom in/out on specific parts using double tap and I thought of two options:

  1. Make the camera itself move to that part, similar to that question, scenekit - zoom in/out to selected node of scene
    and It didn't zoom out when I took this approach or even zoom in accurately.
  2. Add camera node in front of each part, so when the user tap on a part it should reposition the default camera of the scene to the configured camera I added, but I was thinking this would affect the performance due to the nodes I keep adding. Should I try this?

This is the code I tried to the first approach.

  @objc
    internal func handleTapGesture(_ gestureRecognizer: UIGestureRecognizer) {
        let hitPoint = gestureRecognizer.location(in: sceneViewVehicle)
        let hitResults = sceneViewVehicle.hitTest(hitPoint, options: nil)
    
        if hitResults.count > 0 {
            let result = hitResults.first!
            let scale = CGFloat(result.node.simdScale.y)

              switch gestureRecognizer.state {
                case .changed: fallthrough
                case .ended:
                           cameraNode.camera?.multiplyFOV(by: scale)
              default: break
                        }
}

Adding the Gesture

 let tapGesture = UITapGestureRecognizer(target: self, action: #selector(handleTapGesture(_:)))
       tapGesture.numberOfTapsRequired = 2
       sceneViewVehicle.addGestureRecognizer(tapGesture)

Zooming for camera

extension SCNCamera {
    public func setFOV(_ value: CGFloat) {
            fieldOfView = value
    }
    
    public func multiplyFOV(by multiplier: CGFloat) {
            fieldOfView *= multiplier
    }
}
esraaed
  • 41
  • 1
  • 8
  • I build a camera class like here: 55129224, just a basic one and if you can focus on a node, then it's just about the distance with some basic math - if I'm understanding this correctly. – Voltan Aug 06 '20 at 20:24
  • @Voltan Thank you for your answer, yeah I manged to position the camera correctly, but I'm kinda confused which approach I should take. Did you reposition camera every time user double tap on a part? – esraaed Aug 09 '20 at 07:46
  • Yeah, I don't exactly have a visual here - but seems like as long as you don't confuse the user, certainly isn't an issue to move the camera often. Something you could do to avoid a snap to feel - once you know where you want it, you could do an SCN action and move it in a bit slower... kind of ease the transition maybe, cool effect if that works for you – Voltan Aug 09 '20 at 15:08
  • I found a solution similar to my case here .. https://stackoverflow.com/questions/56736387/move-camera-to-tapped-scnnode – esraaed Aug 19 '20 at 16:14

0 Answers0