SceneKit,相机方向和几何体之间的“命中"测试 [英] SceneKit, 'hit' testing between camera orientation and geometry

查看:49
本文介绍了SceneKit,相机方向和几何体之间的“命中"测试的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在关注 David Roonqvist 的 3D Graphics with SceneKit 书籍.

I'm currently following David Roonqvist's 3D Graphics with SceneKit book.

第 5 章涉及命中测试,实现它没有问题,但仅涉及他对鼠标事件的测试.

Chapter 5 deals with hit testing, no issues implementing it, but only deals with his testing from mouse events.

现在,我知道我的相机的方向将始终与某个几何体相交.

Now, I know my camera's orientation will ALWAYS intersect a certain geometry.

我需要获取相机方向和几何体相交点的纹理坐标.

I need to obtain the texture coordinate of the intersecting point between the camera orientation and the geometry.

任何关于如何去做的指示?我一直在寻找,但没有取得多大成功.

Any pointers as how to go about it? I've been looking all over without much success.

感谢任何帮助.

推荐答案

我还没试过这个但是...

I haven't tried this but...

SCNHitTestResult 返回,其中包括 textureCoordinatesWithMappingChannel(_:).文档引用了在游戏角色被激光击中后为其纹理添加焦痕的示例.

SCNHitTestResult returns, among other things, textureCoordinatesWithMappingChannel(_:). Documentation cites the example of adding scorch marks to a game character's texture after it's been hit by a laser.

看来SCNNode

hitTestWithSegmentFromPoint(_ pointA: SCNVector3,
                     toPoint pointB: SCNVector3,
                     options options: [String : AnyObject]?) -> [SCNHitTestResult]

无论相机的方向如何,都会在相机和几何体之间为您提供所需的命中.如果相机和目标使用不同的局部节点坐标系,则必须使用 convertPosition(_:from:Node:) 或类似函数进行一些转换.

will give you the hits you need, between the camera and the geometry, regardless of the orientation of the camera. If the camera and the target are using different local node coordinate systems, you'll have to do some conversion using convertPosition(_:from:Node:) or similar functions.

这篇关于SceneKit,相机方向和几何体之间的“命中"测试的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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