viro
viro copied to clipboard
Move object along detected ground plane via camera center (without dragging/touch events)
Environment
- Development OS: Mac (OS:
Ventura 13.3.1 (a)
) - Device OS & Version: Android 12
- Version: ViroReact:
2.23.0
, React Native:0.71.7
, React:18.2.0
- Device(s): Samsung Galaxy A71 (
SM-A715F
)
Description
I would like to place an object (in my case, a simple ViroBox
) on a ground plane that has been before detected manually. For this, I would need to continuously determine a 3D position on (/relative to) said ground floor (which itself is a very thing ViroBox
) based on which direction the camera is currently facing.
I am aware that this could be achieved by using a drag plane, but need to avoid any user interaction except rotating the device, so manually dragging the object along the ground plane is not an option.
I tried to illustrate the issue in the following image:
Possible Approaches
1: ViroARScene.performARHitTestWithPoint(x,y)
- The array of
ARHitTestResult
objects returned from callingperformARHitTestWithPoint()
for my scene only returns anything I can work with (withtype
being eitherExistingPlaneUsingExtent
orExistingPlane
) when the camera center is really close to the ground plane's origin. - Since I can't control the size of the detected anchor that defines my ground plane, this method can't be used in a way that works for all cases ❌
2: ViroARScene.getCameraOrientationAsync()
+ ViroBox.getTransformAsync()
- The current camera position & orientation can be determined with the
ViroARScene.getCameraOrientationAsync()
function, - the current ground plane's rotation can be determined with the
ViroBox.getTransformAsync()
function. - It may be possible to use these 2 infos to cast a ray from the current camera center onto the ground plane, but I don't know how to since my vector math is kind of bad.
So basically my question is: Can I (and if yes, how) "convert" the camera center (a 2D point) to a 3D point (either in world coordinates, or relative to my found anchor) in my Viro 3D scene?
Thank you for any insights and this great library in general!