コード例 #1
0
 /// <summary>
 /// Create the space pins in an idle state.
 /// </summary>
 /// <remarks>
 /// Pins won't become active until the corresponding QR code is seen.
 /// </remarks>
 private void SetUpSpacePins()
 {
     DestroySpacePins();
     for (int i = 0; i < VirtualMarkers.Count; ++i)
     {
         spacePins.Add(SpacePinPackage.Create(this, VirtualMarkers[i]));
     }
 }
コード例 #2
0
        /// <summary>
        /// Create a new space pin package.
        /// </summary>
        /// <param name="owner">The owning space pin group.</param>
        /// <param name="virtualObject">Corresponding virtual object (for pose) in the scene.</param>
        /// <returns>The created package.</returns>
        /// <remarks>
        /// The created space pin package is ready to deploy, but currently idle.
        /// </remarks>
        public static SpacePinPackage Create(QRSpacePinGroup owner, Transform virtualObject)
        {
            SpacePinPackage package = new SpacePinPackage();

            package.spacePin          = virtualObject.gameObject.AddComponent <SpacePinOrientable>();
            package.spacePin.Orienter = owner.orienter;
            package.highlightProxy    = null;
            package.highlightPrefab   = owner.markerHighlightPrefab;

            package.coordinateSystem = new QRSpatialCoord();

            return(package);
        }
コード例 #3
0
    /// <summary>
    /// Process a newly added QR code.
    /// </summary>
    /// <param name="qrCode">The qr code to process.</param>
    private void OnQRCodeAdded(QRCode qrCode)
    {
        string frameId;

        if (ExtractFrameId(qrCode, out frameId))
        {
            if (spacePins.ContainsKey(frameId) == false)
            {
                Vector3      vecU   = Vector3.zero;
                Quaternion   quatU  = Quaternion.identity;
                TfVector3?   vecTF  = spacePinningService.SharedListener.LookupTranslation("map", frameId);
                TfQuaternion?quatTF = spacePinningService.SharedListener.LookupRotation("map", frameId);

                if (vecTF.HasValue == false || quatTF.HasValue == false)
                {
                    Debug.LogWarning($"Could not find a ROS transform from map to {frameId}; assuming map == frameId");
                }
                else
                {
                    vecU  = TransformHelper.VectorTfToUnity(vecTF.Value);
                    quatU = TransformHelper.QuatTfToUnity(quatTF.Value);

                    if (spacePinningService.UseCenterOfQRCode)
                    {
                        // QRCode zero is at the top left corner; but for mounting center can be better.
                        Vector3 qrCenterOffset = new Vector3(qrCode.PhysicalSideLength / 2.0f, qrCode.PhysicalSideLength / 2.0f, 0.0f);
                        vecU += qrCenterOffset;
                    }

                    Quaternion correction = Quaternion.Euler(-90.0f, 0.0f, 0.0f);
                    quatU = quatU * correction;
                }

                var qrCodeLocationInROSSpace = new GameObject(frameId);
                qrCodeLocationInROSSpace.transform.parent = this.transform;

                qrCodeLocationInROSSpace.transform.SetPositionAndRotation(vecU, quatU);

                spacePins[frameId] = SpacePinPackage.Create(this, qrCodeLocationInROSSpace.transform);
            }
        }
    }