最基本的3D代码对照

xaml代码

<Viewport3D>
<Viewport3D.Camera>
<PerspectiveCamera Position="0, 0, 4"/>
</Viewport3D.Camera> <!-- Button on 3D -->
<Viewport2DVisual3D>
<!-- Give the plane a slight rotation -->
<Viewport2DVisual3D.Transform>
<RotateTransform3D>
<RotateTransform3D.Rotation>
<AxisAngleRotation3D Angle="" Axis="0, 1, 0" />
</RotateTransform3D.Rotation>
</RotateTransform3D>
</Viewport2DVisual3D.Transform> <!-- The Geometry, Material, and Visual for the Viewport2DVisual3D -->
<Viewport2DVisual3D.Geometry>
<MeshGeometry3D Positions="-1,1,0 -1,-1,0 1,-1,0 1,1,0"
TextureCoordinates="0,0 0,1 1,1 1,0" TriangleIndices="0 1 2 0 2 3"/>
</Viewport2DVisual3D.Geometry> <Viewport2DVisual3D.Material>
<DiffuseMaterial Viewport2DVisual3D.IsVisualHostMaterial="True" Brush="White"/>
</Viewport2DVisual3D.Material> <Button>Hello, 3D</Button>
</Viewport2DVisual3D> <!-- Lights -->
<ModelVisual3D>
<ModelVisual3D.Content>
<DirectionalLight Color="#FFFFFFFF" Direction="0,0,-1"/>
</ModelVisual3D.Content>
</ModelVisual3D>
</Viewport3D>

cs后台对照写法

private void Init_Draw()
{
Viewport3D viewport3D = new Viewport3D();
PerspectiveCamera perspectiveCamera = new PerspectiveCamera()
{
Position = new Point3D(, , ),
};
viewport3D.Camera = perspectiveCamera; Viewport2DVisual3D viewport2DVisual3D = new Viewport2DVisual3D();
RotateTransform3D rotateTransform3D = new RotateTransform3D();
AxisAngleRotation3D axisAngleRotation3D = new AxisAngleRotation3D()
{
Angle = ,
Axis = new Vector3D(, , ),
};
rotateTransform3D.Rotation = axisAngleRotation3D;
viewport2DVisual3D.Transform = rotateTransform3D; MeshGeometry3D meshGeometry3D = new MeshGeometry3D()
{
Positions = new Point3DCollection(new Point3D[] { new Point3D(-, , ), new Point3D(-, -, ), new Point3D(, -, ), new Point3D(, , ) }),
TextureCoordinates = new PointCollection { new Point(, ), new Point(, ), new Point(, ), new Point(, ) },
TriangleIndices = new Int32Collection(new int[] { , , , , , }),
};
viewport2DVisual3D.Geometry = meshGeometry3D; DiffuseMaterial diffuseMaterial = new DiffuseMaterial();
Viewport2DVisual3D.SetIsVisualHostMaterial(diffuseMaterial, true);
viewport2DVisual3D.Material = diffuseMaterial; Button button = new Button()
{
Content = "Hello,3D",
          Direction = new Vector3D(0, 0, -1),
};
viewport2DVisual3D.Visual = button; ModelVisual3D modelVisual3D = new ModelVisual3D();
DirectionalLight directionalLight = new DirectionalLight()
{
Color = Color.FromRgb(, , ),
Direction = new Vector3D(0, 0, -1),
};
modelVisual3D.Content = directionalLight; viewport3D.Children.Add(viewport2DVisual3D);
viewport3D.Children.Add(modelVisual3D); Grid组件.Children.Add(viewport3D);
}

引伸一下,按照1:1大小显示原始组件,写入原始宽度和高度。显示出来的是原始UserControl的大小

