Exemple #1
0
        private static void AddEdge(object predecessor, string predecessorRole, object predecessorInfo, object successor, string successorRole,
                                    object successorInfo)
        {
            EdgeInfo edgeInfo;


            revision++;

            Edge edge = new Edge(predecessor, predecessorRole, successor, successorRole);

            if (!edges.TryGetValue(edge, out edgeInfo))
            {
                edgeInfo = new EdgeInfo {
                    Edge = edge, Counter = 1
                };
                edges.Add(edge, edgeInfo);
            }
            else
            {
                edgeInfo.Counter++;
            }


            edgeInfo.LastChange = Environment.TickCount;
            if (predecessorInfo != null)
            {
                edgeInfo.PredecessorInfo = predecessorInfo;
            }
            if (successorInfo != null)
            {
                edgeInfo.SuccessorInfo = successorInfo;
            }
        }
        public override float[] GetRawVertexData()
        {
            int      x          = Tile.X * 16;
            int      y          = Tile.Y * 16;
            EdgeInfo edge       = FindEdgeInfo();
            bool     isWallEdge = edge > 0;
            int      texID      = FindTextureID(edge);
            int      texX       = texID % 16;
            int      texY       = texID / 16;

            if (Tile.IsDefault)
            {
                return(new float[0]);
            }

            int skinOffset = Skin * 2;

            return(new float[]
            {
                x, y,
                (texX + 0) / 16.0f, (texY + skinOffset + 0) / 16.0f,

                x + 16.0f, y,
                (texX + 1) / 16.0f, (texY + skinOffset + 0) / 16.0f,

                x + 16.0f, y + 16.0f,
                (texX + 1) / 16.0f, (texY + skinOffset + 1) / 16.0f,

                x, y + 16.0f,
                (texX + 0) / 16.0f, (texY + skinOffset + 1) / 16.0f
            });
        }
Exemple #3
0
        public TrussInfo CreateTrussInfo(Document doc, XYZ currentPointOnHip, EdgeInfo currentRidgeEdgeInfo, Element firstSupport, Element secondSupport, TrussType tType)
        {
            TrussInfo currentTrussInfo = TrussInfo.BuildTrussAtHip(currentPointOnHip, currentRidgeEdgeInfo, firstSupport, secondSupport);

            using (Transaction t = new Transaction(doc, "Criar treliça"))
            {
                t.Start();

                if (currentTrussInfo != null)
                {
                    SketchPlane stkP = SketchPlane.Create(doc, currentRidgeEdgeInfo.CurrentRoof.LevelId);

                    double levelHeight = currentRidgeEdgeInfo.GetCurrentRoofHeight();

                    XYZ   firstPoint   = new XYZ(currentTrussInfo.FirstPoint.X, currentTrussInfo.FirstPoint.Y, levelHeight);
                    XYZ   secondPoint  = new XYZ(currentTrussInfo.SecondPoint.X, currentTrussInfo.SecondPoint.Y, levelHeight);
                    Truss currentTruss = Truss.Create(doc, tType.Id, stkP.Id, Line.CreateBound(firstPoint, secondPoint));

                    currentTruss.get_Parameter(BuiltInParameter.TRUSS_HEIGHT).Set(currentTrussInfo.Height);
                }

                t.Commit();
            }
            //DEBUG.CreateDebugPoint(doc, currentPointOnHip);

            return(currentTrussInfo);
        }
Exemple #4
0
    EdgeInfo _AddEdge(VertexInfo vertexa, VertexInfo vertexb)
    {
        string   edgeString = EdgeInfo.GetEdgeString(vertexa.index, vertexb.index);
        EdgeInfo edge;

        if (!edges.ContainsKey(edgeString))
        {
            edge = new EdgeInfo();
            edge.vertexAIndex          = vertexa.index;
            edge.vertexBIndex          = vertexb.index;
            edge.belongToTriangleIndex = new List <int> ();
            edge.isConstraintEdge      = false;
            edges [edgeString]         = edge;
        }
        else
        {
            edge = edges[edgeString];
        }

        if (vertexa.belongToEdgeIndex.Contains(edgeString) == false)
        {
            vertexa.belongToEdgeIndex.Add(edgeString);
        }
        if (vertexb.belongToEdgeIndex.Contains(edgeString) == false)
        {
            vertexb.belongToEdgeIndex.Add(edgeString);
        }

        return(edge);
    }
Exemple #5
0
    public static StageInfo LoadStage(int curStage)
    {
        if (mStageXMLText == null)
        {
            TextAsset textAsset = Resources.Load <TextAsset> ("GrayRun/Config/stages");

            mStageXMLText = textAsset.text;
        }

        XmlDocument xmlDoc = new XmlDocument();

        xmlDoc.LoadXml(mStageXMLText);

        StageInfo retInfo = new StageInfo();

        XmlNode stageNode = xmlDoc.SelectSingleNode("stages").ChildNodes[curStage - 1];

        XmlNodeList edgeList = stageNode.ChildNodes;

        foreach (XmlNode edge in edgeList)
        {
            EdgeInfo edgeInfo = new EdgeInfo();
            edgeInfo.name = edge.Attributes ["name"].Value.ToString();
            edgeInfo.x    = int.Parse(edge.Attributes ["x"].Value.ToString());
            edgeInfo.y    = int.Parse(edge.Attributes ["y"].Value.ToString());
            edgeInfo.Description();
            retInfo.edgeInfos.Add(edgeInfo);
        }

        return(retInfo);
    }
    void DrawFieldOfView()
    {
        int            stepCount     = Mathf.RoundToInt(viewAngle * meshResolution); // Numbers of rays
        float          stepAngleSize = viewAngle / stepCount;
        List <Vector3> points        = new List <Vector3>();
        ViewCastInfo   oldViewCast   = new ViewCastInfo();

        for (int i = 0; i <= stepCount; i++)
        {
            //float angle = 95 - viewAngle / 2 + stepAngleSize * i ;
            float        angle        = (-transform.eulerAngles.z - viewAngle / 2 + stepAngleSize * i);
            ViewCastInfo viewCastInfo = ViewCast(angle);
            points.Add(viewCastInfo.point);

            if (i > 0)
            {
                bool edgeDistanceThresholdExceeded = Mathf.Abs(oldViewCast.distance - viewCastInfo.distance) > edgeDistanceThreshold;
                if (oldViewCast.hit != viewCastInfo.hit || (oldViewCast.hit && viewCastInfo.hit && edgeDistanceThresholdExceeded))
                {
                    EdgeInfo edge = FindEdge(oldViewCast, viewCastInfo);

                    if (edge.pointA != Vector2.zero)
                    {
                        points.Add(edge.pointA);
                    }
                    else
                    {
                        points.Add(edge.pointB);
                    }
                }
            }

            oldViewCast = viewCastInfo;
            // Debug.DrawLine(transform.position, transform.position + DirFromAngle(angle, true) * viewRadius, Color.red);
        }

        int vertexCount = points.Count + 1;

        Vector3[] vertices  = new Vector3[vertexCount];
        int[]     triangles = new int[(vertexCount - 2) * 3];

        vertices[0] = Vector3.zero; // Initial

        for (int i = 0; i < vertexCount - 1; i++)
        {
            vertices[i + 1] = transform.InverseTransformPoint(points[i]);

            if (i < vertexCount - 2)
            {
                triangles[i * 3]     = 0;
                triangles[i * 3 + 1] = i + 1;
                triangles[i * 3 + 2] = i + 2;
            }
        }

        viewMesh.Clear();
        viewMesh.vertices  = vertices;
        viewMesh.triangles = triangles;
        viewMesh.RecalculateNormals();
    }
    /// <summary>
    /// This method will visualize the light. First it will Viewcast multiple times to get get the hitpoints. From these hitpoints this method will draw the mesh.
    /// </summary>
    void DrawFieldOfView()
    {
        int   stepCount     = Mathf.RoundToInt(viewAngle * meshResolution);
        float stepAngleSize = viewAngle / stepCount;

        //This part will raycast multiple times to get the hitpoints.
        List <Vector3> viewPoints  = new List <Vector3>();
        ViewCastInfo   oldViewCast = ViewCast(transform.position, transform.eulerAngles.y - viewAngle / 2, viewRadius);

        viewPoints.Add(oldViewCast.point);
        for (int i = 1; i <= stepCount; i++)
        {
            float        angle       = transform.eulerAngles.y - viewAngle / 2 + stepAngleSize * i;
            ViewCastInfo newViewCast = ViewCast(transform.position, angle, viewRadius);
            bool         edgeDistanceThresholdExceed = Mathf.Abs(oldViewCast.distance - newViewCast.distance) > edgeThresholdDistance;
            if (oldViewCast.hit != newViewCast.hit || (oldViewCast.hit && newViewCast.hit && edgeDistanceThresholdExceed)) // Check if there is an edge inbetween raycasts.
            {
                //Get edge cast
                EdgeInfo edge = FindEdge(oldViewCast, newViewCast);
                if (edge.pointA != Vector3.zero)
                {
                    viewPoints.Add(edge.pointA);
                }
                if (edge.pointB != Vector3.zero)
                {
                    viewPoints.Add(edge.pointB);
                }
            }
            newViewCast.point.y = 0.25f;
            viewPoints.Add(newViewCast.point);
            oldViewCast = newViewCast;
        }
        int vertexCount = viewPoints.Count + 1; // +1 is transform position

        Vector3[] vertices  = new Vector3[vertexCount];
        int[]     triangles = new int[(vertexCount - 2) * 3];
        Vector2[] uvs       = new Vector2[vertices.Length];
        //Mesh will be a child of, so need to calculate in world space
        vertices[0] = Vector3.zero;
        uvs[0]      = new Vector2(0.5f, 0);
        //This part will set the vertices and trinagles for the viewmesh.
        for (int i = 0; i < vertexCount - 1; i++)
        {
            vertices[i + 1]   = transform.InverseTransformPoint(viewPoints[i]);
            vertices[i + 1].y = 0.1f;
            float nextPos = (float)i / (float)vertexCount;
            uvs[i + 1] = new Vector2(nextPos, 1f);
            if (i < vertexCount - 2)
            {
                triangles[i * 3]     = 0;
                triangles[i * 3 + 1] = i + 1;
                triangles[i * 3 + 2] = i + 2;
            }
        }


        //uvs[vertexCount-1] = new Vector2(0.5f, 0f);

        CreateMesh(viewMesh, vertices, triangles, uvs);
    }
