<Window x:Class="TransformExamples.Rotate"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    Title="RotateTransform3D" Height="300" Width="300"
    >
  <Window.Resources>
    <MaterialGroup x:Key="shinyDarkBlueMaterial" >
      <DiffuseMaterial Brush="#0000FF" />
      <SpecularMaterial SpecularPower="30" Brush="White" />
    </MaterialGroup>

    <GeometryModel3D x:Key="cylinderModel"
             Geometry="{StaticResource cylinderMesh}"
             Material="{StaticResource shinyDarkBlueMaterial}" />

  </Window.Resources>
  <Viewbox Grid.Row="1" 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>
          </ResourceDictionary>
        </Viewport3D.Resources>

        <ModelVisual3D>
          <ModelVisual3D.Content>
            <Model3DGroup>
              <AmbientLight Color="#333333" />
              <DirectionalLight Color="#FFFFFF" Direction="0.0156948,-0.897322,-0.4410982" />
              <DirectionalLight Color="#FFFFFF" Direction="0.795738,0.0155303,-0.605442" />
            </Model3DGroup>
          </ModelVisual3D.Content>


          <ModelVisual3D Content="{StaticResource cylinderModel}">
            <ModelVisual3D.Transform>
              <Transform3DGroup>
                <RotateTransform3D>
                  <RotateTransform3D.Rotation>
                    <AxisAngleRotation3D Axis="0,1,0" Angle="45" />
                  </RotateTransform3D.Rotation>
                </RotateTransform3D>
                <TranslateTransform3D OffsetX="-1" />
              </Transform3DGroup>
            </ModelVisual3D.Transform>
          </ModelVisual3D>

          <!-- Example 17-22. Rotation around the X axis -->

          <ModelVisual3D Content="{StaticResource cylinderModel}">
            <ModelVisual3D.Transform>
              <RotateTransform3D>
                <RotateTransform3D.Rotation>
                  <AxisAngleRotation3D Axis="1,0,0" Angle="45" />
                </RotateTransform3D.Rotation>
              </RotateTransform3D>
            </ModelVisual3D.Transform>
          </ModelVisual3D>

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

          <ModelVisual3D Content="{StaticResource cylinderModel}">
            <ModelVisual3D.Transform>
              <Transform3DGroup>
                <RotateTransform3D>
                  <RotateTransform3D.Rotation>
                    <AxisAngleRotation3D Axis="0,0,1" Angle="45" />
                  </RotateTransform3D.Rotation>
                </RotateTransform3D>
                <TranslateTransform3D OffsetX="1" />
              </Transform3DGroup>
            </ModelVisual3D.Transform>
          </ModelVisual3D>

          <ModelVisual3D Content="{StaticResource cylinderModel}">
            <ModelVisual3D.Transform>
              <Transform3DGroup>

                <!-- Example 17-23. QuaternionRotation -->

                <RotateTransform3D>
                  <RotateTransform3D.Rotation>
                    <QuaternionRotation3D Quaternion="-0.5,0.5,0.5,0.5" />
                  </RotateTransform3D.Rotation>
                </RotateTransform3D>
                
                <!-- End of Example 17-23. -->
                
                <TranslateTransform3D OffsetY="-0.75" />
              </Transform3DGroup>
            </ModelVisual3D.Transform>
          </ModelVisual3D>

        </ModelVisual3D>
      </Viewport3D>

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