public string CreateAnchor(Vec3 at, string id = null) { string anchorID = id == null ? Guid.NewGuid().ToString() : id; SpatialLocator locator = SpatialLocator.GetDefault(); SpatialStationaryFrameOfReference stationary = locator.CreateStationaryFrameOfReferenceAtCurrentLocation(); SpatialAnchor anchor = SpatialAnchor.TryCreateRelativeTo(stationary.CoordinateSystem); Pose pose = World.FromPerceptionAnchor(anchor); Pose newAnchor = pose.ToMatrix().Inverse.Transform(new Pose(at, Quat.Identity)); anchor = SpatialAnchor.TryCreateRelativeTo(stationary.CoordinateSystem, newAnchor.position, newAnchor.orientation); pose = World.FromPerceptionAnchor(anchor); if (anchor != null) { anchorPoses.Add(anchorID, pose); } return(anchorStore.TrySave(anchorID, anchor) ? anchorID : null); }
/// <summary> /// Converts a <see cref="CoordinateSystem"/> in \psi basis to a <see cref="SpatialCoordinateSystem"/> in HoloLens basis. /// </summary> /// <param name="coordinateSystem">The <see cref="CoordinateSystem"/> in \psi basis.</param> /// <returns>The <see cref="SpatialCoordinateSystem"/>.</returns> public static SpatialCoordinateSystem TryConvertPsiCoordinateSystemToSpatialCoordinateSystem(this CoordinateSystem coordinateSystem) { var holoLensMatrix = coordinateSystem.RebaseToHoloLensSystemMatrix(); var translation = holoLensMatrix.Translation; holoLensMatrix.Translation = Vector3.Zero; var rotation = Quaternion.CreateFromRotationMatrix(holoLensMatrix); var spatialAnchor = SpatialAnchor.TryCreateRelativeTo(MixedReality.WorldSpatialCoordinateSystem, translation, rotation); return(spatialAnchor?.CoordinateSystem); }
private void OnLocated(SpatialLocator loc, object args) { if (frame != null || loc.Locatability != SpatialLocatability.PositionalTrackingActive) { return; } frame = loc.CreateStationaryFrameOfReferenceAtCurrentLocation(); anchor = SpatialAnchor.TryCreateRelativeTo(frame.CoordinateSystem); root = World.FromPerceptionAnchor(anchor).ToMatrix(); UpdateBounds(center, radius); }