WPF实现3D翻转的动画效果

2021-04-14 14:28

阅读:656

标签:isa   idt   obj   坐标系   前端   集合   显示   wpf   find   

1、前端代码实现

1.1 原理见代码注析

 1 Grid MouseDown="Grid_MouseDown">
 2     Viewport3D>
 3         Viewport3D.Camera>
 4             
 5             PerspectiveCamera Position="0 0 500" LookDirection="0 0 -1" />
 6         Viewport3D.Camera>
 7         Viewport3D.Children>
 8             ContainerUIElement3D>
 9                 Viewport2DVisual3D>
10                     Viewport2DVisual3D.Geometry>
11                         
12                         
13                         MeshGeometry3D Positions="-200 200 0  -200 -200 0  200 -200 0  200 200 0" TriangleIndices="0 1 2  0 2 3" TextureCoordinates="0 0  0 1  1 1  1 0"/>
14                     Viewport2DVisual3D.Geometry>
15                     Viewport2DVisual3D.Material>
16                         DiffuseMaterial Viewport2DVisual3D.IsVisualHostMaterial="True"/>
17                     Viewport2DVisual3D.Material>
18                     Viewport2DVisual3D.Visual>
19                         
20                         Page:Win1 Width="400" Height="400"/>
21                     Viewport2DVisual3D.Visual>
22                 Viewport2DVisual3D>
23                 Viewport2DVisual3D>
24                     Viewport2DVisual3D.Geometry>
25                         MeshGeometry3D Positions="200 200 0  200 -200 0  -200 -200 0  -200 200 0" TriangleIndices="0 1 2  0 2 3" TextureCoordinates="0 0  0 1  1 1  1 0"/>
26                     Viewport2DVisual3D.Geometry>
27                     Viewport2DVisual3D.Material>
28                         DiffuseMaterial Viewport2DVisual3D.IsVisualHostMaterial="True"/>
29                     Viewport2DVisual3D.Material>
30                     Viewport2DVisual3D.Visual>
31                         
32                         Page:Win2 Width="400" Height="400"/>
33                     Viewport2DVisual3D.Visual>
34                 Viewport2DVisual3D>
35                 ContainerUIElement3D.Transform>
36                     RotateTransform3D>
37                         RotateTransform3D.Rotation>
38                             
39                             AxisAngleRotation3D x:Name="aar" Angle="0" Axis="0 1 0"/>
40                         RotateTransform3D.Rotation>
41                     RotateTransform3D>
42                 ContainerUIElement3D.Transform>
43             ContainerUIElement3D>
44             ModelVisual3D>
45                 ModelVisual3D.Content>
46                     
47                     DirectionalLight Color="Transparent"/>
48                 ModelVisual3D.Content>
49             ModelVisual3D>
50         Viewport3D.Children>
51     Viewport3D>
52 Grid>

2、后端代码实现

2.1 通过鼠标单击翻转动画180度显示对象反面,鼠标双击翻转动画0度显示对象正面。

 1 private void Grid_MouseDown(object sender, MouseButtonEventArgs e)
 2 {
 3     DoubleAnimation da = new DoubleAnimation();
 4     da.Duration = new Duration(TimeSpan.FromSeconds(1));
 5     if (e.ClickCount == 2)
 6         da.To = 0d;
 7     else
 8         da.To = 180d;
 9     AxisAngleRotation3D aar = Application.Current.MainWindow.FindName("aar") as AxisAngleRotation3D;
10     aar.BeginAnimation(AxisAngleRotation3D.AngleProperty, da);  
11 }

技术分享图片

WPF实现3D翻转的动画效果

标签:isa   idt   obj   坐标系   前端   集合   显示   wpf   find   

原文地址:https://www.cnblogs.com/softwyy/p/8954538.html


评论


亲,登录后才可以留言!