public Square[,] squares;   //  2D array

        //  Constructor
        public SquareGrid(int[,] map, float squareSize) {
            //  Variables
            int nodeCountX = map.GetLength(0);
            int nodeCountY = map.GetLength(1);
            float mapWidth = nodeCountX * squareSize;
            float mapHeight = nodeCountY * squareSize;

            //  2D array of ControlNodes
            ControlNode[,] controlNodes = new ControlNode[nodeCountX, nodeCountY];

            //  Creating grid of ControlNodes
            for (int x = 0; x < nodeCountX; x++) {
                for (int y = 0; y < nodeCountY; y++) {
                    //  Calculate position
                    Vector3 pos = new Vector3(-mapWidth / 2 + x * squareSize + squareSize / 2, 0, -mapHeight / 2 + y * squareSize + squareSize / 2);
                    controlNodes[x, y] = new ControlNode(pos, map[x, y] == 1, squareSize);
                }   //  inner for
            }   //  for

            
            squares = new Square[nodeCountX - 1, nodeCountY - 1];

            //  Go through each each square
            //  Creating grid of squares out of ControlNodes
            for (int x = 0; x < nodeCountX - 1; x++) {
                for (int y = 0; y < nodeCountY - 1; y++) {
                    //  Top left, top right, bottom right, bottom left control nodes
                    squares[x, y] = new Square(controlNodes[x, y + 1], controlNodes[x + 1, y + 1], controlNodes[x + 1, y], controlNodes[x, y]);
                }   //  inner for
            }   //  for

        }  //   SquareGrid() 
Example #2
0
        public Square[,] squares; //array de cuadrados

        public SquareGrid(int[,] map, float squareSize)
        {
            int   nodeCountX = map.GetLength(0);
            int   nodeCountY = map.GetLength(1);
            float mapWidth   = nodeCountX * squareSize;
            float mapHeight  = nodeCountY * squareSize;

            ControlNode[,] controlNodes = new ControlNode[nodeCountX, nodeCountY];

            for (int x = 0; x < nodeCountX; x++)
            {
                for (int y = 0; y < nodeCountY; y++)
                {
                    Vector3 pos = new Vector3(-mapWidth / 2 + x * squareSize + squareSize / 2, 0, -mapHeight / 2 + y * squareSize + squareSize / 2);
                    //-mapWith/2 far left (no antec)
                    controlNodes[x, y] = new ControlNode(pos, map[x, y] == 1, squareSize);//pasa true or false (==1)
                }
            }

            squares = new Square[nodeCountX - 1, nodeCountY - 1]; //sempre hi ha un quadrat menos que nodos
            for (int x = 0; x < nodeCountX - 1; x++)
            {
                for (int y = 0; y < nodeCountY - 1; y++)
                {
                    squares[x, y] = new Square(controlNodes[x, y + 1], controlNodes[x + 1, y + 1], controlNodes[x + 1, y], controlNodes[x, y]);
                }
            }
            //va a cada quadrat i fa els seus control Nodes, bottom left, bottom right etc.
        }
Example #3
0
        public override void PaintControl(RichTextBox control, ControlPaintArgs args)
        {
            INode    controlNode = new ControlNode(control);
            IRuleset ruleset     = args.StyleSheet.GetRuleset(controlNode);

            RenderUtilities.ApplyColorProperties(control, ruleset);

            Rectangle clientRect = control.ClientRectangle;
            Rectangle borderRect = new Rectangle(clientRect.X - 3, clientRect.Y - 3, clientRect.Width + 6, clientRect.Height + 6);

            ScrollBars visibleScrollbars = ControlUtilities.GetVisibleScrollBars(control);

            if (visibleScrollbars.HasFlag(ScrollBars.Vertical))
            {
                borderRect = new Rectangle(borderRect.X, borderRect.Y, borderRect.Width + SystemInformation.VerticalScrollBarWidth, borderRect.Height);
            }

            if (visibleScrollbars.HasFlag(ScrollBars.Horizontal))
            {
                borderRect = new Rectangle(borderRect.X, borderRect.Y, borderRect.Width, borderRect.Height + SystemInformation.HorizontalScrollBarHeight);
            }

            args.PaintBackground(borderRect);
            args.PaintBorder(borderRect);
        }
Example #4
0
        public int squareConfiguration;                                // this value will equal this squares marching squares configuration, please see documentation to see marching square configurations.

        // the square constructor
        public Square(ControlNode _topLeft, ControlNode _topRight, ControlNode _bottomRight, ControlNode _bottomLeft)
        {
            // set the control Nodes
            topLeft     = _topLeft;
            topRight    = _topRight;
            bottomRight = _bottomRight;
            bottomLeft  = _bottomLeft;

            //set the nodes depending on the control nodes
            centreTop   = topLeft.right;
            centreRight = bottomRight.above;
            centreBot   = bottomLeft.right;
            centreLeft  = bottomLeft.above;

            if (topLeft.active)           // if the top left node is active
            {
                squareConfiguration += 8; // add 8 to the square configuration
            }
            if (topRight.active)          // if the top right node is active
            {
                squareConfiguration += 4; // add 4 to the square configuration
            }
            if (bottomRight.active)       // if the bottom right node is active
            {
                squareConfiguration += 2; // add 2 to the square configuration
            }
            if (bottomLeft.active)        // if the bottom left node is active
            {
                squareConfiguration += 1; // add one to the square configuration
            }
            // the configuration is ued for the marching squares  formula.
        }
        // Private members

        private void PaintDropDownArrow(ComboBox control, ControlPaintArgs e)
        {
            INode    controlNode       = new ControlNode(control);
            UserNode dropDownArrowNode = new UserNode(string.Empty, new[] { "DropDownArrow" });

            dropDownArrowNode.SetParent(controlNode);
            dropDownArrowNode.SetStates(controlNode.States);

            IRuleset ruleset = e.StyleSheet.GetRuleset(dropDownArrowNode);

            // Create the arrow rectangle to match the bounds of the default control.

            Rectangle clientRect = control.ClientRectangle;
            Rectangle arrowRect  = new Rectangle(clientRect.Right - 12, clientRect.Y + 9, 7, 6);

            e.Graphics.SmoothingMode = SmoothingMode.AntiAlias;

            using (Pen pen = new Pen(ruleset.Color?.Value ?? SystemColors.ControlText)) {
                pen.Width     = 2.0f;
                pen.Alignment = PenAlignment.Center;
                pen.StartCap  = LineCap.Flat;
                pen.EndCap    = LineCap.Flat;

                PointF bottomMidpoint = new PointF(arrowRect.Left + arrowRect.Width / 2.0f, arrowRect.Bottom - 1);

                e.Graphics.DrawLine(pen, new PointF(arrowRect.Left, arrowRect.Top), bottomMidpoint);
                e.Graphics.DrawLine(pen, new PointF(arrowRect.Right, arrowRect.Top), bottomMidpoint);
            }
        }
