Пример #1
0
        private void RenderGizmos_Obsolete(XZGrid grid, CameraViewVolume cameraViewVolume)
        {
            if (!grid.RenderSettings.IsVisible)
            {
                return;
            }

            var visibleCellRangeCalculator          = new XZVisibleGridCellRangeCalculator();
            XZVisibleGridCellRange visibleCellRange = visibleCellRangeCalculator.Calculate(grid, cameraViewVolume);

            GizmosMatrix.Push(grid.TransformMatrix.ToMatrix4x4x);
            RenderGridPlane_Obsolete(grid, visibleCellRange);
            RenderGridCellLines_Obsolete(grid, visibleCellRange);
            grid.RenderableCoordinateSystem.RenderGizmos();
            GizmosMatrix.Pop();
        }
Пример #2
0
        private void RenderGridCellLines_Obsolete(XZGrid grid, XZVisibleGridCellRange visibleCellRange)
        {
            int   minCellIndexX    = visibleCellRange.XAxisVisibleCellRange.Min;
            int   maxCellIndexX    = visibleCellRange.XAxisVisibleCellRange.Max;
            float numberOfCellsOnX = maxCellIndexX - minCellIndexX + 1.0f;

            int   minCellIndexZ    = visibleCellRange.ZAxisVisibleCellRange.Min;
            int   maxCellIndexZ    = visibleCellRange.ZAxisVisibleCellRange.Max;
            float numberOfCellsOnZ = maxCellIndexZ - minCellIndexZ + 1.0f;

            XZGridCellSizeSettings gridCellSizeSettings = grid.CellSizeSettings;
            XZGridRenderSettings   gridRenderSettings   = grid.RenderSettings;

            Vector3 startPointOnX, startPointOnZ;
            Vector3 lineCubeSize = Vector3.zero;

            // Render the grid lines which extend along the grid's X axis
            GizmosColor.Push(grid.RenderSettings.CellLineColor);
            startPointOnX  = grid.GetCellHrzStart(minCellIndexX);
            lineCubeSize.z = gridRenderSettings.CellLineThickness;
            int maxLineIndex = maxCellIndexZ + 1;

            for (int lineIndex = minCellIndexZ; lineIndex <= maxLineIndex; ++lineIndex)
            {
                startPointOnZ = grid.GetCellDepthStart(lineIndex);
                Vector3 firstPoint  = startPointOnX + startPointOnZ;
                Vector3 secondPoint = firstPoint + XZGrid.ModelSpaceRightAxis * (numberOfCellsOnX * gridCellSizeSettings.CellSizeX);

                lineCubeSize.x = (firstPoint - secondPoint).magnitude + gridRenderSettings.CellLineThickness;
                Gizmos.DrawCube((firstPoint + secondPoint) * 0.5f, lineCubeSize);
            }

            // Render the grid lines which extend along the grid's Z axis
            startPointOnZ  = grid.GetCellDepthStart(minCellIndexZ);
            lineCubeSize.x = gridRenderSettings.CellLineThickness;
            maxLineIndex   = maxCellIndexX + 1;
            for (int lineIndex = minCellIndexX; lineIndex <= maxLineIndex; ++lineIndex)
            {
                startPointOnX = grid.GetCellHrzStart(lineIndex);
                Vector3 firstPoint  = startPointOnX + startPointOnZ;
                Vector3 secondPoint = firstPoint + XZGrid.ModelSpaceLookAxis * (numberOfCellsOnZ * gridCellSizeSettings.CellSizeZ);

                lineCubeSize.z = (firstPoint - secondPoint).magnitude;
                Gizmos.DrawCube((firstPoint + secondPoint) * 0.5f, lineCubeSize);
            }
            GizmosColor.Pop();
        }
