Exemplo n.º 1
0
 /// <summary>
 /// 添加三角形
 /// </summary>
 /// <param name="TriID"></param>
 public void AddTri(GolfMaptriangle Tri)
 {
     if (m_ListTriangle.Contains(Tri) == false)
     {
         m_ListTriangle.Add(Tri);
     }
 }
Exemplo n.º 2
0
        /// <summary>
        /// 搜索点在的地图块及三角形
        /// </summary>
        /// <returns></returns>
        public bool SearchMapTriangle(Vector3 Point, ref SearchResult result)
        {
            Vector2 p = new Vector2(Point.x, Point.z);

            if (this.CheckProjectionInArea(p) == false)
            {
                return(false);
            }
            List <Index2> l = m_Qtree.GetAllTri(Point);

            if (l == null || l.Count == 0)
            {
                return(false);
            }
            foreach (Index2 v in l)
            {
                GolfMaptriangle tri = GetMapTriangle(v);
                if (tri.CheckProjectionInArea(Point) == true)
                {
                    if (result == null)
                    {
                        result = new SearchResult();
                    }
                    result.Poly = tri.Parent;
                    result.Type = GetSubMap(v.MapID).Type;
                    return(true);
                }
            }
            return(false);
        }
Exemplo n.º 3
0
 /// <summary>
 /// 构建4叉树
 /// </summary>
 public void Create(List <Index2> listAB, GolfCourseMap map)
 {
     if (listAB == null || listAB.Count == 0)
     {
         return;
     }
     if (listAB.Count <= MaxCount)
     {
         m_SelfList = new List <Index2>();
         m_SelfList.AddRange(listAB);
     }
     else
     {
         Vector2 cc = (this.AA2 + this.BB2) * 0.5f;
         m_UpLeftTree    = new QuadTree(this.AA2, cc);
         m_UpRightTree   = new QuadTree(new Vector2(cc.x, this.AA2.y), new Vector2(this.BB2.x, cc.y));
         m_DownLeftTree  = new QuadTree(new Vector2(this.AA2.x, cc.y), new Vector2(cc.x, this.BB2.y));
         m_DownRightTree = new QuadTree(cc, this.BB2);
         List <Index2> lUpLeft    = new List <Index2>();
         List <Index2> lUpRight   = new List <Index2>();
         List <Index2> lDownLeft  = new List <Index2>();
         List <Index2> lDownRight = new List <Index2>();
         for (int i = 0; i < listAB.Count; i++)
         {
             GolfMaptriangle tri = map.GetMapTriangle(listAB[i]);
             if (tri == null)
             {
                 continue;
             }
             if (m_UpLeftTree.CheckProjectionContains(tri) == true)
             {
                 lUpLeft.Add(listAB[i]);
             }
             if (m_UpRightTree.CheckProjectionContains(tri) == true)
             {
                 lUpRight.Add(listAB[i]);
             }
             if (m_DownLeftTree.CheckProjectionContains(tri) == true)
             {
                 lDownLeft.Add(listAB[i]);
             }
             if (m_DownRightTree.CheckProjectionContains(tri) == true)
             {
                 lDownRight.Add(listAB[i]);
             }
         }
         CreateSubTree(ref m_UpLeftTree, ref lUpLeft, map);
         CreateSubTree(ref m_UpRightTree, ref lUpRight, map);
         CreateSubTree(ref m_DownLeftTree, ref lDownLeft, map);
         CreateSubTree(ref m_DownRightTree, ref lDownRight, map);
     }
 }
