private void Update() { if (hasAuthority && WhichDeviceManager.Instance.IsHoloLens()) { // this code will only run on the HoloLens // first, check if we have our world anchor (do it here, in case we connected to the network before the world anchor was set up) if (worldAnchorOnHoloLens == null) { worldAnchorOnHoloLens = anchorPlacer.GetMarkerViveOrigin(); } // now, only proceed if we know it's actually not null if (worldAnchorOnHoloLens != null) { // on the HoloLens, the world position of the world anchor represents where the Vive origin is relative to the HoloLens. Matrix4x4 mat = worldAnchorOnHoloLens.transform.localToWorldMatrix; Matrix4x4 inverseMat = mat.inverse; // adjust the world-space transform of the WorldAnchorInverter to be these inverse position/rotation values. transform.position = ExtractTranslationFromMatrix(ref inverseMat); transform.rotation = ExtractRotationFromMatrix(ref inverseMat); } } if (!hasAuthority && WhichDeviceManager.Instance.IsVive()) { // this is on the vive. the local pose of the WorldAnchorInverter represents where the HoloOrigin should be relative to the Vive's origin. holoOrigin.transform.SetPositionAndRotation(transform.position, transform.rotation); } }
public override bool Equals(object obj) { if (obj == null || GetType() != obj.GetType()) { return(false); } AnchorMarker otherMarker = obj as AnchorMarker; return(Id.Equals(otherMarker.Id)); }
private AnchorMarker CreateNewMarker(string newMarkerId) { Vector3 hitPoint = Camera.main.transform.position + Camera.main.transform.forward; Vector3 directionToCamera = -Camera.main.transform.forward; directionToCamera.y = 0f; GameObject marker = (GameObject)Instantiate(WorldAnchorMarker, hitPoint, Quaternion.LookRotation(directionToCamera)); AnchorMarker anchorMarker = marker.GetComponent <AnchorMarker>(); anchorMarker.Init(newMarkerId, worldAnchorManager); anchorMarker.AttachAnchor(); return(anchorMarker); }
private void WorldAnchorStoreLoaded(WorldAnchorStore store) { Debug.Log("AnchorPlacer: WorldAnchorStoreLoaded"); string[] anchorIdsInStore = store.GetAllIds(); List <string> persistedAnchorMarkerIdsToRemove = new List <string>(); foreach (string persistedMarkerId in PersistedAnchorMarkersIds) { bool markerIdInAnchorStore = Array.Exists(anchorIdsInStore, id => id == persistedMarkerId); bool markerIdShouldBeSpawned = markerIdInAnchorStore && (persistedMarkerId == ANCHOR_VIVE_ORIGIN); if (markerIdShouldBeSpawned) { Debug.Log("Reload Marker from store with id [" + persistedMarkerId + "]"); GameObject markerClone = (GameObject)Instantiate(WorldAnchorMarker, Vector3.zero, Quaternion.identity); AnchorMarker anchorMarker = markerClone.GetComponent <AnchorMarker>(); anchorMarker.Init(persistedMarkerId, worldAnchorManager); anchorMarker.AttachAnchor(); Markers.Add(anchorMarker.gameObject); MarkerViveOrigin = anchorMarker; } else { Debug.Log("Marker with id [" + persistedMarkerId + "] was not found in AnchorStore"); persistedAnchorMarkerIdsToRemove.Add(persistedMarkerId); } } foreach (string persistedMarkerIdToRemove in persistedAnchorMarkerIdsToRemove) { Debug.Log("Removing marker with id [" + persistedMarkerIdToRemove + "]"); PersistedAnchorMarkersIds.Remove(persistedMarkerIdToRemove); } SaveMarkersToFile(); }
public void OnPointerUp(MixedRealityPointerEventData eventData) { if (WhichDeviceManager.Instance.IsHoloLens()) { bool shouldCreateMarkerHere = (MarkerViveOrigin == null); // only create a new marker if we don't already have a loaded marker string newMarkerId = ANCHOR_VIVE_ORIGIN; if (shouldCreateMarkerHere) { AnchorMarker newCreatedMarker = CreateNewMarker(newMarkerId); Debug.Log("newly created marker has id [" + newCreatedMarker.Id + "]"); PersistedAnchorMarkersIds.Add(newCreatedMarker.Id); Markers.Add(newCreatedMarker.gameObject); MarkerViveOrigin = newCreatedMarker; SaveMarkersToFile(); } eventData.Use(); } }