<Window x:Class="SphereLighting.Window1"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    Title="SphereLighting" Height="300" Width="300"
    >
  <Grid>
    <Grid.RowDefinitions>
      <RowDefinition Height="Auto" />
      <RowDefinition Height="Auto" />
      <RowDefinition />
    </Grid.RowDefinitions>
    <Grid.Resources>
      <DataTemplate DataType="{x:Type Light}">
        <TextBlock Text="{Binding}" />
      </DataTemplate>
      
      <x:Array x:Key="lights">
        <!-- Example 17-13. AmbientLight -->

        <AmbientLight Color="White" />

        <!-- End of Example 17-13. -->


        <!-- Example 17-14. DirectionalLight. -->
                
        <DirectionalLight Color="White" Direction="0,-1,-0.5" />

        <!-- End of Example 17-14. -->


        <!-- Example 17-15. PointLight -->
        
        <PointLight Color="White" Position="0,1,1.5" />
        
        <!-- End of Example 17-15. -->

        <PointLight Color="White" Position="0.6,1,1.5" />
        <PointLight Color="White" Position="-0.6,1,1.5" />

        
        <!-- Example 17-16. SpotLight -->
        
        <SpotLight Color="White" Position="-2,2,6" Direction="2,-2,-6"
           InnerConeAngle="8" OuterConeAngle="12" />

        <!-- End of Example 17-16. -->

        
        <SpotLight Color="White" Position="-2,2,6" Direction="2,-2,-6"
                   InnerConeAngle="4" OuterConeAngle="6" />

      </x:Array>
    </Grid.Resources>

    <ListBox SelectedIndex="0" x:Name="lightsSelector" DataContext="{StaticResource lights}" ItemsSource="{Binding Items}" />

    <CheckBox Grid.Row="1" x:Name="blackBackground" Content="_Black background" />

    <Rectangle Grid.Row="2">
      <Rectangle.Style>
        <Style>
          <Style.Triggers>
            <DataTrigger Binding="{Binding ElementName=blackBackground,Path=IsChecked}" Value="True">
              <Setter Property="Rectangle.Fill" Value="Black" />
            </DataTrigger>
          </Style.Triggers>
        </Style>
      </Rectangle.Style>
    </Rectangle>
    <Viewbox Grid.Row="2" ClipToBounds="True">
      <Border BorderBrush="Black" BorderThickness="1" Margin="2">

        <Viewport3D ClipToBounds="True" Width="300" Height="200">
          <Viewport3D.Camera>
            <PerspectiveCamera Position="0,0,4" LookDirection="0,0,-1"
                   UpDirection="0,1,0" FieldOfView="45" />
          </Viewport3D.Camera>
          <Viewport3D.Resources>
            <ResourceDictionary>
              <GeometryModel3D x:Key="sphereModel"
                               Geometry="{StaticResource sphereMesh}">
                <GeometryModel3D.Material>
                  <MaterialGroup>
                    <DiffuseMaterial Brush="#00FFFF" />
                    <SpecularMaterial SpecularPower="30" Brush="White" />
                  </MaterialGroup>

                </GeometryModel3D.Material>
              </GeometryModel3D>

            </ResourceDictionary>
          </Viewport3D.Resources>

          <ModelVisual3D>
            <ModelVisual3D.Content>
              <Model3DGroup x:Name="modelLights">
              </Model3DGroup>
            </ModelVisual3D.Content>

            <ModelVisual3D Content="{StaticResource sphereModel}">
              <ModelVisual3D.Transform>
                <ScaleTransform3D ScaleY="-1" />
              </ModelVisual3D.Transform>
            </ModelVisual3D>

          </ModelVisual3D>
        </Viewport3D>

      </Border>
    </Viewbox>
  </Grid>
</Window>
