Пример #1
0
        /// <summary>
        ///  Calculate the distance between a point in a space and a plane. This method is used
        ///  to calculate the distance between a camera in a space and a specified plane.
        /// </summary>
        /// <param name="planePose">ARPose of a plane.</param>
        /// <param name="cameraPose">ARPose of a camera.</param>
        /// <returns>Calculation results.</returns>
        private static float CalculateDistanceToPlane(ARPose planePose, ARPose cameraPose)
        {
            // The dimension of the direction vector is 3.
            float[] normals = new float[3];

            // Obtain the unit coordinate vector of a normal vector of a plane.
            planePose.GetTransformedAxis(1, 1.0f, normals, 0);

            // Calculate the distance based on projection.
            return((cameraPose.Tx() - planePose.Tx()) * normals[0]     // 0:x
                   + (cameraPose.Ty() - planePose.Ty()) * normals[1]   // 1:y
                   + (cameraPose.Tz() - planePose.Tz()) * normals[2]); // 2:z
        }
        private List <ARPlane> GetSortedPlanes(System.Collections.ICollection allPlanes, ARPose cameraPose)
        {
            // Planes must be sorted by the distance from the camera so that we can
            // first draw the closer planes, and have them block the further planes.
            Java.Util.ArrayList pairPlanes = new Java.Util.ArrayList();
            foreach (Java.Lang.Object item in allPlanes)
            {
                ARPlane plane = item.JavaCast <ARPlane>();
                if ((plane.Type == ARPlane.PlaneType.UnknownFacing) ||
                    plane.TrackingState != ARTrackableTrackingState.Tracking ||
                    plane.SubsumedBy != null)
                {
                    continue;
                }

                // Store the normal vector of the current plane.
                float[] planeNormalVector = new float[3];
                ARPose  planeCenterPose   = plane.CenterPose;
                planeCenterPose.GetTransformedAxis(1, 1.0f, planeNormalVector, 0);

                // Calculate the distance from the camera to the plane. If the value is negative,
                // it indicates that the camera is behind the plane (the normal vector distinguishes
                // the front side from the back side).
                float distanceBetweenPlaneAndCamera = (cameraPose.Tx() - planeCenterPose.Tx()) * planeNormalVector[0]
                                                      + (cameraPose.Ty() - planeCenterPose.Ty()) * planeNormalVector[1]
                                                      + (cameraPose.Tz() - planeCenterPose.Tz()) * planeNormalVector[2];
                pairPlanes.Add(new Pair(plane, distanceBetweenPlaneAndCamera));
            }
            //Get Pair object from ArrayList
            List <Pair> sortedList = new List <Pair>();
            IIterator   myit       = pairPlanes.Iterator();

            while (myit.HasNext)
            {
                sortedList.Add((Pair)(myit.Next()));
            }
            //Sort Pair objects by plane in list
            sortedList.Sort(new PlanCompare());

            //Obtain plane list.
            List <ARPlane> listOfPlane = new List <ARPlane>();

            foreach (Pair item in sortedList)
            {
                listOfPlane.Add((item.First).JavaCast <ARPlane>());
            }

            return(listOfPlane);
        }