Intersects() public method

Intersection test with an AxisAlignedBox.
May return false positives but will never miss an intersection.
public Intersects ( AxisAlignedBox box ) : bool
box AxisAlignedBox Box to test.
return bool
Exemplo n.º 1
0
		private void CheckShadowCasters( IList casters,
										 PlaneBoundedVolume nearClipVol,
										 Light light,
										 bool extrudeInSoftware,
										 bool finiteExtrude,
										 bool zfailAlgo,
										 Camera camera,
										 float extrudeDistance,
										 bool stencil2sided,
										 LightList tmpLightList )
		{
			int flags;
			for ( int i = 0; i < casters.Count; i++ )
			{
				ShadowCaster caster = (ShadowCaster)casters[ i ];

				if ( nearClipVol.Intersects( caster.GetWorldBoundingBox() ) )
				{
					// We have a zfail case, we must use zfail for all objects
					zfailAlgo = true;

					break;
				}
			}

			for ( int ci = 0; ci < casters.Count; ci++ )
			{
				ShadowCaster caster = (ShadowCaster)casters[ ci ];
				flags = 0;

				if ( light.Type != LightType.Directional )
				{
					extrudeDistance = caster.GetPointExtrusionDistance( light );
				}

				if ( !extrudeInSoftware && !finiteExtrude )
				{
					// hardware extrusion, to infinity (and beyond!)
					flags |= (int)ShadowRenderableFlags.ExtrudeToInfinity;
				}

				if ( zfailAlgo )
				{
					// We need to include the light and / or dark cap
					// But only if they will be visible
					if ( camera.IsObjectVisible( caster.GetLightCapBounds() ) )
					{
						flags |= (int)ShadowRenderableFlags.IncludeLightCap;
					}
				}

				// Dark cap (no dark cap for directional lights using
				// hardware extrusion to infinity)
				if ( !( ( flags & (int)ShadowRenderableFlags.ExtrudeToInfinity ) != 0 &&
						light.Type == LightType.Directional ) &&
					 camera.IsObjectVisible( caster.GetDarkCapBounds( light, extrudeDistance ) ) )
				{
					flags |= (int)ShadowRenderableFlags.IncludeDarkCap;
				}

				// get shadow renderables
				IEnumerator renderables = caster.GetShadowVolumeRenderableEnumerator(
					this.shadowTechnique, light, this.shadowIndexBuffer, extrudeInSoftware, extrudeDistance, flags );

				// If using one-sided stencil, render the first pass of all shadow
				// renderables before all the second passes
				for ( int i = 0; i < ( stencil2sided ? 1 : 2 ); i++ )
				{
					if ( i == 1 )
					{
						renderables = caster.GetLastShadowVolumeRenderableEnumerator();
					}

					while ( renderables.MoveNext() )
					{
						ShadowRenderable sr = (ShadowRenderable)renderables.Current;

						// omit hidden renderables
						if ( sr.IsVisible )
						{
							// render volume, including dark and (maybe) light caps
							this.RenderSingleShadowVolumeToStencil( sr,
																	zfailAlgo,
																	stencil2sided,
																	tmpLightList,
																	( i > 0 ) );

							// optionally render separate light cap
							if ( sr.IsLightCapSeperate
								 && ( ( flags & (int)ShadowRenderableFlags.IncludeLightCap ) ) > 0 )
							{
								// must always fail depth check
								this.targetRenderSystem.DepthBufferFunction = CompareFunction.AlwaysFail;

								Debug.Assert( sr.LightCapRenderable != null,
											  "Shadow renderable is missing a separate light cap renderable!" );

								this.RenderSingleShadowVolumeToStencil( sr.LightCapRenderable,
																		zfailAlgo,
																		stencil2sided,
																		tmpLightList,
																		( i > 0 ) );
								// reset depth function
                                this.targetRenderSystem.DepthBufferFunction = CompareFunction.Less;
							}
						}
					}
				}
			}
		}
Exemplo n.º 2
0
		public override void FindNodes( PlaneBoundedVolume t,
									  ref List<PCZSceneNode> list,
									  List<Portal> visitedPortals,
									  bool includeVisitors,
									  bool recurseThruPortals,
									  PCZSceneNode exclude )
		{
			// if this zone has an enclosure, check against the enclosure AABB first
			if ( null != mEnclosureNode )
			{
				if ( !t.Intersects( mEnclosureNode.WorldAABB ) )
				{
					// AABB of zone does not intersect t, just return.
					return;
				}
			}

			// check nodes at home in this zone
			foreach ( PCZSceneNode pczsn in mHomeNodeList )
			{
				if ( pczsn != exclude )
				{
					// make sure node is not already in the list (might have been added in another
					// zone it was visiting)
					if ( !list.Contains( pczsn ) )
					{
						bool nsect = t.Intersects( pczsn.WorldAABB );
						if ( nsect )
						{
							list.Add( pczsn );
						}
					}
				}
			}

			if ( includeVisitors )
			{
				// check visitor nodes
				foreach ( PCZSceneNode pczsn in mVisitorNodeList )
				{
					if ( pczsn != exclude )
					{
						// make sure node is not already in the list (might have been added in another
						// zone it was visiting)
						if ( !list.Contains( pczsn ) )
						{
							bool nsect = t.Intersects( pczsn.WorldAABB );
							if ( nsect )
							{
								list.Add( pczsn );
							}
						}
					}
				}
			}

			// if asked to, recurse through portals
			if ( recurseThruPortals )
			{
				foreach ( Portal portal in mPortals )
				{
					// check portal versus boundign box
					if ( portal.intersects( t ) )
					{
						// make sure portal hasn't already been recursed through
						if ( !visitedPortals.Contains( portal ) )
						{
							// save portal to the visitedPortals list
							visitedPortals.Add( portal );
							// recurse into the connected zone
							portal.getTargetZone().FindNodes( t,
																ref list,
																visitedPortals,
																includeVisitors,
																recurseThruPortals,
																exclude );
						}
					}
				}
			}

		}
