2017-10-13 54 views

回答

1

我有同样的问题,这些天,我尝试过2个解决方案,

frame.hitTest(MotionEvent)

2.项目从ARCORE世界顶点到2d在视图坐标

起初我用1.在飞机上得到命中姿势,并与已经存在的3d物体的姿势进行比较,但一旦3d物体离开飞机,这将不起作用。

最后我用2.来查看3D物体的顶点,然后用水龙头位置做点击测试。

如果你正在跟踪的ARCORE样品,你可以看到这条线在ObjectRenderer.java的绘制方法

Matrix.multiplyMM(mModelViewProjectionMatrix, 0, 
        cameraPerspective, 0, mModelViewMatrix, 0); 

“mModelViewProjectionMatrix”只是用这个ModelViewProjection矩阵来映射您已经添加3D对象的顶点从3d弧光世界到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; 

我ARCORE测量应用程序中使用此,
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

相关问题