Example #6
0
        public Square(ControlNode _bL, ControlNode _bR, ControlNode _tL, ControlNode _tR)
        {
            topLeft     = _tL;
            topRight    = _tR;
            bottomLeft  = _bL;
            bottomRight = _bR;

            top    = topLeft.right;
            bottom = bottomLeft.right;
            left   = bottomLeft.above;
            right  = bottomRight.above;

            configuration = 0;
            if (topLeft.active)
            {
                configuration += 8;
            }
            if (topRight.active)
            {
                configuration += 4;
            }
            if (bottomRight.active)
            {
                configuration += 2;
            }
            if (bottomLeft.active)
            {
                configuration += 1;
            }
        }
        public SquareGrid(int[,] map, float squareSize)
        {
            int   nodeCountX = map.GetLength(0);
            int   nodeCountY = map.GetLength(1);
            float mapWidth   = nodeCountX * squareSize;
            float mapHeight  = nodeCountY * squareSize;

            ControlNode[,] controlNodes = new ControlNode[nodeCountX, nodeCountY];

            for (int x = 0; x < nodeCountX; x++)
            {
                for (int y = 0; y < nodeCountY; y++)
                {
                    /*
                     * RaycastHit hitInfo;
                     * Vector3 fwd = transform.TransformDirection(Vector3.down);
                     * Vector3 VecPos = new Vector3(-mapWidth/2 + x * squareSize + squareSize/2, 0, -mapHeight/2 + y * squareSize + squareSize/2);
                     * if (Physics.Raycast(VecPos, fwd, out hitInfo) {
                     *      print("____________________hitInfo.distance__"+hitInfo.distance);
                     * }*/

                    Vector3 pos = new Vector3(-mapWidth / 2 + x * squareSize + squareSize / 2, 0, -mapHeight / 2 + y * squareSize + squareSize / 2);
                    controlNodes[x, y] = new ControlNode(pos, map[x, y] == 1, squareSize);
                }
            }

            squares = new Square[nodeCountX - 1, nodeCountY - 1];
            for (int x = 0; x < nodeCountX - 1; x++)
            {
                for (int y = 0; y < nodeCountY - 1; y++)
                {
                    squares[x, y] = new Square(controlNodes[x, y + 1], controlNodes[x + 1, y + 1], controlNodes[x + 1, y], controlNodes[x, y]);
                }
            }
        }
        public Square(ControlNode _topLeft, ControlNode _topRight,
                      ControlNode _bottomRight, ControlNode _bottomLeft)
        {
            topLeft     = _topLeft;
            topRight    = _topRight;
            bottomRight = _bottomRight;
            bottomLeft  = _bottomLeft;

            centreTop    = topLeft.right;
            centreRight  = bottomRight.above;
            centreBottom = bottomLeft.right;
            centreLeft   = bottomLeft.above;

            //in binary 0000
            if (topLeft.active)
            {
                configuration += 8; //1000
            }
            if (topRight.active)
            {
                configuration += 4; //0100
            }
            if (bottomRight.active)
            {
                configuration += 2; //0010
            }
            if (bottomLeft.active)
            {
                configuration += 1; //0001
            }
        }
Example #9
0
        public SquareGrid(int[,] map, float squareSize)
        {
            int nodeCountX = map.GetLength(0);
            int nodeCountY = map.GetLength(1);
            float mapWidth = nodeCountX * squareSize;
            float mapHeight = nodeCountY * squareSize;

            ControlNode[,] controlNodes = new ControlNode[nodeCountX, nodeCountY];

            for (int x = 0; x < nodeCountX; x++)
            {
                for (int y = 0; y < nodeCountY; y++)
                {
                    Vector3 pos = new Vector3(-mapWidth / 2 + x * squareSize + squareSize / 2, 0, -mapHeight / 2 + y * squareSize + squareSize / 2);
                    controlNodes[x, y] = new ControlNode(pos, map[x, y] == 1, squareSize);
                }
            }

            Squares = new Square[nodeCountX - 1, nodeCountY - 1];
            for (int x = 0; x < nodeCountX - 1; x++)
            {
                for (int y = 0; y < nodeCountY - 1; y++)
                {
                    Squares[x, y] = new Square(controlNodes[x, y + 1], controlNodes[x + 1, y + 1], controlNodes[x + 1, y], controlNodes[x, y]);
                }
            }
        }
        public Square(ControlNode _topLeft, ControlNode _topRight, ControlNode _bottomRight, ControlNode _bottomLeft)
        {
            topLeft     = _topLeft;
            topRight    = _topRight;
            bottomRight = _bottomRight;
            bottomLeft  = _bottomLeft;

            centreTop    = topLeft.right;
            centreRight  = bottomRight.above;
            centreBottom = bottomLeft.right;
            centreLeft   = bottomLeft.above;

            if (topLeft.active)
            {
                configuration += 8;
            }
            if (topRight.active)
            {
                configuration += 4;
            }
            if (bottomRight.active)
            {
                configuration += 2;
            }
            if (bottomLeft.active)
            {
                configuration += 1;
            }
        }
Example #11
0
        public SquareGrid(int[,] map, float squareSize, AnimationCurve heightCurve = null, float heightMultiplier = 0, float[,] noiseMap = null, float[,] fallofMap = null, float[,] _noiseOffsetMap = null)
        {
            int   nodeCountX = map.GetLength(0);
            int   nodeCountY = map.GetLength(1);
            float mapWidth   = nodeCountX * squareSize;
            float mapHeight  = nodeCountY * squareSize;

            ControlNode[,] controlNodes = new ControlNode[nodeCountX, nodeCountY];

            for (int x = 0; x < nodeCountX; x++)
            {
                for (int y = 0; y < nodeCountY; y++)
                {
                    float heightValue = (heightCurve != null && noiseMap != null) ? (heightCurve.Evaluate((float)noiseMap[x, y]) + ((_noiseOffsetMap != null)?_noiseOffsetMap[x, y]: 0)) * (float)heightMultiplier : 0;

                    Vector3 pos = new Vector3(-mapWidth / 2 + x * squareSize + squareSize / 2, heightValue, -mapHeight / 2 + y * squareSize + squareSize / 2);
                    controlNodes[x, y] = new ControlNode(pos, map[x, y] == 1, squareSize, new int[x, y]);
                }
            }

            squares = new Square[nodeCountX - 1, nodeCountY - 1];
            for (int x = 0; x < nodeCountX - 1; x++)
            {
                for (int y = 0; y < nodeCountY - 1; y++)
                {
                    squares[x, y] = new Square(controlNodes[x, y + 1], controlNodes[x + 1, y + 1], controlNodes[x + 1, y], controlNodes[x, y]);
                }
            }
        }
    public SquareGrid(int[,] map, float squareSize) // a new grid created for use as the new generation
    {
        int   nodeCountX = map.GetLength(0);        //the x direction amount to create the grid horizonally
        int   nodeCountY = map.GetLength(1);        //the x direction amounnt to create the grid vertically
        float mapWidth   = nodeCountX * squareSize; //the size the grid will be based on the size of each square
        float mapHeight  = nodeCountY * squareSize;

        ControlNode[,] controlNodes = new ControlNode[nodeCountX, nodeCountY];// the 2d array version of the grids controle nodes

        for (int x = 0; x < nodeCountX; x++)
        {
            for (int y = 0; y < nodeCountY; y++)
            {
                Vector3 pos = new Vector3(-mapWidth / 2 + x * squareSize + squareSize / 2, -mapHeight / 2 + y * squareSize + squareSize / 2, 0); //finding the center position of the square
                controlNodes[x, y] = new ControlNode(pos, map[x, y] == 1, squareSize);                                                           // crates the series of the control/nodes for each generated square
            }
        }

        squares = new Square[nodeCountX - 1, nodeCountY - 1];

        for (int x = 0; x < nodeCountX - 1; x++)//loop to check was position in  2d array squares
        {
            for (int y = 0; y < nodeCountY - 1; y++)
            {
                squares[x, y] = new Square(controlNodes[x, y + 1], controlNodes[x + 1, y + 1], controlNodes[x + 1, y], controlNodes[x, y]);// assings the instance of the control nodes in square (which inturn assings nodes)
            }//for each of the positions in the 2d array squares
        }
    }
