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

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

问题描述

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天全站免登陆