WPF Viewport3D放置组件图像不清晰

desperaso 2018-05-01 09:08:06
Viewport3D内放置组件旋转,组件内包含图像的话,图像不清晰发虚,如何设置?


using System;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Media.Media3D;

public class RotatingEffect
{
private AxisAngleRotation3D axisAngleRotation;
private double delay;

/// <summary>
/// 3D 旋转切换组件
/// </summary>
/// <param name="width">宽度</param>
/// <param name="height">高度</param>
/// <param name="direction">旋转方向 0-横向 1-纵向</param>
/// <param name="control_First">正面显示的组件</param>
/// <param name="control_Second">背面显示的组件</param>
/// <param name="timeDelay">动画时长</param>
/// <returns>Viewport3D 组件</returns>
public Viewport3D rotatingEffect(double width, double height, int direction, UserControl control_First, UserControl control_Second, double timeDelay)
{
delay = timeDelay;
double Mesh_Width = width / 2;
double Mesh_Height = height / 2;

Viewport3D viewport3D = new Viewport3D();
PerspectiveCamera perspectiveCamera = new PerspectiveCamera()
{
Position = new Point3D(0, 0, width * 2), // 可调整
LookDirection = new Vector3D(0, 0, -1),
NearPlaneDistance = 100 // 可调整
};
viewport3D.Camera = perspectiveCamera;
ContainerUIElement3D containerUIElement3D = new ContainerUIElement3D();
DiffuseMaterial diffuseMaterial = new DiffuseMaterial();
Viewport2DVisual3D.SetIsVisualHostMaterial(diffuseMaterial, true);
MeshGeometry3D MeshGeometry_1 = new MeshGeometry3D()
{
TriangleIndices = new Int32Collection(new int[] { 0, 1, 2, 0, 2, 3 }),
TextureCoordinates = new PointCollection(new Point[] { new Point(0, 0), new Point(0, 1), new Point(1, 1), new Point(1, 0) }),
Positions = new Point3DCollection(new Point3D[] {
new Point3D(-Mesh_Width, Mesh_Height, 0),
new Point3D(-Mesh_Width, -Mesh_Height, 0),
new Point3D(Mesh_Width, -Mesh_Height, 0),
new Point3D(Mesh_Width, Mesh_Height, 0)
})
};
Viewport2DVisual3D viewport2DVisual3D_1 = new Viewport2DVisual3D()
{
Geometry = MeshGeometry_1,
Visual = control_First,
Material = diffuseMaterial
};
PointCollection Direction;
Vector3D vector3D;
if (direction == 0)
{
Direction = new PointCollection(new Point[] { new Point(0, 0), new Point(0, 1), new Point(1, 1), new Point(1, 0) });
vector3D = new Vector3D(0, 1, 0);
}
else
{
Direction = new PointCollection(new Point[] { new Point(1, 1), new Point(1, 0), new Point(0, 0), new Point(0, 1) });
vector3D = new Vector3D(1, 0, 0);
}
MeshGeometry3D MeshGeometry_2 = new MeshGeometry3D()
{
TriangleIndices = new Int32Collection(new int[] { 0, 1, 2, 0, 2, 3 }),
TextureCoordinates = Direction,
Positions = new Point3DCollection(new Point3D[] {
new Point3D(Mesh_Width, Mesh_Height, 0),
new Point3D(Mesh_Width, -Mesh_Height, 0),
new Point3D(-Mesh_Width, -Mesh_Height, 0),
new Point3D(-Mesh_Width, Mesh_Height, 0)
})
};
Viewport2DVisual3D viewport2DVisual3D_2 = new Viewport2DVisual3D()
{
Geometry = MeshGeometry_2,
Visual = control_Second,
Material = diffuseMaterial
};
containerUIElement3D.Children.Add(viewport2DVisual3D_1);
containerUIElement3D.Children.Add(viewport2DVisual3D_2);
axisAngleRotation = new AxisAngleRotation3D()
{
Angle = 0,
Axis = vector3D
};
RotateTransform3D rotateTransform3D = new RotateTransform3D()
{
CenterX = 0.5,
CenterY = 0.5,
CenterZ = 0.5,
Rotation = axisAngleRotation
};
containerUIElement3D.Transform = rotateTransform3D;
ModelVisual3D modelVisual3D = new ModelVisual3D()
{
Content = new DirectionalLight(Colors.Transparent, new Vector3D(0, 0, -1))
};
viewport3D.Children.Add(containerUIElement3D);
viewport3D.Children.Add(modelVisual3D);
return viewport3D;
}

/// <summary>
/// 旋转角度
/// </summary>
/// <param name="degrees">角度</param>
public void Turn(double degrees)
{
DoubleAnimation da = new DoubleAnimation();
da.Duration = new Duration(TimeSpan.FromSeconds(delay));
da.To = degrees;
axisAngleRotation.BeginAnimation(AxisAngleRotation3D.AngleProperty, da);
}
}


...全文
925 2 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
xuzuning 2018-05-03
  • 打赏
  • 举报
回复
形变首先牺牲的就是清晰度 角速度过高也会导致模糊,虽然这是软硬件响应速度问题,但符合现实生活
desperaso 2018-05-03
  • 打赏
  • 举报
回复

111,095

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • AIGC Browser
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