Example #1
0
        public TriangleOver(Triangle t)
        {
            triangles = JavaSystem.Dim <float>(t.GetTriangleCount() * 6 * 3, 2);

            int tcount = 0;

            for (int i = 0; i < t.GetTriangleCount(); i++)
            {
                float cx = 0;
                float cy = 0;
                for (int p = 0; p < 3; p++)
                {
                    float[] pt = t.GetTrianglePoint(i, p);
                    cx += pt[0];
                    cy += pt[1];
                }

                cx /= 3;
                cy /= 3;

                for (int p = 0; p < 3; p++)
                {
                    int n = p + 1;
                    if (n > 2)
                    {
                        n = 0;
                    }

                    float[] pt1 = t.GetTrianglePoint(i, p);
                    float[] pt2 = t.GetTrianglePoint(i, n);

                    pt1[0] = (pt1[0] + pt2[0]) / 2;
                    pt1[1] = (pt1[1] + pt2[1]) / 2;

                    triangles[(tcount * 3) + 0][0] = cx;
                    triangles[(tcount * 3) + 0][1] = cy;
                    triangles[(tcount * 3) + 1][0] = pt1[0];
                    triangles[(tcount * 3) + 1][1] = pt1[1];
                    triangles[(tcount * 3) + 2][0] = pt2[0];
                    triangles[(tcount * 3) + 2][1] = pt2[1];
                    tcount++;
                }

                for (int p = 0; p < 3; p++)
                {
                    int n = p + 1;
                    if (n > 2)
                    {
                        n = 0;
                    }

                    float[] pt1 = t.GetTrianglePoint(i, p);
                    float[] pt2 = t.GetTrianglePoint(i, n);

                    pt2[0] = (pt1[0] + pt2[0]) / 2;
                    pt2[1] = (pt1[1] + pt2[1]) / 2;

                    triangles[(tcount * 3) + 0][0] = cx;
                    triangles[(tcount * 3) + 0][1] = cy;
                    triangles[(tcount * 3) + 1][0] = pt1[0];
                    triangles[(tcount * 3) + 1][1] = pt1[1];
                    triangles[(tcount * 3) + 2][0] = pt2[0];
                    triangles[(tcount * 3) + 2][1] = pt2[1];
                    tcount++;
                }
            }
        }