Ejemplo n.º 1
0
        /// <summary>
        /// Query distance between boundary and point
        /// </summary>
        /// <param name="point">point</param>
        /// <returns>
        /// Distance > 0.0, Inside the Boundary
        /// Distance = 0.0, On the Boundary
        /// Distance < 0.0, Outside the Boundary
        /// -1 : Error
        /// </returns>
        public double QueryDistanceOfPoint(Vector3 point, bool isPlayArea, ref Vector3 closestPoint, ref Vector3 normalDir)
        {
            //point.Set(point.x * 1000, point.y * 1000, point.z * 1000); // m -> mm
            //IntPtr pointPtr = Pvr_BoundaryAPI.StructToIntPtr<Vector3>(point);
            //double distance = Pvr_SafeAreaAlgoAPI.Pvr_GSABoundaryDetector(pointPtr);
            //Marshal.FreeHGlobal(pointPtr);

            Pvr_SafeAreaAlgoAPI.GSAPoint3i point3i = new Pvr_SafeAreaAlgoAPI.GSAPoint3i();
            point3i.x = (int)(point.x * 1000);
            point3i.y = (int)(point.y * 1000);
            point3i.z = (int)(point.z * 1000);


            Pvr_SafeAreaAlgoAPI.GSAPoint3i closestPoint3i = new Pvr_SafeAreaAlgoAPI.GSAPoint3i();
            Pvr_SafeAreaAlgoAPI.GSAPoint3i normalDir3i    = new Pvr_SafeAreaAlgoAPI.GSAPoint3i();

            double distance = Pvr_SafeAreaAlgoAPI.Pvr_GSABoundaryDetector2(ref point3i, isPlayArea, ref closestPoint3i, ref normalDir3i);

            closestPoint.x = closestPoint3i.x / 1000.0f;
            closestPoint.y = closestPoint3i.y / 1000.0f;
            closestPoint.z = closestPoint3i.z / 1000.0f;

            normalDir.x = normalDir3i.x / 1000.0f;
            normalDir.y = normalDir3i.y / 1000.0f;
            normalDir.z = normalDir3i.z / 1000.0f;

            return(distance / 1000.0f); // mm -> m
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Commit new line
        /// </summary>
        /// <param name="isFistLine">init or reset</param>
        /// <param name="points">point set</param>
        /// <returns></returns>
        public bool CommitNewLineData(bool isFistLine, Vector3[] points)
        {
            Pvr_SafeAreaAlgoAPI.GSALineCollection lineCollection = new Pvr_SafeAreaAlgoAPI.GSALineCollection();
            lineCollection.lineCount = 2;

            Pvr_SafeAreaAlgoAPI.GSALine[] lineArray = new Pvr_SafeAreaAlgoAPI.GSALine[2];
            if (isFistLine)
            {
                lineArray[0].pointArray = IntPtr.Zero;
                lineArray[0].pointCount = 0;
            }
            else
            {
                Pvr_SafeAreaAlgoAPI.GSAPoint3i[] tPoint = new Pvr_SafeAreaAlgoAPI.GSAPoint3i[1];
                tPoint[0] = new Pvr_SafeAreaAlgoAPI.GSAPoint3i()
                {
                    x = 0, y = 0, z = 0
                };
                lineArray[0].pointArray = Marshal.UnsafeAddrOfPinnedArrayElement(tPoint, 0); // unsafe
                lineArray[0].pointCount = 1;
            }

            Pvr_SafeAreaAlgoAPI.GSAPoint3i[] pointArray = new Pvr_SafeAreaAlgoAPI.GSAPoint3i[points.Length];
            for (int i = 0; i < points.Length; i++)
            {
                Pvr_SafeAreaAlgoAPI.GSAPoint3i newPoint = new Pvr_SafeAreaAlgoAPI.GSAPoint3i();
                newPoint.x = (int)(points[i].x * 1000);
                newPoint.y = (int)(points[i].y * 1000);
                newPoint.z = (int)(points[i].z * 1000);

                pointArray[i] = newPoint;
            }


            lineArray[1].pointArray = Marshal.UnsafeAddrOfPinnedArrayElement(pointArray, 0); // unsafe
            lineArray[1].pointCount = pointArray.Length;

            lineCollection.lineArray = Marshal.UnsafeAddrOfPinnedArrayElement(lineArray, 0);

            IntPtr collectionPtr = Pvr_BoundaryAPI.StructToIntPtr <Pvr_SafeAreaAlgoAPI.GSALineCollection>(lineCollection);

            int ret = Pvr_SafeAreaAlgoAPI.Pvr_GSAUpDateData(collectionPtr);

            Marshal.FreeHGlobal(collectionPtr);

            if (ret != 0)
            {
                Debug.LogError("BoundarySystem commit new line data failed!");
                return(false);
            }

            return(true);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Shutdown BoundarySystem Algo
        /// </summary>
        /// <returns></returns>
        public bool Shutdown()
        {
            int ret = Pvr_SafeAreaAlgoAPI.Pvr_GSAShutDown();

            if (ret != 0)
            {
                Debug.LogError("BoundarySystem shutdown failed!");
                return(false);
            }

            return(true);
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Query distance between boundary and point
        /// </summary>
        /// <param name="point">point</param>
        /// <returns>
        /// Distance > 0.0, Inside the Boundary
        /// Distance = 0.0, On the Boundary
        /// Distance < 0.0, Outside the Boundary
        /// -1 : Error
        /// </returns>
        public double QueryDistanceOfPoint(Vector3 point)
        {
            //point.Set(point.x * 1000, point.y * 1000, point.z * 1000); // m -> mm
            //IntPtr pointPtr = Pvr_BoundaryAPI.StructToIntPtr<Vector3>(point);
            //double distance = Pvr_SafeAreaAlgoAPI.Pvr_GSABoundaryDetector(pointPtr);
            //Marshal.FreeHGlobal(pointPtr);

            Pvr_SafeAreaAlgoAPI.GSAPoint3i point3i = new Pvr_SafeAreaAlgoAPI.GSAPoint3i();
            point3i.x = (int)(point.x * 1000);
            point3i.y = (int)(point.y * 1000);
            point3i.z = (int)(point.z * 1000);

            double distance = Pvr_SafeAreaAlgoAPI.Pvr_GSABoundaryDetector(ref point3i);

            return(distance / 1000.0f); // mm -> m
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Start BoundarySystem Algo
        /// </summary>
        /// <param name="callback"></param>
        /// <returns></returns>
        public bool Start()
        {
            // First:Register callback
            int ret1 = Pvr_SafeAreaAlgoAPI.Pvr_GSASetCallback(_SafeAreaCallback);
            int ret2 = Pvr_SafeAreaAlgoAPI.Pvr_GSASetCallbackShrink(_SafeAreaCallbackShrink);

            if (ret1 != 0 || ret2 != 0)
            {
                Debug.LogError("BoundarySystem register callback failed!");
                return(false);
            }

            // Second:Init Boundary System,using 300cm * 300cm
            int ret = Pvr_SafeAreaAlgoAPI.Pvr_GSAInit(300, 300);

            if (ret != 0)
            {
                Debug.LogError("BoundarySystem init failed!");
                return(false);
            }

            return(true);
        }