Example #13
0
        public SquareGrid(int[,] _map, float _squareSize)
        {
            int   _nodeCountX = _map.GetLength(0);
            int   _nodeCountY = _map.GetLength(1);
            float _mapWidth   = _nodeCountX * _squareSize;
            float _mapHeight  = _nodeCountY * _squareSize;

            ControlNode[,] controlNodes = new ControlNode[_nodeCountX, _nodeCountY];

            for (int x = 0; x < _nodeCountX; x++)
            {
                for (int y = 0; y < _nodeCountY; y++)
                {
                    Vector3 _position = new Vector3(-_mapWidth / 2 + x * _squareSize + _squareSize / 2,
                                                    0,
                                                    -_mapHeight / 2 + y * _squareSize + _squareSize / 2);
                    controlNodes[x, y] = new ControlNode(_position, _map[x, y] == 1, _squareSize);
                }
            }

            squares = new Square[_nodeCountX - 1, _nodeCountY - 1];
            for (int x = 0; x < _nodeCountX - 1; x++)
            {
                for (int y = 0; y < _nodeCountY - 1; y++)
                {
                    squares[x, y] = new Square(controlNodes[x, y + 1], controlNodes[x + 1, y + 1], controlNodes[x + 1, y], controlNodes[x, y]);
                }
            }
        }
Example #14
0
        public int configuration;//guarda els bits ctius

        public Square(ControlNode _topLeft, ControlNode _topRight, ControlNode _bottomRight, ControlNode _bottomLeft)
        {
            topLeft     = _topLeft;
            topRight    = _topRight;
            bottomRight = _bottomRight;
            bottomLeft  = _bottomLeft;

            centreTop    = topLeft.right;
            centreRight  = bottomRight.above;
            centreBottom = bottomLeft.right;
            centreLeft   = bottomLeft.above;

            if (topLeft.active)
            {
                configuration += 8; //el bists que se sumen segons el nodo actiu
            }
            if (topRight.active)
            {
                configuration += 4;
            }
            if (bottomRight.active)
            {
                configuration += 2;
            }
            if (bottomLeft.active)
            {
                configuration += 1;
            }
        }
Example #15
0
        public SquareGrid(int[,] map, float squareSize)
        {
            int   nodeCountX = map.GetLength(0);
            int   nodeCountY = map.GetLength(1);
            float mapWidth   = nodeCountX * squareSize;
            float mapHeight  = nodeCountY * squareSize;

            ControlNode[,] controlNodes = new ControlNode[nodeCountX, nodeCountY];

            for (int x = 0; x < nodeCountX; x++)
            {
                for (int y = 0; y < nodeCountY; y++)
                {
                    Vector3 pos = new Vector3(-mapWidth / 2 + x * squareSize + squareSize / 2, 0, -mapHeight / 2 + y * squareSize + squareSize / 2);
                    controlNodes[x, y] = new ControlNode(pos, map[x, y] == 1, squareSize);
                }
            }

            squares = new Square[nodeCountX - 1, nodeCountY - 1];
            for (int x = 0; x < nodeCountX - 1; x++)
            {
                for (int y = 0; y < nodeCountY - 1; y++)
                {
                    squares[x, y] = new Square(controlNodes[x, y + 1], controlNodes[x + 1, y + 1], controlNodes[x + 1, y], controlNodes[x, y]);
                }
            }
        }
Example #16
0
        public Grid(int[,] map, float squareSize)
        {
            var nodeCountX = map.GetLength(0);
            var nodeCountY = map.GetLength(1);

            Width  = nodeCountX - 1;
            Height = nodeCountY - 1;
            var mapWidth  = nodeCountX * squareSize;
            var mapHeight = nodeCountY * squareSize;

            var controlNodes = new ControlNode[nodeCountX, nodeCountY];

            For.Xy(nodeCountX, nodeCountY, (x, y) =>
            {
                var position       = new Vector3(-mapWidth / 2 + x * squareSize + squareSize / 2, 0, -mapHeight / 2 + y * squareSize + squareSize / 2);
                controlNodes[x, y] = new ControlNode(position, map[x, y] == 1, squareSize);
            });

            _squares = new Square[Width, Height];

            For.Xy(Width, Height, (x, y) =>
            {
                _squares[x, y] = new Square(
                    controlNodes[x, y + 1],
                    controlNodes[x + 1, y + 1],
                    controlNodes[x + 1, y],
                    controlNodes[x, y]
                    );
            });
        }
Example #17
0
        public int Configuration = 0; // The configuration the square is in (16 possibles in marching squares)

        public Square(ControlNode topLeft, ControlNode topRight, ControlNode bottomRight, ControlNode bottomLeft)
        {
            TopLeft     = topLeft;
            TopRight    = topRight;
            BottomLeft  = bottomLeft;
            BottomRight = bottomRight;

            CenterTop    = TopLeft.Right;
            CenterRight  = BottomRight.Above;
            CenterBottom = BottomLeft.Right;
            CenterLeft   = BottomLeft.Above;

            // Determine the configuration based on the active nodes
            if (TopLeft.Active) // 1000 = 8
            {
                Configuration += 8;
            }
            if (TopRight.Active) // 0100 = 4
            {
                Configuration += 4;
            }
            if (BottomRight.Active) // 0010 = 2
            {
                Configuration += 2;
            }
            if (BottomLeft.Active) // 0001 = 1
            {
                Configuration += 1;
            }
        }
Example #18
0
            public Square(ControlNode topLeft, ControlNode topRight, ControlNode bottomRight, ControlNode bottomLeft)
            {
                this.topLeft     = topLeft;
                this.topRight    = topRight;
                this.bottomRight = bottomRight;
                this.bottomLeft  = bottomLeft;

                centerTop    = topLeft.right;
                centerRight  = bottomRight.above;
                centerBottom = bottomLeft.right;
                centerLeft   = bottomLeft.above;

                if (topLeft.active)
                {
                    configuration += 8;
                }
                if (topRight.active)
                {
                    configuration += 4;
                }
                if (bottomRight.active)
                {
                    configuration += 2;
                }
                if (bottomLeft.active)
                {
                    configuration += 1;
                }
            }
Example #19
0
        public SquareGrid(int[,] map, float squareSize)
        {
            int   nodeCountX = map.GetLength(0);
            int   nodeCountY = map.GetLength(1);
            float mapWidth   = nodeCountX * squareSize;
            float mapHeight  = nodeCountY * squareSize;

            ControlNode[,] controlNodes = new ControlNode[nodeCountX, nodeCountY];

            Vector3 pos = Vector3.zero;

            for (int i = 0; i < nodeCountX; i++)
            {
                for (int j = 0; j < nodeCountY; j++)
                {
                    pos.x = -mapWidth / 2.0f + i * squareSize + squareSize / 2.0f;
                    pos.z = -mapHeight / 2.0f + j * squareSize + squareSize / 2.0f;
                    controlNodes[i, j] = new ControlNode(pos, map[i, j] == 1, squareSize);
                }
            }

            Squares = new Square[nodeCountX - 1, nodeCountY - 1]; // There is one less square than there are nodes
            for (int i = 0; i < nodeCountX - 1; i++)
            {
                for (int j = 0; j < nodeCountY - 1; j++)
                {
                    Squares[i, j] = new Square(controlNodes[i, j + 1], controlNodes[i + 1, j + 1], controlNodes[i + 1, j], controlNodes[i, j]);
                }
            }
        }
