android – 检测带有ARCore的tap事件是否命中已添加的3d对象

android – 检测带有ARCore的tap事件是否命中已添加的3d对象,第1张

概述我正在关注ARCore示例( https://github.com/google-ar/arcore-android-sdk),我正在尝试删除已添加对象3d(andy). 如何检测带有ARCore的点击事件是否会触发已添加的3d对象? 这几天我有同样的问题,我试过2个解决方案, 1. frame.hitTest(MotionEvent) 2.将arcore世界的顶点投影到视图中的2d坐标 首先, 我正在关注ARCore示例( https://github.com/google-ar/arcore-android-sdk),我正在尝试删除已添加的对象3d(andy).
如何检测带有ARCore的点击事件是否会触发已添加的3d对象?解决方法 这几天我有同样的问题,我试过2个解决方案,

1. frame.hitTest(MotionEvent)

2.将arcore世界的顶点投影到视图中的2d坐标

首先,我使用1.来获取平面上的命中姿势并与已存在的3d对象的姿势进行比较,但是一旦3d对象离开了平面,这将无法工作.

最后,我使用2.来获取视图上的3d对象的顶点,然后使用点击位置进行命中测试.

如果您正在关注ARCore示例,则可以在ObjectRenderer.java的draw方法中看到此行

Matrix.multiplyMM(mModelVIEwProjectionMatrix,cameraPerspective,mModelVIEwMatrix,0);

“mModelVIEwProjectionMatrix”只是使用此ModelVIEwProjection矩阵将已添加的3d对象的顶点从3d arcore世界映射到2d视图.

在我的情况下,我做这样的事情,

pose.toMatrix(mAnchorMatrix,0);objectRenderer.updateModelMatrix(mAnchorMatrix,1);objectRenderer.draw(cameraview,lightIntensity);float[] centerVertexOf3dobject = {0f,0f,1};float[] vertexResult = new float[4];Matrix.multiplyMV(vertexResult,objectRenderer.getModelVIEwProjectionMatrix(),centerVertexOf3dobject,0);// circle hit testfloat radius = (vIEwWIDth / 2) * (cubeHitArearadius/vertexResult[3]);float dx = event.getX() - (vIEwWIDth / 2) * (1 + vertexResult[0]/vertexResult[3]);float dy = event.getY() - (vIEwHeight / 2) * (1 - vertexResult[1]/vertexResult[3]);double distance = Math.sqrt(dx * dx + dy * dy);boolean isHit = distance < radius;

我在ARCore Measure应用程序中使用它,
https://play.google.com/store/apps/details?id=com.hl3hl3.arcoremeasure

和源代码,
https://github.com/hl3hl3/ARCoreMeasure/blob/master/app/src/main/java/com/hl3hl3/arcoremeasure/ArMeasureActivity.java

总结

以上是内存溢出为你收集整理的android – 检测带有ARCore的tap事件是否命中已添加的3d对象全部内容,希望文章能够帮你解决android – 检测带有ARCore的tap事件是否命中已添加的3d对象所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/web/1126118.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-30
下一篇 2022-05-30

发表评论

登录后才能评论

评论列表(0条)

保存