Exemple #8
0
    private void DrawFieldOfView()
    {
        int            stepCount     = Mathf.RoundToInt(viewAngle * meshResolution);
        float          stepAngleSize = viewAngle / stepCount;
        List <Vector3> viewPoints    = new List <Vector3>(1024);

        ViewCastInfo oldViewCast = new ViewCastInfo();
        float        eulerZ      = transform.eulerAngles.z;

        for (int i = 0; i <= stepCount; i++)
        {
            float        angle       = eulerZ - viewAngle / 2 + stepAngleSize * i;
            ViewCastInfo newViewCast = ViewCast(angle);

            if (i > 0)
            {
                bool edgeDstThreshholdExceeded = Mathf.Abs(oldViewCast.dst - newViewCast.dst) > edgeDistanceThreshhold;
                if (oldViewCast.hit != newViewCast.hit ||
                    oldViewCast.hit && newViewCast.hit && edgeDstThreshholdExceeded)
                {
                    EdgeInfo edge = FindEdge(oldViewCast, newViewCast);
                    if (edge.pointA != Vector3.zero)
                    {
                        viewPoints.Add(edge.pointA);
                    }
                    if (edge.pointB != Vector3.zero)
                    {
                        viewPoints.Add(edge.pointB);
                    }
                }
            }

            viewPoints.Add(newViewCast.point);
            oldViewCast = newViewCast;
        }

        int vertexCount = viewPoints.Count + 1;

        Vector3[] verticies = new Vector3[vertexCount];
        int[]     triangles = new int[(vertexCount - 2) * 3];

        verticies[0] = Vector3.zero;

        for (int i = 0; i < vertexCount - 1; i++)
        {
            verticies[i + 1] = transform.InverseTransformPoint(viewPoints[i]);

            if (i < vertexCount - 2)
            {
                triangles[i * 3]     = 0;
                triangles[i * 3 + 1] = i + 1;
                triangles[i * 3 + 2] = i + 2;
            }
        }

        viewMesh.Clear();
        viewMesh.vertices  = verticies;
        viewMesh.triangles = triangles;
        viewMesh.RecalculateNormals();
    }
Exemple #9
0
    void DrawFieldOfView()
    {
        int            stepCount     = Mathf.RoundToInt(viewAngle * _meshResolution);
        float          stepAngleSize = viewAngle / stepCount;
        List <Vector2> viewPoints    = new List <Vector2>();

        ViewCastInfo oldViewCast = new ViewCastInfo();

        for (int i = 0; i <= stepCount; i++)
        {
            float angle = (-transform.eulerAngles.z - (viewAngle / 2)) + stepAngleSize * i;

            //Debug.DrawLine(transform.position, transform.position + DirFromAngle(angle, true) * viewRadius, Color.red);
            ViewCastInfo newViewCast = ViewCast(angle);
            viewPoints.Add(newViewCast.point2D);

            if (i > 0)
            {
                bool edgeDistThresholdExceeded = Mathf.Abs(oldViewCast.dist - newViewCast.dist) > edgeDistanceThreshold;
                if (oldViewCast.hit != newViewCast.hit || (oldViewCast.hit && newViewCast.hit && edgeDistThresholdExceeded))
                {
                    EdgeInfo edge = FindEdge(oldViewCast, newViewCast);

                    if (edge.pointA != Vector3.zero)
                    {
                        viewPoints.Add(edge.pointA);
                    }
                    if (edge.pointB != Vector3.zero)
                    {
                        viewPoints.Add(edge.pointB);
                    }
                }
            }

            oldViewCast = newViewCast;
        }

        int vertexCount = viewPoints.Count + 1;

        Vector3[] vertices  = new Vector3[vertexCount];
        int[]     triangles = new int[(vertexCount - 2) * 3];

        vertices[0] = Vector3.zero;
        for (int i = 0; i < (vertexCount - 1); i++)
        {
            vertices[i + 1] = transform.InverseTransformPoint(viewPoints[i]);

            if (i < vertexCount - 2)
            {
                triangles[i * 3]     = 0;
                triangles[i * 3 + 1] = i + 1;
                triangles[i * 3 + 2] = i + 2;
            }
        }

        viewMesh.Clear();
        viewMesh.vertices  = vertices;
        viewMesh.triangles = triangles;
        viewMesh.RecalculateNormals();
    }
        /// <summary>
        /// Метод рисования направленной дуги между вершинами с настройками по умолчанию
        /// </summary>
        /// <param name="g">Контекст рисования</param>
        /// <param name="edge">Дуга</param>
        private void DrawEdge(Graphics g, EdgeInfo edge)
        {
            // Узнаём цвет дуги и рисуем
            var eColor = edgesMarkingColors.ContainsKey(edge) ? edgesMarkingColors[edge] : edgeColor;

            DrawEdge(g, edge, eColor);
        }
        /// <summary>
        /// Метод проверки нахождения указателя мыши над дугой
        /// </summary>
        /// <param name="edge">Дуга</param>
        /// <param name="mouseX">Координата X мыши</param>
        /// <param name="mouseY">Координата Y мыши</param>
        /// <returns>true - да, false - нет</returns>
        private bool IsMouseOnEdge(EdgeInfo edge, float mouseX, float mouseY)
        {
            // Получаем параметры дуги: точки начала и конца рисования
            GetEdgeParams(edge, out PointF sPoint, out PointF fPoint, out _, out _, out _, out _);
            // Из координат X начальной и конечной точек выбираем max и min (для удобства дальнейших сравнений)
            float maxX = Math.Max(sPoint.X, fPoint.X);
            float minX = Math.Min(sPoint.X, fPoint.X);
            // Из координат Y начальной и конечной точек выбираем max и min (для удобства дальнейших сравнений)
            float maxY = Math.Max(sPoint.Y, fPoint.Y);
            float minY = Math.Min(sPoint.Y, fPoint.Y);

            // Проверяем точку на принадлежность отрезку (с учётом погрешностей)
            bool isBelogToEdge = false; // принадлежит ли точка отрезку

            // Смотрим, подходит ли проверяемый отрезок по координатам X или Y
            if (minX <= mouseX && mouseX <= maxX || minY <= mouseY && mouseY <= maxY)
            {
                // Проверям принадлежность прямой, если она вертикальная
                if (sPoint.X == fPoint.X && minY <= mouseY && mouseY <= maxY && Math.Abs(sPoint.X - mouseX) <= 2)
                {
                    isBelogToEdge = true;
                }
                // Проверям принадлежность прямой, если она горизонтальная
                else if (sPoint.Y == fPoint.Y && minX <= mouseX && mouseX <= maxX && Math.Abs(sPoint.Y - mouseY) <= 2)
                {
                    isBelogToEdge = true;
                }
                // Проверяем с помощью уравнения прямой
                else if (Math.Abs((mouseX - sPoint.X) / (fPoint.X - sPoint.X) - (mouseY - sPoint.Y) / (fPoint.Y - sPoint.Y)) <= 0.1)
                {
                    isBelogToEdge = true;
                }
            }
            return(isBelogToEdge);
        }
        public void DrawEdge(EdgeInfo e, Mesh m, Color color)
        {
            Vector3 p1 = m.vertices[e.v1];
            Vector3 p2 = m.vertices[e.v2];

            DrawLine(p1, p2, color);
        }
