Пример #1
0
        private bool IsVisible(int a, int b)
        {
            float ax      = _nodes[a].x;
            float ay      = _nodes[a].z;
            float bx      = _nodes[b].x;
            float by      = _nodes[b].z;
            float abx     = bx - ax;
            float aby     = by - ay;
            float sqrDist = SomeMath.SqrDistance(ax, ay, bx, by);

            isVisibleTemp.Clear();

            DDARasterization.DrawLine(ax - chunkPos.x, ay - chunkPos.y, bx - chunkPos.x, by - chunkPos.y, edgeMapPiselSize, IsVisibleDelegate);

            foreach (var edge in isVisibleTemp)
            {
                if (edge.Contains(a, b))
                {
                    continue;
                }

                float ix, iy;
                if (SomeMath.RayIntersectSegment(ax, ay, abx, aby, _nodes[edge.a].x, _nodes[edge.a].z, _nodes[edge.b].x, _nodes[edge.b].z, out ix, out iy) && SomeMath.SqrDistance(ax, ay, ix, iy) < sqrDist)
                {
                    return(false);
                }
            }
            return(true);

            //Vector2 aPos = _nodes[a].positionV2;
            //Vector2 bPos = _nodes[b].positionV2;
            //Vector2 dir = bPos - aPos;
            //float curSqrDist = SomeMath.SqrDistance(aPos, bPos);


            //foreach (var edge in edges) {
            //    if (edge.Contains(a, b))
            //        continue;

            //    Vector2 intersection;
            //    if (SomeMath.RayIntersectXZ(
            //        aPos, dir, //from, direction
            //        NodePosV2(edge.a), NodePosV2(edge.b), //a, b
            //        out intersection)
            //        && SomeMath.SqrDistance(aPos, intersection) < curSqrDist) {

            //        //Debuger3.AddRay(new Vector3(intersection.x, 0, intersection.y), Vector3.up, Color.magenta);
            //        //Debuger3.AddLine(ds.NodePosV3(a), new Vector3(intersection.x, 0, intersection.y), Color.magenta);
            //        //Debuger3.AddLine(ds.NodePosV3(b), new Vector3(intersection.x, 0, intersection.y), Color.magenta);
            //        return false;
            //    }
            //}

            //return true;
        }
Пример #2
0
 public bool RayIntersectXZ(float rayOriginX, float rayOriginY, float rayDirectionX, float rayDirectionZ, out float resultX, out float resultZ)
 {
     return(SomeMath.RayIntersectSegment(rayOriginX, rayOriginY, rayDirectionX, rayDirectionZ, xLeft, zLeft, xRight, zRight, out resultX, out resultZ));
 }