效果圖預覽:
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技術做一份貢獻。-----------------