Пример #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>
    /// 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);
            }
        }
    }