Seif Selmi
Seif Selmi

Reputation: 77

Xamarin ARcore change position of 3D object

I am trying to implement ARcore with Xamarin and want to set a 3D object in a specific geolocation (like in pokemongo). I tried to go through this sample that I found in this forum: https://blog.xamarin.com/augmented-reality-xamarin-android-arcore/ but it seems that I can't change the position of the 3d object and it is set according to the tap gesture only on a plane.

Is there a way to place an object and track it? I did manage to do that with ARkit, but until now no success for the ARcore Android.

Any ideas would be helpful.

Upvotes: 1

Views: 733

Answers (1)

ACVM
ACVM

Reputation: 1527

It looks like the Xamarin wrapper for ARCore simply wraps OpenGL. As a result, drawing the object requires setting multiple matrices (Model, View and Projection) matrices:

objectRenderer.UpdateModelMatrix(anchorMatrix, scaleFactor);
objectRenderer.Draw(viewMatrix, projectionMatrix, lightIntensity);

If you simply remove this from within the foreach (var planeAttachment in planeAttachments) { loop, then you can set the anchorMatrix (a.k.a. the modelMatrix) to a fixed/hardcoded translation then it'll fix itself relative to the camera.

Here's a decent article on View matrices: https://www.3dgep.com/understanding-the-view-matrix/#The_View_Matrix

-- Begin Shameless Plug --

However, if you are open to trying new platforms, my team has built a cross-platform React-Native library for AR/VR development (Viro React): https://viromedia.com/viroreact/

If you're more familiar with SceneKit on iOS, we have built an analogous solution on Android w/ AR/VR support (ViroCore): https://viromedia.com/virocore/

Either solution would allow you to skip over the intricacies of OpenGL and simply position your objects/models with relative ease.

ie.

Placing your model 1 meter in front of you would be as simple as (in Viro React):

<Viro3dObject source={require("./res/model.obj")} position={[0,0,-1]} type="OBJ" />

Upvotes: 2

Related Questions