コード例 #1
0
    public void DirtyZ()
    {
        SurfaceTextureUpdate = true;

        // Invalidate all normals in this patch
        UInt32 i;

        for (i = 0; i < 9; i++)
        {
            NormalsInvalid[i] = true;
        }

        // Invalidate normals in this and neighbouring patches
        for (i = 0; i < 8; i++)
        {
            DirectionIndex dir = (DirectionIndex)i;
            if (GetNeighbourPatch(dir) != null)
            {
                GetNeighbourPatch(dir).NormalsInvalid[(int)World.DirOpposite[i]] = true;
                GetNeighbourPatch(dir).SetDirty();
                if (i < 4)
                {
                    GetNeighbourPatch(dir).NormalsInvalid[(int)World.DirAdjacent[(int)World.DirOpposite[i], 0]] = true;
                    GetNeighbourPatch(dir).NormalsInvalid[(int)World.DirAdjacent[(int)World.DirOpposite[i], 1]] = true;
                }
            }
        }

        SetDirty();
        LastUpdateTime = Time.time;
    }
コード例 #2
0
 public void SetNeighbourPatch(DirectionIndex direction, SurfacePatch neighbor)
 {
     NeighborPatches[(UInt32)direction] = neighbor;
     NormalsInvalid[(UInt32)direction]  = true;
     if ((UInt32)direction < 4)
     {
         NormalsInvalid[(UInt32)World.DirAdjacent[(UInt32)direction, 0]] = true;
         NormalsInvalid[(UInt32)World.DirAdjacent[(UInt32)direction, 1]] = true;
     }
 }
コード例 #3
0
    public void ConnectNeighbour(SurfacePatch neighbour, DirectionIndex direction)
    {
        if (neighbour == null)
        {
            // TODO: Should I throw an exception?
            return;
        }

        NormalsInvalid[(int)direction] = true;
        neighbour.NormalsInvalid[(int)World.DirOpposite[(int)direction]] = true;

        SetNeighbourPatch(direction, neighbour);
        neighbour.SetNeighbourPatch(World.DirOpposite[(int)direction], this);

        switch (direction)
        {
        case DirectionIndex.East:
            ConnectedEdge           |= EdgeType.East;
            neighbour.ConnectedEdge |= EdgeType.West;
            break;

        case DirectionIndex.North:
            ConnectedEdge           |= EdgeType.North;
            neighbour.ConnectedEdge |= EdgeType.South;
            break;

        case DirectionIndex.West:
            ConnectedEdge           |= EdgeType.West;
            neighbour.ConnectedEdge |= EdgeType.East;
            break;

        case DirectionIndex.South:
            ConnectedEdge           |= EdgeType.South;
            neighbour.ConnectedEdge |= EdgeType.North;
            break;
        }
    }
コード例 #4
0
ファイル: Region.cs プロジェクト: Siccity/UnitySL
 public void ConnectNeighbour(Region neighbour, DirectionIndex direction)
 {
     Land.ConnectNeighbour(neighbour.Land, direction);
 }
