WPF实现3D翻转的动画效果
2021-07-09 13:07
标签:soscw mouse 平行光 visual button 后端 camera containe 设置 1.1 原理见代码注析 2.1 通过鼠标单击翻转动画180度显示对象反面,鼠标双击翻转动画0度显示对象正面。 3.1 效果图如下 WPF实现3D翻转的动画效果 标签:soscw mouse 平行光 visual button 后端 camera containe 设置 原文地址:https://www.cnblogs.com/lonelyxmas/p/9704246.html1、前端代码实现
Grid MouseDown="Grid_MouseDown">
Viewport3D>
Viewport3D.Camera>
PerspectiveCamera Position="0 0 500" LookDirection="0 0 -1" />
Viewport3D.Camera>
Viewport3D.Children>
ContainerUIElement3D>
Viewport2DVisual3D>
Viewport2DVisual3D.Geometry>
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"/>
Viewport2DVisual3D.Geometry>
Viewport2DVisual3D.Material>
DiffuseMaterial Viewport2DVisual3D.IsVisualHostMaterial="True"/>
Viewport2DVisual3D.Material>
Viewport2DVisual3D.Visual>
Page:Win1 Width="400" Height="400"/>
Viewport2DVisual3D.Visual>
Viewport2DVisual3D>
Viewport2DVisual3D>
Viewport2DVisual3D.Geometry>
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"/>
Viewport2DVisual3D.Geometry>
Viewport2DVisual3D.Material>
DiffuseMaterial Viewport2DVisual3D.IsVisualHostMaterial="True"/>
Viewport2DVisual3D.Material>
Viewport2DVisual3D.Visual>
Page:Win2 Width="400" Height="400"/>
Viewport2DVisual3D.Visual>
Viewport2DVisual3D>
ContainerUIElement3D.Transform>
RotateTransform3D>
RotateTransform3D.Rotation>
AxisAngleRotation3D x:Name="aar" Angle="0" Axis="0 1 0"/>
RotateTransform3D.Rotation>
RotateTransform3D>
ContainerUIElement3D.Transform>
ContainerUIElement3D>
ModelVisual3D>
ModelVisual3D.Content>
DirectionalLight Color="Transparent"/>
ModelVisual3D.Content>
ModelVisual3D>
Viewport3D.Children>
Viewport3D>
Grid>
2、后端代码实现
private void Grid_MouseDown(object sender, MouseButtonEventArgs e)
{
DoubleAnimation da = new DoubleAnimation();
da.Duration = new Duration(TimeSpan.FromSeconds(1));
if (e.ClickCount == 2)
da.To = 0d;
else
da.To = 180d;
AxisAngleRotation3D aar = Application.Current.MainWindow.FindName("aar") as AxisAngleRotation3D;
aar.BeginAnimation(AxisAngleRotation3D.AngleProperty, da);
}
3、运行效果
上一篇:WPF实现渐变淡入淡出的动画效果
下一篇:WPF 画线动画效果实现