Axiom.SceneManagers.Octree.OctreeCamera.GetVisibility C# (CSharp) Method

GetVisibility() public method

Returns the visiblity of the box.
public GetVisibility ( AxisAlignedBox bound ) : Visibility
bound Axiom.Math.AxisAlignedBox
return Visibility
		public Visibility GetVisibility( AxisAlignedBox bound )
		{
			if ( bound.IsNull )
			{
				return Visibility.None;
			}

			UpdateView();

			Vector3[] boxCorners = bound.Corners;

			// For each plane, see if all points are on the negative side
			// If so, object is not visible.
			// If one or more are, it's partial.
			// If all aren't, full

			bool AllInside = true;

			for ( int plane = 0; plane < 6; plane++ )
			{
				bool AllOutside = false;

				float distance = 0;

				for ( int corner = 0; corner < 8; corner++ )
				{
					distance = _planes[ plane ].GetDistance( boxCorners[ corners[ corner ] ] );
					AllOutside = AllOutside && ( distance < 0 );
					AllInside = AllInside && ( distance >= 0 );

					if ( !AllOutside && !AllInside )
					{
						break;
					}
				}

				if ( AllOutside )
				{
					return Visibility.None;
				}
			}

			if ( AllInside )
			{
				return Visibility.Full;
			}
			else
			{
				return Visibility.Partial;
			}

		}

Usage Example

Example #1
0
		/** Walks through the octree, adding any visible objects to the render queue.
		@remarks
		If any octant in the octree if completely within the the view frustum,
		all subchildren are automatically added with no visibility tests.
		*/
		public void WalkOctree( OctreeCamera camera, RenderQueue queue, Octree octant, bool foundVisible )
		{

			Queue<WalkQueueObject> q = new Queue<WalkQueueObject>();
			WalkQueueObject temp = new WalkQueueObject( octant, foundVisible );

			q.Enqueue( temp );

			while ( q.Count > 0 )
			{

				temp = q.Dequeue();

				//return immediately if nothing is in the node.
				if ( temp.Octant.NumNodes == 0 )
				{
					continue;
				}

				Visibility v = Visibility.None;

				if ( temp.FoundVisible )
				{
					v = Visibility.Full;
				}
				else if ( temp.Octant == octree )
				{
					v = Visibility.Partial;
				}
				else
				{
					AxisAlignedBox box = temp.Octant.CullBounds;
					v = camera.GetVisibility( box );
				}



				// if the octant is visible, or if it's the root node...
				if ( v != Visibility.None )
				{
					if ( this.ShowBoundingBoxes )
					{
						boxList.Add( temp.Octant.WireBoundingBox );
					}

					bool vis = true;

					foreach ( OctreeNode node in temp.Octant.NodeList.Values )
					{
						// if this octree is partially visible, manually cull all
						// scene nodes attached directly to this level.

						if ( v == Visibility.Partial )
						{
							vis = camera.IsObjectVisible( node.WorldAABB );
						}

						if ( vis )
						{
							numObjects++;
							node.AddToRenderQueue( camera, queue );

							visible.Add( node );

							if ( DisplayNodes )
							{
								GetRenderQueue().AddRenderable( node.GetDebugRenderable() );
							}

							// check if the scene manager or this node wants the bounding box shown.
							if ( node.ShowBoundingBox || this.ShowBoundingBoxes )
							{
								node.AddBoundingBoxToQueue( queue );
							}
						}
					}

					if ( temp.Octant.Children[ 0, 0, 0 ] != null )
					{
						q.Enqueue( new WalkQueueObject( temp.Octant.Children[ 0, 0, 0 ], v == Visibility.Full ) );
						//WalkOctree( camera, queue, octant.Children[ 0, 0, 0 ], ( v == Visibility.Full ) );
						//continue;
					}

					if ( temp.Octant.Children[ 1, 0, 0 ] != null )
					{
						q.Enqueue( new WalkQueueObject( temp.Octant.Children[ 1, 0, 0 ], v == Visibility.Full ) );
						//WalkOctree( camera, queue, octant.Children[ 1, 0, 0 ], ( v == Visibility.Full ) );
						//continue;
					}

					if ( temp.Octant.Children[ 0, 1, 0 ] != null )
					{
						q.Enqueue( new WalkQueueObject( temp.Octant.Children[ 0, 1, 0 ], v == Visibility.Full ) );
						//WalkOctree( camera, queue, octant.Children[ 0, 1, 0 ], ( v == Visibility.Full ) );
						//continue;
					}

					if ( temp.Octant.Children[ 1, 1, 0 ] != null )
					{
						q.Enqueue( new WalkQueueObject( temp.Octant.Children[ 1, 1, 0 ], v == Visibility.Full ) );
						//WalkOctree( camera, queue, octant.Children[ 1, 1, 0 ], ( v == Visibility.Full ) );
						//continue;
					}

					if ( temp.Octant.Children[ 0, 0, 1 ] != null )
					{
						q.Enqueue( new WalkQueueObject( temp.Octant.Children[ 0, 0, 1 ], v == Visibility.Full ) );
						//WalkOctree( camera, queue, octant.Children[ 0, 0, 1 ], ( v == Visibility.Full ) );
						//continue;
					}

					if ( temp.Octant.Children[ 1, 0, 1 ] != null )
					{
						q.Enqueue( new WalkQueueObject( temp.Octant.Children[ 1, 0, 1 ], v == Visibility.Full ) );
						//WalkOctree( camera, queue, octant.Children[ 1, 0, 1 ], ( v == Visibility.Full ) );
						//continue;
					}

					if ( temp.Octant.Children[ 0, 1, 1 ] != null )
					{
						q.Enqueue( new WalkQueueObject( temp.Octant.Children[ 0, 1, 1 ], v == Visibility.Full ) );
						//WalkOctree( camera, queue, octant.Children[ 0, 1, 1 ], ( v == Visibility.Full ) );
						//continue;
					}

					if ( temp.Octant.Children[ 1, 1, 1 ] != null )
					{
						q.Enqueue( new WalkQueueObject( temp.Octant.Children[ 1, 1, 1 ], v == Visibility.Full ) );
						//WalkOctree( camera, queue, octant.Children[ 1, 1, 1 ], ( v == Visibility.Full ) );
						//continue;
					}
				}
			}
		}
All Usage Examples Of Axiom.SceneManagers.Octree.OctreeCamera::GetVisibility