找出锚点是否在当前屏幕中可见 [英] Figuring out if Anchor is visible in current screen

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

问题描述

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

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 .

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

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