Exemplo n.º 4
0
        /// <summary>
        /// 构建
        /// </summary>
        /// <param name="data"></param>
        public void Create(SubMapData data)
        {
            if (data == null)
            {
                return;
            }
            List <GolfAIPoint> lp = new List <GolfAIPoint>();

            for (int i = 0; i < data.Listpt.Count; i++)
            {
                lp.Add(new GolfAIPoint(data.Listpt[i]));
            }

            List <GolfMaptriangle> ListT = new List <GolfMaptriangle>();
            int total = data.ListTriangle.Count / 3;

            for (int i = 0; i < total; i++)
            {
                int             index = i * 3;
                GolfMaptriangle c     = new GolfMaptriangle(lp[data.ListTriangle[index]], lp[data.ListTriangle[index + 1]], lp[data.ListTriangle[index + 2]]);
                ListT.Add(c);
            }

            List <GolfAIMapPolygon> lpoly = new List <GolfAIMapPolygon>();

            total = data.ListPoly.Count;
            for (int i = 0; i < total; i++)
            {
                List <GolfMaptriangle> l = new List <GolfMaptriangle>();
                for (int j = 0; j < data.ListPoly[i].ListTriangle.Count; j++)
                {
                    l.Add(ListT[data.ListPoly[i].ListTriangle[j]]);
                }
                List <GolfAIPoint> ll = new List <GolfAIPoint>();
                for (int j = 0; j < data.ListPoly[i].ListPt.Count; j++)
                {
                    ll.Add(lp[data.ListPoly[i].ListPt[j]]);
                }
                lpoly.Add(new GolfAIMapPolygon(l, ll, data.ListPoly[i].m_normal));
            }
            Create(lp, ListT, lpoly, data.m_Type);
        }
Exemplo n.º 5
0
        /// <summary>
        /// 获取滚动进入的邻边多边形形
        /// </summary>
        /// <param name="s">起点,s点在目标三角形内</param>
        /// <param name="e">终点</param>
        /// <param name="TargetTri">目标三角形</param>
        /// <param name="collision"></param>
        /// <returns>true:有进入 false 未进入</returns>
        public bool CheckIntoNearTriangle(Vector3 s, Vector3 e, GolfAIMapPolygon PolyTarget, ref GolfIntoTriCollision collision)
        {
            Vector3 hitPoint = Vector3.zero;

            if (PolyTarget == null)
            {
                return(false);
            }
            // 判断是否在多边形内部
            if (PolyTarget.CheckProjectionInArea(e) == true)
            {
                return(false);
            }
            //
            if (collision == null)
            {
                collision = new GolfIntoTriCollision();
            }

            collision.ColType = CollisionType.Out;
            List <Index2> l = m_Qtree.GetAllTri(e);

            if (l == null || l.Count == 0)
            {
                return(false);
            }
            foreach (Index2 v in l)
            {
                GolfMaptriangle tri = GetMapTriangle(v);
                if (tri.Parent == PolyTarget)
                {
                    continue;
                }
                if (tri.GetLineIntersectPoint(s, e, ref hitPoint) == true)
                {
                    collision.Poly  = tri.Parent;
                    collision.Point = hitPoint;
                    return(true);
                }
            }
            return(false);
        }
Exemplo n.º 6
0
        public bool CheckCollisionPoint(Vector3 s, Vector3 e, ref GolfMapFlyCollision ret)
        {
            if (s.Equals(e) == true)
            {
                return(false);
            }

            if (CheckIsOut(s, e) == true || m_Qtree == null)
            {
                if (ret == null)
                {
                    ret = new GolfMapFlyCollision();
                }
                ret.Point   = e;
                ret.ColType = CollisionType.Out;
                return(true);
            }

            QuadTree tree = m_Qtree.GetTree(s, e);

            if (tree == null)
            {
                if (ret == null)
                {
                    ret = new GolfMapFlyCollision();
                }
                ret.Point   = e;
                ret.ColType = CollisionType.Out;
                return(true);
            }
            else
            {
                Vector3       Hitpoint = Vector3.zero;
                List <Index2> l        = tree.GetAllTri(s, e);
                if (l == null || l.Count == 0)
                {
                    return(false);
                }
                foreach (Index2 v in l)
                {
                    GolfMaptriangle tri = GetMapTriangle(v);
                    if (tri.CalcIntersectPoint(s, e, ref Hitpoint) == true)
                    {
                        if (ret == null)
                        {
                            ret = new GolfMapFlyCollision();
                        }
                        ret.Point   = Hitpoint;
                        ret.Type    = GetSubMap(v.MapID).Type;
                        ret.Poly    = tri.Parent;
                        ret.ColType = CollisionType.Normal;
                        ret.Normal  = ret.Poly.Normal;
                        return(true);
                    }
                }
            }
            if (s.y >= 0 && e.y < 0)
            {
                if (s.y >= 0 && e.y < 0)
                {
                    Debug.Log("XXXXXXXXXXXXXPPPPP:");
                    Debug.Log("s:" + s.x + "," + s.y + "," + s.z);
                    Debug.Log("e:" + e.x + "," + e.y + "," + e.z);
                }
            }
            return(false);
        }