Axiom.Core.SceneManager.PopulateLightList C# (CSharp) Method

PopulateLightList() public method

Populate a light list with an ordered set of the lights which are closest

Note that since directional lights have no position, they are always considered closer than any point lights and as such will always take precedence.

Subclasses of the default SceneManager may wish to take into account other issues such as possible visibility of the light if that information is included in their data structures. This basic scenemanager simply orders by distance, eliminating those lights which are out of range.

The number of items in the list max exceed the maximum number of lights supported by the renderer, but the extraneous ones will never be used. In fact the limit will be imposed by Pass::getMaxSimultaneousLights.

public PopulateLightList ( Vector3 position, float radius, LightList destList ) : void
position Vector3 The position at which to evaluate the list of lights
radius float The bounding radius to test
destList LightList List to be populated with ordered set of lights; will be cleared by this method before population.
return void
		public virtual void PopulateLightList( Vector3 position, float radius, LightList destList )
		{
			// Really basic trawl of the lights, then sort
			// Subclasses could do something smarter
			destList.Clear();
			float squaredRadius = radius * radius;

			MovableObjectCollection lightList = this.GetMovableObjectCollection( LightFactory.TypeName );

			// loop through the scene lights an add ones in range
			foreach ( Light light in lightList.Values )
			{
				if ( light.IsVisible )
				{
					if ( light.Type == LightType.Directional )
					{
						// no distance
						light.tempSquaredDist = 0.0f;
						destList.Add( light );
					}
					else
					{
						light.tempSquaredDist = ( light.DerivedPosition - position ).LengthSquared;
						light.tempSquaredDist -= squaredRadius;
						// only add in-range lights
						float range = light.AttenuationRange;
						if ( light.tempSquaredDist <= ( range * range ) )
						{
							destList.Add( light );
						}
					}
				} // if
			} // for

			// Sort Destination light list.
			// TODO: Not needed yet since the current LightList is a sorted list under the hood already
			//destList.Sort();
		}
SceneManager