Example #20
0
        public Square(ControlNode _topLeft, ControlNode _topRight, ControlNode _bottomRight, ControlNode _bottomLeft)
        {
            topLeft     = _topLeft;
            topRight    = _topRight;
            bottomLeft  = _bottomLeft;
            bottomRight = _bottomRight;

            midTop    = topLeft.right;
            midRight  = bottomRight.above;
            midBottom = bottomLeft.right;
            midLeft   = bottomLeft.above;

            if (topLeft.active)
            {
                config += 8;
            }
            if (topRight.active)
            {
                config += 4;
            }
            if (bottomRight.active)
            {
                config += 2;
            }
            if (bottomLeft.active)
            {
                config += 1;
            }
        }
Example #21
0
        public SquareGrid(int[,] map)
        {
            int   nodeCols  = map.GetLength(1);
            int   nodeRows  = map.GetLength(0);
            float mapWidth  = nodeCols * SQUARE_SIZE;
            float mapHeight = nodeRows * SQUARE_SIZE;

            ControlNode[,] controlNodes = new ControlNode[nodeRows, nodeCols];
            for (int i = 0; i < nodeRows; i++)
            {
                for (int j = 0; j < nodeCols; j++)
                {
                    Vector3 position = new Vector3(-mapWidth / 2 + j * SQUARE_SIZE + SQUARE_SIZE / 2, mapHeight / 2 - i * SQUARE_SIZE - SQUARE_SIZE / 2, MESH_Z);
                    controlNodes[i, j] = new ControlNode(position, map[i, j] == 1);
                }
            }
            int rows = nodeRows - 1;
            int cols = nodeCols - 1;

            squares = new Square[rows, cols];
            for (int i = 0; i < rows; i++)
            {
                for (int j = 0; j < cols; j++)
                {
                    squares[i, j] = new Square(controlNodes[i, j], controlNodes[i, j + 1], controlNodes[i + 1, j + 1], controlNodes[i + 1, j]);
                }
            }
        }
Example #22
0
        public Square(ControlNode _topLeft, ControlNode _topRight, ControlNode _bottomRight, ControlNode _bottomLeft)
        {
            topLeft     = _topLeft;
            topRight    = _topRight;
            bottomRight = _bottomRight;
            bottomLeft  = _bottomLeft;

            centreTop    = topLeft.right;
            centreRight  = bottomRight.above;
            centreBottom = bottomLeft.right;
            centreLeft   = bottomLeft.above;

            centre = new Node(new Vector3(centreTop.position.x, centreTop.position.y, centreRight.position.z));

            if (topLeft.active)
            {
                configuration += 8;
            }
            if (topRight.active)
            {
                configuration += 4;
            }
            if (bottomRight.active)
            {
                configuration += 2;
            }
            if (bottomLeft.active)
            {
                configuration += 1;
            }
        }
Example #23
0
        public Square(ControlNode _tL, ControlNode _tR, ControlNode _bR, ControlNode _bL)
        {
            topLeft     = _tL;
            topRight    = _tR;
            bottomLeft  = _bL;
            bottomRight = _bR;

            centerTop    = topLeft.right;
            centerRight  = bottomRight.above;
            centerLeft   = bottomLeft.above;
            centerBottom = bottomLeft.right;


            if (topLeft.active)
            {
                configuration += 8;
            }
            if (topRight.active)
            {
                configuration += 4;
            }
            if (bottomRight.active)
            {
                configuration += 2;
            }
            if (bottomLeft.active)
            {
                configuration += 1;
            }
        }
Example #24
0
        public int         Configuration; // one of the 16 possible states

        public Cell(ControlNode topLeft, ControlNode topRight, ControlNode bottomLeft, ControlNode bottomRight)
        {
            this.topLeft     = topLeft;
            this.topRight    = topRight;
            this.bottomLeft  = bottomLeft;
            this.bottomRight = bottomRight;

            centerTop   = topLeft.rightNode;
            centerRight = bottomRight.topNode;
            centerLeft  = bottomLeft.topNode;
            centerDown  = bottomLeft.rightNode;

            Configuration = 0;
            if (topLeft.isActive)
            {
                Configuration += 0x1000;
            }
            if (topRight.isActive)
            {
                Configuration += 0x0100;
            }
            if (bottomRight.isActive)
            {
                Configuration += 0x0010;
            }
            if (bottomLeft.isActive)
            {
                Configuration += 0x0001;
            }
        }
Example #25
0
        public int configuration;                                           // 16 Ways to turn the nodes on/off

        // Constructor
        public Square(ControlNode _topLeft, ControlNode _topRight, ControlNode _bottomRight, ControlNode _bottomLeft)
        {
            topLeft     = _topLeft;
            topRight    = _topRight;
            bottomLeft  = _bottomLeft;
            bottomRight = _bottomRight;

            centreTop    = topLeft.right;
            centreRight  = bottomRight.above;
            centreBottom = bottomLeft.right;
            centreLeft   = bottomLeft.above;

            // Check to see if the nodes are active
            if (topLeft.active)
            {
                configuration += 8;     // 1000 = 8
            }
            if (topRight.active)
            {
                configuration += 4;     // 0100 = 4
            }
            if (bottomRight.active)
            {
                configuration += 2;     // 0010 = 2
            }
            if (bottomLeft.active)
            {
                configuration += 1;     // 0001 = 1
            }
        }
Example #26
0
        public SquareGrid(int[,] _map, float _squareSize)
        {
            int   nodeCountX = _map.GetLength(0);
            int   nodeCountY = _map.GetLength(1);
            float mapWidth   = _squareSize * nodeCountX;
            float mapHeight  = _squareSize * nodeCountY;

            ControlNode[,] controlNodes = new ControlNode[nodeCountX, nodeCountY];

            for (int x = 0; x < nodeCountX; x++)
            {
                for (int y = 0; y < nodeCountY; y++)
                {
                    Vector3 pos = new Vector3(-mapWidth / 2 + x * _squareSize + _squareSize / 2, 0, -mapHeight / 2 + y * _squareSize + _squareSize / 2);
                    controlNodes[x, y] = new ControlNode(pos, _map[x, y] == 1, _squareSize);
                }
            }

            grid = new Square[nodeCountX - 1, nodeCountY - 1];
            for (int x = 0; x < nodeCountX - 1; x++)
            {
                for (int y = 0; y < nodeCountY - 1; y++)
                {
                    grid[x, y] = new Square(controlNodes[x, y + 1], controlNodes[x + 1, y + 1], controlNodes[x + 1, y], controlNodes[x, y]);
                }
            }
        }
Example #27
0
    public SquareGrid(TileType[,] map, float squareSize)
    {
        int   nodeCountX = map.GetLength(0);
        int   nodeCountY = map.GetLength(1);
        float mapWidth   = nodeCountX * squareSize;
        float mapHeight  = nodeCountY * squareSize;

        ControlNode[,] controlNodes = new ControlNode[nodeCountX, nodeCountY];

        for (int x = 0; x < nodeCountX; x++)
        {
            for (int y = 0; y < nodeCountY; y++)
            {
                Vector3 pos = new Vector3(-mapWidth / 2 + x * squareSize + squareSize / 2, 0, -mapHeight / 2 + y * squareSize + squareSize / 2);
                controlNodes[x, y] = new ControlNode(pos, map[x, y] == TileType.Wall, squareSize);
            }
        }

        squares = new Square[nodeCountX - 1, nodeCountY - 1];   //因为不需要多出外边没有的点,所有最大值减一。
        for (int x = 0; x < nodeCountX - 1; x++)
        {
            for (int y = 0; y < nodeCountY - 1; y++)
            {
                squares[x, y] = new Square(controlNodes[x, y + 1], controlNodes[x + 1, y + 1], controlNodes[x + 1, y], controlNodes[x, y]);
                if (x == 0 || y == 0 || x == nodeCountX - 2 || y == nodeCountY - 2)
                {
                    squares[x, y].isBorder = true;
                }
            }
        }
    }
