Ejemplo n.º 1
0
 /// @cond EXCLUDE_FROM_DOXYGEN
 /// <summary>
 /// Constructs a TrackableHit.
 /// </summary>
 public TrackableHit(Vector3 point, Vector3 normal, float distance, TrackableHitFlag flags, TrackedPlane plane)
 {
     Point    = point;
     Normal   = normal;
     Distance = distance;
     Flags    = flags;
     Plane    = plane;
 }
Ejemplo n.º 2
0
        /// <summary>
        /// Update the plane's data with APIPlaneData
        /// Note that this will convert plane's pose from Tango space to Unity world space.
        /// </summary>
        /// <param name="apiPlaneData">ApiPlaneData source.</param>
        /// <param name="subsumedBy">The plane subsuming this plane or null.</param>
        /// <param name="forceUpdate">Force to update.</param>
        private void _UpdatePlaneIfNeeded(ApiPlaneData apiPlaneData, TrackedPlane subsumedBy, bool forceUpdate)
        {
            if (m_initialized && apiPlaneData.id != m_apiPlaneData.id)
            {
                ARDebug.LogError("Cannot update plane with mismatched id.");
                return;
            }
            else if (m_initialized && !forceUpdate && apiPlaneData.timestamp == m_apiPlaneData.timestamp)
            {
                return;
            }

            if (subsumedBy != null)
            {
                SubsumedBy = subsumedBy;
            }

            m_apiPlaneData     = apiPlaneData;
            m_initialized      = true;
            m_lastUpdatedFrame = Time.frameCount;

            Matrix4x4 startServiceTplane = Matrix4x4.TRS(apiPlaneData.pose.translation.ToVector3(),
                                                         apiPlaneData.pose.orientation.ToQuaternion(), Vector3.one);

            // Because startServiceTplane is a Pose (position, orientation), the multiplication of the first two terms
            // rotates plane orientation.  This must be undone with the last term (inverse) of the equation.
            m_unityWorldTPlane = Constants.UNITY_WORLD_T_START_SERVICE * startServiceTplane *
                                 Constants.UNITY_WORLD_T_START_SERVICE.inverse;

            Position  = m_unityWorldTPlane.GetColumn(3);
            Position += new Vector3((float)apiPlaneData.centerX, 0.0f, (float)apiPlaneData.centerY);

            Quaternion yaw = Quaternion.Euler(0.0f, -Mathf.Rad2Deg * (float)apiPlaneData.yaw, 0.0f);

            Rotation = yaw * Quaternion.LookRotation(m_unityWorldTPlane.GetColumn(2), m_unityWorldTPlane.GetColumn(1));

            m_boundaryPolygonPoints.Clear();
            int boudaryLength = m_apiPlaneData.boundaryPointNum;

            if (boudaryLength != 0)
            {
                double[] apiBoundaryPolygon = new double[boudaryLength * 2];
                Marshal.Copy(m_apiPlaneData.boundaryPolygon, apiBoundaryPolygon, 0, boudaryLength * 2);

                m_boundaryPolygonPoints.Clear();
                for (int i = 0; i < boudaryLength; ++i)
                {
                    Vector3 localPoint = new Vector3((float)apiBoundaryPolygon[2 * i],
                                                     0.0f, (float)apiBoundaryPolygon[2 * i + 1]);
                    m_boundaryPolygonPoints.Add(m_unityWorldTPlane.MultiplyPoint3x4(localPoint));
                }
            }

            // Reverse the m_boundaryPolygonPoints because the raw data is in counter-clockwise.
            // As Unity is left handed system, this should be clockwise.
            m_boundaryPolygonPoints.Reverse();
        }