private void OnLocalizationSuccessful() { if (SetPositionWhen == SetPositionOn.LocalizationSuccessful) { transform.position = XRSessionManager.GetSession().GpsToLocalPosition(GpsPosition); } }
private void OnSessionReady() { if (SetPositionWhen == SetPositionOn.SessionReady) { transform.position = XRSessionManager.GetSession().GpsToLocalPosition(GpsPosition); } }
private void LateUpdate() { if (_editGPS) { GpsPosition = XRSessionManager.GetSession().LocalPositionToGps(transform.position); } }
private void Log(bool isLocalizationRequest) { Data data = new Data(); data.XrCamPos = XRSessionManager.GetSession().GetXRCameraPosition(); data.XrCamOrient = XRSessionManager.GetSession().GetXRCameraOrientation(); data.GpsPos = XRSessionManager.GetSession().GetXRCameraLocation(); data.GpsOrient = OrientationUtils.UnityToWorld(XRSessionManager.GetSession().GetXRCameraOrientation()); data.ProjectionMatrix = XRSessionManager.GetSession().VideoProvider.GetProjectionMatrix(); data.TimeStamp = DateTime.Now.ToString("O"); data.IsLocalizationRequest = isLocalizationRequest; _datas.Add(data); string jsonData = JsonHelper.ToJson <Data>(_datas.ToArray()); File.WriteAllText(_path, jsonData); //Debug.Log("XR Cam Position: " + XRSessionManager.GetSession().GetXRCameraPosition()); //Debug.Log("XR Cam Orientation: " + XRSessionManager.GetSession().GetXRCameraOrientation()); //Debug.Log("GPS Position: " + XRSessionManager.GetSession().GetXRCameraLocation()); //Debug.Log("GPS Orientation" + OrientationUtils.UnityToWorld(XRSessionManager.GetSession().GetXRCameraOrientation())); //Debug.Log("XR Cam Projection Matrix: " + XRSessionManager.GetSession().GetXRCameraPosition()); //Debug.Log("Localization Request: " + isLocalizationRequest); //Debug.Log("Time Stamp: " + DateTime.Now.ToString("O")); }
public void OnUpdateGpsClick() { XRSessionManager.GetSession().ForceLocationUpdate(); MiniMapCamera.Instance.CenterCamOverPos(PlayerController.Instance.transform.position); FullMapCamera.Instance.CenterCamOverPos(PlayerController.Instance.transform.position); // PlayerController.Instance.PreScanInitialize (); }
private void Update() { if (!_localized) { _absolutePos = XRSessionManager.GetSession().GetXRCameraPosition(); } }
private void CalculateBulletProjection() { var camRay = GetComponentInParent <Camera>().ScreenPointToRay(_screenCenterPos); Vector3 direction; bool raycastShot; RaycastHit hit; if (Physics.Raycast(camRay, out hit, 1000.0f, BulletRaycastMask)) { direction = (hit.point - _bulletSpawnPoint.position).normalized; raycastShot = true; } else { direction = transform.forward; raycastShot = false; } // Convert the bullet's spawn point to a GPS position that can be synced across the network var bulletSpawnGpsPos = XRSessionManager.GetSession().LocalPositionToGps(_bulletSpawnPoint.position); GpsStruct bulletGpsPos = new GpsStruct { Latitude = bulletSpawnGpsPos.Latitude, Longitude = bulletSpawnGpsPos.Longitude, Height = bulletSpawnGpsPos.Height }; CmdShootBullet(bulletGpsPos, direction, raycastShot); }
/// <summary> /// Rotates a point based on orientation correction received from VPS service. /// </summary> /// <returns>The point.</returns> /// <param name="pos">Position.</param> private static Vector3 RotatePoint(Vector3 pos) { Vector3 rotatedPos = new Vector3(); //Create a parent object to rotate pos around this object GameObject parent = new GameObject(); GameObject posToRotate = new GameObject(); posToRotate.transform.parent = parent.transform; //Before rotation posToRotate.transform.position = pos; //GetOrientationCorrection() is identity before Localization Quaternion rotInWorld = XRSessionManager.GetSession().GetOrientationCorrection() * OrientationUtils.UnityToWorld(parent.transform.rotation); //Rotate parent object which will rotate its child(posToRotate) around it parent.transform.rotation = OrientationUtils.WorldToUnity(rotInWorld); rotatedPos = posToRotate.transform.position; // Unity WorldPos of pos Destroy(posToRotate); Destroy(parent); return(rotatedPos); }
private void LateUpdate() { if (Dynamic) { transform.position = XRSessionManager.GetSession().GpsToLocalPosition(GpsPosition); } }
public void InitializeMap() { //XRSessionManager.GetSession().ForceLocationUpdate(); Vector3 mapPos = Map.transform.position; mapPos.y = XRSessionManager.GetSession().GetXRCameraPosition().y; Map.transform.position = mapPos; var gpsPos = XRSessionManager.GetSession().LocalPositionToGps(mapPos); Vector2d mapboxCoord = new Vector2d(gpsPos.Latitude, gpsPos.Longitude); Map.Initialize(mapboxCoord, 15); Map.transform.position += Vector3.down * 0.3f; //XRSessionManager.GetSession().ForceLocationUpdate(); //Vector3 playerPos = XRSessionManager.GetSession().GetXRCameraPosition(); //Map.transform.position = playerPos + (Vector3.down * 0.1f); //var gpsPos = XRSessionManager.GetSession ().GpsProvider.GetGPSPosition (); //Vector2d gpsLatLongPos = new Vector2d (gpsPos.Latitude, gpsPos.Longitude); //Map.Initialize (gpsLatLongPos, 15); MiniMapCam.gameObject.SetActive(true); _initialized = true; }
private float GetCursorPosition() { float width = _scanUI.GetComponent <RectTransform>().rect.width; int yaw = (int)XRSessionManager.GetSession().GetXRCameraOrientation().eulerAngles.y; int yawDiff = yaw - _startYaw; int absYawDiff = Mathf.Abs(yawDiff); if (absYawDiff > 180) { yawDiff = yawDiff > 0 ? -(360 - absYawDiff) : 360 - absYawDiff; } //If our capture range goes above 180 float captureRange = (ScanProperties.TargetCount - 1) * ScanProperties.YawAngle; if (yawDiff < 0 && captureRange > 180) { if (yawDiff > -180 && yawDiff <= captureRange - 360 + 5) // + 5 is added for sanity just in case we want cursorPos beyond last gaze target { yawDiff += 360; } } float multiplier = _factor / ScanProperties.YawAngle; return((yawDiff * multiplier) + _padding); }
public void PerformRelocalization() { if (!_relocalizationEnabled) { Debug.LogError("Relocalization not enabled"); return; } try { _relocalizing = true; _lastRelocTime = Time.time; XRSessionManager.GetSession().PerformLocalization(); } catch (Exception ex) { Debug.Log(ex.Message); if (ex is PitchRequestException) { _relocalizing = false; } else if (ex is RollRequestException) { _relocalizing = false; } } }
/// <summary> /// Rotates a point based on orientation correction received from VPS service. /// </summary> /// <returns>The point.</returns> /// <param name="point">Position.</param> private static Vector3 RotatePoint(Vector3 point, bool useCompass = true) { // Ar orgin where all values recieved rom Arcore/Arkit will be under this origin GameObject arOrigin = new GameObject("ArOrigin"); // Create a child Gameobject and set its localPosition to the point we get from ArCore/ArKit GameObject pointGO = new GameObject("Point"); pointGO.transform.parent = arOrigin.transform; pointGO.transform.localPosition = point; pointGO.transform.localRotation = Quaternion.identity; if (useCompass) { // First rotate this origin to align with trueHeading received from sensor arOrigin.transform.rotation = Quaternion.Euler(0, ArWorldTracking.TrueHeading, 0); } // Then rotate this again based on offset received from VPS Service Quaternion rotInWorld = XRSessionManager.GetSession().GetYawOrientationCorrection() * OrientationUtils.UnityToWorld(arOrigin.transform.rotation) * XRSessionManager.GetSession().GetPitchOrientationCorrection(); arOrigin.transform.rotation = OrientationUtils.WorldToUnity(rotInWorld); var rotatedPos = pointGO.transform.position; // Unity WorldPos of pos Destroy(arOrigin); Destroy(pointGO); return(rotatedPos); }
private IEnumerator GetFoursquareVenueData(Vector3 pos, bool addUnityCoord, Action <List <FoursquareAPI.Venue> > callback) { var gps = XRSessionManager.GetSession().LocalPositionToGps(pos); string url = "https://api.foursquare.com/v2/venues/search?ll=" + gps.Latitude.ToString() /*Lat*/ + "," + gps.Longitude.ToString() /*Lng*/ + "&radius=30&oauth_token=VXIREDRYNSJEZL3OOQ3GLUF03HZXQQLRENNA5ERWUF1DYBMH&v=20160419&intent=browse"; using (UnityWebRequest www = UnityWebRequest.Get(url)) { yield return(www.SendWebRequest()); if (www.isNetworkError) { Debug.Log(www.error); } else { var d = JsonUtility.FromJson <FoursquareAPI.RootObject>(www.downloadHandler.text); List <FoursquareAPI.Venue> venues = d.response.venues; if (addUnityCoord) { AddUnityCoord(venues); } callback(venues); } } }
public static void SaveArItem(Transform arItem) { // Convert the AR item's Unity data into serializable format that can be saved ArItemData arItemData = new ArItemData(); arItemData.ItemType = (int)arItem.GetComponent <ArItem>().ItemType; QuaternionSerializable newQuat = new QuaternionSerializable(); newQuat.Fill(arItem.rotation); arItemData.Orientation = newQuat; var rawGpsPos = XRSessionManager.GetSession().LocalPositionToGps(arItem.position); GpsSerializable gpsPos = new GpsSerializable(); gpsPos.Height = rawGpsPos.Height; gpsPos.Latitude = rawGpsPos.Latitude; gpsPos.Longitude = rawGpsPos.Longitude; arItemData.GpsPos = gpsPos; // Create (almost) unique ID for this AR item string itemId = arItem.GetInstanceID().ToString() + "." + rawGpsPos.Latitude.ToString() + "." + rawGpsPos.Longitude.ToString(); arItemData.Id = itemId; arItem.GetComponent <ArItem> ().Id = itemId; Debug.Log("Added AR item to save data"); ArItemList.Add(arItemData); Save(); }
private void OnDestroy() { SturfeeEventManager.Instance.OnSessionReady -= OnSessionReady; SturfeeEventManager.Instance.OnSessionFailed -= OnSessionFailed; XRSessionManager.DestroySession(); }
private void OnSessionReady() { _sessionIsReady = true; // once the XR Sessions is ready, we need to make sure the user's location is in a supported coverage city/area // refer to: https://sturfee.com/faq.html#cities XRSessionManager.GetSession().CheckAlignment(); }
private void Update() { if (XRSessionManager.GetSession() != null) { _progressText.text = ((int)XRSessionManager.GetSession().Progress).ToString() + "%"; _progressSlider.value = XRSessionManager.GetSession().Progress; } }
private void OnSessionReady() { _sessionIsReady = true; //Uncomment this once portrait mode is supported //UpdateOrientation(); XRSessionManager.GetSession().CheckCoverage(); }
private void SetGrid(Vector3 normal) { // Copied from GridEffect script Vector3 camPos = (XRSessionManager.GetSession() != null) ? XRSessionManager.GetSession().GetXRCameraPosition() : Camera.main.transform.position; var distance = Vector3.Distance(camPos, transform.position); var scaleAmount = (distance * 2) / Mathf.Pow(distance, 0.75f); GridMarker.localScale = Vector3.one * scaleAmount; }
private void OnLocalizationSuccessful() { if (!_localized) { _localized = true; ToastManager.Instance.ShowToastTimed(" Tap anywhere to place planes "); } _lastLocalizedPosition = XRSessionManager.GetSession().GetXRCameraPosition(); }
public void SetToFullMap() { FullMapCam.SetActive(true); FullMapCam.transform.position = XRSessionManager.GetSession().GetXRCameraPosition() + (Vector3.up * 100); MapTouchPanel.SetActive(true); MapMode = MapMode.Full; MiniMap.SetActive(false); SetupManager.Instance.PreLocalizedScanButtonSet(false); }
private void Update() { if (!_sessionIsReady) { return; } transform.position = XRSessionManager.GetSession().GetXRCameraPosition(); transform.rotation = XRSessionManager.GetSession().GetXRCameraOrientation(); }
public void InitializeMap() { transform.position = XRSessionManager.GetSession().GetXRCameraPosition(); transform.rotation = Quaternion.identity; transform.position += Vector3.down * 100; var gpsPos = XRSessionManager.GetSession().GetLocationCorrection(); Vector2d gpsLatLongPos = new Vector2d(gpsPos.Latitude, gpsPos.Longitude); Map.Initialize(gpsLatLongPos, 15); }
private void OnSessionReady() { _latitude = XRSessionManager.GetSession().GetXRCameraLocation().Latitude; _longitude = XRSessionManager.GetSession().GetXRCameraLocation().Longitude; _time = DateTime.Now; SetPosition(); _light.intensity = _intensity; _light.transform.rotation = _direction; }
private void AddGround() { if (AccessHelper.CurrentTier == Tierlevel.Tier1) { Debug.Log("Adding Ground plane"); GameObject plane = GameObject.CreatePrimitive(PrimitiveType.Plane); plane.GetComponent <MeshRenderer>().material = (Material)Resources.Load("Materials/BuildingHide"); plane.transform.position = XRSessionManager.GetSession().GetXRCameraPosition() - new Vector3(0, 1.5f, 0); } }
public void Initialize() { SturfeeEventManager.Instance.OnLocalizationLoading += OnLocalizationLoading; SturfeeEventManager.Instance.OnLocalizationSuccessful += OnLocalizationSuccessful; SturfeeEventManager.Instance.OnLocalizationFail += OnLocalizationFail; _relocalizationEnabled = true; _distSinceLastReloc = 0; _lastTrackedPoint = XRSessionManager.GetSession().GetXRCameraPosition(); _lastRelocTime = Time.time; }
private void OnLocalizationSuccessful() { _localized = true; // We set _relativeOrigin to current position from tracking plugin. This enables us to calculate new relativePos from // this point onwards. _relativeOrigin = XRSessionManager.GetSession().ImuProvider.GetOffsetPosition(); //AbsolutePos is now set to VPS and at this stage XrCamPos = VPS --> Local and relativePos = 0. _absolutePos = XRSessionManager.GetSession().GpsToLocalPosition(XRSessionManager.GetSession().GetLocationCorrection()); }
private void SetupMultiframe() { _resetCalled = false; _gazeTargets = new List <GameObject>(); _cursor.SetActive(true); _centerYaw = (int)XRSessionManager.GetSession().GetXRCameraOrientation().eulerAngles.y; _multiframeRequestId = 0; AddToMultiframeLocalizationCall(); }
// Computes and adds the Unity (Vector3) coordinates to the venues via the lat/long values of the venue locations private List <FoursquareAPI.Venue> AddUnityCoord(List <FoursquareAPI.Venue> venues) { for (int i = 0; i < venues.Count; i++) { var gpsPos = new Sturfee.Unity.XR.Core.Models.Location.GpsPosition(); gpsPos.Latitude = venues[i].location.lat; gpsPos.Longitude = venues[i].location.lng; gpsPos.Height = 0; venues[i].unityCoord = XRSessionManager.GetSession().GpsToLocalPosition(gpsPos); } return(venues); }