private void FrustumCullList(FFrustum frustum, List <IRenderable> sourceList, List <IRenderable> outputList) { for (int i = 0; i < sourceList.Count; i++) { Halfspace contains = frustum.ContainsSphere(sourceList[i].GetPosition(), sourceList[i].GetBoundingRadius()); if (contains != Halfspace.Negative) { outputList.Add(sourceList[i]); } } }
/// <summary> /// Get item enumerator based on viewpoint /// </summary> /// <param name="point"></param> /// <returns></returns> public IEnumerable <T> Select(Point3D viewpoint) { Halfspace halfspace = partition.Classify(viewpoint); if (halfspace == Halfspace.Negative) { if (front != null) { foreach (var item in front.Select(viewpoint)) { yield return(item); } } } else if (back != null) { foreach (var item in back.Select(viewpoint)) { yield return(item); } } foreach (var item in items) { yield return(item); } if (halfspace == Halfspace.Negative) { if (back != null) { foreach (var item in back.Select(viewpoint)) { yield return(item); } } } else if (front != null) { foreach (var item in front.Select(viewpoint)) { yield return(item); } } }
/* /// <summary> * /// Render 2D scene * /// </summary> * /// <param name="tree">BSP tree</param> * /// <param name="camera">Camera</param> * /// <param name="frustum">View frustum</param> * /// <param name="depthPlanes">Depth planes</param> * private void Render2D( BSPTree tree, IList<IBSPItem> items, Point3D cameraPos, Matrix3D displayMatrix, Frustum frustum, DepthPlanes depthPlanes ) * { * int index = 0; * bool clipFade = ClipFade; * * foreach ( BSPCube cube in items ) * { * ContainmentType type = frustum.Contains( cube.Bounds ); * * if ( type != ContainmentType.Disjoint * && ( clipFade || type != ContainmentType.Intersects ) * && depthPlanes.Includes( cube.Position ) ) * { * Sphere sphere; * * if ( index < canvas.Children.Count ) sphere = canvas.Children[ index ] as Sphere; * else canvas.Children.Add( sphere = new Sphere() ); * * sphere.Visibility = Visibility.Visible; * sphere.RenderTransform = new MatrixTransform( cube.SphereMatrix( cameraPos, displayMatrix ) ); * sphere.Brush = ( cube.MaterialOffset >= 0.5 ) ? SphereBrush : SelectedSphereBrush; * sphere.Opacity = Math.Abs( 0.5 - cube.MaterialOffset ) * 2; * * if ( type == ContainmentType.Intersects ) sphere.Opacity *= 0.2; * ++index; * } * } * * while ( index < canvas.Children.Count ) canvas.Children[ index++ ].Visibility = Visibility.Hidden; * } */ /// <summary> /// Recursively render tree /// </summary> /// <param name="tree">Tree node</param> private void RenderTree(BSPTree tree, IList <IBSPItem> items, Point3D cameraPos, Frustum frustum, DepthPlanes depthPlanes) { bool limitDepth = LimitDepth; if (tree != null && frustum.Contains(tree.Bounds) != ContainmentType.Disjoint && (!limitDepth || depthPlanes.Includes(tree.Bounds))) { Halfspace halfspace = tree.Partition.Classify(cameraPos); if (halfspace == Halfspace.Negative) { if (tree.Front != null) { RenderTree(tree.Front, items, cameraPos, frustum, depthPlanes); } } else if (tree.Back != null) { RenderTree(tree.Back, items, cameraPos, frustum, depthPlanes); } foreach (IBSPItem item in tree.Items) { items.Add(item); } if (halfspace == Halfspace.Negative) { if (tree.Back != null) { RenderTree(tree.Back, items, cameraPos, frustum, depthPlanes); } } else if (tree.Front != null) { RenderTree(tree.Front, items, cameraPos, frustum, depthPlanes); } } }
public static float Distance(Halfspace h, Vector p) { return(Vector.Dot(h.Normal, p) - h.D); }