Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to put an object in the air?

Tags:

arcore

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?

like image 788
redpearl Avatar asked Dec 19 '22 04:12

redpearl


1 Answers

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.

like image 192
Ian M Avatar answered Jan 12 '23 13:01

Ian M