Scenekit - 放大/缩小到选定的场景节点 [英] scenekit - zoom in/out to selected node of scene

查看:63
本文介绍了Scenekit - 放大/缩小到选定的场景节点的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个显示人体的场景.当用户点击它时,我想放大到特定的身体部位.

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.

我将相机的位置更改为 Node 的位置,但它并不完全指向它.

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.

如何实现放大/缩小?

推荐答案

我通过移动相机而不是缩放模型解决了我的问题.我通过 Gesture Recognizer 获得了点击点和类似的触摸点.

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.

这篇关于Scenekit - 放大/缩小到选定的场景节点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