Ejemplo n.º 1
0
        private static bool _HitTestTrianglesResult(IHitTestSource model, DataPair pair, LazyArray <Point3F, PointF> pointsTransformed, RectF rectInWpf, bool isFullContain, ref bool flag1, ref bool flag2)
        {
            var stopCond = false;
            var stride   = model.Mode == GLPrimitiveMode.GL_TRIANGLES ? 3 : 1;

            for (int i = 0; i < pair.Count - 2; i += stride)
            {
                var pt1 = pointsTransformed[i + pair.Start];
                var pt2 = pointsTransformed[i + 1 + pair.Start];
                var pt3 = pointsTransformed[i + 2 + pair.Start];

                var triangle = new Triangle(pt1, pt2, pt3);
                if (!isFullContain)
                {
                    if (rectInWpf.Contains(triangle.P1) || rectInWpf.Contains(triangle.P2) || rectInWpf.Contains(triangle.P3) ||
                        triangle.IsPointInside(rectInWpf.TopLeft) || triangle.IsPointInside(rectInWpf.TopRight) || triangle.IsPointInside(rectInWpf.BottomLeft) || triangle.IsPointInside(rectInWpf.BottomRight))
                    {
                        flag1    = true;
                        stopCond = true;
                        break;
                    }
                }
                else
                {
                    if (!triangle.IsCompletelyInside(rectInWpf))
                    {
                        flag2    = false;
                        stopCond = true;
                        break;
                    }
                }
            }
            return(stopCond);
        }
Ejemplo n.º 2
0
        private static bool _HitTestTriangleFansResult(DataPair pair, LazyArray <Point3F, PointF> pointsTransformed, RectF rectInWpf, bool isFullContain, ref bool flag1, ref bool flag2)
        {
            var stopCond = false;
            var pt1      = pointsTransformed[pair.Start];

            for (int i = 2; i < pair.Count; i++)
            {
                var pt2 = pointsTransformed[i - 1 + pair.Start];
                var pt3 = pointsTransformed[i + pair.Start];

                var triangle = new Triangle(pt1, pt2, pt3);
                if (!isFullContain)
                {
                    if (rectInWpf.Contains(triangle.P1) || rectInWpf.Contains(triangle.P2) || rectInWpf.Contains(triangle.P3) ||
                        triangle.IsPointInside(rectInWpf.TopLeft) || triangle.IsPointInside(rectInWpf.TopRight) || triangle.IsPointInside(rectInWpf.BottomLeft) || triangle.IsPointInside(rectInWpf.BottomRight))
                    {
                        flag1    = true;
                        stopCond = true;
                        break;
                    }
                }
                else
                {
                    if (!triangle.IsCompletelyInside(rectInWpf))
                    {
                        flag2    = false;
                        stopCond = true;
                        break;
                    }
                }
            }
            return(stopCond);
        }
Ejemplo n.º 3
0
        private static bool _HitTestPointResult(DataPair pair, LazyArray <Point3F, PointF> pointsTransformed, RectF rectInWpf, bool isFullContain, float sensity, ref bool flag1, ref bool flag2)
        {
            var stopCond = false;

            for (int i = 0; i < pair.Count; i++)
            {
                var pt = pointsTransformed[i + pair.Start];
                if (!isFullContain)
                {
                    if (rectInWpf.Contains(pt, sensity))
                    {
                        flag1    = true;
                        stopCond = true;
                        break;
                    }
                }
                else
                {
                    var rect = new RectF(pt, pt);
                    rect.Extents(sensity);
                    if (!rectInWpf.Contains(rect))
                    {
                        flag2    = false;
                        stopCond = true;
                        break;
                    }
                }
            }
            return(stopCond);
        }
