[Aaronyang] 写给自己的WPF4.5 笔记23 [3d交互与动画 4/4]

效果图预览:

[Aaronyang] 写给自己的WPF4.5 笔记23 [3d交互与动画 4/4]

1. 3d中的命中测试

我新建了一个空的窗口,用zam做了一个长方体,深度很小。然后导出xaml

<Viewport3D x:Name="ZAM3DViewport3D" ClipToBounds="true" Width="400" Height="300" 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/interactivedesigner/2006" xmlns:c="http://schemas.openxmlformats.org/markup-compatibility/2006" c:Ignorable="d">
<Viewport3D.Resources>
<ResourceDictionary>
<MaterialGroup x:Key="ER___Flat_06MR1" >
<DiffuseMaterial>
<DiffuseMaterial.Brush>
<SolidColorBrush Color="#999999" Opacity="1.000000"/>
</DiffuseMaterial.Brush>
</DiffuseMaterial>
</MaterialGroup>
<Transform3DGroup x:Key="SceneTR7" >
<TranslateTransform3D OffsetX="0" OffsetY="0" OffsetZ="0"/>
<ScaleTransform3D ScaleX="1" ScaleY="1" ScaleZ="1"/>
<RotateTransform3D>
<RotateTransform3D.Rotation>
<AxisAngleRotation3D Angle="0" Axis="0 1 0"/>
</RotateTransform3D.Rotation>
</RotateTransform3D>
<TranslateTransform3D OffsetX="0" OffsetY="0" OffsetZ="0"/>
</Transform3DGroup>
<Transform3DGroup x:Key="立方体OR9TR8" >
<TranslateTransform3D OffsetX="0" OffsetY="0" OffsetZ="0"/>
<ScaleTransform3D ScaleX="1" ScaleY="1" ScaleZ="1"/>
<RotateTransform3D>
<RotateTransform3D.Rotation>
<AxisAngleRotation3D Angle="0" Axis="0 1 0"/>
</RotateTransform3D.Rotation>
</RotateTransform3D>
<TranslateTransform3D OffsetX="-0.258329" OffsetY="0.0941457" OffsetZ="-0.662509"/>
</Transform3DGroup>
<MeshGeometry3D x:Key="立方体OR9GR10"
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 "
Normals="0,0,-1 0,0,-1 0,0,-1 0,0,-1 0,0,1 0,0,1 0,0,1 0,0,1 0,-1,0 0,-1,0 0,-1,0 0,-1,0 1,0,0 1,0,0 1,0,0 1,0,0 0,1,0 0,1,0 0,1,0 0,1,0 -1,0,0 -1,0,0 -1,0,0 -1,0,0 "
Positions="-0.66,-0.405,0 -0.66,0.405,0 0.66,0.405,0 0.66,-0.405,0 -0.66,-0.405,0 0.66,-0.405,0 0.66,0.405,0 -0.66,0.405,0 -0.66,-0.405,0 0.66,-0.405,0 0.66,-0.405,0 -0.66,-0.405,0 0.66,-0.405,0 0.66,0.405,0 0.66,0.405,0 0.66,-0.405,0 0.66,0.405,0 -0.66,0.405,0 -0.66,0.405,0 0.66,0.405,0 -0.66,0.405,0 -0.66,-0.405,0 -0.66,-0.405,0 -0.66,0.405,0 "
/>
</ResourceDictionary>
</Viewport3D.Resources> <Viewport3D.Camera>
<PerspectiveCamera x:Name="前视OR6" FarPlaneDistance="10" LookDirection="0,0,-1" UpDirection="0,1,0" NearPlaneDistance="2" Position="0,0,2.38396" FieldOfView="39.5978" />
</Viewport3D.Camera> <ModelVisual3D>
<ModelVisual3D.Content>
<Model3DGroup x:Name="Scene" Transform="{DynamicResource SceneTR7}"> <!-- 场景 (XAML Path = ) -->
<AmbientLight Color="#333333" />
<DirectionalLight Color="#FFFFFF" Direction="0.0397419,0.00265522,-0.999206" />
<DirectionalLight Color="#FFFFFF" Direction="0.648078,0.0259535,-0.761131" />
<Model3DGroup x:Name="立方体OR9" Transform="{DynamicResource 立方体OR9TR8}"> <!-- 立方体 (XAML Path = (Viewport3D.Children)[0].(ModelVisual3D.Content).(Model3DGroup.Children)[3]) -->
<GeometryModel3D x:Name="立方体OR9GR10" Geometry="{DynamicResource 立方体OR9GR10}" Material="{DynamicResource ER___Flat_06MR1}" BackMaterial="{DynamicResource ER___Flat_06MR1}"/>
</Model3DGroup>
</Model3DGroup>
</ModelVisual3D.Content>
</ModelVisual3D>
</Viewport3D>

我们给ModelVisual3D.Transform中的RotateTransform3D中的AxisAngleRotation3D加上一个名字axisRotation

内容已经迁移到:http://www.ayjs.net/post/62.html

OK,到目前为止,WPF的基础3D知识已经讲完了,谢谢你的阅读。

       =============潇洒的版权线==========www.ayjs.net===== Aaronyang ========= AY =========== 安徽 六安 杨洋 ==========   未经允许不许转载 =========

       -------------------小小的推荐,作者的肯定,读者的支持。推不推荐不重要,重要的是希望大家能把WPF推广出去,别让这么好的技术消失了,求求了,让我们为WPF技术做一份贡献。-----------------

上一篇:Android View 的事件分发原理解析


下一篇:viewpager与子view的事件冲突解决