如何将物体置于空中? [英] How to put an object in the air?

查看:31
本文介绍了如何将物体置于空中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

似乎 HitResult 只为我们提供了与表面(平面)或点云的交集.如何通过单击在空气中间获得一个点,从而使物体漂浮在空中?

It seems HitResult only gives us intersection with a surface (plane) or a point cloud. How can I get a point in the middle of air with my click, and thus put an object floating in the air?

推荐答案

这实际上取决于您所说的在空中"是什么意思.我看到了两种可能性:

It really depends on what you mean by "in the air". Two possibilities I see:

在检测到的表面之上" 对平面进行正常的命中测试,并将返回的姿势偏移一些 Y 距离以获得悬停位置.例如:

"Above a detected surface" Do a normal hit test against a plane, and offset the returned pose by some Y distance to get the hovering location. For example:

Pose.makeTranslation(0, 0.5f, 0).compose(hitResult.getHitPose())

返回命中位置上方 50 厘米的姿势.从这里创建一个锚点,你就可以开始了.您也可以只在命中位置创建锚点,并在每一帧中使用 y 平移进行组合,以便为悬停高度设置动画.

returns a pose that is 50cm above the hit location. Create an anchor from this and you're good to go. You also could just create the anchor at the hit location and compose with the y translation each frame to allow for animating the hover height.

浮动在当前设备位置的前面" 为此,您可能希望在相机姿势的右侧进行翻译:

"Floating in front of the current device position" For this you probably want to compose a translation on the right hand side of the camera pose:

frame.getPose().compose(Pose.makeTranslation(0, 0, -1.0f)).extractTranslation()

为您提供一个位于显示器中心前方 1m 处的仅平移姿势.如果你想在一个特定的屏幕位置前面,我在这个答案中放了一些代码来做屏幕指向世界光线转换.

gives you a translation-only pose that is 1m in front of the center of the display. If you want to be in front of a particular screen location, I put some code in this answer to do screen point to world ray conversion.

抱歉,如果您使用的是 Unity/Unreal,您的问题没有具体说明,所以我假设使用 Java.

Apologies if you're in Unity/Unreal, your question didn't specify so I assumed Java.

这篇关于如何将物体置于空中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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