Ejemplo n.º 1
0
 private void ReJoinChild(byte childIndex, PatchNeighborDirection direction)
 {
     Children[childIndex].Neighbors[(int)direction].Node.Neighbors[(int)Children[childIndex].Neighbors[(int)direction].Direction].Node    = this;
     Children[childIndex].Neighbors[(int)direction].Node.Neighbors[(int)Children[childIndex].Neighbors[(int)direction].Direction].isFixed = false;
     Children[childIndex].Neighbors[(int)direction].Node.GapFixMask |= (byte)(1 << (int)Children[childIndex].Neighbors[(int)direction].Direction);
     Children[childIndex].Neighbors[(int)direction].Node.NeedsReedge = true;
 }
Ejemplo n.º 2
0
    void CalculateGapError(PatchNeighborDirection direction, PatchNeighborDirection neighborDirection, ref PatchTree neighborNode, out short add)
    {
        var node   = Neighbors[(int)neighborDirection].Node;
        var parent = node.Parent;

        bool trueParent = (parent != null && Parent != null && parent == Parent);

        add = (short)(trueParent && node.Neighbors[(int)direction].Node == neighborNode ? 0 : PatchSettings.VerticesPerSide >> 1);
    }
Ejemplo n.º 3
0
 private void ReLinkChild(byte childIndex, PatchNeighborDirection direction)
 {
     Children[childIndex].SetNeighbor(direction, Neighbors[(int)direction].Node, Neighbors[(int)direction].Direction);
 }
Ejemplo n.º 4
0
    void PositionThereIncrement(ref short idxTR, ref short idxBL, ref short idxTL, ref short idxBR, out short positionThere, out short incrementThere, PatchNeighborDirection direction)
    {
        positionThere  = 0;
        incrementThere = 0;

        switch (Neighbors[(int)direction].Direction)
        {
        case PatchNeighborDirection.Top:
        {
            positionThere  = idxTR;
            incrementThere = -1;
            break;
        }

        case PatchNeighborDirection.Bottom:
        {
            positionThere  = idxBL;
            incrementThere = 1;
            break;
        }

        case PatchNeighborDirection.Left:
        {
            positionThere  = idxTL;
            incrementThere = (short)PatchSettings.VerticesPerSide;
            break;
        }

        case PatchNeighborDirection.Right:
        {
            positionThere  = idxBR;
            incrementThere = (short)-PatchSettings.VerticesPerSide;
            break;
        }

        default:
            break;
        }
    }
Ejemplo n.º 5
0
    public void SetNeighbor(PatchNeighborDirection direction, PatchTree tree, PatchNeighborDirection directionFromThere)
    {
        if (tree.HasChildren)
        {
            //the other node has children, which means this node was in coarse resolution,
            //so find correct child to link to...
            //need to find which two of the 4 children
            //of the other node that links to the parent of this node or to this node itself
            //then, decide which of the two children is closer to this node
            //and update the correct (nearest) child to link to this node

            PatchTree correctNode = null;

            float dist = 0;

            byte neighDirection = 0;

            //for each child of that node...
            for (byte i = 0; i < 4; i++)
            {
                var child = tree.Children[i];

                //for each direction of that child of that node...
                for (byte j = 0; j < 4; j++)
                {
                    //check if that child links from that direction to our parent
                    if (child.Neighbors[j].Node.Equals(Parent))
                    {
                        if (correctNode == null)
                        {
                            //as there is no best correct child yet,
                            //temporarily selects that child as the correct
                            correctNode    = child;
                            neighDirection = j;
                            dist           = VectorHelper.QuickDistance(child.Middle, Middle);
                            break;
                        }
                        else
                        {
                            //check if this child is closer than
                            //the currently selected as the closer child
                            if (VectorHelper.QuickDistance(child.Middle, Middle) < dist)
                            {
                                correctNode    = child;
                                neighDirection = j;

                                //as we can have only two childs
                                //pointing to our own parent, and the other child has been scanned already,
                                //we can safely bail out of the outer loop and stop searching
                                i = 4;
                                break;
                            }
                        }
                    }
                    else if (child.Neighbors[j].Node == this)
                    {
                        //that child relinked to this node first
                        //which means both nodes are at same level
                        //so just get it and bail out
                        correctNode    = child;
                        neighDirection = j;

                        //link back to that node
                        Neighbors[(int)direction].Node      = correctNode;
                        Neighbors[(int)direction].Direction = (PatchNeighborDirection)neighDirection;

                        //update edges of this node
                        NeedsReedge = true;

                        //bail out
                        return;
                    }
                }
            }

            if (correctNode != null)
            {
                //link to that node
                Neighbors[(int)direction].Node      = correctNode;
                Neighbors[(int)direction].Direction = (PatchNeighborDirection)neighDirection;

                //link that node back to this node
                correctNode.Neighbors[neighDirection].Node      = this;
                correctNode.Neighbors[neighDirection].Direction = direction;

                //update edges and gaps
                NeedsReedge             = true;
                correctNode.NeedsReedge = true;

                //the other node was discarding resolution
                //because this node was at coarse level
                //now that both are at same level,
                //lets force the other node to use full mesh at the edge that links to this node
                correctNode.GapFixMask |= (byte)(1 << neighDirection);
                correctNode.Neighbors[neighDirection].isFixed = false;
            }
        }
        else
        {
            //the other node has no children...
            //so, the other node is at a coarse level
            //or at same level (a brother node);
            //link directly to that node
            Neighbors[(int)direction].Node             = tree;
            Neighbors[(int)direction].Direction        = directionFromThere;
            Neighbors[(int)direction].Node.NeedsReedge = true;

            //only this node needs to update edges and fix gaps
            NeedsReedge = true;
            GapFixMask |= (byte)(1 << (int)direction);
            Neighbors[(int)direction].isFixed = false;

            //the other node stays linked to the node it is already linked to.
        }
    }