Exemple #13
0
    void GetEdgePoints(ViewCastInfo oldCastInfo, ViewCastInfo newCastInfo, List <Vector2> points)
    {
        bool edgeDetectionThresholdExceeded = Mathf.Abs(oldCastInfo.distance - newCastInfo.distance) > edgeDetectionThreshold;

        if ((oldCastInfo.hit && !newCastInfo.hit) || (oldCastInfo.hit && newCastInfo.hit && edgeDetectionThresholdExceeded))
        {
            EdgeInfo edgeInfo = FindEdge(oldCastInfo, newCastInfo);
            if (edgeInfo.pointA != Vector2.zero)
            {
                // Debug.DrawLine(
                //     transform.position,
                //     new Vector3(edgeInfo.pointA.x, edgeInfo.pointA.y, 0),
                //     Color.blue
                // );
                points.Add(edgeInfo.pointA);
            }
            if (edgeInfo.pointB != Vector2.zero)
            {
                // Debug.DrawLine(
                //     transform.position,
                //     new Vector3(edgeInfo.pointB.x, edgeInfo.pointB.y, 0),
                //     Color.green
                // );
                points.Add(edgeInfo.pointB);
            }
        }
    }
Exemple #14
0
    //绘制视野效果(绘制一个mesh)
    private void DrawFieldOfView()
    {
        int            stepCount     = Mathf.RoundToInt(viewAngle * meshResolution);
        float          stepAngleSize = viewAngle / stepCount;
        List <Vector3> viewPoints    = new List <Vector3>();

        ViewCastInfo oldViewCast = new ViewCastInfo();

        for (int i = 0; i <= stepCount; i++)
        {
            float        angle       = transform.eulerAngles.y - viewAngle / 2 + stepAngleSize * i;
            ViewCastInfo newViewCast = ViewCast(angle);

            //二分法逼近障碍物的边缘,从而使绘制的mesh更加光滑
            if (i > 0)
            {
                //角度很接近的两条射线可能碰撞到两个不同的物体上,造成mesh绘制错误,需要避免
                bool edgeDstThresholdExceeded = Mathf.Abs(oldViewCast.dst - newViewCast.dst) > edgeDstThreshold;
                if (oldViewCast.hit != newViewCast.hit || (oldViewCast.hit && newViewCast.hit && edgeDstThresholdExceeded))
                {
                    EdgeInfo edge = FindEdge(oldViewCast, newViewCast);
                    if (edge.pointA != Vector3.zero)
                    {
                        viewPoints.Add(edge.pointA);
                    }
                    if (edge.pointB != Vector3.zero)
                    {
                        viewPoints.Add(edge.pointB);
                    }
                }
            }

            viewPoints.Add(newViewCast.point);
            oldViewCast = newViewCast;
        }

        int vertexCount = viewPoints.Count + 1;

        Vector3[] vertices  = new Vector3[vertexCount];
        int[]     triangles = new int[(vertexCount - 2) * 3];

        vertices[0] = Vector3.zero;
        for (int i = 0; i < vertexCount - 1; i++)
        {
            //viewPoints 是世界坐标下的点, 需要转换回 localscale
            vertices[i + 1] = transform.InverseTransformPoint(viewPoints[i]);

            if (i < vertexCount - 2)
            {
                triangles[i * 3]     = 0;
                triangles[i * 3 + 1] = i + 1;
                triangles[i * 3 + 2] = i + 2;
            }
        }

        viewMesh.Clear();
        viewMesh.vertices  = vertices;
        viewMesh.triangles = triangles;
        viewMesh.RecalculateNormals();
    }
        public void DrawEdge(EdgeInfo e, List <Vector3> vertices, Color color, float offset = 0)
        {
            Vector3 p1 = vertices[e.v1] + new Vector3(offset, 0, 0);
            Vector3 p2 = vertices[e.v2] + new Vector3(offset, 0, 0);

            DrawLine(p1, p2, color);
        }
Exemple #16
0
        private void ScanLineFill1()
        {
            EdgeInfo[] edgelist = new EdgeInfo[100];
            int        j = 0, yu = 0, yd = 1024;

            group[PressNum] = group[0];
            for (int i = 0; i < PressNum; i++)
            {
                if (group[i].Y > yu)
                {
                    yu = group[i].Y;
                }
                if (group[i].Y < yd)
                {
                    yd = group[i].Y;
                }
                if (group[i].Y != group[i + 1].Y)
                {
                    if (group[i].Y > group[i + 1].Y)
                    {
                        edgelist[j++] = new EdgeInfo(group[i + 1].X, group[i + 1].Y, group[i].X, group[i].Y);
                    }
                    else
                    {
                        edgelist[j++] = new EdgeInfo(group[i].X, group[i].Y, group[i + 1].X, group[i + 1].Y);
                    }
                }
            }
            Graphics g = CreateGraphics();

            for (int y = yd; y < yu; y++)
            {
                var sorted =
                    from item in edgelist
                    where y < item.YMax && y >= item.YMin
                    orderby item.XMin, item.K
                select item;
                int flag = 0;
                foreach (var item in sorted)
                {
                    if (flag == 0)
                    {
                        FirstX = (int)(item.XMin + 0.5);
                        flag++;
                    }
                    else
                    {
                        g.DrawLine(Pens.Blue, (int)(item.XMin + 0.5), y, FirstX - 1, y);
                        flag = 0;
                    }
                }
                for (int i = 0; i < j; i++)
                {
                    if (y < edgelist[i].YMax - 1 && y > edgelist[i].YMin)
                    {
                        edgelist[i].XMin += edgelist[i].K;
                    }
                }
            }
        }
 private GraphPath(GraphPath parent, Identity node, EdgeInfo fromEdge)
 {
     DomainModel = parent.DomainModel;
     _parent     = parent;
     EndElement  = node;
     LastTraversedRelationship = fromEdge;
 }
