确定 Anchor 在当前屏幕中是否可见 [英] Figuring out if Anchor is visible in current screen

查看:32
本文介绍了确定 Anchor 在当前屏幕中是否可见的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 ARCore 构建我的 android 应用程序,我允许用户在其中放置锚点.我需要能够检查 Anchor 是否在当前帧中.知道我该怎么做吗?谢谢!

I'm using ARCore to build my android app, where I allowing users to place anchors. I need to be able to check if the Anchor is in the current frame. Any idea how can I do it? Thanks!

推荐答案

如果您使用的是 ARCore,您可能会在不渲染不在可视空间内的对象的情况下进行视锥体剔除,这是使用的优化阻止您调用 gl 来渲染场景的不可见"元素.

If you're using ARCore, you're probably doing frustum culling where you don't render objects that aren't within the viewable space, an optimization used to stop you from making gl calls to render "unviewable" elements of your scene.

如果在渲染器计算完之后您可以访问对象,那么您可以使用该值.

If you have access to the objects after the renderer calculates this, then you can use that value.

另一种方法是抓取相机并获取视图和投影矩阵.然后,您可以将锚点坐标投影到 2D 屏幕坐标上,如果计算出的坐标在屏幕之外(即 x/y 值 > 或 <屏幕宽度/高度).您还必须考虑相机后面的物体(相机前向和从相机到锚点的矢量之间的点积应该为正).

Another way you can do this, is by grabbing the Camera and getting the View and Projection matrices. Then you can project the anchor coordinates onto 2D screen coordinates and if the calculated coordinates are outside the screen (ie. x/y values are > or < the screen width/height). You'll have to account for objects that are behind the camera too (the dot product between the camera forward and vector from camera to anchor should be positive).

https://developers.google.com/ar/reference/java/com/google/ar/core/Camera.html.

这篇关于确定 Anchor 在当前屏幕中是否可见的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