Пример #3
0
        private void RenderGridPlane_Obsolete(XZGrid grid, XZVisibleGridCellRange visibleCellRange)
        {
            int minCellIndexX = visibleCellRange.XAxisVisibleCellRange.Min;
            int maxCellIndexX = visibleCellRange.XAxisVisibleCellRange.Max;

            int minCellIndexZ = visibleCellRange.ZAxisVisibleCellRange.Min;
            int maxCellIndexZ = visibleCellRange.ZAxisVisibleCellRange.Max;

            float numberOfCellsOnX = maxCellIndexX - minCellIndexX + 1.0f;
            float numberOfCellsOnZ = maxCellIndexZ - minCellIndexZ + 1.0f;

            XZGridCellSizeSettings gridCellSizeSettings = grid.CellSizeSettings;
            Vector3 planeCenter = (grid.GetCellHrzStart(minCellIndexX) + grid.GetCellDepthStart(minCellIndexZ) +
                                   grid.GetCellHrzStart(maxCellIndexX + 1) + grid.GetCellDepthStart(maxCellIndexZ + 1)) * 0.5f;
            Vector3 planeSize = new Vector3(numberOfCellsOnX * gridCellSizeSettings.CellSizeX, 0.0f, numberOfCellsOnZ * gridCellSizeSettings.CellSizeZ);

            GizmosColor.Push(grid.RenderSettings.PlaneColor);
            Gizmos.DrawCube(planeCenter, planeSize);
            GizmosColor.Pop();
        }
Пример #4
0
        private XZVisibleGridCellRange CalculateVisibleCellRangeFromGridCells(XZGrid grid, List <XZGridCell> gridCells)
        {
            int minCellIndexX = int.MaxValue;
            int maxCellIndexX = int.MinValue;
            int minCellIndexZ = int.MaxValue;
            int maxCellIndexZ = int.MinValue;

            foreach (XZGridCell cell in gridCells)
            {
                if (cell.XIndex < minCellIndexX)
                {
                    minCellIndexX = cell.XIndex;
                }
                if (cell.XIndex > maxCellIndexX)
                {
                    maxCellIndexX = cell.XIndex;
                }

                if (cell.ZIndex < minCellIndexZ)
                {
                    minCellIndexZ = cell.ZIndex;
                }
                if (cell.ZIndex > maxCellIndexZ)
                {
                    maxCellIndexZ = cell.ZIndex;
                }
            }

            XZGridDimensionSettings gridDimensionSettings = grid.DimensionSettings;

            if (gridDimensionSettings.DimensionType == XZGridDimensionType.Finite)
            {
                XZGridFiniteDimensionSettings gridFiniteDimensionSettings = grid.DimensionSettings.FiniteDimensionSettings;

                if (minCellIndexX < gridFiniteDimensionSettings.XAxisCellIndexRange.Min)
                {
                    minCellIndexX = gridFiniteDimensionSettings.XAxisCellIndexRange.Min;
                }
                if (maxCellIndexX > gridFiniteDimensionSettings.XAxisCellIndexRange.Max)
                {
                    maxCellIndexX = gridFiniteDimensionSettings.XAxisCellIndexRange.Max;
                }

                if (minCellIndexZ < gridFiniteDimensionSettings.ZAxisCellIndexRange.Min)
                {
                    minCellIndexZ = gridFiniteDimensionSettings.ZAxisCellIndexRange.Min;
                }
                if (maxCellIndexZ > gridFiniteDimensionSettings.ZAxisCellIndexRange.Max)
                {
                    maxCellIndexZ = gridFiniteDimensionSettings.ZAxisCellIndexRange.Max;
                }

                if (minCellIndexX > maxCellIndexX)
                {
                    minCellIndexX = maxCellIndexX;
                }
                if (minCellIndexZ > maxCellIndexZ)
                {
                    minCellIndexZ = maxCellIndexZ;
                }
            }

            var visibleCellRange = new XZVisibleGridCellRange();

            visibleCellRange.XAxisVisibleCellRange.Min = minCellIndexX;
            visibleCellRange.XAxisVisibleCellRange.Max = maxCellIndexX;
            visibleCellRange.ZAxisVisibleCellRange.Min = minCellIndexZ;
            visibleCellRange.ZAxisVisibleCellRange.Max = maxCellIndexZ;

            return(visibleCellRange);
        }