com.google.ar.sceneform.HitTestResult Java Examples

The following examples show how to use com.google.ar.sceneform.HitTestResult. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: LightingActivity.java    From sceneform-samples with Apache License 2.0 6 votes vote down vote up
private Node createMenuNode(Node node, Vector3 localPosition) {
  Node menu = new Node();
  menu.setParent(node);
  addMenuToNode(menu, localPosition);
  node.setOnTapListener(
      new OnTapListener() {
        @Override
        public void onTap(HitTestResult hitTestResult, MotionEvent motionEvent) {
          menu.setEnabled(!menu.isEnabled());
          if (openMenuNode != null) {
            openMenuNode.setEnabled(false);
            openMenuNode = (openMenuNode == menu) ? null : menu;
          } else {
            openMenuNode = menu;
          }
        }
      });
  return menu;
}
 
Example #2
Source File: LocationNode.java    From ARCore-Location with MIT License 6 votes vote down vote up
private boolean isOverlapping(Node n, Ray ray, Vector3 target, Vector3 cameraPosition) {
    Vector3 nodeDirection = Vector3.subtract(target, cameraPosition);
    ray.setDirection(nodeDirection);

    ArrayList<HitTestResult> hitTestResults = locationScene.mArSceneView.getScene().hitTestAll(ray);
    if (hitTestResults.size() > 0) {

        HitTestResult closestHit = null;
        for (HitTestResult hit : hitTestResults) {
            //Get the closest hit on enabled Node
            if (hit.getNode() != null && hit.getNode().isEnabled()) {
                closestHit = hit;
                break;
            }
        }

        // if closest hit is not the current node, it is hidden behind another node that is closer
        return closestHit != null && closestHit.getNode() != n;
    }
    return false;
}