awesome7 / XamAR

Cross-platform Augmented Reality (AR) SDK for Xamarin

Home Page:https://xamar.io

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

AR objects jitter and don't remain in position

Minneth opened this issue · comments

I'm testing the samples on Android but I'm noticing that the created AR objects are jittering and not staying in position. I've tested with all samples and I get the same issue on all. I'm using a Samsung S22 Ultra which should definitely be able to handle AR.

Any advice would be great, thanks.

About samples, first thing that comes to my mind is location problem.
We are currently using only GPS for positioning, and since it has margin of error, it could be the reason for such behavior.
It would help if you choose coordinates of destination object to be few kilometers from you current position. This should cancel that margin of error.

And, of course, you need to be in area where you have GPS signal (for example, it could be problem if you are in a building).

Can you give more details? Is object constantly moving (like running away from destination position), or is it moving around destination point (like it is close to it, but not steady). Does it move along Y axis (up and down)?

Many thanks for the response. I've now retested in another geographical location and also outdoors and unfortunately continue to get the same issue.

I have recorded a video to demonstrate the issue: https://youtube.com/shorts/iP87q2ptGT4

The code I'm using is pretty much as per the same, maybe modified slightly while I try to work out what is causing the issue - As you can see I am setting coordinates of the destination object, hopefully that's what you meant:

var world = XamAR.World.Instance; var sphere = world.CreateModel("sphere"); var location = new Location(53.5264209, -2.1839973, 10); IPositionSource positionSource = new FixedLocation(location); var sphereObject = world.AddModel(positionSource, sphere); sphereObject.DistanceOverride = new FixedDistance(2);

Many thanks for the response. I'm unsure how to scale the object, I've followed the guide to create a new Sphere Factory and set its radius to a large number, but when I then render out that object (which I've named something specific) I don't see any AR objects in my scene. I've also set the distance to a further distance as you've suggested but, even when I set the distance to close, I see nothing.

Android Project:
public class SphereFactory : ModelFactory { public override ARModel CreateModel() { var nodeSphere = new Node() { LocalPosition = new Google.AR.Sceneform.Math.Vector3() }; ModelRenderable model; MaterialFactory .MakeOpaqueWithColor(Android.App.Application.Context, new Color(100, 150, 40)).ThenAccept(new DelegateConsumer<Material>((m) => { model = ShapeFactory.MakeSphere(10000f, new Google.AR.Sceneform.Math.Vector3(0f, 0, 0), m); nodeSphere.Renderable = model; }) ); return nodeSphere.AsARModel(); } }

MainActivity:
FactoryService.RegisterFactory<SphereFactory>("minssphere");

Xamarin Forms:
`
protected override void OnAppearing()
{
base.OnAppearing();
var world = XamAR.World.Instance;
var sphere = world.CreateModel("minssphere");

var location = new Location(53.541501, -2.184694, 0);
IPositionSource positionSource = new FixedLocation(location);

var sphereObject = world.AddModel(positionSource, sphere);
}
`

Hello, sorry for delay.

I have tested by myself in test project, and similar thing happens.
Unfortunately, without deeper testing i can't provide you with exact answer. But, i think this happens because of small changes in GPS coordinates and all of calculations performed to place an object.

Current version of XamAR is using only GPS coordinates for positioning objects.
AR, in general terms, works with local environment. It scans surrounding space using camera and other sensors (like lidar), and then can place objects to more strict anchor points - using them, objects in AR world are much stable (no jitter as you are experiencing it).
We are trying to combine real world with AR world in a library which encapsulates all hard work and calculations, and gives user an APi which is easy to use and understand. Partially, current XamAR is doing exactly that, but we still need to integrate above-mentioned functionality.


One feature i would point out is DistanceOverride.
Wherever GPS location of sphere is, it will display it at provided distance (so it takes just direction of location). This should make debugging much easier.

Here is example:

var sphereObject = world.AddModel(positionSource, sphere);    
sphereObject.DistanceOverride = new FixedDistance(5f);    

// Add Point of interest as well.    
var poi = world.AddPointOfInterest(location, "TEST");    
poi.DistanceOverride = new XamAR.Core.Models.Distance.FixedDistance(2f);  

So you don't need to scale sphere, create it with 1m diameter and place it (for start) on 3 meters from you. You understand the idea...


Additionally, you can get current GPS location with

var currentLocation = XamAR.Core.Sensors.LocationMonitor.LastLocation;

And be sure to check this class for some helpful calculations

XamAR.Core.Geometry.GeolocationHelpers

Hopefully this is helpful. Feel free to post any additional questions.

Regards

What triggers the updates that make the objects "jitter"?
Is it just the phone's own location? If so, if I blocked all updates in LocationMonitor after the first location is read, would all objects stay in place?
I'm new to AR and it seems to me that once an object has a given offset, what makes it "move" are all changes to a "conversion" matrix: if I "blocked" this in XamAR (wherever that matrix is), would the objects stop changing their place?
Thank in you advance!