コード例 #1
0
        /// <summary>
        /// Creates a new anchor at the specified geodetic location and orientation
        /// relative to the Earth.
        ///
        /// Latitude and longitude are defined by the
        /// <a href="https://en.wikipedia.org/wiki/World_Geodetic_System">WGS84
        /// specification</a>, and altitude values are defined by the elevation above
        /// the WGS84 ellipsoid.
        ///
        /// Creating anchors near the north pole or south pole is not supported. If
        /// the latitude is within 0.1 degrees of the north pole or south pole (90
        /// degrees or -90 degrees), this function will return <c>null</c>.
        ///
        /// The rotation provided by <paramref name="eunRotation"/> is a rotation
        /// with respect to an east-up-north coordinate frame. An identity rotation
        /// will have the anchor oriented such that X+ points to the east, Y+ points up
        /// away from the center of the earth, and Z+ points to the north.
        ///
        /// To create a quaternion that represents a clockwise angle theta from
        /// north around the +Y anchor frame axis, use the following formula:
        /// <code>
        /// Quaternion.AngleAxis(180f - theta, Vector3.up);
        /// </code>
        ///
        /// An anchor's tracking state will be TrackingState.None while
        /// <see cref="AREarthManager.EarthTrackingState"/> is TrackingState.None.
        /// The tracking state will permanently become TrackingState.None if the
        /// configuration is set to <see cref="GeospatialMode"/>.<c>Disabled</c>.
        /// </summary>
        /// <param name="anchorManager">The ARAnchorManager instance.</param>
        /// <param name="latitude">
        /// The latitude of the anchor relative to the WGS84 ellipsoid.</param>
        /// <param name="longitude">
        /// The longitude of the anchor relative to the WGS84 ellipsoid.</param>
        /// <param name="altitude">
        /// The altitude of the anchor relative to the WGS84 ellipsoid.</param>
        /// <param name="eunRotation">The rotation of the anchor with respect to
        /// the east-up-north coordinate frame where X+ points east, Y+ points up
        /// away from gravity, and Z+ points north. A rotation about the Y+ axis
        /// creates a rotation counterclockwise from north.</param>
        /// <returns>
        /// If successful, a <see cref="ARGeospatialAnchor"/>, otherwise, <c>null</c>.
        /// </returns>
        public static ARGeospatialAnchor AddAnchor(
            this ARAnchorManager anchorManager, double latitude, double longitude,
            double altitude, Quaternion eunRotation)
        {
            IntPtr earthHandle = SessionApi.AcquireEarth(
                ARCoreExtensions._instance.currentARCoreSessionHandle);

            if (earthHandle == IntPtr.Zero)
            {
                Debug.LogError("Failed to acquire earth.");
                return(null);
            }

            IntPtr anchorHandle = EarthApi.AddAnchor(
                ARCoreExtensions._instance.currentARCoreSessionHandle,
                earthHandle, latitude, longitude, altitude, eunRotation);

            if (anchorHandle == IntPtr.Zero)
            {
                Debug.LogError("Failed to add geospatial anchor.");
                return(null);
            }

            // Create the GameObject that is the Geospatial Anchor.
            ARGeospatialAnchor anchor =
                new GameObject(_geospatialAnchorName).AddComponent <ARGeospatialAnchor>();

            if (anchor)
            {
                anchor.SetAnchorHandle(anchorHandle);
            }

            // Parent the new Geospatial Anchor to the session origin.
            anchor.transform.SetParent(
                ARCoreExtensions._instance.SessionOrigin.trackablesParent, false);
            return(anchor);
        }