Example #28
0
    // Function to add the effect of an impact (position, force) to the mesh
    public void ImpactEffect(Vector3 position, Vector3 force)
    {
        // Get the nearest node from the impact and create a new node from it moving it of the force value divided by the impact attenuator parameter
        ControlNode node    = GetNearestNode(position);
        ControlNode newNode = new ControlNode(node.position, true);

        newNode.position += force / impactAttenuator;

        // From the first index of the node in the vertices list, replace the node by the new node and try to find the node again (to replace it)
        // Exit the loop when the node is not in the vertices list anymore
        int index = vertices.IndexOf(node.position);

        while (index != -1)
        {
            vertices[index] = newNode.position;
            index           = vertices.IndexOf(node.position);
        }

        // Replace the node by the new node in the ControlNodes list
        index = controlNodes.IndexOf(node);
        controlNodes[index] = newNode;

        // Update the vertices of the mesh (the triangles stay the same), recalculate Normals and update collider mesh as well
        objectMesh.mesh.vertices = vertices.ToArray();
        objectMesh.mesh.RecalculateNormals();
        objectMesh.GetComponent <MeshCollider>().sharedMesh = objectMesh.mesh;
    }
Example #29
0
        public Square(ControlNode _topLeft, ControlNode _topRight, ControlNode _bottomLeft, ControlNode _bottomRight)
        {
            topLeft     = _topLeft;
            topRight    = _topRight;
            bottomLeft  = _bottomLeft;
            bottomRight = _bottomRight;

            centerTop    = topLeft.right;
            centerRight  = bottomRight.above;
            centerBottom = bottomLeft.right;
            centerLeft   = bottomLeft.above;

            if (topLeft.active)
            {
                configIndex += 8;
            }
            if (topRight.active)
            {
                configIndex += 4;
            }
            if (bottomRight.active)
            {
                configIndex += 2;
            }
            if (bottomLeft.active)
            {
                configIndex += 1;
            }
        }
Example #30
0
            public Square(ControlNode _topLeft, ControlNode _topRight, ControlNode _bottomRight, ControlNode _bottomLeft)
            {
                topLeft     = _topLeft;
                topRight    = _topRight;
                bottomRight = _bottomRight;
                bottomLeft  = _bottomLeft;

                //Move in Clocwise Direction
                centreTop    = topLeft.right;
                centreRight  = bottomRight.above;
                centreBottom = bottomLeft.right;
                centreLeft   = bottomLeft.above;

                //Set up Configuration as to a Byte.
                if (topLeft.active)
                {
                    config += 8;
                }
                if (topRight.active)
                {
                    config += 4;
                }
                if (bottomRight.active)
                {
                    config += 2;
                }
                if (bottomLeft.active)
                {
                    config += 1;
                }
            }
Example #31
0
        public SquareGrid(int[,] map, float xspace, float yspace)
        {
            int   nodeCountX = map.GetLength(0);
            int   nodeCountY = map.GetLength(1);
            float mapWidth   = nodeCountX * xspace;
            float mapHeight  = nodeCountY * yspace;

            ControlNode[,] controlNodes = new ControlNode[nodeCountX, nodeCountY];

            for (int x = 0; x < nodeCountX; x++)
            {
                for (int y = 0; y < nodeCountY; y++)
                {
                    Vector3 pos = new Vector3(-mapWidth / 2.0f + x * xspace + xspace / 2.0f,
                                              0.0f,
                                              -mapHeight / 2.0f + y * yspace + yspace / 2.0f);
                    controlNodes[x, y] = new ControlNode(pos, map[x, y] == 1, yspace, xspace);
                }
            }

            squares = new Square[nodeCountX - 1, nodeCountY - 1];
            for (int x = 0; x < nodeCountX - 1; x++)
            {
                for (int y = 0; y < nodeCountY - 1; y++)
                {
                    squares[x, y] = new Square(controlNodes[x, y + 1],
                                               controlNodes[x + 1, y + 1],
                                               controlNodes[x + 1, y],
                                               controlNodes[x, y]);
                }
            }
            gateSquare = null;
        }
		public Square (ControlNode _topLeft, ControlNode _topRight, ControlNode _bottomRight, ControlNode _bottomLeft) {
			topLeft = _topLeft;
			topRight = _topRight;
			bottomRight = _bottomRight;
			bottomLeft = _bottomLeft;

			centreTop = topLeft.right;
			centreRight = bottomRight.above;
			centreBottom = bottomLeft.right;
			centreLeft = bottomLeft.above;
		}
        public ControlNode topLeft, topRight, bottomRight, bottomLeft; // Reference to all corners of the nodes

        #endregion Fields

        #region Constructors

        // Constructor
        public Square(ControlNode _topLeft, ControlNode _topRight, ControlNode _bottomRight, ControlNode _bottomLeft)
        {
            topLeft = _topLeft;
            topRight = _topRight;
            bottomLeft = _bottomLeft;
            bottomRight = _bottomRight;

            centreTop = topLeft.right;
            centreRight = bottomRight.above;
            centreBottom = bottomLeft.right;
            centreLeft = bottomLeft.above;

            // Check to see if the nodes are active
            if (topLeft.active)
            {
                configuration += 8;     // 1000 = 8
            }
            if (topRight.active)
            {
                configuration += 4;     // 0100 = 4
            }
            if (bottomRight.active)
            {
                configuration += 2;     // 0010 = 2
            }
            if (bottomLeft.active)
            {
                configuration += 1;     // 0001 = 1
            }
        }
        public Square(ControlNode topLeft, ControlNode topRight, ControlNode bottomRight, ControlNode bottomLeft)
        {
            this.topLeft = topLeft;
            this.topRight = topRight;
            this.bottomRight = bottomRight;
            this.bottomLeft = bottomLeft;

            centreTop = topLeft.right;
            centreRight = bottomRight.above;
            centreLeft = bottomLeft.above;
            centreBottom = bottomLeft.right;

            if (topLeft.active)
            {
                configuration += 8;
            }
            if (topRight.active)
            {
                configuration += 4;
            }
            if (bottomRight.active)
            {
                configuration += 2;
            }
            if (bottomLeft.active)
            {
                configuration += 1;
            }
        }
Example #35
0
        public SquareGrid(int[,] map, float xspace, float yspace)
        {
            int nodeCountX = map.GetLength(0);
            int nodeCountY = map.GetLength (1);
            float mapWidth = nodeCountX * xspace;
            float mapHeight = nodeCountY * yspace;

            ControlNode[,] controlNodes = new ControlNode[nodeCountX,nodeCountY];

            for (int x = 0; x < nodeCountX; x ++) {
                for (int y = 0; y < nodeCountY; y ++) {
                    Vector3 pos = new Vector3(-mapWidth/2.0f + x * xspace + xspace/2.0f,
                                              0.0f,
                                              -mapHeight/2.0f + y * yspace + yspace/2.0f);
                    controlNodes[x,y] = new ControlNode(pos, map[x,y] == 1, yspace, xspace);
                }
            }

            squares = new Square[nodeCountX -1,nodeCountY -1];
            for (int x = 0; x < nodeCountX-1; x ++) {
                for (int y = 0; y < nodeCountY-1; y ++) {
                    squares[x,y] = new Square(controlNodes[x,y+1],
                                              controlNodes[x+1,y+1],
                                              controlNodes[x+1,y],
                                              controlNodes[x,y]);
                }
            }
            gateSquare = null;
        }