Exemple #18
0
        private IngoingEdgesOverlay ComputeIngoingEdges(BuildGraph graph)
        {
            var ingoing = new IngoingEdgesOverlay(() => new List <EdgeInfo>());

            var visited = new OrdinalOverlay <BuildNodeId, BuildNode, bool>();

            var stack = new Stack <BuildNode>();

            stack.Push(graph.EnterNode);
            visited[graph.EnterNode] = true;

            while (stack.Count > 0)
            {
                var node = stack.Pop();

                foreach (var edge in node.OutgoingEdges)
                {
                    var edgeInfo = new EdgeInfo(edge, node);
                    ingoing[edge.To].Add(edgeInfo);

                    if (!visited[edge.To])
                    {
                        stack.Push(edge.To);
                        visited[edge.To] = true;
                    }
                }
            }

            return(ingoing);
        }
    void DrawFieldOfView()
    {
        int   stepCount     = Mathf.RoundToInt(viewAngle * meshResolution);
        float stepAngleSize = viewAngle / stepCount;

        List <Vector3> viewPoints  = new List <Vector3>();
        ViewCastInfo   oldViewCast = new ViewCastInfo();

        for (int i = 0; i <= stepCount; i++)
        {
            float        angle       = transform.eulerAngles.y - viewAngle / 2 + stepAngleSize * i;
            ViewCastInfo newViewCast = ViewCast(angle);

            // skip first iteration
            if (i > 0)
            {
                bool edgeDistanceThresholdExceeded = Mathf.Abs(oldViewCast.distance - newViewCast.distance) > edgeDistanceThreshold;
                // check if edge lies between these casts
                if (oldViewCast.hit != newViewCast.hit || oldViewCast.hit && newViewCast.hit && edgeDistanceThresholdExceeded)
                {
                    EdgeInfo edge = FindEdge(oldViewCast, newViewCast);
                    if (edge.pointA != Vector3.zero)
                    {
                        viewPoints.Add(edge.pointA);
                    }
                    if (edge.pointB != Vector3.zero)
                    {
                        viewPoints.Add(edge.pointB);
                    }
                }
            }

            viewPoints.Add(newViewCast.point);
            oldViewCast = newViewCast;
        }

        int vertexCount = viewPoints.Count + 1;

        Vector3[] vertices  = new Vector3[vertexCount];
        int[]     triangles = new int[(vertexCount - 2) * 3];

        vertices[0] = Vector3.zero;
        for (int i = 0; i < vertexCount - 1; i++)
        {
            // convert to local position of character
            vertices[i + 1] = transform.InverseTransformPoint(viewPoints[i] + Vector3.forward * maskCutawayDistance);
            if (i < vertexCount - 2)
            {
                triangles[i * 3]     = 0;
                triangles[i * 3 + 1] = i + 1;
                triangles[i * 3 + 2] = i + 2;
            }
        }

        viewMesh.Clear();
        viewMesh.vertices  = vertices;
        viewMesh.triangles = triangles;
        viewMesh.RecalculateNormals();
    }
Exemple #20
0
    // Cria triangulações entre cada vertice de pontos do raycast
    void DrawFieldOfView()
    {
        int            stepCount     = Mathf.RoundToInt(AnguloVisao * meshResolution);
        float          stepAngleSize = AnguloVisao / stepCount;
        List <Vector3> viewPoints    = new List <Vector3>();
        ViewCastInfo   oldViewCast   = new ViewCastInfo();


        for (int i = 0; i <= stepCount; i++)
        {
            float        angle       = transform.eulerAngles.y - AnguloVisao / 2 + stepAngleSize * i;
            ViewCastInfo newViewcast = viewCast(angle);

            // verifica se encostou em um objeto ou fora
            if (i > 0)
            {
                bool edgeDstThresholdExceeded = Mathf.Abs(oldViewCast.dst - newViewcast.dst) > edgeDstThreshold;
                if (oldViewCast.hit != newViewcast.hit || (oldViewCast.hit && newViewcast.hit && edgeDstThresholdExceeded))
                {
                    EdgeInfo edge = FindEdge(oldViewCast, newViewcast);
                    if (edge.pointA != Vector3.zero)
                    {
                        viewPoints.Add(edge.pointA);
                    }
                    if (edge.pointB != Vector3.zero)
                    {
                        viewPoints.Add(edge.pointB);
                    }
                }
            }

            viewPoints.Add(newViewcast.point);
            oldViewCast = newViewcast;
        }

        // + 1 é vertice de origem
        int vertexCount = viewPoints.Count + 1;

        Vector3[] vertices  = new Vector3[vertexCount];
        int[]     triangles = new int[(vertexCount - 2) * 3];

        vertices[0] = Vector3.zero;               // origem
        for (int i = 0; i < vertexCount - 1; i++) // forma os triangulos
        {
            vertices[i + 1] = transform.InverseTransformPoint(viewPoints[i]);

            if (i < vertexCount - 2)
            {
                triangles[i * 3]     = 0;
                triangles[i * 3 + 1] = i + 1;
                triangles[i * 3 + 2] = i + 2;
            }
        }

        _viewMesh.Clear();
        _viewMesh.vertices  = vertices;
        _viewMesh.triangles = triangles;
        _viewMesh.RecalculateNormals();
    }
    private void DrawFieldOfVision()
    {
        // get vision increments
        int   stepCount     = Mathf.RoundToInt(_targetManager.VisionAngle * _fovResolution);
        float stepAngleSize = _targetManager.VisionAngle / stepCount;

        List <Vector3> viewPoints  = new List <Vector3>();
        ViewCastInfo   oldViewCast = new ViewCastInfo();

        // generate list of viewpoints based on angle and resolution
        for (int i = 0; i <= stepCount * 2; i++)
        {
            float        angle        = (_targetManager.transform.eulerAngles.z - _targetManager.VisionAngle + stepAngleSize * i) - 180;
            ViewCastInfo viewCastInfo = ViewCast(angle);
            if (i > 0)
            {
                if (ShouldPerformEdgeCast(oldViewCast, viewCastInfo))
                {
                    EdgeInfo edge = FindEdge(oldViewCast, viewCastInfo);
                    if (edge.PointA != Vector3.zero)
                    {
                        viewPoints.Add(edge.PointA);
                    }
                    if (edge.PointB != Vector3.zero)
                    {
                        viewPoints.Add(edge.PointB);
                    }
                }
            }
            viewPoints.Add(viewCastInfo.Point);
            oldViewCast = viewCastInfo;
        }

        // build list of vertices and triangles
        int vertexCount = viewPoints.Count + 1;

        Vector3[] vertices  = new Vector3[vertexCount];
        int[]     triangles = new int[(vertexCount - 2) * 3];

        // this mesh is built on a child object. So the first position is the local origin
        vertices[0] = Vector3.zero;
        for (int i = 0; i < vertexCount - 1; i++)
        {
            vertices[i + 1] = _targetManager.transform.InverseTransformPoint(viewPoints[i]);

            // set the vertices of the triangle
            if (i < vertexCount - 2)
            {
                triangles[i * 3]     = 0;
                triangles[i * 3 + 1] = i + 2;
                triangles[i * 3 + 2] = i + 1;
            }
        }
        // apply vertices and triangles to the mesh
        _visionMesh.Clear();
        _visionMesh.vertices  = vertices;
        _visionMesh.triangles = triangles;
        _visionMesh.RecalculateNormals();
    }