Exemplo n.º 3
0
		public override void FindNodes( PlaneBoundedVolume t, ref List<PCZSceneNode> list, List<Portal> visitedPortals, bool includeVisitors, bool recurseThruPortals, PCZSceneNode exclude )
		{
			// if this zone has an enclosure, check against the enclosure AABB first
			if ( null != mEnclosureNode )
			{
				if ( !t.Intersects( mEnclosureNode.WorldAABB ) )
				{
					// AABB of zone does not intersect t, just return.
					return;
				}
			}

			// use the Octree to more efficiently find nodes intersecting the plane bounded volume
			rootOctree._findNodes( t, ref list, exclude, includeVisitors, false );

			// if asked to, recurse through portals
			if ( recurseThruPortals )
			{
				foreach ( Portal portal in mPortals )
				{
					// check portal versus boundign box
					if ( portal.intersects( t ) )
					{
						// make sure portal hasn't already been recursed through

						if ( !visitedPortals.Contains( portal ) )
						{
							// save portal to the visitedPortals list
							visitedPortals.Add( portal );
							// recurse into the connected zone
							portal.getTargetZone().FindNodes( t,
															  ref list,
															  visitedPortals,
															  includeVisitors,
															  recurseThruPortals,
															  exclude );
						}
					}
				}
			}

		}
Exemplo n.º 4
0
		protected virtual void ProcessLeaf( BspNode leaf )
		{
			//Check sphere against objects
			foreach ( MovableObject obj in leaf.Objects.Values )
			{
				// Skip this object if collision not enabled
				if ( ( obj.QueryFlags & queryMask ) == 0 )
				{
					continue;
				}

				//Test object as bounding box
				if ( sphere.Intersects( obj.GetWorldBoundingBox() ) )
				{
					if ( !this.foundIntersections.Contains( obj ) )
					{
						this.listener.OnQueryResult( obj );
						this.foundIntersections.Add( obj );
					}
				}
			}

			var boundedVolume = new PlaneBoundedVolume( PlaneSide.Positive );

			// Check ray against brushes
			for ( int brushPoint = 0; brushPoint < leaf.SolidBrushes.Length; brushPoint++ )
			{
				BspBrush brush = leaf.SolidBrushes[ brushPoint ];
				if ( brush == null )
				{
					continue;
				}

				boundedVolume.planes = brush.Planes;
				if ( boundedVolume.Intersects( sphere ) )
				{
					this.listener.OnQueryResult( brush.Fragment );
				}
			}
		}
Exemplo n.º 5
0
		// Check if a portal intersects a plane bounded volume
		// NOTE: This check is not exact.
		// NOTE: UNTESTED as of 5/30/07 (EC)
		public bool intersects( PlaneBoundedVolume pbv )
		{
			// Only check if portal is open
			if ( mOpen )
			{
				switch ( mType )
				{
					case PORTAL_TYPE.PORTAL_TYPE_QUAD:
						{
							// first check sphere of the portal
							if ( !pbv.Intersects( mDerivedSphere ) )
							{
								return false;
							}
							// if the portal corners are all outside one of the planes of the pbv,
							// then the portal does not intersect the pbv. (this can result in
							// some false positives, but it's the best I can do for now)
							foreach ( Plane plane in pbv.planes )
							{
								bool allOutside = true;
								for ( int i = 0; i < 4; i++ )
								{
									if ( plane.GetSide( mDerivedCorners[ i ] ) != pbv.outside )
									{
										allOutside = false;
									}
								}
								if ( allOutside )
								{
									return false;
								}

							}
						}
						break;
					case PORTAL_TYPE.PORTAL_TYPE_AABB:
						{
							AxisAlignedBox aabb = new AxisAlignedBox( mDerivedCorners[ 0 ], mDerivedCorners[ 1 ] );
							if ( !pbv.Intersects( aabb ) )
							{
								return false;
							}
						}
						break;
					case PORTAL_TYPE.PORTAL_TYPE_SPHERE:
						if ( !pbv.Intersects( mDerivedSphere ) )
						{
							return false;
						}
						break;
				}
			}
			return false;
		}