Ejemplo n.º 1
0
        public static void splitRect(int axis, Rect3d source, Rect3d b1, Rect3d b2, float[] midpoint)
        {
            switch (axis)
            {
            case 0:
                b1.SetMin(source.mMin);
                b1.SetMax(midpoint[0], source.mMax[1], source.mMax[2]);

                b2.SetMin(midpoint[0], source.mMin[1], source.mMin[2]);
                b2.SetMax(source.mMax);
                break;

            case 1:
                b1.SetMin(source.mMin);
                b1.SetMax(source.mMax[0], midpoint[1], source.mMax[2]);

                b2.SetMin(source.mMin[0], midpoint[1], source.mMin[2]);
                b2.SetMax(source.mMax);
                break;

            case 2:
                b1.SetMin(source.mMin);
                b1.SetMax(source.mMax[0], source.mMax[1], midpoint[2]);

                b2.SetMin(source.mMin[0], source.mMin[1], midpoint[2]);
                b2.SetMax(source.mMax);
                break;
            }
        }
Ejemplo n.º 2
0
        public static void splitRect(int axis, Rect3d source, Rect3d b1, Rect3d b2, float[] midpoint)
        {
            switch (axis)
            {
                case 0:
                    b1.SetMin(source.mMin);
                    b1.SetMax(midpoint[0], source.mMax[1], source.mMax[2]);

                    b2.SetMin(midpoint[0], source.mMin[1], source.mMin[2]);
                    b2.SetMax(source.mMax);
                    break;
                case 1:
                    b1.SetMin(source.mMin);
                    b1.SetMax(source.mMax[0], midpoint[1], source.mMax[2]);

                    b2.SetMin(source.mMin[0], midpoint[1], source.mMin[2]);
                    b2.SetMax(source.mMax);
                    break;
                case 2:
                    b1.SetMin(source.mMin);
                    b1.SetMax(source.mMax[0], source.mMax[1], midpoint[2]);

                    b2.SetMin(source.mMin[0], source.mMin[1], midpoint[2]);
                    b2.SetMax(source.mMax);
                    break;
            }
        }
Ejemplo n.º 3
0
        public static bool computeSplitPlane(List<float3> vertices, List<int> indices, ref float4 plane)
        {
            float[] bmin = { Single.MaxValue, Single.MaxValue, Single.MaxValue };
            float[] bmax = { Single.MinValue, Single.MinValue, Single.MinValue };

            for (int i = 0; i < vertices.Count; i++)
            {
                float3 p = vertices[i];

                if (p[0] < bmin[0])
                    bmin[0] = p[0];
                if (p[1] < bmin[1])
                    bmin[1] = p[1];
                if (p[2] < bmin[2])
                    bmin[2] = p[2];

                if (p[0] > bmax[0])
                    bmax[0] = p[0];
                if (p[1] > bmax[1])
                    bmax[1] = p[1];
                if (p[2] > bmax[2])
                    bmax[2] = p[2];
            }

            float dx = bmax[0] - bmin[0];
            float dy = bmax[1] - bmin[1];
            float dz = bmax[2] - bmin[2];

            // 20131224 not used            float laxis = dx;

            int axis = 0;

            if (dy > dx)
            {
                axis = 1;
            // 20131224 not used                laxis = dy;
            }

            if (dz > dx && dz > dy)
            {
                axis = 2;
            // 20131224 not used                laxis = dz;
            }

            float[] p1 = new float[3];
            float[] p2 = new float[3];
            float[] p3 = new float[3];

            p3[0] = p2[0] = p1[0] = bmin[0] + dx * 0.5f;
            p3[1] = p2[1] = p1[1] = bmin[1] + dy * 0.5f;
            p3[2] = p2[2] = p1[2] = bmin[2] + dz * 0.5f;

            Rect3d b = new Rect3d(bmin, bmax);

            Rect3d b1 = new Rect3d();
            Rect3d b2 = new Rect3d();

            splitRect(axis, b, b1, b2, p1);

            switch (axis)
            {
                case 0:
                    p2[1] = bmin[1];
                    p2[2] = bmin[2];

                    if (dz > dy)
                    {
                        p3[1] = bmax[1];
                        p3[2] = bmin[2];
                    }
                    else
                    {
                        p3[1] = bmin[1];
                        p3[2] = bmax[2];
                    }

                    break;
                case 1:
                    p2[0] = bmin[0];
                    p2[2] = bmin[2];

                    if (dx > dz)
                    {
                        p3[0] = bmax[0];
                        p3[2] = bmin[2];
                    }
                    else
                    {
                        p3[0] = bmin[0];
                        p3[2] = bmax[2];
                    }

                    break;
                case 2:
                    p2[0] = bmin[0];
                    p2[1] = bmin[1];

                    if (dx > dy)
                    {
                        p3[0] = bmax[0];
                        p3[1] = bmin[1];
                    }
                    else
                    {
                        p3[0] = bmin[0];
                        p3[1] = bmax[1];
                    }

                    break;
            }

            computePlane(p1, p2, p3, plane);

            return true;
        }
