Sceneform Collisions With Camera

淺唱寂寞╮ 提交于 2019-12-10 10:42:23

问题


I'm stretching my very limited ARCore knowledge.

My question is similar (but different) to this question


I want to work out if my device camera node intersects/overlaps with my other nodes, but I've not been having any luck so far

I'm trying something like this (the camera is another node):

  scene.setOnUpdateListener(frameTime -> {
        Node x = scene.overlapTest(scene.getCamera());
        if (x != null) {
            Log.i(TAG, "setUpArComponents: CAMERA HIT DETECTED at: " + x.getName());
            logNodeStatus(x);
        }
    });

Firstly, does this make sense?

I can detect all node collisions in my scene using:

for (Node node : nodes) {
        ...
        ArrayList<Node> results = scene.overlapTestAll(node);
        ...
} 

Assuming that there isn't a renderable for the Camera node (so no default collision shape), I tried to set my own collision shape, but this was actually catching all the tap events I was trying to perform, so I figured I must be doing this wrong.

I'm thinking about things like fixing a deactivated node in front of the camera.

I may be asking for too much of ARCore, but has anyone found a way to detect a collision between the "user" (i.e. camera node) and another node? Or should I be doing this "collision detection" via indoor positioning instead?

Thanks in advance :)

UPDATE: it's really hacky and performance-heavy, but you can actually compare the camera's and node's world space positions from within onUpdate inside a node, you'll probably have to manage some tolerance and other things to smooth out interactions.


回答1:


One idea to do the same thing is to use a raycast to hit the objects and if they are close do something. You could use something like this in the onUpdateListener:

Camera camera = arSceneView.getScene().getCamera();
Ray ray = new Ray(camera.getWorldPosition(), camera.getForward());
HitTestResult result = arSceneView.getScene().hitTest(ray);
if (result.getNode() != null && result.getDistance() <= SOME_THRESHOLD) {
  // Hit something
  doSomething (result.getNode());
} 


来源:https://stackoverflow.com/questions/51324954/sceneform-collisions-with-camera

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!