Skip to content
This repository has been archived by the owner on Jun 14, 2024. It is now read-only.

Commit

Permalink
Merge pull request #234 from chrisfromwork/resetLocalization3
Browse files Browse the repository at this point in the history
Enable resetting spatial alignment.
  • Loading branch information
chrisfromwork committed Oct 4, 2019
2 parents e528939 + b378a6f commit 46a7b36
Show file tree
Hide file tree
Showing 16 changed files with 633 additions and 52 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@
// Licensed under the MIT License. See LICENSE in the project root for license information.

using System;
using System.Collections;
using System.Collections.Generic;
using System.Threading.Tasks;
using UnityEngine;

namespace Microsoft.MixedReality.SpectatorView
Expand All @@ -19,12 +18,28 @@ public class SpatialAnchorsCoordinateLocalizationInitializer : SpatialLocalizati

public override Guid PeerSpatialLocalizerId => SpatialAnchorsLocalizer.Id;

public override void RunLocalization(SpatialCoordinateSystemParticipant participant)
/// <inheritdoc />
public override async Task<bool> TryRunLocalizationAsync(SpatialCoordinateSystemParticipant participant)
{
SpatialCoordinateSystemManager.Instance.LocalizeAsync(participant.SocketEndpoint, SpatialAnchorsLocalizer.Id, configuration);
return await TryRunLocalizationImplAsync(participant);
}

/// <inheritdoc />
public override async Task<bool> TryResetLocalizationAsync(SpatialCoordinateSystemParticipant participant)
{
return await TryRunLocalizationImplAsync(participant);
}

private async Task<bool> TryRunLocalizationImplAsync(SpatialCoordinateSystemParticipant participant)
{
configuration.IsCoordinateCreator = false;
Task<bool> localTask = SpatialCoordinateSystemManager.Instance.LocalizeAsync(participant.SocketEndpoint, SpatialAnchorsLocalizer.Id, configuration);
configuration.IsCoordinateCreator = true;
SpatialCoordinateSystemManager.Instance.RunRemoteLocalizationAsync(participant.SocketEndpoint, SpatialAnchorsLocalizer.Id, configuration);
Task<bool> remoteTask = SpatialCoordinateSystemManager.Instance.RunRemoteLocalizationAsync(participant.SocketEndpoint, SpatialAnchorsLocalizer.Id, configuration);
await Task.WhenAll(localTask, remoteTask);
bool localSuccess = await localTask;
bool remoteSuccess = await remoteTask;
return localSuccess && remoteSuccess;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,8 @@ private void Update()

private class SpatialCoordinateLocalizationSession : DisposableBase, ISpatialLocalizationSession
{
public IPeerConnection Peer => peerConnection;

private readonly IPeerConnection peerConnection;
private readonly SpatialAnchorsCoordinateService coordinateService;
private readonly SpatialAnchorsConfiguration configuration;
Expand Down
Loading

0 comments on commit 46a7b36

Please sign in to comment.