Example #36
0
    private void _generateMesh(TerrainData data)
    {
        Vector3 startPosition = transform.position - new Vector3(m_data.Width, 0, m_data.Height) * m_boxSize * 0.5f;
        Vector3 step = new Vector3(m_boxSize, 0, m_boxSize);

        int width = data.Width;
        int height = data.Height;
        
        ControlNode[,] nodes = new ControlNode[width,height];

        for (int y = 0; y < height; y++)
        {
            for (int x = 0; x < width; x++)
            {
                Vector3 offset = startPosition + new Vector3(step.x * x, 0.0f, step.z * y);
                nodes[x, y] = new ControlNode(offset, data.GetBlock(new Point(x, y)), m_boxSize);
            }
        }

        LinkedList<Square> squares = new LinkedList<Square>();

        for (int y = 0; y < height - 1; y++)
        {
            for (int x = 0; x < width - 1; x++)
            {
                ControlNode bottomLeft = nodes[x, y];
                ControlNode bottomRight = nodes[x + 1, y];
                ControlNode topLeft = nodes[x, y + 1];
                ControlNode topRight = nodes[x + 1, y + 1];

                Square square = new Square(topLeft, topRight, bottomLeft, bottomRight);
                squares.AddLast(square);
            }
        }

        LinkedList<Vector3> verticies = new LinkedList<Vector3>();
        LinkedList<int> indicies = new LinkedList<int>();

        foreach (Square square in squares)
        {
            _buildSquare(square, verticies, indicies);
        } 

        Mesh mesh = new Mesh();
        GetComponent<MeshFilter>().mesh = mesh;

        mesh.vertices = verticies.ToArray();
        mesh.triangles = indicies.ToArray();
        mesh.RecalculateNormals();
    }
Example #37
0
        public Square(ControlNode _topLeft, ControlNode _topRight, ControlNode _bottomRight, ControlNode _bottomLeft)
        {
            TopLeftNode = _topLeft;
            TopRightNode = _topRight;
            BottomRightNode = _bottomRight;
            BottomLeftNode = _bottomLeft;

            CenterTopNode = TopLeftNode.Right;
            CenterRightNode = BottomRightNode.Above;
            CenterBottomNode = BottomLeftNode.Right;
            CenterLeftNode = BottomLeftNode.Above;

            if (TopLeftNode.Active)
            {
                Configuration += 8;
            }
            if (TopRightNode.Active)
            {
                Configuration += 4;
            }
            if (BottomRightNode.Active)
            {
                Configuration += 2;
            }
            if (BottomLeftNode.Active)
            {
                Configuration += 1;
            }
        }
Example #38
0
        public Square(ControlNode topLeft, ControlNode topRight, ControlNode bottomRight, ControlNode bottomLeft)
        {
            this.topLeft = topLeft;
            this.topRight = topRight;
            this.bottomRight = bottomRight;
            this.bottomLeft = bottomLeft;

            centerTop = topLeft.right;
            centerRight = bottomRight.above;
            centerBottom = bottomLeft.right;
            centerLeft = bottomLeft.above;

            if (topLeft.active)
                configuration += 8;
            if (topRight.active)
                configuration += 4;
            if (bottomRight.active)
                configuration += 2;
            if (bottomLeft.active)
                configuration += 1;
        }
Example #39
0
        public SquareGrid(int[,] map, float squareSize)
        {
            int nodeCountX = map.GetLength(0);
            int nodeCountY = map.GetLength(1);
            float mapWidth = nodeCountX * squareSize;
            float mapHeight = nodeCountY * squareSize;

            ControlNode[,] controlNodes = new ControlNode[nodeCountX, nodeCountY];

            for (int x = 0; x < nodeCountX; x++) {
                for (int y = 0; y < nodeCountY; y++) {

                }
            }
        }
Example #40
0
		public int configuration; //16 possible configuaration of a square , control nodes 

		public Square (ControlNode _topLeft, ControlNode _topRight, ControlNode _bottomRight, ControlNode _bottomLeft) { // constructor
			topLeft = _topLeft;
			topRight = _topRight;
			bottomRight = _bottomRight;
			bottomLeft = _bottomLeft;

			centreTop = topLeft.right;
			centreRight = bottomRight.above;
			centreBottom = bottomLeft.right;
			centreLeft = bottomLeft.above;

			//Nodes that are active generate number
			if (topLeft.active)
				configuration += 8;
			if (topRight.active)
				configuration += 4;
			if (bottomRight.active)
				configuration += 2;
			if (bottomLeft.active)
				configuration += 1;
		}
Example #41
0
		public Square[,] squares; //holds 2D arrays of squares

		public SquareGrid(int[,] map, float squareSize) { //constructor, gets map from mapGen
			int nodeCountX = map.GetLength(0);
			int nodeCountY = map.GetLength(1);
			float mapWidth = nodeCountX * squareSize;
			float mapHeight = nodeCountY * squareSize;

			ControlNode[,] controlNodes = new ControlNode[nodeCountX,nodeCountY]; //2D array of control nodes

			for (int x = 0; x < nodeCountX; x ++) {
				for (int y = 0; y < nodeCountY; y ++) {
					Vector3 pos = new Vector3(-mapWidth/2 + x * squareSize + squareSize/2, 0, -mapHeight/2 + y * squareSize + squareSize/2); //Calculate positions of control node
					controlNodes[x,y] = new ControlNode(pos,map[x,y] == 1, squareSize); // map is active if = 1 , // grid of control nodes
				}
			}

			squares = new Square[nodeCountX -1,nodeCountY -1]; //creation of grid of squares from control nodes
			for (int x = 0; x < nodeCountX-1; x ++) {
				for (int y = 0; y < nodeCountY-1; y ++) {
					squares[x,y] = new Square(controlNodes[x,y+1] /*topleft*/ , controlNodes[x+1,y+1] /*topright*/ , controlNodes[x+1,y] /*bottomright*/ , controlNodes[x,y] /*bottomleft*/ ); //each square equal to new square with control node attributes from array
				}
			}
		}
Example #42
0
        public SquareGrid(int[,] map, float squareSize)
        {
            int nodeCountX = map.GetLength(0);
            int nodeCountY = map.GetLength(1);
            float mapWidth = nodeCountX * squareSize;
            float mapHeight = nodeCountY * squareSize;

            ControlNode[,] controlNodes = new ControlNode[nodeCountX,nodeCountY];

            for (int x = 0; x < nodeCountX; ++x)
            {
                for (int y = 0; y < nodeCountY; ++y)
                {
                    Vector3 p = new Vector3(-mapWidth / 2.0f + x * squareSize + squareSize / 2.0f, 0.0f, -mapHeight / 2.0f + y * squareSize + squareSize / 2.0f);
                    controlNodes[x,y] = new ControlNode(p, map[x,y] != 0, squareSize);
                }
            }

            squares = new Square[nodeCountX - 1, nodeCountY - 1];

            for (int x = 0; x < nodeCountX-1; ++x)
            {
                for (int y = 0; y < nodeCountY-1; ++y)
                {
                    squares[x,y] = new Square(
                        controlNodes[x,y+1],
                        controlNodes[x+1,y+1],
                        controlNodes[x+1,y],
                        controlNodes[x,y]);
                }
            }
        }
