private void ComputeLod(Node root, double k, EntityManager entityManager)
        {
            var mesh = entityManager.GetComponent<StaticMesh>(root.Entity);

            var side = (root.Bounds.Max - root.Bounds.Min).X;
            var radius = Math.Sqrt(side*side + side*side);

            for (int i = 0; i < 6; i++)
            {
                if (PlaneDistance(_frustumPlanes[i], root.Bounds.Center) <= -radius)
                {
                    return;
                }
            }

            var error = root.GeometricError;
            var distance = (root.Bounds.Center - _camera.Position).Length;
            var rho = (error / distance) * k;

            var threshhold = 100;
            if (rho <= threshhold || root.Leafs.Length == 0)
            {
                mesh.IsVisible = true;
            }
            else
            {
                for (int j = 0; j < root.Leafs.Length; j++)
                {
                    ComputeLod(root.Leafs[j], k, entityManager);
                }
            }
        }
        public void Update(double elapsedTime, EntityManager entityManager)
        {
            if (_root == null)
            {
                _root = CreateNode(new Box3D(new Vector3d(-100, 0, -100f), new Vector3d(100f, 0, 100f)), 6, entityManager);
            }

            _frustumPlanes = FrustumPlaneExtractor.ExtractRowMajor(_camera);
            var k = _camera.Width / (Math.Tan(_camera.HorizontalFieldOfView / 2));
            ComputeLod(_root, k, entityManager);
        }
 public Node(Box3D bounds, Node[] leafNodes, Entity entity, double geometricError)
 {
     Entity = entity;
     GeometricError = geometricError;
     Bounds = bounds;
     Leafs = leafNodes;
 }