7.6. Video and 3-D
Although it is beyond the scope of this book to talk about media
and 3-D in detail, it is worth being aware of the support for these features.
Video is supported with the MediaElement
type. This element can be added anywhere in the UI tree. Simply set its Source
property to refer to the video stream it should play, as
Example 7-49 shows.
Example 7-49. Using MediaElement
<MediaElement Source="C:\WINDOWS\system32\oobe\images\intro.wmv" Stretch="Fill" />
3-D content is supported through the Viewport3D control.
As far as WPF's layout system is concerned, the Viewport3D is just a
rectangular control, and it will be sized and positioned like any other
control. However, you provide the control with 3-D model, lighting, and camera
position information, and it will render that model. The control acts as a
window onto a 3-D scene, as shown in Example
7-50.
Example 7-50. Viewport3D
<Viewport3D ClipToBounds="true">
<Viewport3D.Camera>
<PerspectiveCamera NearPlaneDistance="1" FarPlaneDistance="100"
LookAtPoint="0,0,0" Position="30, -2, 20" Up="0, 0, 1"
FieldOfView="45" />
</Viewport3D.Camera>
<Viewport3D.Models>
<Model3DGroup>
<DirectionalLight Color="#FFFFFFFF" Direction="10,25,-1" />
<AmbientLight Color="#66666666" />
<GeometryModel3D>
<GeometryModel3D.Geometry>
<MeshGeometry3D
TriangleIndices="0 1 2 1 2 3 2 3 0 0 1 3"
Normals="-1,-1,0 1,-1,0 1,0,0 0,0,1"
Positions="-2,-2,-2 2,-2,-2 0,2,-2 0,0,1"/>
</GeometryModel3D.Geometry>
<GeometryModel3D.Material>
<MaterialGroup>
<DiffuseMaterial Brush="LightGreen" />
<SpecularMaterial Brush="White" />
</MaterialGroup>
</GeometryModel3D.Material>
</GeometryModel3D >
</Model3DGroup>
</Viewport3D.Models>
</Viewport3D>
This sets up a very simple 3-D model containing a single
square-based pyramid. Figure 7-58
shows the result. The model also contains some light sources to make sure the
model is visible. And the Viewport3D also has a camera position
specified.
In practice, you would normally use some kind of 3-D design tool
to create 3-D models, so you would not typically expect to be working with
model markup such as that shown in Example
7-50. The Viewport3D just provides a convenient way of
integrating the results into your visual tree.
 |