public IEnumerable<Tuple<ITile, TileCoord>> Cull(ViewFrustum frustum) { for (int i=0; i<grids.Count; i++) { TileGrid grid = grids[i]; TileRegion region = grid.GetRegion(i); foreach (int row in region.Rows()) { foreach (int col in region.Cols()) { ITile tile = grid[row, col]; if (tile != null) yield return new Tuple<ITile, TileCoord>(tile, new TileCoord(row, col, i)); } } } }
public virtual void Render(ViewFrustum frustum) { GL.EnableClientState(ArrayCap.VertexArray); GL.EnableClientState(ArrayCap.TextureCoordArray); vertices.Bind(true); GL.VertexPointer(3, VertexPointerType.Float, 0, 0); texCoords.Bind(true); GL.TexCoordPointer(3, TexCoordPointerType.Float, 0, 0); GL.EnableClientState(ArrayCap.IndexArray); GL.DrawElements(BeginMode.Quads, quadCount, DrawElementsType.UnsignedShort, 0); foreach (Tuple<ITile, TileCoord> tile in scene.Cull(frustum)) { TileCoord coord = tile.Item2; GL.PushMatrix(); GL.Translate(coord.Col, coord.Row, 0.0); if (tile.Item1 is FloorTile) { FloorTile ftile = (FloorTile) tile.Item1; Material material = ftile.Material; for (int i=0; i<material.Count; i++) { Texture tex = material[i]; GL.ActiveTexture(TextureUnit.Texture0 + i); tex.Bind(true); } GL.DrawArrays(BeginMode.Quads, 0, 4); } GL.PopMatrix(); } GL.DisableClientState(ArrayCap.VertexArray); GL.DisableClientState(ArrayCap.TextureCoordArray); GL.DisableClientState(ArrayCap.IndexArray); }
public List<Tuple<ITile, TileCoord>> Culling(ViewFrustum frustum, LevelScene scene) { List<Tuple<ITile, TileCoord>> viewTiles = new List<Tuple<ITile, TileCoord>>(); Culling(frustum, scene, viewTiles); return viewTiles; }
private void Culling(ViewFrustum frustum, LevelScene scene, List<Tuple<ITile, TileCoord>> viewTiles) { if (IsLeaf) { foreach (TileCoord tileCoord in region.TileCoords()) { ITile tile = scene.GetTile(tileCoord); if (tile != null) { viewTiles.Add(new Tuple<ITile, TileCoord>(tile, tileCoord)); } } } else { for (int k = 0; k < 4; k++) { if (children[k] == null) continue; if (frustum.Intersects(children[k].Bounds)) Culling(frustum, scene, viewTiles); } } }