Exemple #22
0
    void DrawFieldOfScreaming()
    {
        viewMeshFilter.gameObject.GetComponent <MeshRenderer>().material.SetColor("_Color", new Color(1, 0, 0, 0.5f));
        int            stepCount     = Mathf.RoundToInt(360 * meshResolution);
        float          stepAngleSize = 360 / stepCount;
        List <Vector3> viewPoints    = new List <Vector3>();
        ViewCastInfo   oldViewCast   = new ViewCastInfo();

        for (int i = 0; i <= stepCount; i++)
        {
            float        angle       = transform.eulerAngles.y - 360 / 2 + stepAngleSize * i;
            ViewCastInfo newViewCast = ViewCast(angle, _screamingRadius);

            if (i > 0)
            {
                bool edgeDstThresholdExceeded = Mathf.Abs(oldViewCast.dst - newViewCast.dst) > edgeDstThreshold;
                if (oldViewCast.hit != newViewCast.hit || (oldViewCast.hit && newViewCast.hit && edgeDstThresholdExceeded))
                {
                    EdgeInfo edge = FindEdge(oldViewCast, newViewCast, _screamingRadius);
                    if (edge.pointA != Vector3.zero)
                    {
                        viewPoints.Add(edge.pointA);
                    }
                    if (edge.pointB != Vector3.zero)
                    {
                        viewPoints.Add(edge.pointB);
                    }
                }
            }


            viewPoints.Add(newViewCast.point);
            oldViewCast = newViewCast;
        }

        int vertexCount = viewPoints.Count + 1;

        Vector3[] vertices  = new Vector3[vertexCount];
        int[]     triangles = new int[(vertexCount - 2) * 3];

        vertices[0] = Vector3.zero;
        for (int i = 0; i < vertexCount - 1; i++)
        {
            vertices[i + 1] = transform.InverseTransformPoint(viewPoints[i]);

            if (i < vertexCount - 2)
            {
                triangles[i * 3]     = 0;
                triangles[i * 3 + 1] = i + 1;
                triangles[i * 3 + 2] = i + 2;
            }
        }

        viewMesh.Clear();

        viewMesh.vertices  = vertices;
        viewMesh.triangles = triangles;
        viewMesh.RecalculateNormals();
    }
Exemple #23
0
    private void DrawFieldOfView()
    {
        float          stepAngleInterval = ViewAngle / MeshTriangleCount;
        List <Vector3> viewPoints        = new List <Vector3>();
        ViewCastInfo   oldViewCastInfo   = new ViewCastInfo();

        for (int i = 0; i <= MeshTriangleCount; i++)
        {
            float        angle        = (ViewAngle / 2.0f) - (stepAngleInterval * i);
            ViewCastInfo viewCastInfo = ViewCast(angle);

            if (i > 0)
            {
                bool isEdgeDistanceThresholdExceeded = Mathf.Abs(oldViewCastInfo.Distance - viewCastInfo.Distance) > EdgeDistanceThreshold;

                if (oldViewCastInfo.HasHit != viewCastInfo.HasHit || (oldViewCastInfo.HasHit && viewCastInfo.HasHit && isEdgeDistanceThresholdExceeded))
                {
                    EdgeInfo edgeInfo = FindEdge(oldViewCastInfo, viewCastInfo);

                    if (edgeInfo.PointA != Vector3.zero)
                    {
                        viewPoints.Add(edgeInfo.PointA);
                    }

                    if (edgeInfo.PointB != Vector3.zero)
                    {
                        viewPoints.Add(edgeInfo.PointB);
                    }
                }
            }

            viewPoints.Add(viewCastInfo.Point);
            oldViewCastInfo = viewCastInfo;
        }

        int vertexCount = viewPoints.Count + 1;

        Vector3[] vertices  = new Vector3[vertexCount];
        int[]     triangles = new int[(vertexCount - 2) * 3];

        vertices[0] = Vector3.zero;

        for (int i = 0; i < viewPoints.Count; i++)
        {
            vertices[i + 1] = _transform.InverseTransformPoint(viewPoints[i]);

            if (i < vertexCount - 2)
            {
                triangles[i * 3]     = 0;
                triangles[i * 3 + 1] = i + 1;
                triangles[i * 3 + 2] = i + 2;
            }
        }

        _viewMesh.Clear();
        _viewMesh.vertices  = vertices;
        _viewMesh.triangles = triangles;
        _viewMesh.RecalculateNormals();
    }
    void DrawFieldOfView()
    {
        int            stepCount     = Mathf.RoundToInt(viewAngle * meshResolution);
        float          stepAngleSize = viewAngle / stepCount;
        ViewCastInfo   oldViewCast   = new ViewCastInfo();
        List <Vector3> viewPoints    = new List <Vector3>();

        for (int i = 0; i < stepCount; i++)
        {
            float        angle    = transform.eulerAngles.y - viewAngle / 2 + stepAngleSize * i;
            ViewCastInfo viewCast = ViewCast(angle);
            if (i > 0)
            {
                bool exceededEdgeDistanceThreshold = Mathf.Abs(oldViewCast.distance - viewCast.distance) > edgeDistanceThreshold;
                if (oldViewCast.hit != viewCast.hit || (oldViewCast.hit && viewCast.hit && exceededEdgeDistanceThreshold))
                {
                    // Find the edge
                    EdgeInfo edge = FindEdge(oldViewCast, viewCast);
                    if (edge.pointA != Vector3.zero)
                    {
                        viewPoints.Add(edge.pointA);
                    }
                    if (edge.pointB != Vector3.zero)
                    {
                        viewPoints.Add(edge.pointB);
                    }
                }
            }
            viewPoints.Add(viewCast.point);
            oldViewCast = viewCast;

            // Debug.DrawLine(transform.position, viewCast.point, Color.black);
        }

        int numVertices = viewPoints.Count + 1;

        Vector3[] vertices = new Vector3[numVertices];

        //Stores the indices of each vertex in the triangle.
        int[] triangles = new int[(numVertices - 2) * 3];

        vertices[0] = Vector3.zero;
        for (int i = 0; i < numVertices - 1; i++)
        {
            vertices[i + 1] = transform.InverseTransformPoint(viewPoints[i]);

            if (i < numVertices - 2)
            {
                triangles[i * 3]     = 0;
                triangles[i * 3 + 1] = i + 1;
                triangles[i * 3 + 2] = i + 2;
            }
        }

        mesh.Clear();
        mesh.vertices  = vertices;
        mesh.triangles = triangles;
        mesh.RecalculateNormals();
    }
        public void DrawViewMesh()
        {
            int   stepCount     = Mathf.RoundToInt(ViewAngle * MeshResolution);
            float stepAngleSize = ViewAngle / stepCount;

            List <Vector3> viewPoints  = new List <Vector3>();
            ViewCastInfo   oldViewCast = new ViewCastInfo();

            for (int i = 0; i <= stepCount; i++)
            {
                float        angle       = transform.eulerAngles.y - ViewAngle / 2 + stepAngleSize * i;
                ViewCastInfo newViewCast = ViewCast(angle);

                if (i > 0)
                {
                    bool edgeDstThresholdExceeded = Mathf.Abs(oldViewCast.Distance - newViewCast.Distance) > EdgeDistanceThreshold;
                    if (oldViewCast.Hit != newViewCast.Hit || (oldViewCast.Hit && newViewCast.Hit && edgeDstThresholdExceeded))
                    {
                        EdgeInfo edge = FindEdge(oldViewCast, newViewCast);
                        if (edge.PointA != Vector3.zero)
                        {
                            viewPoints.Add(edge.PointA);
                        }
                        if (edge.PointB != Vector3.zero)
                        {
                            viewPoints.Add(edge.PointB);
                        }
                    }
                }
                viewPoints.Add(newViewCast.Point);
                oldViewCast = newViewCast;
            }

            int vertexCount = viewPoints.Count + 1;

            Vector3[] vertices  = new Vector3[vertexCount];
            int[]     triangles = new int[(vertexCount - 2) * 3];
            vertices[0] = Vector3.zero;

            for (int i = 0; i < vertexCount - 1; i++)
            {
                vertices[i + 1] = transform.InverseTransformPoint(viewPoints[i]) + Vector3.forward * MaskCutawayDistance;

                if (i >= vertexCount - 2)
                {
                    continue;
                }

                triangles[i * 3]     = 0;
                triangles[i * 3 + 1] = i + 1;
                triangles[i * 3 + 2] = i + 2;
            }

            // Clearing and setting up view mesh.
            viewMesh.Clear();
            viewMesh.vertices  = vertices;
            viewMesh.triangles = triangles;
            viewMesh.RecalculateNormals();
        }