Ejemplo n.º 4
0
        public static bool computeSplitPlane(List <float3> vertices, List <int> indices, ref float4 plane)
        {
            float[] bmin = { Single.MaxValue, Single.MaxValue, Single.MaxValue };
            float[] bmax = { Single.MinValue, Single.MinValue, Single.MinValue };

            for (int i = 0; i < vertices.Count; i++)
            {
                float3 p = vertices[i];

                if (p[0] < bmin[0])
                {
                    bmin[0] = p[0];
                }
                if (p[1] < bmin[1])
                {
                    bmin[1] = p[1];
                }
                if (p[2] < bmin[2])
                {
                    bmin[2] = p[2];
                }

                if (p[0] > bmax[0])
                {
                    bmax[0] = p[0];
                }
                if (p[1] > bmax[1])
                {
                    bmax[1] = p[1];
                }
                if (p[2] > bmax[2])
                {
                    bmax[2] = p[2];
                }
            }

            float dx = bmax[0] - bmin[0];
            float dy = bmax[1] - bmin[1];
            float dz = bmax[2] - bmin[2];

// 20131224 not used            float laxis = dx;

            int axis = 0;

            if (dy > dx)
            {
                axis = 1;
// 20131224 not used                laxis = dy;
            }

            if (dz > dx && dz > dy)
            {
                axis = 2;
// 20131224 not used                laxis = dz;
            }

            float[] p1 = new float[3];
            float[] p2 = new float[3];
            float[] p3 = new float[3];

            p3[0] = p2[0] = p1[0] = bmin[0] + dx * 0.5f;
            p3[1] = p2[1] = p1[1] = bmin[1] + dy * 0.5f;
            p3[2] = p2[2] = p1[2] = bmin[2] + dz * 0.5f;

            Rect3d b = new Rect3d(bmin, bmax);

            Rect3d b1 = new Rect3d();
            Rect3d b2 = new Rect3d();

            splitRect(axis, b, b1, b2, p1);

            switch (axis)
            {
            case 0:
                p2[1] = bmin[1];
                p2[2] = bmin[2];

                if (dz > dy)
                {
                    p3[1] = bmax[1];
                    p3[2] = bmin[2];
                }
                else
                {
                    p3[1] = bmin[1];
                    p3[2] = bmax[2];
                }

                break;

            case 1:
                p2[0] = bmin[0];
                p2[2] = bmin[2];

                if (dx > dz)
                {
                    p3[0] = bmax[0];
                    p3[2] = bmin[2];
                }
                else
                {
                    p3[0] = bmin[0];
                    p3[2] = bmax[2];
                }

                break;

            case 2:
                p2[0] = bmin[0];
                p2[1] = bmin[1];

                if (dx > dy)
                {
                    p3[0] = bmax[0];
                    p3[1] = bmin[1];
                }
                else
                {
                    p3[0] = bmin[0];
                    p3[1] = bmax[1];
                }

                break;
            }

            computePlane(p1, p2, p3, plane);

            return(true);
        }