in SamplesCommon/SamplesCommon/LightControl.xaml.cs [206:280]
private void UpdateLight()
{
if (LightTypeSelection.SelectedValue != null)
{
ComboBoxItem item = LightTypeSelection.SelectedValue as ComboBoxItem;
LightTypes lightType = (LightTypes)item.Tag;
if (_light != null)
{
_light.Targets.RemoveAll();
}
switch (lightType)
{
case LightTypes.PointLight:
{
PointLight light = _compositor.CreatePointLight();
light.CoordinateSpace = CoordinateSpace;
light.Offset = new Vector3((float)XOffset.Value, (float)YOffset.Value, (float)ZOffset.Value);
light.ConstantAttenuation = (float)ConstantAttenuation.Value / c_ConstantAttenRange;
light.LinearAttenuation = (float)LinearAttenuation.Value / c_LinearAttenRange * .1f;
light.QuadraticAttenuation = (float)QuadraticAttenuation.Value / c_QuadraticAttenRange * .01f;
light.Color = LightColor.Color;
_light = light;
}
break;
case LightTypes.SpotLight:
{
SpotLight light = _compositor.CreateSpotLight();
light.CoordinateSpace = CoordinateSpace;
light.Offset = new Vector3((float)XOffset.Value, (float)YOffset.Value, (float)ZOffset.Value);
light.ConstantAttenuation = (float)ConstantAttenuation.Value / c_ConstantAttenRange;
light.LinearAttenuation = (float)LinearAttenuation.Value / c_LinearAttenRange *.1f;
light.QuadraticAttenuation = (float)QuadraticAttenuation.Value / c_QuadraticAttenRange * .01f;
light.InnerConeAngleInDegrees = (float)InnerCone.Value;
light.InnerConeColor = InnerConeColor.Color;
light.OuterConeAngleInDegrees = (float)OuterCone.Value;
light.OuterConeColor = OuterConeColor.Color;
Vector3 lookAt = new Vector3((float)DirectionX.Value, (float)DirectionY.Value, 0);
Vector3 direction = Vector3.Normalize(lookAt - new Vector3(300, 300, 300));
light.Direction = direction;
_light = light;
}
break;
case LightTypes.DistantLight:
{
DistantLight light = _compositor.CreateDistantLight();
light.CoordinateSpace = CoordinateSpace;
light.Color = LightColor.Color;
Vector3 lookAt = new Vector3((float)DirectionX.Value, (float)DirectionY.Value, 0);
Vector3 offset = new Vector3(300, 300, 100);
light.Direction = Vector3.Normalize(lookAt - offset);
_light = light;
}
break;
default:
Debug.Assert(false, "Unexpected type");
break;
}
// Add the visual to the light target collection
foreach (Visual target in _targetVisualList)
{
_light.Targets.Add(target);
}
}
}