How to put an object in the air?

≡放荡痞女 提交于 2019-12-22 12:54:22

问题


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?


回答1:


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

"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())

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()

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.

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




回答2:


The reason why you see so often a hit result being interpreted as the desired position by the user is that actually there is no closed-form solution for this user interaction. Which of the infinite possible positions along the ray starting from the camera pointing towards the scene was desired by the User? 2D coordinates from a click still leave the third dimension undefined.

As you said "middle of the air", why not take the centre between the camera position and the hitresult? You can extract the current position using pose.getTranslation https://developers.google.com/ar/reference/java/com/google/ar/core/Pose.html#getTranslation(float[],%20int)



来源:https://stackoverflow.com/questions/46008630/how-to-put-an-object-in-the-air

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