Beispiel #1
0
        public override void Update(float currentFps)
        {
            base.Update(currentFps);

            if (this.Path.Count == 0)
            {
                GameObject player = level.GetChildrens().Find(x => x is Player);

                MatrixNode endNode = MatrixNode.AStar(level.Tiles, (int)this.LocalPosition.X / 32, (int)this.LocalPosition.Y / 32, (int)player.LocalPosition.X / 32, (int)player.LocalPosition.Y / 32);

                //looping through the Parent nodes until we get to the start node
                this.Path = new Stack <MatrixNode>();
                if (endNode != null)
                {
                    while (endNode.x != (int)this.LocalPosition.X / 32 || endNode.y != (int)this.LocalPosition.Y / 32)
                    {
                        for (int i = 0; i < 32; i++)
                        {
                            this.Path.Push(endNode);
                        }

                        endNode = endNode.parent;
                    }
                    this.Path.Push(endNode);
                }
            }

            if (this.Path.Count > 0)
            {
                MatrixNode node = this.Path.Pop();
                this.MoveTo(node.x * 32, node.y * 32);
            }
            this.Rectangle = BoundingBox;
        }
Beispiel #2
0
 private MatrixNodeDTO Create(MatrixNode node)
 {
     return(new MatrixNodeDTO()
     {
         Query = node.Query,
         ToolTip = node.ToolTip
     });
 }
Beispiel #3
0
        public void MatrixNodeProperty()
        {
            var node = new MatrixNode(10, 11, 12);

            Assert.AreEqual(node.Value, 10);
            Assert.AreEqual(node.Row, 11);
            Assert.AreEqual(node.Col, 12);
        }
Beispiel #4
0
 private void WriteRoute(MatrixNode a)
 {
     if (a != null)
     {
         DisplayMatix.Write('*', a.x, a.y, ConsoleColor.Green);
         WriteRoute(a.parent);
     }
 }
Beispiel #5
0
        public static int GetStepsNum(MatrixNode node)
        {
            int step = 0;

            if (node != null)
            {
                step++;
                step += GetStepsNum(node.parent);
            }
            return(step);
        }
    private List <Vector2> GetAsList(MatrixNode end)
    {
        var next = new List <Vector2>();

        while (end != null)
        {
            next.Add(end.Position);
            end = end.Parent;
        }

        return(next.GetRange(1, next.Count - 2));
    }
Beispiel #7
0
        public static MatrixNode GetFirstStep(MatrixNode node)
        {
            MatrixNode parent = null;

            if (node.parent != null && node.parent.fromDistance > 0)
            {
                parent = GetFirstStep(node.parent);
            }
            else
            {
                parent = node;
            }
            return(parent);
        }
            public void Add(int[] data)
            {
                MatrixNode node = new MatrixNode(data);

                if (head == null)
                {
                    head = node;
                }
                else
                {
                    tail.Next = node;
                }
                tail = node;
                count++;
            }
    public MatrixNode FindShortestPath(Vector2 start, Vector2 end)
    {
        var explored  = new Dictionary <string, MatrixNode>();
        var open      = new Dictionary <string, MatrixNode>();
        var neighbors = new List <Vector2>
        {
            new Vector2(-1, 0),
            new Vector2(0, 1),
            new Vector2(1, 0),
            new Vector2(0, -1)
        };
        var startNode = new MatrixNode(start, end);
        var key       = start.x.ToString() + start.y.ToString();

        open.Add(key, startNode);

        while (open.Count > 0)
        {
            var smallest = SmallestNode(open);

            foreach (var neighbor in neighbors)
            {
                var position = smallest.Value.Position + neighbor;
                var current  = new MatrixNode(position, end, smallest.Value);

                if (position == end)
                {
                    return(current);
                }

                key = current.Position.x.ToString() + current.Position.y.ToString();

                if (!open.ContainsKey(key) && !explored.ContainsKey(key))
                {
                    open.Add(key, current);
                }
            }

            open.Remove(smallest.Key);
            explored.Add(smallest.Key, smallest.Value);
        }

        return(null);
    }
