<Window x:Class="ThreeDCube.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
        xmlns:local="clr-namespace:ThreeDCube"
        mc:Ignorable="d"
        Title="ThreeDCube"
        Height="300" Width="300">
    <Grid>
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="*"/>
            <ColumnDefinition Width="20"/>
        </Grid.ColumnDefinitions>
        <Grid.RowDefinitions>
            <RowDefinition Height="*"/>
            <RowDefinition Height="25"/>
        </Grid.RowDefinitions>

        <ScrollBar Name="vscroll" 
            Grid.Row="0" Grid.Column="1"
            Orientation="Vertical"  
            Minimum="-90" Maximum="90" 
            LargeChange="10" SmallChange="1" Value="0" />

        <ScrollBar Name="hscroll" 
            Grid.Row="1" Grid.Column="0"
            Orientation="Horizontal" 
            Minimum="-180" Maximum="180" 
            LargeChange="10" SmallChange="1" Value="-30" />

        <Viewport3D Margin="4,4,4,4" Grid.Row="0" Grid.Column="0">
            <Viewport3D.Camera>
                <PerspectiveCamera 
                  Position = "0, 2, 3"
                  LookDirection = "0, -2, -3"
                  UpDirection = "0, 1, 0"
                  FieldOfView = "60">
                </PerspectiveCamera>
            </Viewport3D.Camera>

            <ModelVisual3D>
                <ModelVisual3D.Content>
                    <Model3DGroup>
                        <!-- Lights -->
                        <AmbientLight Color="Gray" />
                        <DirectionalLight Color="Gray" Direction="1,-2,-3" />
                        <DirectionalLight Color="Gray" Direction="-1,2,3" />

                        <GeometryModel3D>
                            <GeometryModel3D.Transform>
                                <Transform3DGroup>
                                    <RotateTransform3D>
                                        <RotateTransform3D.Rotation>
                                            <AxisAngleRotation3D
                                                Axis="0 1 0" 
                                                Angle="{Binding ElementName=hscroll, Path=Value}" />
                                        </RotateTransform3D.Rotation>
                                    </RotateTransform3D>
                                    <RotateTransform3D>
                                        <RotateTransform3D.Rotation>
                                            <AxisAngleRotation3D
                                                Axis="1 0 0" 
                                                Angle="{Binding ElementName=vscroll, Path=Value}" />
                                        </RotateTransform3D.Rotation>
                                    </RotateTransform3D>
                                </Transform3DGroup>
                            </GeometryModel3D.Transform>
                            
                            <GeometryModel3D.Geometry>
                                <!-- Cube -->
                                <MeshGeometry3D 
                                    Positions="
                                      -1,-1,-1   1,-1,-1   1,-1, 1  -1,-1, 1
                                      -1,-1, 1   1,-1, 1   1, 1, 1  -1, 1, 1
                                       1,-1, 1   1,-1,-1   1, 1,-1   1, 1, 1
                                       1, 1, 1   1, 1,-1  -1, 1,-1  -1, 1, 1
                                      -1,-1, 1  -1, 1, 1  -1, 1,-1  -1,-1,-1 
                                      -1,-1,-1  -1, 1,-1   1, 1,-1   1,-1,-1
                                      "
                                    TriangleIndices="
                                       0  1  2     2  3  0
                                       4  5  6     6  7  4
                                       8  9 10    10 11  8
                                      12 13 14    14 15 12
                                      16 17 18    18 19 16
                                      20 21 22    22 23 20
                                      " />
                            </GeometryModel3D.Geometry>

                            <GeometryModel3D.Material>
                                <DiffuseMaterial Brush="Yellow" />
                            </GeometryModel3D.Material>
                        </GeometryModel3D>
                    </Model3DGroup>
                </ModelVisual3D.Content>
            </ModelVisual3D>
        </Viewport3D>
    </Grid>
</Window>
