Vin*_*lla 6 android augmented-reality arcore
我正在关注ARCore示例(https://github.com/google-ar/arcore-android-sdk),并且正在尝试删除已添加的对象3d(andy)。如何检测带有ARCore的轻击事件是否击中了已添加的3d对象?
小智 3
我这几天也有同样的问题,尝试了2种解决方案,
1.frame.hitTest (MotionEvent)
2.将arcore世界的顶点投影到视图中的2d坐标
首先,我使用1.获取平面上的命中姿势,并与已存在的 3d 对象的姿势进行比较,但是一旦 3d 对象离开平面,这将不起作用。
最后,我使用2.获取视图中 3d 对象的顶点,然后使用点击位置进行命中测试。
如果您正在关注ARCore示例,您可以在ObjectRenderer.java的draw方法中看到这一行
Matrix.multiplyMM(mModelViewProjectionMatrix, 0,
cameraPerspective, 0, mModelViewMatrix, 0);
Run Code Online (Sandbox Code Playgroud)
“mModelViewProjectionMatrix”只需使用此 ModelViewProjection 矩阵将已添加的 3d 对象的顶点从 3d arcore 世界映射到 2d 视图。
就我而言,我做了这样的事情,
pose.toMatrix(mAnchorMatrix, 0);
objectRenderer.updateModelMatrix(mAnchorMatrix, 1);
objectRenderer.draw(cameraView, cameraPerspective, lightIntensity);
float[] centerVertexOf3dObject = {0f, 0f, 0f, 1};
float[] vertexResult = new float[4];
Matrix.multiplyMV(vertexResult, 0,
objectRenderer.getModelViewProjectionMatrix(), 0,
centerVertexOf3dObject, 0);
// circle hit test
float 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;
Run Code Online (Sandbox Code Playgroud)
我在 ARCore Measure 应用程序中使用它,
https://play.google.com/store/apps/details?id=com.hl3hl3.arcoremeasure
| 归档时间: |
|
| 查看次数: |
2327 次 |
| 最近记录: |