Exemple #26
0
        private void ScanLinFill()
        {
            Graphics ggg = CreateGraphics();

            EdgeInfo[] edgelist = new EdgeInfo[100]; //建立边结构数组
            int        j = 0, yu = 0, yd = 1024;     //活化边的扫描范围从yu倒yd

            group[PressNum] = group[0];              //将第一点复制为数组最后一点
            for (int i = 0; i < PressNum; i++)       //建立每一条边的边结构
            {
                if (group[i].Y > yu)
                {
                    yu = group[i].Y;                 //找出图形最高点
                }
                if (group[i].Y < yd)
                {
                    yd = group[i].Y;                 //找出图形最低点
                }
                if (group[i].Y != group[i + 1].Y)    //只处理非水平边
                {
                    if (group[i].Y > group[i + 1].Y) //下端点在前,上端点在后
                    {
                        edgelist[j++] = new EdgeInfo(group[i + 1].X, group[i + 1].Y, group[i].X, group[i].Y);
                    }
                    else
                    {
                        edgelist[j++] = new EdgeInfo(group[i].X, group[i].Y, group[i + 1].X, group[i + 1].Y);
                    }
                }
            }
            for (int y = yd; y < yu; y++)
            {
                var sorted =
                    from item in edgelist
                    where y < item.YMax && y >= item.YMmin
                    orderby item.XMin, item.K
                select item;
                int flag = 0;
                foreach (var item in sorted)
                {
                    if (flag == 0)
                    {
                        FirstX = (int)(item.XMin + 0.5); flag++;
                    }
                    else
                    {
                        ggg.DrawLine(Pens.Green, (int)(item.XMin + 0.5), y, FirstX - 1, y);
                        flag = 0;
                    }
                }
                for (int i = 0; i < j; i++)
                {
                    if (y < edgelist[i].YMax - 1 && y > edgelist[i].YMmin)
                    {
                        edgelist[i].XMin += edgelist[i].K;
                    }
                }
            }
        }
Exemple #27
0
        void DrawFieldOfView()
        {
            int            stepCount     = Mathf.RoundToInt(viewAngle * meshResolution);
            float          stepAngleSize = viewAngle / stepCount;
            List <Vector3> viewPoints    = new List <Vector3>();
            ViewCastInfo   oldViewCast   = new ViewCastInfo();



            for (int i = 0; i <= stepCount; i++)
            {
                float        angle       = transform.eulerAngles.y - viewAngle / 2 + stepAngleSize * i;
                ViewCastInfo newViewCast = ViewCast(angle);

                if (i > 0)
                {
                    bool edgeDstThresholdExceed = Mathf.Abs(oldViewCast.dst - newViewCast.dst) > edgeDstThreshold;
                    if (oldViewCast.hit != newViewCast.hit || (oldViewCast.hit && newViewCast.hit && edgeDstThresholdExceed))
                    {
                        EdgeInfo edge = FindEdge(oldViewCast, newViewCast);
                        if (edge.pointA != Vector3.zero)
                        {
                            viewPoints.Add(edge.pointA);
                        }
                        if (edge.pointB != Vector3.zero)
                        {
                            viewPoints.Add(edge.pointB);
                        }
                    }
                }

                viewPoints.Add(newViewCast.point);
                oldViewCast = newViewCast;
            }

            int vertexCount = viewPoints.Count + 1;

            Vector3[] vertices  = new Vector3[vertexCount];
            int[]     triangles = new int[(vertexCount - 2) * 3];

            vertices[0] = Vector3.zero;
            for (int i = 0; i < vertexCount - 1; i++)
            {
                //add  * maskCutAwayDst at the end if u want a small piece of obstacles to be seem
                vertices[i + 1] = transform.InverseTransformPoint(viewPoints[i]) + Vector3.forward * maskCutAwayDst;

                if (i < vertexCount - 2)
                {
                    triangles[i * 3]     = 0;
                    triangles[i * 3 + 1] = i + 1;
                    triangles[i * 3 + 2] = i + 2;
                }
            }

            viewMesh.Clear();
            viewMesh.vertices  = vertices;
            viewMesh.triangles = triangles;
            viewMesh.RecalculateNormals();
        }
    private static void DrawArrows(Color color, Vector3 cross, Vector3[] edgePoints, EdgeInfo info, bool isSelf, float arrowSize, float outlineWidth, float arrowLength)
    {
        Vector3 a          = edgePoints[1] - edgePoints[0];
        Vector3 normalized = a.normalized;
        Vector3 a2         = a * 0.5f + edgePoints[0];

        a2 -= cross * 0.5f;
        float num  = Mathf.Min(arrowLength * 1.5f, (a2 - edgePoints[0]).magnitude) * 0.66f;
        int   num2 = 1;

        if (info != null && info.hasMultipleTransitions)
        {
            num2 = 3;
        }
        for (int i = 0; i < num2; i++)
        {
            Color color2 = color;
            if (info != null)
            {
                if (info.debugState == EdgeDebugState.MuteAll)
                {
                    color2 = Color.red;
                }
                else if (info.debugState == EdgeDebugState.SoloAll)
                {
                    color2 = Color.green;
                }
                else
                {
                    switch (i)
                    {
                    case 0:
                        if (info.debugState == EdgeDebugState.MuteSome || info.debugState == EdgeDebugState.MuteAndSolo)
                        {
                            color2 = Color.red;
                        }
                        if (info.debugState == EdgeDebugState.SoloSome)
                        {
                            color2 = Color.green;
                        }
                        break;

                    case 2:
                        if (info.debugState == EdgeDebugState.MuteAndSolo)
                        {
                            color2 = Color.green;
                        }
                        break;
                    }
                }
                if (i == 1 && info.edgeType == EdgeType.MixedTransition)
                {
                    color2 = selectorTransitionColor;
                }
            }
            Vector3 center = a2 + (float)((num2 != 1) ? (i - 1) : i) * num * ((!isSelf) ? normalized : cross);
            DrawArrow(color2, cross, normalized, center, arrowSize, outlineWidth);
        }
    }
Exemple #29
0
    /**
     * Draws a polygon representing the light using raycasts to find the edges of objects that block light
     */
    void DrawFieldOfView()
    {
        int            stepCount     = Mathf.RoundToInt(viewAngle * meshResolution);
        float          stepAngleSize = viewAngle / stepCount;
        List <Vector3> viewPoints    = new List <Vector3>();
        ViewCastInfo   oldViewCast   = new ViewCastInfo();

        for (int i = 0; i <= stepCount; i++)
        {
            float        angle       = 360 - transform.eulerAngles.z - viewAngle / 2 + stepAngleSize * i;
            ViewCastInfo newViewCast = ViewCast(angle);

            if (i > 0)
            {
                bool edgeDstThresholdExceeded = Mathf.Abs(oldViewCast.dst - newViewCast.dst) > edgeDstThreshold;
                if (oldViewCast.hit != newViewCast.hit || (oldViewCast.hit && newViewCast.hit && edgeDstThresholdExceeded))
                {
                    EdgeInfo edge = FindEdge(oldViewCast, newViewCast);
                    //adds points to the border of the mesh
                    if (edge.pointA != Vector3.zero)
                    {
                        viewPoints.Add(edge.pointA);
                    }
                    if (edge.pointB != Vector3.zero)
                    {
                        viewPoints.Add(edge.pointB);
                    }
                }
            }

            viewPoints.Add(newViewCast.point);
            oldViewCast = newViewCast;
        }

        //constructs the light's polygonal mesh
        int vertexCount = viewPoints.Count + 1;

        Vector3[] vertices  = new Vector3[vertexCount];
        int[]     triangles = new int[(vertexCount - 2) * 3];

        vertices[0] = Vector3.zero;
        for (int i = 0; i < vertexCount - 1; i++)
        {
            vertices[i + 1] = transform.InverseTransformPoint(viewPoints[i]) + Vector3.up * maskCutawayDst;

            if (i < vertexCount - 2)
            {
                triangles[i * 3]     = 0;
                triangles[i * 3 + 1] = i + 1;
                triangles[i * 3 + 2] = i + 2;
            }
        }

        viewMesh.Clear();

        viewMesh.vertices  = vertices;
        viewMesh.triangles = triangles;
        viewMesh.RecalculateNormals();
    }
