ddd
This commit is contained in:
parent
b761976f8c
commit
8a0c3e3daa
@ -4,6 +4,6 @@
|
||||
xmlns:local="clr-namespace:Wpf_AiSportsMicrospace.MyUserControl"
|
||||
Title="Home" Height="600" Width="800" Loaded="Window_Loaded">
|
||||
<Grid>
|
||||
<local:CoverFlowControl x:Name="coverFlow" HorizontalAlignment="Center" VerticalAlignment="Center"/>
|
||||
<local:CoverFlowControl1 x:Name="coverFlow" HorizontalAlignment="Center" VerticalAlignment="Center"/>
|
||||
</Grid>
|
||||
</Window>
|
||||
|
||||
@ -43,23 +43,30 @@ namespace Wpf_AiSportsMicrospace
|
||||
public Home()
|
||||
{
|
||||
InitializeComponent();
|
||||
_humanPredictor = HumanPredictorFactory.Create(HumanPredictorType.SingleHigh);
|
||||
_objectDetector = ObjectDetectorFactory.CreateSportGoodsDetector();
|
||||
_humanGraphicsRenderer = new HumanGraphicsRenderer();
|
||||
_humanGraphicsRenderer.DrawLabel = false;
|
||||
//_humanPredictor = HumanPredictorFactory.Create(HumanPredictorType.SingleHigh);
|
||||
//_objectDetector = ObjectDetectorFactory.CreateSportGoodsDetector();
|
||||
//_humanGraphicsRenderer = new HumanGraphicsRenderer();
|
||||
//_humanGraphicsRenderer.DrawLabel = false;
|
||||
|
||||
_sports = SportBase.GetSports();
|
||||
_detectQueue = new SportDetectionQueue();
|
||||
//_sports = SportBase.GetSports();
|
||||
//_detectQueue = new SportDetectionQueue();
|
||||
|
||||
string projectRoot = Path.Combine(AppContext.BaseDirectory, @"..\..\..");
|
||||
string albumPath = Path.Combine(projectRoot, "Resources", "Img", "Album");
|
||||
|
||||
// 转换为 Uri
|
||||
coverFlow.Images.Add(new Uri(Path.Combine(albumPath, "1.jpg")));
|
||||
coverFlow.Images.Add(new Uri(Path.Combine(albumPath, "2.jpg")));
|
||||
coverFlow.Images.Add(new Uri(Path.Combine(albumPath, "3.jpg")));
|
||||
coverFlow.Images.Add(new Uri(Path.Combine(albumPath, "4.jpg")));
|
||||
coverFlow.Images.Add(new Uri(Path.Combine(albumPath, "5.jpg")));
|
||||
//coverFlow.Images.Add(new Uri(Path.Combine(albumPath, "1.jpg")));
|
||||
//coverFlow.Images.Add(new Uri(Path.Combine(albumPath, "2.jpg")));
|
||||
//coverFlow.Images.Add(new Uri(Path.Combine(albumPath, "3.jpg")));
|
||||
//coverFlow.Images.Add(new Uri(Path.Combine(albumPath, "4.jpg")));
|
||||
//coverFlow.Images.Add(new Uri(Path.Combine(albumPath, "5.jpg")));
|
||||
|
||||
|
||||
coverFlow.Images.Add(new CoverFlowItem { ImageUri = new Uri(Path.Combine(albumPath, "1.jpg")) });
|
||||
coverFlow.Images.Add(new CoverFlowItem { ImageUri = new Uri(Path.Combine(albumPath, "2.jpg")) });
|
||||
coverFlow.Images.Add(new CoverFlowItem { ImageUri = new Uri(Path.Combine(albumPath, "3.jpg")) });
|
||||
coverFlow.Images.Add(new CoverFlowItem { ImageUri = new Uri(Path.Combine(albumPath, "4.jpg")) });
|
||||
coverFlow.Images.Add(new CoverFlowItem { ImageUri = new Uri(Path.Combine(albumPath, "5.jpg")) });
|
||||
|
||||
// 默认选中第3张
|
||||
coverFlow.SelectedIndex = 2;
|
||||
@ -67,18 +74,18 @@ namespace Wpf_AiSportsMicrospace
|
||||
|
||||
private void Window_Loaded(object sender, RoutedEventArgs e)
|
||||
{
|
||||
_leftTracker = PostureCalculate.CreatePointTracker("left_wrist", 0);
|
||||
_rightTracker = PostureCalculate.CreatePointTracker("right_wrist", 0);
|
||||
_leftElbow = PostureCalculate.CreatePointTracker("left_elbow", 0);
|
||||
_rightElbow = PostureCalculate.CreatePointTracker("right_elbow", 0);
|
||||
//_leftTracker = PostureCalculate.CreatePointTracker("left_wrist", 0);
|
||||
//_rightTracker = PostureCalculate.CreatePointTracker("right_wrist", 0);
|
||||
//_leftElbow = PostureCalculate.CreatePointTracker("left_elbow", 0);
|
||||
//_rightElbow = PostureCalculate.CreatePointTracker("right_elbow", 0);
|
||||
|
||||
_leftTracker.Amplitude = 0.05f;
|
||||
_rightTracker.Amplitude = 0.05f;
|
||||
//_leftTracker.Amplitude = 0.05f;
|
||||
//_rightTracker.Amplitude = 0.05f;
|
||||
|
||||
_leftElbow.Amplitude = 0.05f;
|
||||
_rightElbow.Amplitude = 0.05f;
|
||||
//_leftElbow.Amplitude = 0.05f;
|
||||
//_rightElbow.Amplitude = 0.05f;
|
||||
|
||||
LoadRTSP();
|
||||
//LoadRTSP();
|
||||
}
|
||||
|
||||
private void LoadRTSP()
|
||||
|
||||
@ -5,45 +5,42 @@
|
||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||
xmlns:local="clr-namespace:Wpf_AiSportsMicrospace.MyUserControl"
|
||||
mc:Ignorable="d" Background="Black" x:Name="Root">
|
||||
Height="300" Width="600">
|
||||
<UserControl.Resources>
|
||||
<BooleanToVisibilityConverter x:Key="BoolToVisibilityConverter"/>
|
||||
<local:ProgressToRectangleGeometryConverter x:Key="ProgressToRectangleGeometryConverter"/>
|
||||
</UserControl.Resources>
|
||||
|
||||
<Grid Background="Transparent">
|
||||
<ItemsControl x:Name="ItemsHost" ItemsSource="{Binding Images, RelativeSource={RelativeSource AncestorType=UserControl}}">
|
||||
<ItemsControl.ItemsPanel>
|
||||
<ItemsPanelTemplate>
|
||||
<Canvas/>
|
||||
</ItemsPanelTemplate>
|
||||
</ItemsControl.ItemsPanel>
|
||||
|
||||
<ItemsControl.ItemTemplate>
|
||||
<DataTemplate>
|
||||
<Border x:Name="ImageContainer" RenderTransformOrigin="0.5,0.5"
|
||||
MouseLeftButtonDown="Image_MouseLeftButtonDown"
|
||||
BorderBrush="Transparent" BorderThickness="4">
|
||||
<Border.RenderTransform>
|
||||
<TransformGroup>
|
||||
<ScaleTransform x:Name="scale" ScaleX="1" ScaleY="1"/>
|
||||
<TranslateTransform x:Name="translate" X="0" Y="0"/>
|
||||
</TransformGroup>
|
||||
</Border.RenderTransform>
|
||||
|
||||
<Grid>
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition Height="0.7*"/>
|
||||
<RowDefinition Height="0.3*"/>
|
||||
</Grid.RowDefinitions>
|
||||
<Image Source="{Binding ImageUri}" Stretch="UniformToFill" Width="150" Height="200"/>
|
||||
|
||||
<!-- 3D视图 -->
|
||||
<_3DTools:Interactive3DDecorator>
|
||||
<Viewport3D x:Name="viewport3D">
|
||||
<Viewport3D.Camera>
|
||||
<PerspectiveCamera Position="0,0,10"/>
|
||||
</Viewport3D.Camera>
|
||||
|
||||
<ModelVisual3D>
|
||||
<ModelVisual3D.Content>
|
||||
<AmbientLight Color="White"/>
|
||||
</ModelVisual3D.Content>
|
||||
</ModelVisual3D>
|
||||
</Viewport3D>
|
||||
</_3DTools:Interactive3DDecorator>
|
||||
|
||||
<!-- 控制Slider -->
|
||||
<UniformGrid Grid.Row="1" Columns="2" Rows="2" Background="White">
|
||||
<Slider HorizontalAlignment="Stretch" VerticalAlignment="Center"
|
||||
SmallChange="1" Maximum="90"
|
||||
Value="{Binding Path=ModelAngle, ElementName=Root, Mode=TwoWay}"/>
|
||||
|
||||
<Slider HorizontalAlignment="Stretch" VerticalAlignment="Center"
|
||||
Maximum="3" Minimum="1.5" SmallChange="0.5"
|
||||
Value="{Binding Path=MidModelDistance, ElementName=Root, Mode=TwoWay}"/>
|
||||
|
||||
<Slider VerticalAlignment="Center"
|
||||
Maximum="1" Minimum="0.5"
|
||||
Value="{Binding Path=XDistanceBetweenModels, ElementName=Root, Mode=TwoWay}"/>
|
||||
|
||||
<Slider VerticalAlignment="Center"
|
||||
Maximum="3"
|
||||
Value="{Binding Path=ZDistanceBetweenModels, ElementName=Root, Mode=TwoWay}"/>
|
||||
</UniformGrid>
|
||||
<!-- 矩形进度条 -->
|
||||
<Path Stroke="Red" StrokeThickness="4" Visibility="{Binding IsSelected, Converter={StaticResource BoolToVisibilityConverter}}"
|
||||
Data="{Binding Progress, Converter={StaticResource ProgressToRectangleGeometryConverter}, ConverterParameter='150,200'}"/>
|
||||
</Grid>
|
||||
</Border>
|
||||
</DataTemplate>
|
||||
</ItemsControl.ItemTemplate>
|
||||
</ItemsControl>
|
||||
</Grid>
|
||||
</UserControl>
|
||||
|
||||
@ -1,6 +1,7 @@
|
||||
using _3DTools;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.ObjectModel;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
@ -16,344 +17,151 @@ using System.Windows.Media.Imaging;
|
||||
using System.Windows.Media.Media3D;
|
||||
using System.Windows.Navigation;
|
||||
using System.Windows.Shapes;
|
||||
using System.Windows.Threading;
|
||||
|
||||
namespace Wpf_AiSportsMicrospace.MyUserControl
|
||||
{
|
||||
/// <summary>
|
||||
/// CoverFlowControl1.xaml 的交互逻辑
|
||||
/// </summary>
|
||||
|
||||
public partial class CoverFlowControl1 : UserControl
|
||||
{
|
||||
public ObservableCollection<CoverFlowItem> Images { get; set; } = new ObservableCollection<CoverFlowItem>();
|
||||
private int _selectedIndex = 0;
|
||||
|
||||
public int SelectedIndex
|
||||
{
|
||||
get => _selectedIndex;
|
||||
set
|
||||
{
|
||||
if (Images.Count == 0) return;
|
||||
if (value < 0) _selectedIndex = Images.Count - 1;
|
||||
else if (value >= Images.Count) _selectedIndex = 0;
|
||||
else _selectedIndex = value;
|
||||
|
||||
for (int i = 0; i < Images.Count; i++)
|
||||
{
|
||||
Images[i].IsSelected = (i == _selectedIndex);
|
||||
if (i == _selectedIndex) Images[i].Progress = 0;
|
||||
}
|
||||
|
||||
UpdateLayoutWithAnimation();
|
||||
}
|
||||
}
|
||||
|
||||
public CoverFlowControl1()
|
||||
{
|
||||
InitializeComponent();
|
||||
InitControl();
|
||||
DataContext = this;
|
||||
Loaded += (s, e) => UpdateLayoutWithAnimation(true);
|
||||
|
||||
var timer = new DispatcherTimer { Interval = TimeSpan.FromMilliseconds(30) };
|
||||
timer.Tick += (s, e) =>
|
||||
{
|
||||
if (Images.Count == 0) return;
|
||||
var current = Images[_selectedIndex];
|
||||
if (current.Progress < 1)
|
||||
current.Progress += 0.01; // 调整速度
|
||||
};
|
||||
timer.Start();
|
||||
}
|
||||
|
||||
#region 依赖属性注册
|
||||
public static readonly DependencyProperty CurrentMidIndexProperty =
|
||||
DependencyProperty.Register(
|
||||
"CurrentMidIndex", typeof(double), typeof(CoverFlowControl),
|
||||
new FrameworkPropertyMetadata(new PropertyChangedCallback(CurrentMidIndexPropertyChangedCallback)));
|
||||
|
||||
private static void CurrentMidIndexPropertyChangedCallback(DependencyObject sender, DependencyPropertyChangedEventArgs arg)
|
||||
private void Image_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
|
||||
{
|
||||
var ctrl = sender as CoverFlowControl1;
|
||||
ctrl?.ReLayoutInteractiveVisual3D();
|
||||
if (sender is Border border)
|
||||
{
|
||||
var container = ItemsHost.ItemContainerGenerator.ContainerFromItem(border.DataContext) as ContentPresenter;
|
||||
if (container != null)
|
||||
{
|
||||
int index = ItemsHost.ItemContainerGenerator.IndexFromContainer(container);
|
||||
SelectedIndex = index;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public double CurrentMidIndex
|
||||
private void UpdateLayoutWithAnimation(bool instant = false)
|
||||
{
|
||||
get => (double)GetValue(CurrentMidIndexProperty);
|
||||
set => SetValue(CurrentMidIndexProperty, value);
|
||||
double centerX = ActualWidth / 2;
|
||||
double spacing = 180;
|
||||
double sideScale = 0.8;
|
||||
double centerScale = 1.2;
|
||||
|
||||
for (int i = 0; i < ItemsHost.Items.Count; i++)
|
||||
{
|
||||
var container = ItemsHost.ItemContainerGenerator.ContainerFromIndex(i) as ContentPresenter;
|
||||
if (container == null) continue;
|
||||
|
||||
var border = FindVisualChild<Border>(container);
|
||||
if (border == null) continue;
|
||||
|
||||
var transformGroup = border.RenderTransform as TransformGroup;
|
||||
var scale = transformGroup.Children[0] as ScaleTransform;
|
||||
var translate = transformGroup.Children[1] as TranslateTransform;
|
||||
|
||||
double targetX;
|
||||
double targetScale;
|
||||
double targetOpacity;
|
||||
|
||||
if (i == SelectedIndex)
|
||||
{
|
||||
targetX = centerX - 75;
|
||||
targetScale = centerScale;
|
||||
targetOpacity = 1.0;
|
||||
}
|
||||
|
||||
public static readonly DependencyProperty ModelAngleProperty =
|
||||
DependencyProperty.Register(
|
||||
"ModelAngle", typeof(double), typeof(CoverFlowControl),
|
||||
new FrameworkPropertyMetadata(70.0, new PropertyChangedCallback(ModelAnglePropertyChangedCallback)));
|
||||
|
||||
private static void ModelAnglePropertyChangedCallback(DependencyObject sender, DependencyPropertyChangedEventArgs arg)
|
||||
else if (i == SelectedIndex - 1 || (SelectedIndex == 0 && i == Images.Count - 1))
|
||||
{
|
||||
var ctrl = sender as CoverFlowControl1;
|
||||
ctrl?.ReLayoutInteractiveVisual3D();
|
||||
targetX = centerX - spacing - 75;
|
||||
targetScale = sideScale;
|
||||
targetOpacity = 1.0;
|
||||
}
|
||||
|
||||
public double ModelAngle
|
||||
else if (i == SelectedIndex + 1 || (SelectedIndex == Images.Count - 1 && i == 0))
|
||||
{
|
||||
get => (double)GetValue(ModelAngleProperty);
|
||||
set => SetValue(ModelAngleProperty, value);
|
||||
targetX = centerX + spacing - 75;
|
||||
targetScale = sideScale;
|
||||
targetOpacity = 1.0;
|
||||
}
|
||||
|
||||
public static readonly DependencyProperty XDistanceBetweenModelsProperty =
|
||||
DependencyProperty.Register(
|
||||
"XDistanceBetweenModels", typeof(double), typeof(CoverFlowControl),
|
||||
new FrameworkPropertyMetadata(0.5, XDistanceBetweenModelsPropertyChangedCallback));
|
||||
|
||||
private static void XDistanceBetweenModelsPropertyChangedCallback(DependencyObject sender, DependencyPropertyChangedEventArgs arg)
|
||||
{
|
||||
var ctrl = sender as CoverFlowControl1;
|
||||
ctrl?.ReLayoutInteractiveVisual3D();
|
||||
}
|
||||
|
||||
public double XDistanceBetweenModels
|
||||
{
|
||||
get => (double)GetValue(XDistanceBetweenModelsProperty);
|
||||
set => SetValue(XDistanceBetweenModelsProperty, value);
|
||||
}
|
||||
|
||||
public static readonly DependencyProperty ZDistanceBetweenModelsProperty =
|
||||
DependencyProperty.Register(
|
||||
"ZDistanceBetweenModels", typeof(double), typeof(CoverFlowControl),
|
||||
new FrameworkPropertyMetadata(0.5, ZDistanceBetweenModelsPropertyChangedCallback));
|
||||
|
||||
private static void ZDistanceBetweenModelsPropertyChangedCallback(DependencyObject sender, DependencyPropertyChangedEventArgs arg)
|
||||
{
|
||||
var ctrl = sender as CoverFlowControl1;
|
||||
ctrl?.ReLayoutInteractiveVisual3D();
|
||||
}
|
||||
|
||||
public double ZDistanceBetweenModels
|
||||
{
|
||||
get => (double)GetValue(ZDistanceBetweenModelsProperty);
|
||||
set => SetValue(ZDistanceBetweenModelsProperty, value);
|
||||
}
|
||||
|
||||
public static readonly DependencyProperty MidModelDistanceProperty =
|
||||
DependencyProperty.Register(
|
||||
"MidModelDistance", typeof(double), typeof(CoverFlowControl),
|
||||
new FrameworkPropertyMetadata(1.5, MidModelDistancePropertyChangedCallback));
|
||||
|
||||
private static void MidModelDistancePropertyChangedCallback(DependencyObject sender, DependencyPropertyChangedEventArgs arg)
|
||||
{
|
||||
var ctrl = sender as CoverFlowControl1;
|
||||
ctrl?.ReLayoutInteractiveVisual3D();
|
||||
}
|
||||
|
||||
public double MidModelDistance
|
||||
{
|
||||
get => (double)GetValue(MidModelDistanceProperty);
|
||||
set => SetValue(MidModelDistanceProperty, value);
|
||||
}
|
||||
#endregion
|
||||
private void InitControl()
|
||||
{
|
||||
this.LoadImageToViewport3D(this.GetUserImages());
|
||||
|
||||
// 鼠标事件改为控件自身
|
||||
this.MouseDown += (s, e) =>
|
||||
{
|
||||
if (e.LeftButton == MouseButtonState.Pressed)
|
||||
this.CurrentMidIndex++;
|
||||
else
|
||||
this.CurrentMidIndex--;
|
||||
};
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取当前用户的图片文件夹中的图片(不包含子文件夹)
|
||||
/// </summary>
|
||||
/// <returns>返回图片路径列表</returns>
|
||||
private List<string> GetUserImages()
|
||||
{
|
||||
List<string> images = new List<string>();
|
||||
targetX = centerX - 75;
|
||||
targetScale = sideScale;
|
||||
targetOpacity = 0.0;
|
||||
}
|
||||
|
||||
string path = Environment.GetFolderPath(Environment.SpecialFolder.MyPictures);
|
||||
DirectoryInfo dir = new DirectoryInfo(path);
|
||||
FileInfo[] files = dir.GetFiles("*.jpg", SearchOption.AllDirectories);
|
||||
if (files != null)
|
||||
if (instant)
|
||||
{
|
||||
foreach (FileInfo file in files)
|
||||
translate.X = targetX;
|
||||
scale.ScaleX = scale.ScaleY = targetScale;
|
||||
border.Opacity = targetOpacity;
|
||||
}
|
||||
else
|
||||
{
|
||||
images.Add(file.FullName);
|
||||
translate.BeginAnimation(TranslateTransform.XProperty,
|
||||
new DoubleAnimation(targetX, TimeSpan.FromMilliseconds(400)) { EasingFunction = new QuadraticEase() });
|
||||
scale.BeginAnimation(ScaleTransform.ScaleXProperty,
|
||||
new DoubleAnimation(targetScale, TimeSpan.FromMilliseconds(400)) { EasingFunction = new QuadraticEase() });
|
||||
scale.BeginAnimation(ScaleTransform.ScaleYProperty,
|
||||
new DoubleAnimation(targetScale, TimeSpan.FromMilliseconds(400)) { EasingFunction = new QuadraticEase() });
|
||||
border.BeginAnimation(Border.OpacityProperty,
|
||||
new DoubleAnimation(targetOpacity, TimeSpan.FromMilliseconds(400)));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return images;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 添加图片到视口
|
||||
/// </summary>
|
||||
/// <param name="images"></param>
|
||||
private void LoadImageToViewport3D(List<string> images)
|
||||
private static T FindVisualChild<T>(DependencyObject obj) where T : DependencyObject
|
||||
{
|
||||
if (images == null)
|
||||
for (int i = 0; i < VisualTreeHelper.GetChildrenCount(obj); i++)
|
||||
{
|
||||
return;
|
||||
var child = VisualTreeHelper.GetChild(obj, i);
|
||||
if (child is T target) return target;
|
||||
var result = FindVisualChild<T>(child);
|
||||
if (result != null) return result;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
for (int i = 0; i < images.Count; i++)
|
||||
{
|
||||
string imageFile = images[i];
|
||||
|
||||
InteractiveVisual3D iv3d = this.CreateInteractiveVisual3D(imageFile, i);
|
||||
|
||||
this.viewport3D.Children.Add(iv3d);
|
||||
public void SlideLeft() => SelectedIndex++;
|
||||
public void SlideRight() => SelectedIndex--;
|
||||
}
|
||||
|
||||
this.ReLayoutInteractiveVisual3D();
|
||||
}
|
||||
private InteractiveVisual3D CreateInteractiveVisual3D(string imageFile, int index)
|
||||
{
|
||||
InteractiveVisual3D iv3d = new InteractiveVisual3D();
|
||||
iv3d.Visual = this.CreateVisual(imageFile, index);
|
||||
iv3d.Geometry = this.CreateGeometry3D();
|
||||
iv3d.Transform = this.CreateEmptyTransform3DGroup();
|
||||
|
||||
return iv3d;
|
||||
}
|
||||
/// <summary>
|
||||
/// 创建一个空的Transform3DGroup
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
private Transform3DGroup CreateEmptyTransform3DGroup()
|
||||
{
|
||||
Transform3DGroup group = new Transform3DGroup();
|
||||
group.Children.Add(new RotateTransform3D(new AxisAngleRotation3D(new Vector3D(0, 1, 0), 0)));
|
||||
group.Children.Add(new TranslateTransform3D(new Vector3D()));
|
||||
group.Children.Add(new ScaleTransform3D());
|
||||
|
||||
return group;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 创建3D图形
|
||||
/// </summary>
|
||||
/// <returns>创建的3D图形</returns>
|
||||
private Geometry3D CreateGeometry3D()
|
||||
{
|
||||
MeshGeometry3D geometry = new MeshGeometry3D();
|
||||
|
||||
geometry.Positions = new Point3DCollection();
|
||||
geometry.Positions.Add(new Point3D(-1, 1, 0));
|
||||
geometry.Positions.Add(new Point3D(-1, -1, 0));
|
||||
geometry.Positions.Add(new Point3D(1, -1, 0));
|
||||
geometry.Positions.Add(new Point3D(1, 1, 0));
|
||||
|
||||
geometry.TriangleIndices = new Int32Collection();
|
||||
geometry.TriangleIndices.Add(0);
|
||||
geometry.TriangleIndices.Add(1);
|
||||
geometry.TriangleIndices.Add(2);
|
||||
geometry.TriangleIndices.Add(0);
|
||||
geometry.TriangleIndices.Add(2);
|
||||
geometry.TriangleIndices.Add(3);
|
||||
|
||||
geometry.TextureCoordinates = new PointCollection();
|
||||
geometry.TextureCoordinates.Add(new Point(0, 0));
|
||||
geometry.TextureCoordinates.Add(new Point(0, 1));
|
||||
geometry.TextureCoordinates.Add(new Point(1, 1));
|
||||
geometry.TextureCoordinates.Add(new Point(1, 0));
|
||||
|
||||
return geometry;
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 由指定的图片路径创建一个可视对象
|
||||
/// </summary>
|
||||
/// <param name="imageFile">图片路径</param>
|
||||
/// <returns>创建的可视对象</returns>
|
||||
private Visual CreateVisual(string imageFile, int index)
|
||||
{
|
||||
BitmapImage bmp = null;
|
||||
|
||||
try
|
||||
{
|
||||
bmp = new BitmapImage(new Uri(imageFile));
|
||||
}
|
||||
catch
|
||||
{
|
||||
}
|
||||
|
||||
Image img = new Image();
|
||||
img.Width = 50;
|
||||
img.Source = bmp;
|
||||
|
||||
Border outBordre = new Border();
|
||||
outBordre.BorderBrush = Brushes.White;
|
||||
outBordre.BorderThickness = new Thickness(0.5);
|
||||
outBordre.Child = img;
|
||||
|
||||
outBordre.MouseDown += delegate (object sender, MouseButtonEventArgs e)
|
||||
{
|
||||
this.CurrentMidIndex = index;
|
||||
e.Handled = true;
|
||||
};
|
||||
|
||||
return outBordre;
|
||||
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 重新布局3D内容
|
||||
/// </summary>
|
||||
private void ReLayoutInteractiveVisual3D()
|
||||
{
|
||||
int j = 0;
|
||||
for (int i = 0; i < this.viewport3D.Children.Count; i++)
|
||||
{
|
||||
InteractiveVisual3D iv3d = this.viewport3D.Children[i] as InteractiveVisual3D;
|
||||
if (iv3d != null)
|
||||
{
|
||||
double angle = 0;
|
||||
double offsetX = 0;
|
||||
double offsetZ = 0;
|
||||
this.GetTransformOfInteractiveVisual3D(j++, this.CurrentMidIndex, out angle, out offsetX, out offsetZ);
|
||||
|
||||
|
||||
NameScope.SetNameScope(this, new NameScope());
|
||||
this.RegisterName("iv3d", iv3d);
|
||||
Duration time = new Duration(TimeSpan.FromSeconds(0.3));
|
||||
|
||||
DoubleAnimation angleAnimation = new DoubleAnimation(angle, time);
|
||||
DoubleAnimation xAnimation = new DoubleAnimation(offsetX, time);
|
||||
DoubleAnimation zAnimation = new DoubleAnimation(offsetZ, time);
|
||||
|
||||
Storyboard story = new Storyboard();
|
||||
story.Children.Add(angleAnimation);
|
||||
story.Children.Add(xAnimation);
|
||||
story.Children.Add(zAnimation);
|
||||
|
||||
Storyboard.SetTargetName(angleAnimation, "iv3d");
|
||||
Storyboard.SetTargetName(xAnimation, "iv3d");
|
||||
Storyboard.SetTargetName(zAnimation, "iv3d");
|
||||
|
||||
Storyboard.SetTargetProperty(
|
||||
angleAnimation,
|
||||
new PropertyPath("(ModelVisual3D.Transform).(Transform3DGroup.Children)[0].(RotateTransform3D.Rotation).(AxisAngleRotation3D.Angle)"));
|
||||
|
||||
Storyboard.SetTargetProperty(
|
||||
xAnimation,
|
||||
new PropertyPath("(ModelVisual3D.Transform).(Transform3DGroup.Children)[1].(TranslateTransform3D.OffsetX)"));
|
||||
Storyboard.SetTargetProperty(
|
||||
zAnimation,
|
||||
new PropertyPath("(ModelVisual3D.Transform).(Transform3DGroup.Children)[1].(TranslateTransform3D.OffsetZ)"));
|
||||
|
||||
story.Begin(this);
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 依照InteractiveVisual3D在列表中的序号来变换其位置等
|
||||
/// </summary>
|
||||
/// <param name="index">在列表中的序号</param>
|
||||
/// <param name="midIndex">列表中被作为中间项的序号</param>
|
||||
private void GetTransformOfInteractiveVisual3D(int index, double midIndex, out double angle, out double offsetX, out double offsetZ)
|
||||
{
|
||||
double disToMidIndex = index - midIndex;
|
||||
|
||||
|
||||
//旋转,两翼的图片各旋转一定的度数
|
||||
angle = 0;
|
||||
if (disToMidIndex < 0)
|
||||
{
|
||||
angle = this.ModelAngle;//左边的旋转N度
|
||||
}
|
||||
else if (disToMidIndex > 0)
|
||||
{
|
||||
angle = (-this.ModelAngle);//右边的旋转-N度
|
||||
}
|
||||
|
||||
|
||||
|
||||
//平移,两翼的图片逐渐向X轴负和正两个方向展开
|
||||
offsetX = 0;//中间的不平移
|
||||
if (Math.Abs(disToMidIndex) <= 1)
|
||||
{
|
||||
offsetX = disToMidIndex * this.MidModelDistance;
|
||||
}
|
||||
else if (disToMidIndex != 0)
|
||||
{
|
||||
offsetX = disToMidIndex * this.XDistanceBetweenModels + (disToMidIndex > 0 ? this.MidModelDistance : -this.MidModelDistance);
|
||||
}
|
||||
|
||||
|
||||
//两翼的图片逐渐向Z轴负方向移动一点,造成中间突出(离观众较近的效果)
|
||||
offsetZ = Math.Abs(disToMidIndex) * -this.ZDistanceBetweenModels;
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -8,17 +8,27 @@ using System.Windows;
|
||||
|
||||
namespace Wpf_AiSportsMicrospace.MyUserControl
|
||||
{
|
||||
public class CoverFlowItem : DependencyObject
|
||||
public class CoverFlowItem : INotifyPropertyChanged
|
||||
{
|
||||
private bool _isSelected;
|
||||
private double _progress; // 0~1
|
||||
|
||||
public Uri ImageUri { get; set; }
|
||||
|
||||
public bool IsSelected
|
||||
{
|
||||
get => _isSelected;
|
||||
set { _isSelected = value; OnPropertyChanged(nameof(IsSelected)); }
|
||||
}
|
||||
|
||||
public double Progress
|
||||
{
|
||||
get => (double)GetValue(ProgressProperty);
|
||||
set => SetValue(ProgressProperty, value);
|
||||
get => _progress;
|
||||
set { _progress = value; OnPropertyChanged(nameof(Progress)); }
|
||||
}
|
||||
|
||||
public static readonly DependencyProperty ProgressProperty =
|
||||
DependencyProperty.Register(nameof(Progress), typeof(double), typeof(CoverFlowItem), new PropertyMetadata(0.0));
|
||||
public event PropertyChangedEventHandler PropertyChanged;
|
||||
protected void OnPropertyChanged(string name) =>
|
||||
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(name));
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user