问题
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?
回答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
回答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.
回答3:
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
来源:https://stackoverflow.com/questions/49870884/scenekit-zoom-in-out-to-selected-node-of-scene