Exemple #1
0
        public RelativeEdgePosition Cross(EdgeInterface e, out double t)
        {
            double s = 0.0;
            RelativeEdgePosition crossType = e.Intersect(this, out s);

            if ((crossType == RelativeEdgePosition.COLLINEAR) || (crossType == RelativeEdgePosition.PARALLEL))
            {
                t = 0.0;
                return(crossType);
            }
            if ((s < 0.0) || (s > 1.0))
            {
                t = 0.0;
                return(RelativeEdgePosition.SKEW_NO_CROSS);
            }
            Intersect(e, out t);
            if ((0.0 <= t) && (t <= 1.0))
            {
                return(RelativeEdgePosition.SKEW_CROSS);
            }
            else
            {
                return(RelativeEdgePosition.SKEW_NO_CROSS);
            }
        }
Exemple #2
0
        public RelativeEdgePosition Intersect(EdgeInterface e, out double t)
        {
            Point  a     = this.Org;
            Point  b     = this.Dest;
            Point  c     = e.Org;
            Point  d     = e.Dest;
            Point  n     = new Point((d - c).Y, (c - d).X);
            double denom = DotProduct(n, b - a);

            if (denom == 0.0)
            {
                RelativePointPosition aClass = Geometry.Point.Classify(this.Org, (Edge)e);
                if ((aClass == RelativePointPosition.LEFT) || (aClass == RelativePointPosition.RIGHT))
                {
                    t = 0.0;
                    return(RelativeEdgePosition.PARALLEL);
                }
                else
                {
                    t = 0.0;
                    return(RelativeEdgePosition.COLLINEAR);
                }
            }

            double num = DotProduct(n, a - c);

            t = -num / denom;
            return(RelativeEdgePosition.SKEW);
        }
Exemple #3
0
        public override void Test()
        {
            this.scene = new List <ViewItemInterface>();
            edge0      = new Edge(10, 10, 100, 50);
            edge1      = new Edge(100, 5, 5, 100);
            this.scene.Add(new EdgeView(edge0));
            this.scene.Add(new EdgeView(edge1));

            double t;
            RelativeEdgePosition pos = edge0.Intersect(edge1, out t);
            Point crossPoint         = null;

            if (pos != RelativeEdgePosition.PARALLEL && pos != RelativeEdgePosition.COLLINEAR)
            {
                crossPoint = new Point(edge0.Point(t));
                this.scene.Add(new PointView(crossPoint));
            }
        }
