在Java ARCore中,世界单位是米(我只是意识到我们可能不会对此进行记录… aaa,看起来像不行。 糟糕
,提交了错误)。通过减去两个
Poses 的平移分量,可以得到它们之间的距离。您的代码如下所示:
首次命中为
hitResult:
startAnchor = session.addAnchor(hitResult.getHitPose());
第二击为
hitResult:
Pose startPose = startAnchor.getPose();Pose endPose = hitResult.getHitPose();// Clean up the anchorsession.removeAnchors(Collections.singleton(startAnchor));startAnchor = null;// Compute the difference vector between the two hit locations.float dx = startPose.tx() - endPose.tx();float dy = startPose.ty() - endPose.ty();float dz = startPose.tz() - endPose.tz();// Compute the straight-line distance.float distanceMeters = (float) Math.sqrt(dx*dx + dy*dy + dz*dz);
假设这些命中结果不在同一帧上发生,那么创建一个
Anchor至关重要,因为每次调用时都可以重塑虚拟世界
Session.update()。通过使用锚点而不是仅使用Pose保持该位置,其Pose将更新以在这些重塑过程中跟踪物理特征。