コード例 #5
0
    public void ConnectNeighbour(Surface neighbour, DirectionIndex direction)
    {
        UInt32       i;
        SurfacePatch patch;
        SurfacePatch neighbor_patch;

        Neighbours[(int)direction] = neighbour;
        neighbour.Neighbours[(int)World.DirOpposite[(int)direction]] = this;

        // Connect patches
        DirectionIndex oppositeDir = World.DirOpposite[(int)direction];

        switch (direction)
        {
        case DirectionIndex.NorthEast:
            patch          = GetPatch(PatchesPerEdge - 1, PatchesPerEdge - 1);
            neighbor_patch = neighbour.GetPatch(0, 0);

            patch.ConnectNeighbour(neighbor_patch, direction);
            neighbor_patch.ConnectNeighbour(patch, oppositeDir);

            patch.UpdateNorthEdge();     // Only update one of north or east.
            patch.DirtyZ();
            break;

        case DirectionIndex.NorthWest:
            patch          = GetPatch(0, PatchesPerEdge - 1);
            neighbor_patch = neighbour.GetPatch(PatchesPerEdge - 1, 0);

            patch.ConnectNeighbour(neighbor_patch, direction);
            neighbor_patch.ConnectNeighbour(patch, oppositeDir);
            break;

        case DirectionIndex.SouthWest:
            patch          = GetPatch(0, 0);
            neighbor_patch = neighbour.GetPatch(PatchesPerEdge - 1, PatchesPerEdge - 1);

            patch.ConnectNeighbour(neighbor_patch, direction);
            neighbor_patch.ConnectNeighbour(patch, oppositeDir);

            neighbor_patch.UpdateNorthEdge();     // Only update one of north or east.
            neighbor_patch.DirtyZ();
            break;

        case DirectionIndex.SouthEast:
            patch          = GetPatch(PatchesPerEdge - 1, 0);
            neighbor_patch = neighbour.GetPatch(0, PatchesPerEdge - 1);

            patch.ConnectNeighbour(neighbor_patch, direction);
            neighbor_patch.ConnectNeighbour(patch, oppositeDir);
            break;

        case DirectionIndex.East:
            // Do east/west connections, first
            for (i = 0; i < (int)PatchesPerEdge; i++)
            {
                patch          = GetPatch(PatchesPerEdge - 1, i);
                neighbor_patch = neighbour.GetPatch(0, i);

                patch.ConnectNeighbour(neighbor_patch, direction);
                neighbor_patch.ConnectNeighbour(patch, oppositeDir);

                patch.UpdateEastEdge();
                patch.DirtyZ();
            }

            // Now do northeast/southwest connections
            for (i = 0; i < (int)PatchesPerEdge - 1; i++)
            {
                patch          = GetPatch(PatchesPerEdge - 1, i);
                neighbor_patch = neighbour.GetPatch(0, i + 1);

                patch.ConnectNeighbour(neighbor_patch, DirectionIndex.NorthEast);
                neighbor_patch.ConnectNeighbour(patch, DirectionIndex.SouthWest);
            }
            // Now do southeast/northwest connections
            for (i = 1; i < (int)PatchesPerEdge; i++)
            {
                patch          = GetPatch(PatchesPerEdge - 1, i);
                neighbor_patch = neighbour.GetPatch(0, i - 1);

                patch.ConnectNeighbour(neighbor_patch, DirectionIndex.SouthEast);
                neighbor_patch.ConnectNeighbour(patch, DirectionIndex.NorthWest);
            }
            break;

        case DirectionIndex.North:
            // Do north/south connections, first
            for (i = 0; i < (int)PatchesPerEdge; i++)
            {
                patch          = GetPatch(i, PatchesPerEdge - 1);
                neighbor_patch = neighbour.GetPatch(i, 0);

                patch.ConnectNeighbour(neighbor_patch, direction);
                neighbor_patch.ConnectNeighbour(patch, oppositeDir);

                patch.UpdateNorthEdge();
                patch.DirtyZ();
            }

            // Do northeast/southwest connections
            for (i = 0; i < (int)PatchesPerEdge - 1; i++)
            {
                patch          = GetPatch(i, PatchesPerEdge - 1);
                neighbor_patch = neighbour.GetPatch(i + 1, 0);

                patch.ConnectNeighbour(neighbor_patch, DirectionIndex.NorthEast);
                neighbor_patch.ConnectNeighbour(patch, DirectionIndex.SouthWest);
            }
            // Do southeast/northwest connections
            for (i = 1; i < (int)PatchesPerEdge; i++)
            {
                patch          = GetPatch(i, PatchesPerEdge - 1);
                neighbor_patch = neighbour.GetPatch(i - 1, 0);

                patch.ConnectNeighbour(neighbor_patch, DirectionIndex.NorthWest);
                neighbor_patch.ConnectNeighbour(patch, DirectionIndex.SouthEast);
            }
            break;

        case DirectionIndex.West:
            // Do east/west connections, first
            for (i = 0; i < PatchesPerEdge; i++)
            {
                patch          = GetPatch(0, i);
                neighbor_patch = neighbour.GetPatch(PatchesPerEdge - 1, i);

                patch.ConnectNeighbour(neighbor_patch, direction);
                neighbor_patch.ConnectNeighbour(patch, oppositeDir);

                neighbor_patch.UpdateEastEdge();
                neighbor_patch.DirtyZ();
            }

            // Now do northeast/southwest connections
            for (i = 1; i < PatchesPerEdge; i++)
            {
                patch          = GetPatch(0, i);
                neighbor_patch = neighbour.GetPatch(PatchesPerEdge - 1, i - 1);

                patch.ConnectNeighbour(neighbor_patch, DirectionIndex.SouthWest);
                neighbor_patch.ConnectNeighbour(patch, DirectionIndex.NorthEast);
            }

            // Now do northwest/southeast connections
            for (i = 0; i < PatchesPerEdge - 1; i++)
            {
                patch          = GetPatch(0, i);
                neighbor_patch = neighbour.GetPatch(PatchesPerEdge - 1, i + 1);

                patch.ConnectNeighbour(neighbor_patch, DirectionIndex.NorthWest);
                neighbor_patch.ConnectNeighbour(patch, DirectionIndex.SouthEast);
            }
            break;

        case DirectionIndex.South:
            // Do north/south connections, first
            for (i = 0; i < PatchesPerEdge; i++)
            {
                patch          = GetPatch(i, 0);
                neighbor_patch = neighbour.GetPatch(i, PatchesPerEdge - 1);

                patch.ConnectNeighbour(neighbor_patch, direction);
                neighbor_patch.ConnectNeighbour(patch, oppositeDir);

                neighbor_patch.UpdateNorthEdge();
                neighbor_patch.DirtyZ();
            }

            // Now do northeast/southwest connections
            for (i = 1; i < PatchesPerEdge; i++)
            {
                patch          = GetPatch(i, 0);
                neighbor_patch = neighbour.GetPatch(i - 1, PatchesPerEdge - 1);

                patch.ConnectNeighbour(neighbor_patch, DirectionIndex.SouthWest);
                neighbor_patch.ConnectNeighbour(patch, DirectionIndex.NorthEast);
            }
            // Now do northeast/southwest connections
            for (i = 0; i < PatchesPerEdge - 1; i++)
            {
                patch          = GetPatch(i, 0);
                neighbor_patch = neighbour.GetPatch(i + 1, PatchesPerEdge - 1);

                patch.ConnectNeighbour(neighbor_patch, DirectionIndex.SouthEast);
                neighbor_patch.ConnectNeighbour(patch, DirectionIndex.NorthWest);
            }
            break;
        }
    }
コード例 #6
0
 public SurfacePatch GetNeighbourPatch(DirectionIndex direction)
 {
     return(NeighborPatches[(int)direction]);
 }