Exemple #4
0
    //Fill the triangleFan with the positions rerpesenting the triangles corners
    public void updateLineOfSight(ref List <Vector4> triangleFan)
    {
        //reset all values
        reset(ref triangleFan);


        //Get all edges that are inside the Camera bounds
        List <StaticEdgeScript> isVisible = new List <StaticEdgeScript> ();

        for (int z = 0; z < edgesOfMap.Length; z++)
        {
            if (edgesOfMap [z].needsToBeCalculated(cameraBounds))
            {
                isVisible.Add(edgesOfMap[z]);
            }
        }


        //Iterate through all edges inside the camera bounds and put the edges that are facing the player in a sortedList based on the distance from the player
        for (int z = 0; z < isVisible.Count; z++)
        {
            bool          shouldBeAdded = true;
            EdgeInterface edgeInside;
            shouldBeAdded = isVisible [z].isFacingPlayer(out edgeInside);

            if (shouldBeAdded)
            {
                isVisible [z].key = NearestPointOnFiniteLine((Vector3)isVisible [z].backwardPoint, isVisible [z].forwardPoint, player.transform.position);
                while (allVisibleEdges.ContainsKey(isVisible [z].key))
                {
                    isVisible [z].key += 0.001f;
                }
                allVisibleEdges.Add(isVisible [z].key, edgeInside);
            }
        }

        //Shoot projections from the edges that are facing the player and connect the edges to these projections
        for (int y = 0; y < allVisibleEdges.Count; y++)
        {
            allVisibleEdges.Values[y].shootProjections();
        }

        //add a cameraEdge in case there are no other edges inside the camera
        allVisibleEdges.Add(float.MaxValue, cameraEdge.getStatic(0));

        //get the edge that is closest to the player
        EdgeInterface first    = allVisibleEdges.Values [0];
        EdgeInterface tempEdge = first;



        bool done       = false;
        bool broke      = false;
        int  iterations = 0;
        List <EdgeInterface> alreadyCalculated = new List <EdgeInterface> ();

        alreadyCalculated.Add(tempEdge);

        //Go clockwise forward through the connected edges starting with the edge closest towards the player and collect the corners of the edges that togheter make up the trianglefan. Stop when encountering an already calculated edge or if something went wrong.
        while (!done && iterations < infiniteLoopGuard)
        {
            if (iterations == testNr || testNr == -1 || testNr == -2)               //only for debugging purposes
            {
                Debug.DrawLine(tempEdge.getBackwardPoint(), tempEdge.getForwardPoint(), Color.magenta, 0);
                if (testNr != -1)
                {
                    Debug.Log("name " + tempEdge.getName());
                }
            }

            if (!tempEdge.isProj())                //if the edge is a projection, there is no need to add its corners to the trianglefan
            {
                triangleFan.Add(new Vector4(tempEdge.getBackwardPoint().x, tempEdge.getBackwardPoint().y, tempEdge.getForwardPoint().x, tempEdge.getForwardPoint().y));
            }

            if (tempEdge.getForwardEdge() == null)                //Something went wrong. If you encounter these debug messages, please make sure you followed the instructions layed out in the "StaticEdgeScript"
            //If you are certain that you have, please manually move the characters position to the position writen out in the "Position" message.
            //If the messages keeps coming up from that position, please send your scene to [email protected] so I can fix it
            {
                Debug.Log("iteration " + iterations);
                Debug.Log("ForwadEdge null: " + tempEdge.getName());
                Debug.Log("Point lost: " + tempEdge.getForwardPoint() + " and " + tempEdge.getBackwardPoint());
                Debug.Log("Position " + MyGameManager.itself.player.transform.position.x + " y " + MyGameManager.itself.player.transform.position.y);
                broke = true;
                //Debug.Break (); //Used for debugging purposes
                break;
            }
            alreadyCalculated.Add(tempEdge);
            tempEdge    = tempEdge.getForwardEdge();
            iterations += 1;
            if (alreadyCalculated.Contains(tempEdge))
            {
                done = true;
            }
            if (iterations > infiniteLoopGuard - 1)             //it is good practice in Unity to always have a infiniteLoopGuard preventing infiniteLoops. If you encounter these messages, please increase the infiniteLoopGuard number
            //If these messages still appear, please send your scene to [email protected] so I can fix it
            {
                Debug.Log("Position " + MyGameManager.itself.player.transform.position.x + " y " + MyGameManager.itself.player.transform.position.y);

                Debug.Log("Point loop: " + tempEdge.getName() + " forward " + tempEdge.getForwardEdge().getName() + " forward.forawrd " + tempEdge.getForwardEdge().getForwardEdge().getName());
            }
        }


        //If something broke, but you cannot reproduce the bug (or you don't want to send the scene to me so I can fix it) and you still want to use the algorithm in the scene, this loop will make an attempt to minimize the damge done by the bug by iterating counter clockwise instead of clockwise. This will most likely make the bug not noticeable for players other then perhaps a framedrop
        if (broke)
        {
            tempEdge = first.getBackwardEdge();

            if (!alreadyCalculated.Contains(tempEdge))
            {
                alreadyCalculated.Add(tempEdge);
                while (!done && iterations < infiniteLoopGuard)
                {
                    if (!tempEdge.isProj())
                    {
                        triangleFan.Add(new Vector4(tempEdge.getBackwardPoint().x, tempEdge.getBackwardPoint().y, tempEdge.getForwardPoint().x, tempEdge.getForwardPoint().y));
                    }

                    if (tempEdge.getBackwardEdge() == null)
                    {
                        Debug.Log("iteration " + iterations);
                        Debug.Log("ForwadEdge null: " + tempEdge.getName());
                        Debug.Log("Point lost: " + tempEdge.getForwardPoint() + " and " + tempEdge.getBackwardPoint());
                        Debug.Log("Position " + MyGameManager.itself.player.transform.position.x + " y " + MyGameManager.itself.player.transform.position.y);
                        broke = true;
                        //Debug.Break ();
                        break;
                    }
                    alreadyCalculated.Add(tempEdge);
                    tempEdge    = tempEdge.getBackwardEdge();
                    iterations += 1;

                    if (alreadyCalculated.Contains(tempEdge))
                    {
                        done = true;
                    }
                    if (iterations > infiniteLoopGuard - 1)
                    {
                        Debug.Log("Position " + MyGameManager.itself.player.transform.position.x + " y " + MyGameManager.itself.player.transform.position.y);

                        Debug.Log("Point loop: " + tempEdge.getName() + " forward " + tempEdge.getForwardEdge().getName() + " forward.forawrd " + tempEdge.getForwardEdge().getForwardEdge().getName());
                    }
                }
            }
        }
    }
Exemple #5
0
 public EdgeView(EdgeInterface edge, System.Drawing.Color color)
 {
     this.Edge     = edge;
     this.PenColor = color;
 }
Exemple #6
0
 public EdgeView(EdgeInterface edge)
 {
     this.Edge = edge;
 }
Exemple #7
0
 public void setBackwardEdge(EdgeInterface edge)
 {
     backwardEdge = edge;
 }
Exemple #8
0
 public void setForwardEdge(EdgeInterface edge)
 {
     forwardEdge = edge;
 }
Exemple #9
0
 public EdgeInterface splitThisEdge(bool keepForward, EdgeInterface connectedEdge, Vector2 pointOfIntersect)
 {
     return(this);
 }
Exemple #10
0
 public void Init()
 {
     instance = new EdgeInterface();
 }