/// <summary> /// Static function, Lerps between two LatLongAltitude positions and returns the interpolated result based on the time parameter passed in. /// </summary> /// <param name="from">Starting position of the lerp transition.</param> /// <param name="to">Ending position of the lerp transition.</param> /// <param name="time">Current time that has passed in the transition.</param> public static LatLongAltitude Lerp(LatLongAltitude from, LatLongAltitude to, float time) { return(new LatLongAltitude( from.GetLatitude() + ((to.GetLatitude() - from.GetLatitude()) * time), from.GetLongitude() + ((to.GetLongitude() - from.GetLongitude()) * time), from.GetAltitude() + ((to.GetAltitude() - from.GetAltitude()) * time))); }
/// <summary> /// Convert an Ecef position to LatLongAltitude. Returns converted LatLongALtitude. /// </summary> /// <param name="x">ECEF x coordinate.</param> /// <param name="y">ECEF y coordinate.</param> /// <param name="z">ECEF z coordinate.</param> public static LatLongAltitude ConvertEcefToLatLongAltitude(double x, double y, double z) { double p = Math.Sqrt((z * z) + (-x * -x)); double lat = Math.Atan(y / p); double lon = Math.Atan2(-x, z); double alt = (p / Math.Cos(lat)) - EarthConstants.Radius; return(LatLongAltitude.FromRadians(lat, lon, alt)); }
public void setAltitude(double newAltitude) { Wrld.Space.LatLongAltitude latLongAltitude = new Wrld.Space.LatLongAltitude(); latLongAltitude.SetAltitude(m_distanceToInterest);//// latLongAltitude.SetLatitude(m_latitudeDegrees); latLongAltitude.SetLongitude(m_longitudeDegrees); m_api.SetOriginPoint(latLongAltitude); LatLong latLong = latLongAltitude.GetLatLong(); m_distanceToInterest = newAltitude; Api.Instance.CameraApi.AnimateTo(latLong, distanceFromInterest: m_distanceToInterest, headingDegrees: m_headingDegrees, tiltDegrees: 0); }
private void SetCentralPoint(DoubleVector3 ecefOrigin, LatLongAltitude latLongAltOrigin) { m_originECEF = ecefOrigin; var upEcef = m_originECEF.normalized; var northPole = new DoubleVector3(0.0, 1.0, 0.0); var toNorthPole = (northPole - upEcef).normalized; m_upECEF = upEcef.ToSingleVector(); m_rightECEF = -DoubleVector3.Cross(toNorthPole, upEcef).normalized.ToSingleVector(); m_forwardECEF = -Vector3.Cross(m_upECEF, m_rightECEF); ECEFToLocalRotation = CreateQuaternionFromBasisVectors(m_rightECEF, m_upECEF, m_forwardECEF); LocalToECEFRotation = Quaternion.Inverse(ECEFToLocalRotation); }
void SetupApi() { var config = ConfigParams.MakeDefaultConfig(); config.DistanceToInterest = m_distanceToInterest; config.LatitudeDegrees = m_latitudeDegrees; config.LongitudeDegrees = m_longitudeDegrees; config.HeadingDegrees = m_headingDegrees; config.StreamingLodBasedOnDistance = m_streamingLodBasedOnDistance; config.MaterialsDirectory = m_materialDirectory; config.OverrideLandmarkMaterial = m_overrideLandmarkMaterial; config.Collisions.TerrainCollision = m_terrainCollisions; config.Collisions.RoadCollision = m_roadCollisions; config.Collisions.BuildingCollision = m_buildingCollisions; config.EnableLabels = m_enableLabels; try { Api.Create(GetApiKey(), m_coordSystem, transform, config); } catch (InvalidApiKeyException) { #if UNITY_EDITOR EditorUtility.DisplayDialog( "Error: Invalid WRLD API Key", string.Format("Please enter a valid WRLD API Key (see the WrldMap script on GameObject \"{0}\" in the Inspector).", gameObject.name), "OK"); #endif throw; } m_api = Api.Instance; if (m_useBuiltInCameraControls) { m_api.CameraApi.SetControlledCamera(m_streamingCamera); } Wrld.Space.LatLongAltitude latLongAltitude = new Wrld.Space.LatLongAltitude(); latLongAltitude.SetAltitude(0); ///// latLongAltitude.SetLatitude(m_latitudeDegrees); latLongAltitude.SetLongitude(m_longitudeDegrees); m_api.SetOriginPoint(latLongAltitude); }
void redrawMap() { Vector3 currentMapPosition = gameObject.transform.position; gameObject.transform.parent.transform.position = originalMapPosition; gameObject.transform.position = currentMapPosition; //position of map relative to the map's pivot double x_offset = gameObject.transform.localPosition.x; double z_offset = gameObject.transform.localPosition.z; //coordinates for the api call... double[] newCoordinates = getNewCoordinates(x_offset, z_offset, m_latitudeDegrees, m_longitudeDegrees); m_latitudeDegrees = newCoordinates[0]; m_longitudeDegrees = newCoordinates[1]; //map's centroid is now at the new latlong Wrld.Space.LatLongAltitude latLongAltitude = new Wrld.Space.LatLongAltitude(); latLongAltitude.SetAltitude(0);//// latLongAltitude.SetLatitude(m_latitudeDegrees); latLongAltitude.SetLongitude(m_longitudeDegrees); m_api.SetOriginPoint(latLongAltitude); LatLong latLong = latLongAltitude.GetLatLong(); //transform.position = new Vector3(0.0f, transform.position.y, 0.0f); transform.position = originalMapPosition; //generate new map around the center of the map Api.Instance.CameraApi.AnimateTo(latLong, distanceFromInterest: m_distanceToInterest, headingDegrees: m_headingDegrees, tiltDegrees: 0); //reset the grab offset because if you are grabbing the object while redrawMap() is called, the map is repositioned, but also the grab offset is preserved, so the map is moved double the desired distance. if (GameObject.Find("Controllers").GetComponent <TwoHandControl>().twoGrabbed()) { GameObject.Find("Controllers").GetComponent <TwoHandControl>().recomputeOffset(); } else { GameObject.Find("Controller (right)").GetComponent <OneHandControl>().recomputeOffset(); GameObject.Find("Controller (left)").GetComponent <OneHandControl>().recomputeOffset(); } }
public Vector3 LatLongAltitudeToLocalSpace(LatLongAltitude latLongAlt) { return(ECEFToLocalSpace(latLongAlt.ToECEF())); }
public LatLongAltitude LocalSpaceToLatLongAltitude(Vector3 localSpace) { return(LatLongAltitude.FromECEF(LocalSpaceToECEF(localSpace))); }
public void SetCentralPoint(DoubleVector3 ecefOrigin) { SetCentralPoint(ecefOrigin, LatLongAltitude.FromECEF(ecefOrigin)); }
public void SetCentralPoint(LatLongAltitude latLongAlt) { SetCentralPoint(latLongAlt.ToECEF(), latLongAlt); }
public UnityWorldSpaceCoordinateFrame(LatLongAltitude centralPoint) { SetCentralPoint(centralPoint); }
/// <summary> /// This function has different behaviour depending on the coordinate system in use. /// UnityWorld - Resets the root latitude and longitude of the world such that Unity's origin(0,0) is centered at that point. /// ECEF - Sets the maps world position to that latitude and longitude such that the camera is positioned at that point. /// </summary> /// <param name="lla">the latitude, longitude and altitude of the new point.</param> public void SetOriginPoint(Space.LatLongAltitude lla) { m_implementation.SetOriginPoint(lla); }
/// <summary> /// Try to get the transformed position as a LatLongAltitude of this GeographicTransform. This can be used with SpacesApi.GeographicToWorldPoint to calculate a Vector3 translation for this GeographicTransform. /// </summary> /// <param name="out_latLongAlt">The LatLongAltitude that represents the GeographicTransform's position with the desired elevation and ElevationMode applied. The value is only valid if this function returns true.</param> /// <returns>Whether or not this function was successful.</returns> public bool TryGetLatLongAltitude(out LatLongAltitude out_latLongAlt) { return(m_positioner.TryGetLatLongAltitude(out out_latLongAlt)); }
/// <summary> /// Transforms a point from a LatLongAltitude to a Unity transform position. /// Note: If using the ECEF coordinate system, the returned position will only be valid until the camera is moved. To robustly position an object on the map, use the GeographicTransform component. /// </summary> /// <param name="position">The geographical coordinates of the position to transform to local space.</param> /// <returns>The transformed geographic LatLongAltitude in local space.</returns> public Vector3 GeographicToWorldPoint(LatLongAltitude position) { return(m_apiImplementation.GeographicToWorldPoint(position)); }