代码之家  ›  专栏  ›  技术社区  ›  Hassy

scenekit-放大/缩小到场景的选定节点

  •  1
  • Hassy  · 技术社区  · 7 年前

    我有一个展示人体的场景。我想在用户点击时放大到特定的身体部位。

    我将相机的位置更改为节点的位置,但它并不完全指向它。

    此外,我需要在放大时将选定的部分保持在屏幕中央。

    如何实现放大/缩小?

    3 回复  |  直到 7 年前
        1
  •  1
  •   Vollan    7 年前

    要在Z轴上重新定位,需要将当前节点矩阵与新矩阵相乘。

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

    编辑:有些名字混淆了

        2
  •  1
  •   Hassy    7 年前

    我通过移动相机而不是缩放模型来解决问题。我通过手势识别器得到了轻触点,同样也得到了触摸点。

    现在,我将视图坐标转换为场景坐标

    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];
    

    然后将相机定位到世界点。

        3
  •  0
  •   ingconti    6 年前

    稍微清理一下,更“快速”:

    let transform = childNode.transform
    let adjustedZValue = Float32(3)
    let translation = SCNMatrix4MakeTranslation(1.0, 1.0, adjustedZValue)
    let newTrans = SCNMatrix4Mult(transform, translation)
    childNode.transform = newTrans