Exemplo n.º 1
0
        /// <summary>
        ///     Construye la grilla
        /// </summary>
        private GrillaRegularNode[,,] buildGrid(List <TgcMesh> modelos, TgcBoundingBox sceneBounds, Vector3 cellDim)
        {
            var sceneSize = sceneBounds.calculateSize();

            var gx = (int)FastMath.Ceiling(sceneSize.X / cellDim.X) + 1;
            var gy = (int)FastMath.Ceiling(sceneSize.Y / cellDim.Y) + 1;
            var gz = (int)FastMath.Ceiling(sceneSize.Z / cellDim.Z) + 1;

            var grid = new GrillaRegularNode[gx, gy, gz];

            //Construir grilla
            for (var x = 0; x < gx; x++)
            {
                for (var y = 0; y < gy; y++)
                {
                    for (var z = 0; z < gz; z++)
                    {
                        //Crear celda
                        var node = new GrillaRegularNode();

                        //Crear BoundingBox de celda
                        var pMin = new Vector3(sceneBounds.PMin.X + x * cellDim.X, sceneBounds.PMin.Y + y * cellDim.Y,
                                               sceneBounds.PMin.Z + z * cellDim.Z);
                        var pMax = Vector3.Add(pMin, cellDim);
                        node.BoundingBox = new TgcBoundingBox(pMin, pMax);

                        //Cargar modelos en celda
                        node.Models = new List <TgcMesh>();
                        addModelsToCell(node, modelos);

                        grid[x, y, z] = node;
                    }
                }
            }

            return(grid);
        }