Example #43
0
        public Square(ControlNode tl, ControlNode tr, ControlNode br, ControlNode bl)
        {
            topLeft = tl;
            topRight = tr;
            bottomRight = br;
            bottomLeft = bl;

            centerTop = topLeft.right;
            centerRight = bottomRight.above;
            centerBottom = bottomLeft.right;
            centerLeft = bottomLeft.above;

            if (topLeft.active) configuration |= 0x0008;
            if (topRight.active) configuration |= 0x0004;
            if (bottomRight.active) configuration |= 0x0002;
            if (bottomLeft.active) configuration |= 0x0001;
        }
		public Carre (ControlNode _hautGauche, ControlNode _hautDroit, ControlNode _basDroit, ControlNode _basGauche) {
			hautGauche = _hautGauche;
			hautDroit = _hautDroit;
			basDroit = _basDroit;
			basGauche = _basGauche;

			centreHaut = hautGauche.droite;
			centreDroit = basDroit.dessus;
			centreBas = basGauche.droite;
			centreGauche = basGauche.dessus;

            /* Code binaire pour déterminer les configurations */
			if (hautGauche.active)
				configuration += 8;
			if (hautDroit.active)
				configuration += 4;
			if (basDroit.active)
				configuration += 2;
			if (basGauche.active)
				configuration += 1;
		}
Example #45
0
        public SquareGrid(int[,] map, float squareSize)
        {
            int nodeCountX = map.GetLength(0);
            int nodeCountY = map.GetLength(1);

            ControlNode[,] controlNodes = new ControlNode[nodeCountX,nodeCountY];

            for (int x = 0; x < nodeCountX; x ++) {
                for (int z = 0; z < nodeCountY; z ++) {

                    Vector3 pos = new Vector3(x * squareSize + squareSize/2 -0.5f , terrainHeight, z * squareSize + squareSize/2 -0.5f);
                    controlNodes[x,z] = new ControlNode(pos,map[x,z] == 1, squareSize);
                }
            }

            squares = new Square[nodeCountX -1,nodeCountY -1];
            for (int x = 0; x < nodeCountX-1; x ++) {
                for (int z = 0; z < nodeCountY-1; z ++) {
                    squares[x,z] = new Square(controlNodes[x,z+1], controlNodes[x+1,z+1], controlNodes[x+1,z], controlNodes[x,z]);
                }
            }
        }
Example #46
0
        public Square(ControlNode topLeft, ControlNode topRight, ControlNode bottomRight, ControlNode bottomLeft)
        {
            this.topLeft = topLeft;
            this.topRight = topRight;
            this.bottomLeft = bottomLeft;
            this.bottomRight = bottomRight;

            this.centreTop = topLeft.rightNode;
            this.centreRight = bottomRight.topNode;
            this.centreBottom = bottomLeft.rightNode;
            this.centreLeft = bottomLeft.topNode;

            configuration = 0;
            if (topLeft.active)
                configuration += 8;
            if (topRight.active)
                configuration += 4;
            if (bottomRight.active)
                configuration += 2;
            if (bottomLeft.active)
                configuration += 1;
        }
Example #47
0
        // Constructor
        public Square(ControlNode _topLeft, ControlNode _topRight,
					  ControlNode _bottomRight, ControlNode _bottomLeft)
        {
            topLeft = _topLeft;
            topRight = _topRight;
            bottomRight = _bottomRight;
            bottomLeft = _bottomLeft;

            centerTop = topLeft.right;
            centerRight = bottomRight.above;
            centerBottom = bottomLeft.right;
            centerLeft = bottomLeft.above;

            if (topLeft.active) // 4th binary bit = 1000 = 8 (in base 10)
                configuration += 8;
            if (topRight.active) // 0100 = 4
                configuration += 4;
            if (bottomRight.active) // 0010 = 2
                configuration += 2;
            if (bottomLeft.active) // 0010 = 1
                configuration += 1;
        }
Example #48
0
        // Constructor
        public SquareGrid(int[,] map, float squareSize)
        {
            // map provided by MapGenerator class
            int nodeCountX = map.GetLength(0);
            int nodeCountY = map.GetLength(1);
            float mapWidth = nodeCountX * squareSize;
            float mapHeight = nodeCountY * squareSize;

            ControlNode[,] controlNodes = new ControlNode[nodeCountX,nodeCountY];

            for (int x = 0; x < nodeCountX; x++) {
                for (int y = 0; y < nodeCountY; y++) {
                    Vector3 pos = new Vector3(-mapWidth/2 + x * squareSize + squareSize/2,
                        0, -mapHeight/2 + y * squareSize + squareSize/2);
                    controlNodes[x,y] = new ControlNode(pos,map[x,y] == 1, squareSize);
                }
            }

            squares = new Square[nodeCountX-1,nodeCountY-1];
            for (int x = 0; x < nodeCountX-1; x++) {
                for (int y = 0; y < nodeCountY-1; y++) {
                    squares[x,y] = new Square(controlNodes[x,y+1], // topLeft
                                              controlNodes[x+1,y+1], // topRight
                                              controlNodes[x+1,y], // bottomRight
                                              controlNodes[x,y]); // bottomLeft
                }
            }
        }
        //Defines a new square for marching squares, consisting of the control nodes and nodes
        public Square(ControlNode _topLeft, ControlNode _topRight, ControlNode _bottomRight, ControlNode _bottomLeft)
        {
            topLeft = _topLeft;
            topRight = _topRight;
            bottomRight = _bottomRight;
            bottomLeft = _bottomLeft;

            centerTop = topLeft.right;
            centerRight = bottomRight.above;
            centerBottom = bottomLeft.right;
            centerLeft = bottomLeft.above;

            if (topLeft.active) //First node, starting top left and then going clockwise
                configuration += 8;
            if (topRight.active) //Second node
                configuration += 4;
            if (bottomRight.active) //Third node
                configuration += 2;
            if (bottomLeft.active) //Fourth node
                configuration += 1;
        }
Example #50
0
 public Square(ControlNode topLeft, ControlNode topRight, ControlNode bottomLeft, ControlNode bottomRight)
 {
     m_topLeft = topLeft;
     m_topRight = topRight;
     m_bottomLeft = bottomLeft;
     m_bottomRight = bottomRight;
 }
		public Grille(int[,] map, float tailleCarre) {
			int nbNodeX = map.GetLength(0);
			int nbNodeY = map.GetLength(1);
			float largeurMap = nbNodeX * tailleCarre;
			float hauteurMap = nbNodeY * tailleCarre;

            /* On met sur la grille l'ensemble des nodes de controles*/
            ControlNode[,] controlNodes = new ControlNode[nbNodeX, nbNodeY];
			for (int x = 0; x < nbNodeX; x ++) {
				for (int y = 0; y < nbNodeY; y ++) {
					Vector3 pos = new Vector3(-largeurMap/2 + x * tailleCarre + tailleCarre/2, 0, -hauteurMap/2 + y * tailleCarre + tailleCarre/2);
					controlNodes[x,y] = new ControlNode(pos,map[x,y] == 1, tailleCarre);
				}
			}
            /* Puis les carrés contenant les nodes simple */
			carres = new Carre[nbNodeX -1,nbNodeY -1];
			for (int x = 0; x < nbNodeX-1; x ++) {
				for (int y = 0; y < nbNodeY-1; y ++) {
					carres[x,y] = new Carre(controlNodes[x,y+1], controlNodes[x+1,y+1], controlNodes[x+1,y], controlNodes[x,y]);
				}
			}

		}
