Ejemplo n.º 1
0
 private void FindIntersects(List <Vector2> segments, List <float> intersectX, float lineY)
 {
     for (int i = 0; i < segments.Count - 1; ++i)
     {
         Vector2 s0 = segments[i];
         Vector2 s1 = segments[i + 1];
         Vector2 inter;
         if (PGeometryUtilities.IsIntersectHorizontalLine(
                 s0.x, s0.y,
                 s1.x, s1.y,
                 lineY,
                 out inter))
         {
             intersectX.Add(inter.x);
         }
     }
 }
Ejemplo n.º 2
0
        private void VisualizeIntersections()
        {
            if (water.AreaMeshAnchors.Count < 3)
            {
                return;
            }

            Plane plane    = new Plane(Vector3.up, water.transform.position);
            Ray   r        = HandleUtility.GUIPointToWorldRay(Event.current.mousePosition);
            float distance = -1;

            if (plane.Raycast(r, out distance))
            {
                Vector3 hitWorldPos = r.origin + r.direction * distance;

                float lineY = hitWorldPos.z;
                Handles.color = Color.red;
                Handles.DrawLine(new Vector3(-100, 0, lineY), new Vector3(100, 0, lineY));

                List <Vector3> intersections = new List <Vector3>();
                List <Vector3> anchors       = new List <Vector3>(water.AreaMeshAnchors);
                anchors.Add(water.AreaMeshAnchors[0]);
                for (int i = 0; i < anchors.Count - 1; ++i)
                {
                    Vector3 a0 = anchors[i];
                    Vector3 a1 = anchors[i + 1];
                    Vector2 inter;
                    if (PGeometryUtilities.IsIntersectHorizontalLine(a0.x, a0.z, a1.x, a1.z, lineY, out inter))
                    {
                        intersections.Add(new Vector3(inter.x, 0, inter.y));
                    }
                }

                for (int i = 0; i < intersections.Count; ++i)
                {
                    Handles.color = Color.red;
                    Handles.CubeHandleCap(0, intersections[i], Quaternion.identity, 1, EventType.Repaint);
                }
            }
        }