Exemplo n.º 1
0
        public void RenderSingleGround(List <Vector2d> ground, EPMPoint.PointType type)
        {
            int             groundEnums = EPMPoint.GetGroundEnums();
            List <EPMPoint> plist       = m_terrain.ExtractPoints_ByRegion(ground, null, groundEnums);

            for (int i = 0; i < plist.Count; i++)
            {
                plist[i].SetType(type);
            }

            List <EPMTriangle> triangleList = m_terrain.ExtractTriangles_ByVertex(plist);

            for (int i = 0; i < triangleList.Count; i++)
            {
                if (!triangleList[i].HasShapeType(groundEnums))
                {
                    continue;
                }
                triangleList[i].TryDetermineType();
            }
            EPMPreDefinedTools.CheckAndSetTileTypeByNeighbor(m_terrain, EPMPoint.GetGroundEnums(), EPMPoint.GenerateTypesInt(false, type), type);
        }
Exemplo n.º 2
0
        public void RenderHill()
        {
            List <EPMPoint> hillPoints = m_terrain.ExtractPoints_ByTypes(null, EPMPoint.GenerateTypesInt(false, EPMPoint.PointType.Hill));

            for (int k = 0; k < g_customData.hillLists.Count; k++)
            {
                List <Vector2d> hill = g_customData.hillLists[k];
                for (int i = 1; i < hill.Count; i++)
                {
                    EPMHeightSampler.DistanceToLine(m_defaultHillHeight, hill[i - 1], hill[i], m_hillHalfWidth * 1.2f, hillPoints, EPMHeightSampler.CurveMode.CosineHalf);
                }
            }

            for (int i = 0; i < hillPoints.Count; i++)
            {
                hillPoints[i].ApplyHeight();
            }

            for (int k = 0; k < g_customData.hillLists.Count; k++)
            {
                List <Vector2d> hill = g_customData.hillLists[k];
                for (int i = 1; i < hill.Count; i++)
                {
                    EPMHeightSampler.DirectionalDistance(m_terrain.RandomDouble(2f, 5f), hill[i] - hill[i - 1], 50f, hillPoints, m_defaultHillHeight * 1.5f, 2);
                }
            }

            List <EPMTriangle> hillTriangles = m_terrain.ExtractTriangles_ByVertex(hillPoints);

            for (int i = 0; i < hillTriangles.Count; i++)
            {
                if (hillTriangles[i].HasShapeType(EPMPoint.GetGroundEnums()))
                {
                    hillTriangles[i].SetType(EPMPoint.PointType.Hill);
                }
            }
        }
Exemplo n.º 3
0
        public static void ExtractSide(EPMDelaunayTerrain terrain, EPMPoint.PointType oldType, EPMPoint.PointType sideType, double inLength = 2f)
        {
            List <EPMTriangle> list      = terrain.ExtractTriangles_ByTypes(null, EPMPoint.GenerateTypesInt(false, oldType));
            List <EPMPoint>    allPoints = terrain.ExtractPoints_All();
            List <EPMTriangle> sideList  = new List <EPMTriangle>();
            int groundEnum = EPMPoint.GetGroundEnums();

            for (int i = 0; i < list.Count; i++)
            {
                EPMTriangle t = (EPMTriangle)list[i];
                int         count = 0;
                int         ep1, ep2;
                ep1 = ep2 = 0;
                for (int j = 0; j < t.g_shareEdgeNeighbors.Count; j++)
                {
                    //The edge has an ground tile neighbor.
                    if (t.g_shareEdgeNeighbors[j].HasShapeType(groundEnum))
                    {
                        count++;
                        t.GetShareEdge((EPMTriangle)t.g_shareEdgeNeighbors[j], out ep1, out ep2);
                    }
                }

                if (count == 1)
                {
                    if (!t.g_visited)
                    {
                        sideList.Add(t);
                        t.g_visited = true;
                    }

                    int ep3 = t.g_sortedIndexList[0];
                    if (ep3 == ep1 || ep3 == ep2)
                    {
                        ep3 = t.g_sortedIndexList[1];
                    }
                    if (ep3 == ep1 || ep3 == ep2)
                    {
                        ep3 = t.g_sortedIndexList[2];
                    }

                    Vector2d p1, p2, p3;
                    p1 = allPoints[ep1].pos2d;
                    p2 = allPoints[ep2].pos2d;
                    p3 = allPoints[ep3].pos2d;

                    Vector2d dir    = p2 - p1;
                    Vector2d normal = new Vector2d(-dir.y, dir.x);
                    normal.Normalize();
                    if ((p3 - p1) * normal < 0)
                    {
                        normal = -normal;
                    }

                    for (int k = 0; k < t.g_shareEdgeNeighbors.Count; k++)
                    {
                        if (t.g_shareEdgeNeighbors[k].HasShapeType(oldType))
                        {
                            EPMTriangle nei = (EPMTriangle)t.g_shareEdgeNeighbors[k];
                            if (nei.g_visited == false)
                            {
                                nei.g_visited = true;
                                sideList.Add(nei);
                            }
                            for (int j = 0; j < nei.g_sharePointNeighbors.Count; j++)
                            {
                                EPMTriangle t2 = (EPMTriangle)nei.g_sharePointNeighbors[j];
                                if (t2.HasShapeType(oldType) && t2.g_visited == false)
                                {
                                    Vector2d v2  = t2.g_pointList[0].pos2d;
                                    double   dot = (v2 - p1) * normal;
                                    if (dot >= inLength)
                                    {
                                        continue;
                                    }

                                    v2  = t2.g_pointList[1].pos2d;
                                    dot = (v2 - p1) * normal;
                                    if (dot >= inLength)
                                    {
                                        continue;
                                    }

                                    v2  = t2.g_pointList[2].pos2d;
                                    dot = (v2 - p1) * normal;
                                    if (dot >= inLength)
                                    {
                                        continue;
                                    }

                                    t2.g_visited = true;
                                    sideList.Add((EPMTriangle)nei.g_sharePointNeighbors[j]);
                                }
                            }
                        }
                    }
                }
            }

            for (int i = 0; i < sideList.Count; i++)
            {
                sideList[i].SetType(sideType);
            }

            for (int i = 0; i < list.Count; i++)
            {
                EPMTriangle t = (EPMTriangle)list[i];
                if (t.HasShapeType(sideType))
                {
                    continue;
                }
                bool finded = true;
                for (int j = 0; j < t.g_shareEdgeNeighbors.Count; j++)
                {
                    if (t.g_shareEdgeNeighbors[j].HasShapeType(oldType))
                    {
                        finded = false;
                        break;
                    }
                }
                if (finded)
                {
                    t.SetType(sideType);
                }
            }

            for (int i = 0; i < list.Count; i++)
            {
                list[i].g_visited = false;
            }
        }