private void Init_Draw(FrameworkElement element,double width,double height)
{
double Mesh_Width = width / ;
double Mesh_Height = height / ; Viewport3D viewport3D = new Viewport3D();
viewport3D.Width = width * ; PerspectiveCamera perspectiveCamera = new PerspectiveCamera();
double fieldOfViewInRadians = perspectiveCamera.FieldOfView * (Math.PI / 180.0);
var z = (0.5 * viewport3D.Width) / Math.Tan(0.5 * fieldOfViewInRadians);
perspectiveCamera.Position = new Point3D(, , z); perspectiveCamera.LookDirection = new Vector3D(, , -);
viewport3D.Camera = perspectiveCamera; Viewport2DVisual3D viewport2DVisual3D = new Viewport2DVisual3D();
RotateTransform3D rotateTransform3D = new RotateTransform3D();
axisAngleRotation3D = new AxisAngleRotation3D()
{
Angle = ,
Axis = new Vector3D(, , ),
};
rotateTransform3D.Rotation = axisAngleRotation3D;
viewport2DVisual3D.Transform = rotateTransform3D; MeshGeometry3D meshGeometry3D = new MeshGeometry3D()
{
Positions = new Point3DCollection(new Point3D[] {
new Point3D(-Mesh_Width, Mesh_Height, ),
new Point3D(-Mesh_Width, -Mesh_Height, ),
new Point3D(Mesh_Width, -Mesh_Height, ),
new Point3D(Mesh_Width, Mesh_Height, )
}
),
TextureCoordinates = new PointCollection { new Point(, ), new Point(, ), new Point(, ), new Point(, ) },
TriangleIndices = new Int32Collection(new int[] { , , , , , }),
};
viewport2DVisual3D.Geometry = meshGeometry3D; DiffuseMaterial diffuseMaterial = new DiffuseMaterial();
Viewport2DVisual3D.SetIsVisualHostMaterial(diffuseMaterial, true);
viewport2DVisual3D.Material = diffuseMaterial; viewport2DVisual3D.Visual = element;
element.MouseDown += Element_MouseDown; ModelVisual3D modelVisual3D = new ModelVisual3D();
DirectionalLight directionalLight = new DirectionalLight()
{
Color = Color.FromRgb(, , ),
Direction = new Vector3D(, , -),
};
modelVisual3D.Content = directionalLight; viewport3D.Children.Add(viewport2DVisual3D);
viewport3D.Children.Add(modelVisual3D); MainGrid.Children.Add(viewport3D);
}