Beispiel #10
0
    internal static MatrixNode[,] GetMappedNodes()
    {
        var keys   = Matrix.Matrix.Nodes.keys;
        var values = Matrix.Matrix.Nodes.values;

        var x = new List <int>();
        var y = new List <int>();

        var nodes = new List <MatrixNode>();

        for (int i = 0; i < keys.Count; i++)
        {
            var k = keys[i];
            var v = values[i];

            if (v.GetTiles().Count > 0 ||
                v.GetItems().Count > 0)
            {
                nodes.Add(v);
                x.Add((int)(k >> 32));
                y.Add((int)(k & int.MaxValue));
            }
        }

        int minX = Mathf.Min(x.ToArray());
        int minY = Mathf.Min(y.ToArray());
        int maxX = Mathf.Max(x.ToArray());
        int maxY = Mathf.Max(y.ToArray());

        int width  = maxX - minX;
        int height = maxY - minY;

        MatrixNode[,] nodesMapped = new MatrixNode[height + 1, width + 1];

        for (int i = 0; i < nodes.Count; i++)
        {
            nodesMapped[y[i] - minY, x[i] - minX] = nodes[i];
        }

        return(nodesMapped);
    }
Beispiel #11
0
            public int ItemAt(int i, int j)
            {
                if (i >= count)
                {
                    throw new IndexOutOfRangeException("List is smaller than the index.");
                }
                if (i < 0)
                {
                    throw new IndexOutOfRangeException("Index cannot be negative.");
                }
                MatrixNode current = head;

                for (int k = 0; current != null; k++)
                {
                    if (i == k)
                    {
                        return(current.Data[j]);
                    }
                    else
                    {
                        current = current.Next;
                    }
                }
                return(default);
Beispiel #12
0
            public void UpdateAtIndex(int newData, int i, int j)
            {
                if (i >= count)
                {
                    throw new IndexOutOfRangeException("List does not contain an item at such index.");
                }
                if (i < 0)
                {
                    throw new IndexOutOfRangeException("Index cannot be negative.");
                }
                MatrixNode current = head;

                for (int k = 0; current != null; k++)
                {
                    if (k == j)
                    {
                        current.Data[i] = newData;
                    }
                    else
                    {
                        current = current.Next;
                    }
                }
            }
 public MatrixNode(Vector2 position, Vector2 destination, MatrixNode parent)
 {
     Position    = position;
     Destination = destination;
     Parent      = parent;
 }
Beispiel #14
0
 public void MatrixNodeConstructor()
 {
     var node = new MatrixNode(10, 10, 10);
 }
        public static MatrixNode AStar(char[,] matrix, int fromX, int fromY, int toX, int toY, char[] walls)
        {
            ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
            // in this version an element in a matrix can move left/up/right/down in one step, two steps for a diagonal move.
            ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

            //the keys for greens and reds are x.ToString() + y.ToString() of the matrixNode
            Dictionary <string, MatrixNode> greens = new Dictionary <string, MatrixNode>(); //open
            Dictionary <string, MatrixNode> reds   = new Dictionary <string, MatrixNode>(); //closed

            MatrixNode startNode = new MatrixNode {
                x = fromX, y = fromY
            };
            string key = startNode.x.ToString() + startNode.y.ToString();

            greens.Add(key, startNode);

            KeyValuePair <string, MatrixNode> smallestGreen()
            {
                KeyValuePair <string, MatrixNode> smallest = greens.ElementAt(0);

                foreach (KeyValuePair <string, MatrixNode> item in greens)
                {
                    if ((item.Value.fromDistance < smallest.Value.fromDistance) ||
                        (item.Value.fromDistance == smallest.Value.fromDistance && smallest.Value.y > item.Value.y) ||
                        (item.Value.fromDistance == smallest.Value.fromDistance && smallest.Value.y == item.Value.y && smallest.Value.x > item.Value.x)
                        )
                    {
                        smallest = item;
                    }
                }

                return(smallest);
            }

            //add these values to current node's x and y values to get the left/up/right/bottom neighbors
            List <KeyValuePair <int, int> > fourNeighbors = new List <KeyValuePair <int, int> >()
            {
                new KeyValuePair <int, int>(-1, 0),
                new KeyValuePair <int, int>(0, 1),
                new KeyValuePair <int, int>(1, 0),
                new KeyValuePair <int, int>(0, -1)
            };

            int maxX = matrix.GetLength(0);

            if (maxX == 0)
            {
                return(null);
            }
            int maxY = matrix.GetLength(1);

            while (true)
            {
                if (greens.Count == 0)
                {
                    return(null);
                }

                KeyValuePair <string, MatrixNode> current = smallestGreen();
                if (current.Value.x == toX && current.Value.y == toY)
                {
                    return(current.Value);
                }

                greens.Remove(current.Key);
                reds.Add(current.Key, current.Value);

                foreach (KeyValuePair <int, int> plusXY in fourNeighbors)
                {
                    int    nbrX   = current.Value.x + plusXY.Key;
                    int    nbrY   = current.Value.y + plusXY.Value;
                    string nbrKey = nbrX.ToString() + nbrY.ToString();
                    if (nbrX < 0 || nbrY < 0 || nbrX >= maxX || nbrY >= maxY ||
                        walls.Contains(matrix[nbrX, nbrY]) ||
                        reds.ContainsKey(nbrKey))
                    {
                        continue;
                    }

                    if (greens.ContainsKey(nbrKey))
                    {
                        MatrixNode curNbr = greens[nbrKey];
                        int        from   = Math.Abs(nbrX - fromX) + Math.Abs(nbrY - fromY);
                        if (from < curNbr.fromDistance)
                        {
                            curNbr.fromDistance = from;
                            curNbr.sumDistance  = curNbr.fromDistance + curNbr.toDistance;
                            curNbr.parent       = current.Value;
                        }
                    }
                    else
                    {
                        MatrixNode curNbr = new MatrixNode {
                            x = nbrX, y = nbrY
                        };
                        curNbr.fromDistance = Math.Abs(nbrX - fromX) + Math.Abs(nbrY - fromY);
                        curNbr.toDistance   = Math.Abs(nbrX - toX) + Math.Abs(nbrY - toY);
                        curNbr.sumDistance  = curNbr.fromDistance + curNbr.toDistance;
                        curNbr.parent       = current.Value;
                        greens.Add(nbrKey, curNbr);
                    }
                }
            }
        }
Beispiel #16
0
        private void HandleMouseMove(PointF point)
        {
            this.isMouseMoved = true;
            List <CSMatrix> csMatrixList       = new List <CSMatrix>();
            CSMatrix        anchorWorldMatrix1 = this.CSCom.GetAnchorWorldMatrix();

            this.Print(anchorWorldMatrix1);
            CSMatrix csMatrix1 = this.CSCom.Mat4Inverse(anchorWorldMatrix1);

            this.Print(csMatrix1);
            for (int index = 0; index < this.selectedParentObjects.Count <VisualObject>(); ++index)
            {
                CSMatrix anchorWorldMatrix2 = this.selectedParentObjects.ElementAt <VisualObject>(index).GetCSVisual().GetAnchorWorldMatrix();
                this.Print(anchorWorldMatrix2);
                CSMatrix m = this.CSCom.Mat4Multiply(csMatrix1, anchorWorldMatrix2);
                this.Print(m);
                csMatrixList.Add(m);
            }
            if (this.operationType == OperationType.OPERATION_ANCHOR_POINT)
            {
                this.HandleAnchorPoint(point);
                if (this.SelectedObjects.Count <VisualObject>() > 1)
                {
                    return;
                }
            }
            else if (this.operationType == OperationType.OPERATION_POSITION)
            {
                this.HandlePosition(point);
            }
            else if (this.operationType == OperationType.OPERATION_ROTATION)
            {
                this.HandleRotation(point);
            }
            else if (this.operationType == OperationType.OPERATION_SCALE)
            {
                if (!this.HandleScale(point))
                {
                    this.updateLastMousePoint = false;
                    return;
                }
            }
            else if (this.operationType == OperationType.OPERATION_SKEW)
            {
                this.HandleSkew(point);
            }
            CSMatrix anchorWorldMatrix3 = this.CSCom.GetAnchorWorldMatrix();

            this.Print(anchorWorldMatrix3);
            for (int index = 0; index < this.selectedParentObjects.Count <VisualObject>(); ++index)
            {
                VisualObject node = this.selectedParentObjects.ElementAt <VisualObject>(index);
                if ((VisualObject)(node as NodeObject).Parent == null)
                {
                    VisualObject canvasObject = this.canvasObject;
                }
                CSMatrix parentWorldMatrix = node.GetCSVisual().GetParentWorldMatrix();
                this.Print(parentWorldMatrix);
                CSMatrix csMatrix2 = this.CSCom.Mat4Inverse(parentWorldMatrix);
                this.Print(csMatrix2);
                CSMatrix csMatrix3 = this.CSCom.Mat4Multiply(anchorWorldMatrix3, csMatrixList[index]);
                this.Print(csMatrix3);
                CSMatrix csMatrix4 = this.CSCom.Mat4Multiply(csMatrix2, csMatrix3);
                this.Print(csMatrix4);
                MatrixNode matrixNode = this.CSCom.Mat4ToMatrixNode(csMatrix4);
                if (!this.TestFloatEqual(node.Position.X, matrixNode.CX, 1f / 1000f) || !this.TestFloatEqual(node.Position.Y, matrixNode.CY, 1f / 1000f))
                {
                    if (!this.positionChanged)
                    {
                        this.positionChanged = this.NeedAutoCreateFirstFrame(node, typeof(PositionFrame).Name);
                    }
                    node.Position = new PointF(matrixNode.CX, matrixNode.CY);
                }
                if (!this.TestFloatEqual(node.Scale.ScaleX, matrixNode.CScaleX, 1f / 1000f) || !this.TestFloatEqual(node.Scale.ScaleY, matrixNode.CScaleY, 1f / 1000f))
                {
                    if (!this.scaleChanged)
                    {
                        this.scaleChanged = this.NeedAutoCreateFirstFrame(node, typeof(ScaleFrame).Name);
                    }
                    node.Scale = new ScaleValue(matrixNode.CScaleX, matrixNode.CScaleY, 0.1, -99999999.0, 99999999.0);
                }
                float      v2_1         = this.SimplifyRotation(ComControlNode.CC_RADIANS_TO_DEGREES(-matrixNode.CSkewX));
                float      v2_2         = this.SimplifyRotation(ComControlNode.CC_RADIANS_TO_DEGREES(-matrixNode.CSkewY));
                ScaleValue rotationSkew = node.RotationSkew;
                float      num1         = this.SimplifyRotation(rotationSkew.ScaleX);
                float      num2         = this.SimplifyRotation(rotationSkew.ScaleY);
                if (!this.TestFloatEqual(rotationSkew.ScaleX, v2_1, 1f / 1000f) || !this.TestFloatEqual(rotationSkew.ScaleY, v2_2, 1f / 1000f))
                {
                    if (!this.rotationChanged)
                    {
                        this.rotationChanged = this.NeedAutoCreateFirstFrame(node, typeof(RotationSkewFrame).Name);
                    }
                    float num3 = this.SimplifyRotationDif(v2_1 - num1);
                    float num4 = this.SimplifyRotationDif(v2_2 - num2);
                    rotationSkew.ScaleX += num3;
                    rotationSkew.ScaleY += num4;
                    node.RotationSkew    = rotationSkew;
                }
            }
        }
Beispiel #17
0
        private void HandleMouseMove(PointF point)
        {
            this.isMouseMoved = true;
            List <CSMatrix> list = new List <CSMatrix>();
            CSMatrix        anchorWorldMatrix = this.CSCom.GetAnchorWorldMatrix();

            this.Print(anchorWorldMatrix);
            CSMatrix cSMatrix = this.CSCom.Mat4Inverse(anchorWorldMatrix);

            this.Print(cSMatrix);
            for (int i = 0; i < this.selectedParentObjects.Count <VisualObject>(); i++)
            {
                VisualObject visualObject       = this.selectedParentObjects.ElementAt(i);
                CSMatrix     anchorWorldMatrix2 = visualObject.GetCSVisual().GetAnchorWorldMatrix();
                this.Print(anchorWorldMatrix2);
                CSMatrix cSMatrix2 = this.CSCom.Mat4Multiply(cSMatrix, anchorWorldMatrix2);
                this.Print(cSMatrix2);
                list.Add(cSMatrix2);
            }
            if (this.operationType == OperationType.OPERATION_ANCHOR_POINT)
            {
                this.HandleAnchorPoint(point);
                if (this.SelectedObjects.Count <VisualObject>() > 1)
                {
                    return;
                }
            }
            else if (this.operationType == OperationType.OPERATION_POSITION)
            {
                this.HandlePosition(point);
            }
            else if (this.operationType == OperationType.OPERATION_ROTATION)
            {
                this.HandleRotation(point);
            }
            else if (this.operationType == OperationType.OPERATION_SCALE)
            {
                if (!this.HandleScale(point))
                {
                    this.updateLastMousePoint = false;
                    return;
                }
            }
            else if (this.operationType == OperationType.OPERATION_SKEW)
            {
                this.HandleSkew(point);
            }
            CSMatrix anchorWorldMatrix3 = this.CSCom.GetAnchorWorldMatrix();

            this.Print(anchorWorldMatrix3);
            for (int i = 0; i < this.selectedParentObjects.Count <VisualObject>(); i++)
            {
                VisualObject visualObject = this.selectedParentObjects.ElementAt(i);
                VisualObject parent       = (visualObject as NodeObject).Parent;
                if (parent == null)
                {
                    parent = this.canvasObject;
                }
                CSMatrix cSMatrix3 = visualObject.GetCSVisual().GetParentWorldMatrix();
                this.Print(cSMatrix3);
                cSMatrix3 = this.CSCom.Mat4Inverse(cSMatrix3);
                this.Print(cSMatrix3);
                CSMatrix cSMatrix4 = this.CSCom.Mat4Multiply(anchorWorldMatrix3, list[i]);
                this.Print(cSMatrix4);
                CSMatrix cSMatrix2 = this.CSCom.Mat4Multiply(cSMatrix3, cSMatrix4);
                this.Print(cSMatrix2);
                MatrixNode matrixNode = this.CSCom.Mat4ToMatrixNode(cSMatrix2);
                if (!this.TestFloatEqual(visualObject.Position.X, matrixNode.CX, 0.001f) || !this.TestFloatEqual(visualObject.Position.Y, matrixNode.CY, 0.001f))
                {
                    if (!this.positionChanged)
                    {
                        this.positionChanged = this.NeedAutoCreateFirstFrame(visualObject, typeof(PositionFrame).Name);
                    }
                    visualObject.Position = new PointF(matrixNode.CX, matrixNode.CY);
                }
                if (!this.TestFloatEqual(visualObject.Scale.ScaleX, matrixNode.CScaleX, 0.001f) || !this.TestFloatEqual(visualObject.Scale.ScaleY, matrixNode.CScaleY, 0.001f))
                {
                    if (!this.scaleChanged)
                    {
                        this.scaleChanged = this.NeedAutoCreateFirstFrame(visualObject, typeof(ScaleFrame).Name);
                    }
                    visualObject.Scale = new ScaleValue(matrixNode.CScaleX, matrixNode.CScaleY, 0.1, -99999999.0, 99999999.0);
                }
                float      num          = this.SimplifyRotation(ComControlNode.CC_RADIANS_TO_DEGREES(-matrixNode.CSkewX));
                float      num2         = this.SimplifyRotation(ComControlNode.CC_RADIANS_TO_DEGREES(-matrixNode.CSkewY));
                ScaleValue rotationSkew = visualObject.RotationSkew;
                float      num3         = this.SimplifyRotation(rotationSkew.ScaleX);
                float      num4         = this.SimplifyRotation(rotationSkew.ScaleY);
                if (!this.TestFloatEqual(rotationSkew.ScaleX, num, 0.001f) || !this.TestFloatEqual(rotationSkew.ScaleY, num2, 0.001f))
                {
                    if (!this.rotationChanged)
                    {
                        this.rotationChanged = this.NeedAutoCreateFirstFrame(visualObject, typeof(RotationSkewFrame).Name);
                    }
                    float num5 = this.SimplifyRotationDif(num - num3);
                    float num6 = this.SimplifyRotationDif(num2 - num4);
                    rotationSkew.ScaleX      += num5;
                    rotationSkew.ScaleY      += num6;
                    visualObject.RotationSkew = rotationSkew;
                }
            }
        }