Ejemplo n.º 4
0
        private static bool _HitTestTriangleFansResult(IHitTestSource model, DataPair pair, Point3F[] points, LazyArray <Point3F, Point3F> pointsTransformed, List <HitResult> results, PointF pointInWpf)
        {
            var flag   = false;
            var index1 = pair.Start;
            var p1     = points[index1];
            var pt1    = pointsTransformed[index1];

            for (int i = 2; i < pair.Count; i++)
            {
                var index2 = i - 1 + pair.Start;
                var index3 = i + pair.Start;
                var p2     = points[index2];
                var p3     = points[index3];
                var pt2    = pointsTransformed[index2];
                var pt3    = pointsTransformed[index3];

                var   triangle = new Triangle((PointF)pt1, (PointF)pt2, (PointF)pt3);
                float a, b;
                triangle.CalcBarycentric(pointInWpf, out a, out b);
                if (a >= 0 && b >= 0 && a + b <= 1)
                {
                    var c = 1 - a - b;
                    var z = pt1.Z * a + pt2.Z * b + pt3.Z * c;
                    results.Add(new HitResult(new TriangleMesh(p1, p2, p3, model.GetIndex(index1), model.GetIndex(index2), model.GetIndex(index3), a, b, c), model, z));
                    flag = true;
                }
            }
            return(flag);
        }
Ejemplo n.º 5
0
        private static bool _HitTestLinesResult(IHitTestSource model, DataPair pair, Point3F[] points, LazyArray <Point3F, Point3F> pointsTransformed, List <HitResult> results, PointF pointInWpf, float sensity)
        {
            var flag   = false;
            var cond   = pair.Count - 1;
            var stride = model.Mode == GLPrimitiveMode.GL_LINES ? 2 : 1;
            var limit  = model.Mode == GLPrimitiveMode.GL_LINE_LOOP ? pair.Count : pair.Count - 1;

            for (int i = 0; i < limit; i += stride)
            {
                var index1 = i + pair.Start;
                var index2 = i + 1 + pair.Start;
                if (i == cond)
                {
                    index2 = 0;
                }

                var p1  = points[index1];
                var p2  = points[index2];
                var pt1 = pointsTransformed[index1];
                var pt2 = pointsTransformed[index2];

                var line = new Line((PointF)pt1, (PointF)pt2);
                var cp   = _LineHitTest(pointInWpf, line, sensity);
                if (cp.HasValue)
                {
                    var p = cp.Value;
                    var t = line.CalcT(p);
                    GeometryHelper.Clamp(ref t, 0, 1);
                    var z = t * pt1.Z + (1 - t) * pt2.Z;
                    results.Add(new HitResult(new LineMesh(p1, p2, model.GetIndex(index1), model.GetIndex(index2), t, 1 - t), model, z));
                    flag = true;
                }
            }
            return(flag);
        }
Ejemplo n.º 6
0
        private static bool _HitTestPointResult(IHitTestSource model, DataPair pair, Point3F[] points, LazyArray <Point3F, Point3F> pointsTransformed, List <HitResult> results, PointF pointInWpf, float sensity)
        {
            var flag  = false;
            var index = pair.Start;

            for (int i = 0; i < pair.Count; i++, index++)
            {
                var p    = points[index];
                var pt   = pointsTransformed[index];
                var dist = (pointInWpf - (PointF)pt).Length;
                if (dist <= sensity)
                {
                    results.Add(new HitResult(new PointMesh(p), model, pt.Z));
                    flag = true;
                }
            }
            return(flag);
        }
Ejemplo n.º 7
0
        private static bool _HitTestLinesResult(IHitTestSource model, DataPair pair, LazyArray <Point3F, PointF> pointsTransformed, RectF rectInWpf, bool isFullContain, float sensity, ref bool flag1, ref bool flag2)
        {
            var stopCond = false;
            var cond     = pair.Count - 1;
            var stride   = model.Mode == GLPrimitiveMode.GL_LINES ? 2 : 1;
            var limit    = model.Mode == GLPrimitiveMode.GL_LINE_LOOP ? pair.Count : pair.Count - 1;

            for (int i = 0; i < limit; i += stride)
            {
                var index1 = i + pair.Start;
                var index2 = i + 1 + pair.Start;
                if (i == cond)
                {
                    index2 = 0;
                }
                var pt1 = pointsTransformed[index1];
                var pt2 = pointsTransformed[index2];

                var line   = new Line(pt1, pt2);
                var bounds = line.GetBounds();
                bounds.Extents(sensity);
                if (!isFullContain)
                {
                    if (bounds.IntersectsWith(rectInWpf) && line.HitTest(rectInWpf, sensity))
                    {
                        flag1    = true;
                        stopCond = true;
                        break;
                    }
                }
                else
                {
                    if (!rectInWpf.Contains(bounds))
                    {
                        flag2    = false;
                        stopCond = true;
                        break;
                    }
                }
            }
            return(stopCond);
        }