WPF 最基本的前后台代码对照的更多相关文章

  1. 分页 工具类 前后台代码 Java JavaScript (ajax) 实现 讲解

    [博客园cnblogs笔者m-yb原创, 转载请加本文博客链接,笔者github: https://github.com/mayangbo666,公众号aandb7,QQ群927113708]http ...

  2. FreeMarker中的list集合前后台代码

    freemarker中的list集合前后台代码: FreeMarker是一款模板引擎: 即一种基于模板和要改变的数据, 并用来生成输出文本(HTML网页.电子邮件.配置文件.源代码等)的通用工具. 它 ...

  3. 示例:WPF中自定义StoryBoarService在代码中封装StoryBoard、Animation用于简化动画编写

    原文:示例:WPF中自定义StoryBoarService在代码中封装StoryBoard.Animation用于简化动画编写 一.目的:通过对StoryBoard和Animation的封装来简化动画 ...

  4. 捕捉WPF应用程序中XAML代码解析异常

    原文:捕捉WPF应用程序中XAML代码解析异常 由于WPF应用程序中XAML代码在很多时候是运行时加载处理的.比如DynamicResource,但是在编译或者运行的过程中,编写的XAML代码很可能有 ...

  5. WPF DataGrid分页功能实现代码

    在Silverlight中DataGrid分页可以结合DataPager控件很容易实现,但是在WPF中没有类似的,需要手动实现这样一个控件: 1.创建一个UserControl,DP.xaml,代码如 ...

  6. WPF设计界面不执行代码

    一般在我们在设计WPF XAML界面时,XAML 引用一些后端的类.比如UserControl.Converter.MVVM,引用 xmlns:ALLUserControl="clr-nam ...

  7. WPF/WP/Silverlight/Metro App代码创建动画的思路

    在2010年之前,我都是用Blend创建动画,添加触发器实现自动动画,后来写成代码创建的方式.如今Blend已经集成到Visual Studio安装镜像中了,最新的VS2015安装,Blend的操作界 ...

  8. [WPF自定义控件库] 自定义控件的代码如何与ControlTemplate交互

    1. 前言 WPF有一个灵活的UI框架,用户可以轻松地使用代码控制控件的外观.例设我需要一个控件在鼠标进入的时候背景变成蓝色,我可以用下面这段代码实现: protected override void ...

  9. 将Winform和wpf的界面转换为CPF代码用来实现跨平台

    CPF的设计器里带界面代码转换功能,将运行中的Winform或者wpf的程序界面转换为cpf代码,主要转换控件类型和布局,默认支持的是常用的原生控件.不支持Netcore,只支持.Netframewo ...

随机推荐

  1. 五月天的线上演唱会你看了吗?用Python分析网友对这场线上演唱会的看法

    前言 本文的文字及图片来源于网络,仅供学习.交流使用,不具有任何商业用途,版权归原作者所有,如有问题请及时联系我们以作处理. 作者:CDA数据分析师 豆瓣9.4分!这场线上演唱会到底多好看? 首先让我 ...

  2. .NetCore对接各大财务软件凭证API——用友系列(2)

    一. 前言 今天我们继续来分析用友系列的第二个产品--U8Cloud2.5 ,apilink方式的API.官网的API文档地址如下:U8API文档 因为我们主要是凭证对接,所以使用到的模块有总账.基础 ...

  3. shell编程(一):功能、执行、基础

    1.shell的功能 (1)自动化批量初始化系统:对N台系统初始化(装系统时对系统的时区.yum源.软件包的更新.安全的设置进行初始化) (2)自动化批量部署软件程序:(LAMP/LNMP/Tomca ...

  4. 从零开始的Spring Boot(1、搭建一个Spring Boot项目Hello World)

    搭建一个Spring Boot项目Hello World 写在前面 从零开始的Spring Boot(2.在Spring Boot中整合Servlet.Filter.Listener的方式):http ...

  5. opencv3.1.0 计算机中丢失 opencv_world310d.dll _vs2017解决方法

    ---------------------------opencv1.exe - 系统错误---------------------------无法启动此程序,因为计算机中丢失 opencv_worl ...

  6. 为什么启动线程是start方法?

    为什么启动线程是start方法 十年可见春去秋来,百年可证生老病死,千年可叹王朝更替,万年可见斗转星移.   凡人如果用一天的视野,去窥探百万年的天地,是否就如同井底之蛙? 背景:启动线程是start ...

  7. MDX

    简介 把md文件里的图片转成base64,方便发给别人和上传博客园等博客平台 初衷 用Typora写markdown的感觉很爽,但是每当我写好一篇文章,想要发给小伙伴们炫耀炫耀,或者上传博客园,CSD ...

  8. GoAccess分析Web日志

    简介 为什么要用GoAccess? GoAccess 被设计成快速的并基于终端的日志分析工具.其核心理念是不需要通过 Web 浏览器就能快速分析并实时查看 Web 服务器的统计数据(这对于需要使用 S ...

  9. 探索ADC的原理(自制3位并行比较型ADC)

    摘要 本文通过列举历史中出现的产品,梳理了模数转换器在20世纪30年代~~20世纪80年代末的发展历史.接下来,简要介绍模数转换器的原理.技术指标.分类和未来发展方向.最后,提供了一种自制3位FLAS ...

  10. yum 安装JDK

    系统:CentOS 7 查看当前系统是否已安装JDK yum list installed |grep java 如果没有就选择yum库中的包进行安装,查看yum库中JDK列表 yum -y list ...