awesome7 / XamAR

Cross-platform Augmented Reality (AR) SDK for Xamarin
https://xamar.io
MIT License
33 stars 6 forks source link

AR objects jitter and don't remain in position #75

Open Minneth opened 2 years ago

Minneth commented 2 years ago

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.

miki-bgd commented 2 years ago

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

Minneth commented 2 years ago

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

miki-bgd commented 2 years ago

Hi, thanks for the video. This seems ok, you define GPS location, put object there, and then override distance so it is always displayed 2 metres from you (in direction of location). What is not looking right is that height, which i will need to check.

I am currently on holiday, will get back to you when i am back.

PS. Maybe you can try follwing: put object 1km from you, without overriding distance (you will need to scale it to be able to see it), and check if same thing happens. And put height 0.

Regards, Miki

On Mon, Aug 22, 2022, 21:22 Minneth @.***> wrote:

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

`

— Reply to this email directly, view it on GitHub https://github.com/awesome7/XamAR/issues/75#issuecomment-1222751837, or unsubscribe https://github.com/notifications/unsubscribe-auth/ABQKHKCTRSFLY3P6CLEY5MTV2PAPPANCNFSM56OTQOSA . You are receiving this because you commented.Message ID: @.***>

Minneth commented 2 years ago

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); } `

miki-bgd commented 2 years ago

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

fzbeatrice commented 2 years ago

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!