2D和3-D的比较:
2d Type 3D type
Drawinig Model3D
Geometry Geometry3D
Visual Visual3D
Transform Transform3D
Creating 3-D Graphics
3-D graphics content in WPF is encapsulated in the Viewport3D element, which can participate in the 2-D element structure. A 3-D graphic is composed of four components: a model(形状), a material(表面的材料), a camera(照相机), and a light(光源) source. The Camera class enables you to specify the point of view for a 3-D scene by using a PerspectiveCamera, an OrthographicCamera, or a custom MatrixCamera.
四大组件
- A mesh model defines the shape of the object.
- A material specifies the surface of the object.
- A camera specifies what part of the 3-D scene is viewable.
- A directional light is created to shine on the object.
三维坐标系:
x向右,y向上,z面向观察者。
Carema包括:
PerspectiveCarema:透视投影,默认的,物体越近越大。
OrthographicCamera:正投影,物体一样大小,与距离无关;
位置Location属性,指向LookDirection属性,向上UpDirection属性。
Material包括:
DiffuseMaterial,不会反射光,跟2维的一样;
SpecularMatreial,模型表面很光亮
EmissiveMaterial,指定纹理
Light包括:
AmbientLight:以一致的方式照亮模型
DirectionLight:平行光
PointLight,SpotLight(既有位置又有方向)
Model:
Position属性(3个值代表一个点),TriangleIndices表示Position中指定的点按照哪种顺序来确定三角形
Manipulating the 3-D Environment
To make a 3-D mesh look like a 3-D object, you must apply a material to cover the surface so that the camera can light it and project it. Each model object has a Transform property that you can use to move, reposition, or resize the model. To animate a 3-D object in WPF, you create a timeline, define an animation, and specify the property to which to apply the animation.
包括:TranslateTransform平移变换, ScaleTransform缩放变换(相对于中心点), RotateTransform旋转变换。
Adding Multimedia
The multimedia features that WPF provides enable you to integrate sound and video into your applications. The MediaElement control can play both video and audio, and is extensible enough to allow the easy creation of custom UIs. The MediaPlayer control presents media in a Drawing by using the VideoDrawing class. Both controls can be controlled interactively or clock-driven.
独立模式
在独立模式下,由媒体内容驱动媒体播放。独立模式实现了下列功能选项:
-
可直接指定媒体的 Uri。
-
可直接控制媒体播放。
-
可修改媒体的 Position 和 SpeedRatio 属性。
通过设置 MediaElement 对象的 Source 属性或者调用 MediaPlayer 对象的 Open 方法来加载媒体。
若要在独立模式下控制媒体播放,可使用媒体对象的控制方法。提供了下列控制方法:Play、Pause、Close 和 Stop。对于 MediaElement,仅当将 LoadedBehavior 设置为 Manual 时,使用这些方法的交互式控件才可用。当媒体对象处于时钟模式时,这些方法将不可用。
有关独立模式的示例,请参见如何:控制 MediaElement(播放、暂停、停止、音量和速度)。
时钟模式
在时钟模式下,由 MediaTimeline 驱动媒体播放。时钟模式具有下列特征:
-
媒体的 Uri 是通过 MediaTimeline 间接设置的。
-
可由时钟控制媒体播放。不能使用媒体对象的控制方法。
-
可通过以下方法加载媒体:设置 MediaTimeline 对象的 Source 属性,从时间线创建时钟,并将时钟分配给媒体对象。当位于 Storyboard 中的 MediaTimeline 针对 MediaElement 时,也可用这种方法加载媒体。
若要在时钟模式下控制媒体播放,必须使用 ClockController 控制方法。ClockController 是从 MediaClock 的 ClockController 属性获取的。如果尝试在时钟模式下使用 MediaElement 或 MediaPlayer 对象的控制方法,则会引发 InvalidOperationException。
一个完整的XAML例子:
<
Viewport3D>包括<Carema>和<ModelVisual3D>
<Viewport3D.Camera> <包括Position, LookDirection and UpDirection>
<PerspectiveCamera Position="-40,40,40" LookDirection="40,-40,-40 "
UpDirection="0,0,1"></PerspectiveCamera>
</Viewport3D.Camera>
<ModelVisual3D>包括<Content>
<ModelVisual3D.Content>
<Model3DGroup>包括Light, GeometryModel3D
<DirectionalLight Color="White" Direction="-1,-1,-3"> </DirectionalLight>
<GeometryModel3D>包括Geometry和Material
<GeometryModel3D.Geometry>
<MeshGeometry3D Positions="0,0,0 10,0,0 10,10,0 0,10,0 0,0,10
10,0,10 10,10,10 0,10,10"
TriangleIndices="0 1 3 1 2 3 0 4 3 4 7 3 4 6 7 4 5 6
0 4 1 1 4 5 1 2 6 6 5 1 2 3 7 7 6 2">
</MeshGeometry3D>
</GeometryModel3D.Geometry>
<GeometryModel3D.Material>
<MaterialGroup>
<DiffuseMaterial Brush="Black"></DiffuseMaterial>
<SpecularMaterial Brush="Red"> </SpecularMaterial>
</MaterialGroup>
</GeometryModel3D.Material>
</GeometryModel3D>
</Model3DGroup>
</ModelVisual3D.Content>
</ModelVisual3D>
</Viewport3D>
-