Exemple #30
0
        /// <summary>
        /// Draw field of view.
        /// </summary>
        private void _DrawFieldOfView()
        {
            List <Vector3> viewPoints       = new List <Vector3>();
            ViewInfo       oldViewInfo      = new ViewInfo();
            int            numLine          = (int)(_angle / _anglePerDraw) + 1;
            float          realAnglePerDraw = _angle / numLine;
            float          startAngle       = transform.eulerAngles.y - (_angle / 2);

            for (int i = 0; i < numLine; ++i)
            {
                float    angle       = startAngle + (realAnglePerDraw * i);
                ViewInfo newViewCast = _FindView(angle);
                if (i > 0)
                {
                    bool isEdgeDistanceExceeded = Mathf.Abs(oldViewInfo.Distance - newViewCast.Distance) > _edgeDistanceThreshold;
                    if ((oldViewInfo.IsHit != newViewCast.IsHit) || (isEdgeDistanceExceeded && oldViewInfo.IsHit && newViewCast.IsHit))
                    {
                        EdgeInfo edge = _FindEdge(oldViewInfo, newViewCast);
                        if (edge.PointA != Vector3.zero)
                        {
                            viewPoints.Add(edge.PointA);
                        }
                        if (edge.PointB != Vector3.zero)
                        {
                            viewPoints.Add(edge.PointB);
                        }
                    }
                }
                viewPoints.Add(newViewCast.Point);
                oldViewInfo = newViewCast;
            }

            int numVertex = viewPoints.Count + 1;

            int[]     triangles = new int[(numVertex - 2) * 3];
            Vector3[] vertices  = new Vector3[numVertex];
            vertices[0] = Vector3.zero;
            Vector3 cutwayDistance = Vector3.forward * _cutwayDistance;

            for (int i = 0; i < numVertex - 1; ++i)
            {
                int iPlusOne = i + 1;
                vertices[iPlusOne] = transform.InverseTransformPoint(viewPoints[i]) + cutwayDistance;
                if (i < numVertex - 2)
                {
                    int iPlusTwo           = i + 2;
                    int triangleFirstIndex = i * 3;
                    triangles[triangleFirstIndex]     = 0;
                    triangles[triangleFirstIndex + 1] = iPlusOne;
                    triangles[triangleFirstIndex + 2] = iPlusTwo;
                }
            }

            _mesh.Clear();
            _mesh.vertices  = vertices;
            _mesh.triangles = triangles;
            _mesh.RecalculateNormals();
        }
Exemple #31
0
        public List<Body> generateLevel()
        {
            String pathToCollisionFile = level.levelConfig.GlobalSection["collision"];

            var vertices = new Vector2[4];

            var startPointsStatic = new List<Vector2>();

            var grays = new List<Vector2>();

            var map = new Bitmap(pathToCollisionFile);

            for (int x = 0; x < map.Size.Width; ++x)
            {
                for (int y = 0; y < map.Size.Height; ++y)
                {
                    var pixel = map.GetPixel(x, y);
                    if (isRed(pixel))
                    {
                        startPointsStatic.Add(new Vector2(x, y));
                    }
                }
            }

            foreach (var startPoint in startPointsStatic)
            {
                vertices = GetVertices(map, startPoint);
                var bodyDef = new BodyDef();
                bodyDef.type = BodyType.Static;

                bodyDef.angle = 0;
                bodyDef.position = level.ConvertToBox2D(startPoint);

                var body = level.World.CreateBody(bodyDef);

                var edges = new List<EdgeInfo>();

                if (vertices.Length < 2)
                {
                    throw new Exception();
                }

                for (int i = 1; i < vertices.Length; ++i)
                {
                    var vertexA = vertices[i - 1];
                    var vertexB = vertices[i];

                    var edgeInfo = new EdgeInfo();
                    edgeInfo.shape = new EdgeShape();
                    edgeInfo.isVertical = vertexA.X == vertexB.X;
                    edgeInfo.shape.Set(vertexA, vertexB);
                    edges.Add(edgeInfo);

                }

                foreach (var edge in edges)
                {
                    var fixture = new FixtureDef();
                    var elementInfo = new LevelElementInfo();
                    fixture.shape = edge.shape;
                    if (edge.isVertical)
                    {
                        fixture.friction = 0.0f;
                        elementInfo.type = LevelElementType.Wall;
                    }
                    else
                    {
                        fixture.friction = level.GroundFriction;
                        elementInfo.type = LevelElementType.Ground;
                    }
                    fixture.userData = elementInfo;
                    body.CreateFixture(fixture);
                }

                bodyList.Add(body);
            }

            return bodyList;
        }
Exemple #32
0
		/// <summary>
		/// Add an edge to the edge list if it hasn't been done so already
		/// </summary>
		/// <param name="edges">Edge list</param>
		/// <param name="s">Endpt 0</param>
		/// <param name="t">Endpt 1</param>
		/// <param name="leftFace">Left face value</param>
		/// <param name="rightFace">Right face value</param>
		/// <returns>The index of the edge (edge can already exist in the list).</returns>
		private int AddEdge(List<EdgeInfo> edges, int s, int t, int leftFace, int rightFace)
		{
			//add edge
			int e = FindEdge(edges, s, t);
			if (e == -1)
			{
				EdgeInfo edge = new EdgeInfo(s, t, rightFace, leftFace);
				edges.Add(edge);

				return edges.Count - 1;
			}
			else
				return e;
		}
        /// <summary>
        /// Processes the edges of the given triangle.  It does so by updating 
        /// the adjacency information based on the direction the polygon is facing.
        /// If there is a silhouette edge found, then this edge is added to the list 
        /// of edges if it is within the texture coordinate bounds passed to the function. 
        /// </summary>
        /// <param name="p">The triangle's vertices</param> 
        /// <param name="uv">The texture coordinates for those vertices</param>
        /// <param name="visualTexCoordBounds">The texture coordinate edges being searched for</param>
        /// <param name="polygonSide">Which side the polygon is facing (greateer than 0 front, less than 0 back)</param>
        /// <param name="edgeList">The list of edges comprosing the visual outline</param> 
        /// <param name="adjInformation">The adjacency information structure</param>
        private void ProcessTriangleEdges(Point3D[] p, 
                                          Point[] uv, 
                                          Point[] visualTexCoordBounds,
                                          PolygonSide polygonSide, 
                                          List<HitTestEdge> edgeList,
                                          Dictionary<Edge, EdgeInfo> adjInformation)
        {
            // loop over all the edges and add them to the adjacency list 
            for (int i = 0; i < p.Length; i++)
            { 
                Point uv1, uv2; 
                Point3D p3D1 = p[i];
                Point3D p3D2 = p[(i + 1) % p.Length]; 

                Edge edge;

                // order the edge points so insertion in to adjInformation is consistent 
                if (p3D1.X < p3D2.X ||
                   (p3D1.X == p3D2.X && p3D1.Y < p3D2.Y) || 
                   (p3D1.X == p3D2.X && p3D1.Y == p3D2.Y && p3D1.Z < p3D1.Z)) 
                {
                    edge = new Edge(p3D1, p3D2); 
                    uv1 = uv[i];
                    uv2 = uv[(i + 1) % p.Length];
                }
                else 
                {
                    edge = new Edge(p3D2, p3D1); 
                    uv2 = uv[i]; 
                    uv1 = uv[(i + 1) % p.Length];
                } 

                // look up the edge information
                EdgeInfo edgeInfo;
                if (adjInformation.ContainsKey(edge)) 
                {
                    edgeInfo = adjInformation[edge]; 
                } 
                else
                { 
                    edgeInfo = new EdgeInfo();
                    adjInformation[edge] = edgeInfo;
                }
                edgeInfo._numSharing++; 

                // whether or not the edge has already been added to the edge list 
                bool alreadyAdded = edgeInfo._hasBackFace && edgeInfo._hasFrontFace; 

                // add the edge to the info list 
                if (polygonSide == PolygonSide.FRONT)
                {
                    edgeInfo._hasFrontFace = true;
                    edgeInfo._uv1 = uv1; 
                    edgeInfo._uv2 = uv2;
                } 
                else 
                {
                    edgeInfo._hasBackFace = true; 
                }

                // if the sides are different we may need to add an edge
                if (!alreadyAdded && edgeInfo._hasBackFace && edgeInfo._hasFrontFace) 
                {
                    HandleSilhouetteEdge(edgeInfo._uv1, edgeInfo._uv2, 
                                        edge._start, edge._end, 
                                        visualTexCoordBounds,
                                        edgeList); 
                }
            }
        }
