public void Render(TerrainTile tile, TerrainGlobal terrainGlobal, Matrix4 projection, Matrix4 view, Vector3 eye) { Vector3 xformeye = Vector4.Transform(new Vector4(eye, 0.0f), tile.InverseModelMatrix).Xyz; // construct our top-level quadtree node var root = new QuadTreeNode() { TopLeft = new QuadTreeVertex() { Position = new Vector3(0f, 0f, 0f) //Position = Vector3.Transform(new Vector3(0f, 0f, 0f), tile.ModelMatrix) }, TopRight = new QuadTreeVertex() { Position = new Vector3((float)tile.Width, 0f, 0f) //Position = Vector3.Transform(new Vector3((float)tile.Width, 0f, 0f), tile.ModelMatrix) }, BottomLeft = new QuadTreeVertex() { Position = new Vector3(0f, 0f, (float)tile.Height) //Position = Vector3.Transform(new Vector3(0f, 0f, (float)tile.Height), tile.ModelMatrix) }, BottomRight = new QuadTreeVertex() { Position = new Vector3((float)tile.Width, 0f, (float)tile.Height) //Position = Vector3.Transform(new Vector3((float)tile.Width, 0f, (float)tile.Height), tile.ModelMatrix) }, TileSize = tile.Width // assume width == height }; // check to see if we're completely outside the far detail radius if (!root.IsViewerInDetailRange(xformeye, this.DistantTileRadius)) { var distrenderer = (IPatchRenderer)fullTileDistantRenderer; //float distancepastdetail = (xformeye.Xz - new Vector2((float)tile.Width * 0.5f,(float)tile.Height * 0.5f)).Length - ; distrenderer.Width = tile.Width / 16; distrenderer.Height = distrenderer.Width; //distrenderer.DetailScale = (float)this.TileSize / (float)tileDetailRenderer.Width; distrenderer.Scale = 1.0f; distrenderer.Offset = new Vector2(0.0f, 0.0f); fullTileDistantRenderer.Render(tile, terrainGlobal, projection, view, eye); } else // check inner detail radius { if (!root.IsViewerInDetailRange(xformeye, this.DetailRadius)) { // HACK because we're using the same patch renderer as the detail patches and it keeps state (fullTileNearRenderer as IPatchRenderer).Scale = 1.0f; (fullTileNearRenderer as IPatchRenderer).Offset = Vector2.Zero; (fullTileNearRenderer as IPatchRenderer).Width = tile.Width; (fullTileNearRenderer as IPatchRenderer).Height = tile.Height; fullTileNearRenderer.Render(tile, terrainGlobal, projection, view, eye); } else { root.Render(tile, terrainGlobal, projection, view, eye, xformeye, this.DetailRadius, this.subTileRenderer, this.subTileDetailRenderer); } } }