嘿,亲!知识可是无价之宝呢,但咱这精心整理的资料也耗费了不少心血呀。小小地破费一下,绝对物超所值哦!如有下载和支付问题,请联系我们QQ(微信同号):78630559
本次赞助数额为: 1 元微信扫码支付:1 元
请留下您的邮箱,我们将在2小时内将文件发到您的邮箱
WPF 3D照片效果(翻转和预览)
/// <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>
/// 创建一个空的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>
/// <param name="imageFile"></param>
/// <returns></returns>
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>
/// 依照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;
}
/// <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);
}
}
}