Beispiel #1
0
        private static bool inCone(int i, int n, int[] verts, int pj, int[] vertpj)
        {
            int pi   = i * 4;
            int pi1  = RecastMesh.next(i, n) * 4;
            int pin1 = RecastMesh.prev(i, n) * 4;

            int[] pverts = new int[4 * 4];
            for (int g = 0; g < 4; g++)
            {
                pverts[g]      = verts[pi + g];
                pverts[4 + g]  = verts[pi1 + g];
                pverts[8 + g]  = verts[pin1 + g];
                pverts[12 + g] = vertpj[pj + g];
            }
            pi   = 0;
            pi1  = 4;
            pin1 = 8;
            pj   = 12;
            // If P[i] is a convex vertex [ i+1 left or on (i-1,i) ].
            if (RecastMesh.leftOn(pverts, pin1, pi, pi1))
            {
                return(RecastMesh.left(pverts, pi, pj, pin1) && RecastMesh.left(pverts, pj, pi, pi1));
            }
            // Assume (i-1,i,i+1) not collinear.
            // else P[i] is reflex.
            return(!(RecastMesh.leftOn(pverts, pi, pj, pi1) && RecastMesh.leftOn(pverts, pj, pi, pin1)));
        }
Beispiel #2
0
        private static bool intersectSegCountour(int d0, int d1, int i, int n, int[] verts, int[] d0verts, int[] d1verts)
        {
            // For each edge (k,k+1) of P
            int[] pverts = new int[4 * 4];
            for (int g = 0; g < 4; g++)
            {
                pverts[g]     = d0verts[d0 + g];
                pverts[4 + g] = d1verts[d1 + g];
            }
            d0 = 0;
            d1 = 4;
            for (int k = 0; k < n; k++)
            {
                int k1 = RecastMesh.next(k, n);
                // Skip edges incident to i.
                if (i == k || i == k1)
                {
                    continue;
                }
                int p0 = k * 4;
                int p1 = k1 * 4;
                for (int g = 0; g < 4; g++)
                {
                    pverts[8 + g]  = verts[p0 + g];
                    pverts[12 + g] = verts[p1 + g];
                }
                p0 = 8;
                p1 = 12;
                if (RecastMesh.vequal(pverts, d0, p0) || RecastMesh.vequal(pverts, d1, p0) || RecastMesh.vequal(pverts, d0, p1) || RecastMesh.vequal(pverts, d1, p1))
                {
                    continue;
                }

                if (RecastMesh.intersect(pverts, d0, d1, p0, p1))
                {
                    return(true);
                }
            }
            return(false);
        }
Beispiel #3
0
        private static void removeDegenerateSegments(List <int> simplified)
        {
            // Remove adjacent vertices which are equal on xz-plane,
            // or else the triangulator will get confused.
            int npts = simplified.Count / 4;

            for (int i = 0; i < npts; ++i)
            {
                int ni = RecastMesh.next(i, npts);

                //			if (vequal(&simplified[i*4], &simplified[ni*4]))
                if (simplified[i * 4] == simplified[ni * 4] && simplified[i * 4 + 2] == simplified[ni * 4 + 2])
                {
                    // Degenerate segment, remove.
                    simplified.RemoveAt(i * 4);
                    simplified.RemoveAt(i * 4);
                    simplified.RemoveAt(i * 4);
                    simplified.RemoveAt(i * 4);
                    npts--;
                }
            }
        }