Exemple #34
0
			/// <summary>
			/// If the left face is undefined, assign it a value
			/// </summary>
			/// <param name="e">The current edge</param>
			/// <param name="s">Endpoint A</param>
			/// <param name="t">Endpoint B</param>
			/// <param name="f">The face value</param>
			public static void UpdateLeftFace(ref EdgeInfo e, int s, int t, int f)
			{
				if (e.EndPt0 == s && e.EndPt1 == t && e.LeftFace == (int)EdgeValues.Undefined)
					e.LeftFace = f;
				else if (e.EndPt1 == s && e.EndPt0 == t && e.RightFace == (int)EdgeValues.Undefined)
					e.RightFace = f;
			}
Exemple #35
0
        public List<scBody> generateLevel()
        {
            String pathToCollisionFile = level.levelConfig.GlobalSection["collision"];

            var vertices = new Vector2[4];

            var startPointsStatic = new List<Vector2>();

            var grays = new List<Vector2>();

            var map = new Bitmap(pathToCollisionFile);

            for (int x = 0; x < map.Size.Width; ++x)
            {
                for (int y = 0; y < map.Size.Height; ++y)
                {
                    var pixel = map.GetPixel(x, y);
                    if (isRed(pixel))
                    {
                        startPointsStatic.Add(new Vector2(x, y));
                    }
                }
            }

            foreach (var startPoint in startPointsStatic)
            {
                vertices = GetVertices(map, startPoint);

                var edges = new List<EdgeInfo>();

                if (vertices.Length < 2)
                {
                    throw new Exception();
                }

                for (int i = 1; i < vertices.Length; ++i)
                {
                    var vertexA = vertices[i - 1];
                    var vertexB = vertices[i];

                    var edgeInfo = new EdgeInfo();
                    edgeInfo.shape = new scEdgeShape();
                    edgeInfo.isVertical = vertexA.X == vertexB.X;
                    edgeInfo.shape.start = vertexA;
                    edgeInfo.shape.end = vertexB;
                    edges.Add(edgeInfo);

                }

                IList<scBodyPartDescription> bodyPartDescriptions = new List<scBodyPartDescription>();

                foreach (var edge in edges)
                {
                    var bodyPartDescription = new scBodyPartDescription();
                    var elementInfo = new LevelElementInfo();
                    bodyPartDescription.shape = edge.shape;
                    if (edge.isVertical)
                    {
                        bodyPartDescription.friction = 0.0f;
                        elementInfo.type = LevelElementType.Wall;
                    }
                    else
                    {
                        bodyPartDescription.friction = level.GroundFriction;
                        elementInfo.type = LevelElementType.Ground;
                    }
                    bodyPartDescription.userData = elementInfo;
                    bodyPartDescriptions.Add(bodyPartDescription);
                }

                var bodyDescription = new scBodyDescription();
                bodyDescription.bodyType = scBodyType.Static;

                bodyDescription.transform.rotation.radians = 0;
                bodyDescription.transform.position = startPoint;

                var body = level.World.createBody(bodyDescription, bodyPartDescriptions);

                bodyList.Add(body);
            }

            return bodyList;
        }
Exemple #36
0
	EdgeInfo _AddEdge(VertexInfo vertexa, VertexInfo vertexb)
	{
		string edgeString = EdgeInfo.GetEdgeString (vertexa.index, vertexb.index);
		EdgeInfo edge;
		if (!edges.ContainsKey (edgeString)) {
			edge = new EdgeInfo ();
			edge.vertexAIndex = vertexa.index;
			edge.vertexBIndex = vertexb.index;
			edge.belongToTriangleIndex = new List<int> ();
			edge.isConstraintEdge = false;
			edges [edgeString] = edge;
		} else {
			edge = edges[edgeString];
		}

		if(vertexa.belongToEdgeIndex.Contains(edgeString) == false)
			vertexa.belongToEdgeIndex.Add (edgeString);
		if(vertexb.belongToEdgeIndex.Contains (edgeString) == false)
			vertexb.belongToEdgeIndex.Add (edgeString);
	
		return edge;
	}
 public void ExecuteEdgeDecimation(double length)
 {
     Queue<EdgeInfo> queue = new Queue<EdgeInfo>();
     for (int i = 0; i < Points.Count; i++)
     {
         for (int j = 0; j < Points.Count; j++)
         {
             if (i < j && Edges[i, j].IsValid())
             {
                 if (Edges[i, j].GetEdgeType() == 0)
                 {
                     throw new Exception();
                 }
                 if (Edges[i, j].Length > length && Edges[i, j].GetEdgeType() == 1)
                 {
                     queue.Enqueue(Edges[i, j]);
                 }
             }
         }
     }
     EdgeInfo[] opp1Temp = new EdgeInfo[2];
     while (queue.Count != 0)
     {
         EdgeInfo info = queue.Dequeue();
         if (info.AdjTriangle.Count != 1)
             throw new Exception();
         int tindex = info.AdjTriangle[0];
         Triangle t = Faces[tindex];
         InitOppEdge(opp1Temp, t, info);
         SetInvalid(info.P0Index, info.P1Index);
         for (int i = 0; i < 2; i++)
         {
             EdgeInfo e = opp1Temp[i];
             e.AdjTriangle.Remove(tindex);
             if (e.GetEdgeType() == 0)
             {
                 SetInvalid(e.P0Index, e.P1Index);
             }
             else if (e.GetEdgeType() == 1 && e.Length > length)
             {
                 queue.Enqueue(e);
             }
         }
     }
 }
            private void InitOppEdge(EdgeInfo[] opp1Temp, Triangle t, EdgeInfo info)
            {
                int vindex = t.P0Index + t.P1Index + t.P2Index - info.P0Index - info.P1Index;
                if (vindex < info.P0Index)
                {
                    opp1Temp[0] = Edges[vindex, info.P0Index];
                }
                else
                {
                    opp1Temp[0] = Edges[info.P0Index, vindex];
                }

                if (vindex < info.P1Index)
                {
                    opp1Temp[1] = Edges[vindex, info.P1Index];
                }
                else
                {
                    opp1Temp[1] = Edges[info.P1Index, vindex];
                }
            }
            public void InitEdgesInfo()
            {
                Edges = new EdgeInfo[Points.Count, Points.Count];
                for (int i = 0; i < Points.Count; i++)
                {
                    for (int j = 0; j < Points.Count; j++)
                    {
                        Edges[i, j] = new EdgeInfo(0);
                    }
                }
                for (int i = 0; i < Faces.Count; i++)
                {
                    Triangle t = Faces[i];
                    SetEdge(t, i);
                }

            }