public void MergePoints(ref IndexedVector4 plane, float margin, IndexedVector3[] points, int point_count)
        {
            m_point_count       = 0;
            m_penetration_depth = -1000.0f;

            int _k;

            for (_k = 0; _k < point_count; _k++)
            {
                float _dist = -ClipPolygon.DistancePointPlane(ref plane, ref points[_k]) + margin;

                if (_dist >= 0.0f)
                {
                    if (_dist > m_penetration_depth)
                    {
                        m_penetration_depth = _dist;
                        point_indices[0]    = _k;
                        m_point_count       = 1;
                    }
                    else if ((_dist + MathUtil.SIMD_EPSILON) >= m_penetration_depth)
                    {
                        point_indices[m_point_count] = _k;
                        m_point_count++;
                    }
                }
            }

            for (_k = 0; _k < m_point_count; _k++)
            {
                m_points[_k] = points[point_indices[_k]];
            }
        }
        //! Test if triangles could collide
        public bool OverlapTestConservative(PrimitiveTriangle other)
        {
            float total_margin = m_margin + other.m_margin;
            // classify points on other triangle
            float dis0 = ClipPolygon.DistancePointPlane(ref m_plane, ref other.m_vertices[0]) - total_margin;

            float dis1 = ClipPolygon.DistancePointPlane(ref m_plane, ref other.m_vertices[1]) - total_margin;

            float dis2 = ClipPolygon.DistancePointPlane(ref m_plane, ref other.m_vertices[2]) - total_margin;

            if (dis0 > 0.0f && dis1 > 0.0f && dis2 > 0.0f)
            {
                return(false);
            }

            // classify points on this triangle
            dis0 = ClipPolygon.DistancePointPlane(ref other.m_plane, ref m_vertices[0]) - total_margin;

            dis1 = ClipPolygon.DistancePointPlane(ref other.m_plane, ref m_vertices[1]) - total_margin;

            dis2 = ClipPolygon.DistancePointPlane(ref other.m_plane, ref m_vertices[2]) - total_margin;

            if (dis0 > 0.0f && dis1 > 0.0f && dis2 > 0.0f)
            {
                return(false);
            }

            return(true);
        }
        public int ClipTriangle(PrimitiveTriangle other, IndexedVector3[] clipped_points)
        {
            // edge 0

            //ObjectArray<IndexedVector3> temp_points = new ObjectArray<IndexedVector3>(GIM_TRIANGLE_CONTACT.MAX_TRI_CLIPPING);

            IndexedVector4 edgeplane;

            GetEdgePlane(0, out edgeplane);


            int clipped_count = ClipPolygon.PlaneClipTriangle(ref edgeplane, ref other.m_vertices[0], ref other.m_vertices[1], ref other.m_vertices[2], temp_points);

            if (clipped_count == 0)
            {
                return(0);
            }

            //ObjectArray<IndexedVector3> temp_points1 = new ObjectArray<IndexedVector3>(GIM_TRIANGLE_CONTACT.MAX_TRI_CLIPPING);


            // edge 1
            GetEdgePlane(1, out edgeplane);


            clipped_count = ClipPolygon.PlaneClipPolygon(ref edgeplane, temp_points, clipped_count, temp_points1);

            if (clipped_count == 0)
            {
                return(0);
            }

            // edge 2
            GetEdgePlane(2, out edgeplane);

            Debug.Assert(clipped_count < GIM_TRIANGLE_CONTACT.MAX_TRI_CLIPPING);


            clipped_count = ClipPolygon.PlaneClipPolygon(ref edgeplane, temp_points1, clipped_count, clipped_points);

            return(clipped_count);
        }
        public bool OverlapTestConservative(TriangleShapeEx other)
        {
            float total_margin = GetMargin() + other.GetMargin();

            IndexedVector4 plane0;

            BuildTriPlane(out plane0);
            IndexedVector4 plane1;

            other.BuildTriPlane(out plane1);

            // classify points on other triangle
            float dis0 = ClipPolygon.DistancePointPlane(ref plane0, ref other.m_vertices1[0]) - total_margin;

            float dis1 = ClipPolygon.DistancePointPlane(ref plane0, ref other.m_vertices1[1]) - total_margin;

            float dis2 = ClipPolygon.DistancePointPlane(ref plane0, ref other.m_vertices1[2]) - total_margin;

            if (dis0 > 0.0f && dis1 > 0.0f && dis2 > 0.0f)
            {
                return(false);
            }

            // classify points on this triangle
            dis0 = ClipPolygon.DistancePointPlane(ref plane1, ref m_vertices1[0]) - total_margin;

            dis1 = ClipPolygon.DistancePointPlane(ref plane1, ref m_vertices1[1]) - total_margin;

            dis2 = ClipPolygon.DistancePointPlane(ref plane1, ref m_vertices1[2]) - total_margin;

            if (dis0 > 0.0f && dis1 > 0.0f && dis2 > 0.0f)
            {
                return(false);
            }

            return(true);
        }