1

I have a scene in which a human body is displayed. I want to zoom in to a specific body part when a user taps on it.

I changed the position of the camera to the position of Node but it points not exactly on it.

Also I need to keep the selected part in center of the screen when zoom in.

How can I accomplish zoom in / out?

rmaddy
  • 314,917
  • 42
  • 532
  • 579
Hassy
  • 5,068
  • 5
  • 38
  • 63

3 Answers3

2

I solved my problem by moving the camera instead of scaling the Model. I got the tap point by Gesture Recognizer and similarly the point of touch.

Now I converted the View-Coordinates to Scene Coordinates

CGPoint p = [gestureRecognize locationInView:scnView];

    NSArray *hitResults = [scnView hitTest:p options:nil];

    SCNVector3 projectedOrigin = [scnView projectPoint:SCNVector3Zero];

    SCNVector3 vector = SCNVector3Make(p.x, p.y, projectedOrigin.z);

    SCNVector3 worldPoint = [scnView unprojectPoint:vector];

and then positioned the Camera to the worldPoint.

Hassy
  • 5,068
  • 5
  • 38
  • 63
1

To reposition it in a Z-axis you want to multiply the currents node matrix with the new matrix.

var node = childNode.transform
var translation = SCNMatrix4MakeTranslation(1.0, 1.0, adjustedZValue)
var newTrans = SCNMatrix4Mult(node, translation)
childNode.transform = newTrans

Edit: Had some names mixed up

Vollan
  • 1,887
  • 11
  • 26
1

a bit cleaned up and more "swifty":

let transform = childNode.transform
let adjustedZValue = Float32(3)
let translation = SCNMatrix4MakeTranslation(1.0, 1.0, adjustedZValue)
let newTrans = SCNMatrix4Mult(transform, translation)
childNode.transform = newTrans
ingconti
  • 10,876
  • 3
  • 61
  • 48