Example #52
0
 private void BuildControlNodes(float[,] map)
 {
     ControlNodes = new ControlNode[MapSize.x, MapSize.y];
     for (int y = 0; y < MapSize.y; y++)
     {
         for (int x = 0; x < MapSize.x; x++)
         {
             Vector2i p = new Vector2i(x, y);
             ControlNodes[x, y] =
                 new ControlNode(
                     p,
                     map,
                     p.ToVector2() - WorldSize * 0.5f + Vector2.one * 0.5f,
                     SquareSize);
         }
     }
 }
	public void SetNext(ControlNode[] nodes) {
		nextNodes = nodes;
	}
        public Cube(
            ControlNode _topLeftFront, 
            ControlNode _topRightFront, 
            ControlNode _bottomRightFront, 
            ControlNode _bottomLeftFront, 
            ControlNode _topLeftBack, 
            ControlNode _topRightBack, 
            ControlNode _bottomRightBack, 
            ControlNode _bottomLeftBack)
        {
            topLeftFront      = _topLeftFront;
            topRightFront     = _topRightFront;
            bottomRightFront  = _bottomRightFront;
            bottomLeftFront   = _bottomLeftFront;
            topLeftBack       = _topLeftBack;
            topRightBack      = _topRightBack;
            bottomRightBack   = _bottomRightBack;
            bottomLeftBack    = _bottomLeftBack;

            centerTopFront    = topRightFront.left;
            centerRightFront  = bottomRightFront.above;
            centerBottomFront = bottomRightFront.left;
            centerLeftFront   = bottomLeftFront.above;
            topLeftCenter     = topLeftBack.front;
            topRightCenter    = topRightBack.front;
            bottomRightCenter = bottomRightBack.front;
            bottomLeftCenter  = bottomLeftBack.front;
            centerTopBack     = topRightBack.left;
            centerRightBack   = bottomRightBack.above;
            centerBottomBack  = bottomRightBack.left;
            centerLeftBack    = bottomLeftBack.above;

            if (topLeftFront.active)
                configuration += 1;
            if (topLeftBack.active)
                configuration += 2;
            if (topRightFront.active)
                configuration += 4;
            if (topRightBack.active)
                configuration += 8;
            if (bottomRightFront.active)
                configuration += 16;
            if (bottomRightBack.active)
                configuration += 32;
            if (bottomLeftFront.active)
                configuration += 64;
            if (bottomLeftBack.active)
                configuration += 128;
        }
Example #55
0
        public Square( ControlNode _topLeft, ControlNode _topRight, ControlNode _bottomRight, ControlNode _bottomLeft )
        {
            topLeft = _topLeft;
            topRight = _topRight;
            bottomRight = _bottomRight;
            bottomLeft = _bottomLeft;

            centreTop = topLeft.right;
            centreRight = bottomRight.above;
            centreBottom = bottomLeft.right;
            centreLeft = bottomLeft.above;

            //Lesson 3
            if( topLeft.active )
                configuration += 8;
            if( topRight.active )
                configuration += 4;
            if( bottomLeft.active )
                configuration += 1;
            if( bottomRight.active )
                configuration += 2;
        }
        public void rotateRightHoriz()
        {
            ControlNode tempTLF = topLeftFront,
            tempBLF = bottomLeftFront;

            Node tempCLF = centerLeftFront,
            tempTLC = topLeftCenter,
            tempBLC = bottomLeftCenter;

            topLeftFront = topRightFront;
            centerLeftFront = centerRightFront;
            bottomLeftFront = bottomRightFront;
            topLeftCenter = centerTopFront;
            bottomLeftCenter = centerBottomFront;

            topRightFront = topRightBack;
            centerRightFront = centerRightBack;
            bottomRightFront = bottomRightBack;
            centerTopFront = topRightCenter;
            centerBottomFront = bottomRightCenter;

            topRightBack = topLeftBack;
            centerRightBack = centerLeftBack;
            bottomRightBack = bottomLeftBack;
            topRightCenter = centerTopBack;
            bottomRightCenter = centerBottomBack;

            topLeftBack = tempTLF;
            centerLeftBack = tempCLF;
            bottomLeftBack = tempBLF;
            centerTopBack = tempTLC;
            centerBottomBack = tempBLC;
        }
Example #57
0
            public Square(
                ControlNode bottomLeft,
                ControlNode topLeft,
                ControlNode topRight,
                ControlNode bottomRight)
            {
                SquareCenter = (bottomLeft.Position + topRight.Position) * 0.5f;
                BottomLeft = bottomLeft;
                TopLeft = topLeft;
                TopRight = topRight;
                BottomRight = bottomRight;

                CenterLeft = BottomLeft.Up;
                CenterRight = BottomRight.Up;
                CenterTop = TopLeft.Right;
                CenterBottom = BottomLeft.Right;
            }
        public void rotateRightVert()
        {
            ControlNode tempBLF = bottomLeftFront,
            tempBLB = bottomLeftBack;

            Node tempBLC = bottomLeftCenter,
            tempCLF = centerLeftFront,
            tempCLB = centerLeftBack;

            bottomLeftFront = bottomRightFront;
            bottomLeftCenter = bottomRightCenter;
            bottomLeftBack = bottomRightBack;
            centerLeftFront = centerBottomFront;
            centerLeftBack = centerBottomBack;

            bottomRightFront = topRightFront;
            bottomRightCenter = topRightCenter;
            bottomRightBack = topRightBack;
            centerBottomFront = centerRightFront;
            centerBottomBack = centerRightBack;

            topRightFront = topLeftFront;
            topRightCenter = topLeftCenter;
            topRightBack = topLeftBack;
            centerRightFront = centerTopFront;
            centerRightBack = centerTopBack;

            topLeftFront = tempBLF;
            topLeftCenter = tempBLC;
            topLeftBack = tempBLB;
            centerTopFront = tempCLF;
            centerTopBack = tempCLB;
        }
Example #59
0
		public Square (ControlNode _topLeft, ControlNode _topRight, ControlNode _bottomRight, ControlNode _bottomLeft){
			topLeft = _topLeft;
			topRight = _topRight;
			bottomRight = _bottomRight;
			bottomLeft = _bottomLeft;

			centerTop = topLeft.right;
			centerRight = bottomRight.above;
			centerBottom = bottomLeft.right;
			centerLeft = bottomLeft.above;

			if(topLeft.active)
				config += 8;
			if(topRight.active)
				config += 4;
			if(bottomRight.active)
				config += 2;
			if(bottomLeft.active)
				config +=1;
		}
        public SquareGrid(int[,,] map, float squareSize)
        {
            int nodeCountX = map.GetLength(0);
            int nodeCountY = map.GetLength(1);
            int nodeCountZ = map.GetLength(2);
            float mapWidth = nodeCountX * squareSize;
            float mapHeight = nodeCountY * squareSize;
            float mapDepth = nodeCountZ * squareSize;

            ControlNode[,,] controlNodes = new ControlNode[nodeCountX, nodeCountY, nodeCountZ];

            for (int x = 0; x < nodeCountX; x++)
            {
                for (int y = 0; y < nodeCountY; y++)
                {
                    for (int z = 0; z < nodeCountZ; z++)
                    {
                        Vector3 pos = new Vector3(-mapWidth / 2 + x * squareSize + squareSize / 2, -mapDepth / 2 + z * squareSize + squareSize / 2, -mapHeight / 2 + y * squareSize + squareSize / 2);
                        controlNodes[x, y, z] = new ControlNode(pos, map[x, y, z] == 1, squareSize);
                    }
                }
            }

            cubes = new Cube[nodeCountX - 1, nodeCountY - 1, nodeCountZ - 1];
            for (int x = 0; x < nodeCountX - 1; x++)
            {
                for (int y = 0; y < nodeCountY - 1; y++)
                {
                    for (int z = 0; z < nodeCountZ - 1; z++)
                    {
                        cubes[x, y, z] = new Cube(
                            controlNodes[x  , y+1, z+1],
                            controlNodes[x+1, y+1, z+1],
                            controlNodes[x+1, y  , z+1],
                            controlNodes[x  , y  , z+1],
                            controlNodes[x  , y+1, z  ],
                            controlNodes[x+1, y+1, z  ],
                            controlNodes[x+1, y  , z  ],
                            controlNodes[x  , y  , z  ]);
                    }
                }
            }
        }