WPF中WayFinder应用程序的实现 [英] Implementation of WayFinder application in wpf

查看:51
本文介绍了WPF中WayFinder应用程序的实现的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我必须实现Wayfinder才能显示两个位置之间的路径,例如购物中心.我该怎么做.请提出建议.

I have to implement Wayfinder to show path between two location like a mall.How can I do this.Please Suggest me.

推荐答案

据我所知,Windows Presentation Foundation(WPF)中的3-D功能使开发人员可以在标记和过程代码中绘制,变换和制作3-D图形动画.

As far as I know, the 3-D functionality in Windows Presentation Foundation (WPF) enables developers to draw, transform, and animate 3-D graphics in both markup and procedural code.

3-D图形概述

这是一个简单的示例,您可以看到:

Here is a simple sample you can see:

 public partial class sample3 : Window
    {
        public sample3()
        {
            InitializeComponent();
        }
        // Save the current image.
        private void mnuSave_Click(Object sender, RoutedEventArgs e)
        {
            // Draw the viewport into a RenderTargetBitmap.
            RenderTargetBitmap bm = new RenderTargetBitmap(
                (int)dockCube.ActualWidth, (int)dockCube.ActualHeight,
                96, 96, PixelFormats.Pbgra32);
            bm.Render(dockCube);

            // Make a PNG encoder.
            PngBitmapEncoder encoder = new PngBitmapEncoder();
            encoder.Frames.Add(BitmapFrame.Create(bm));

            // Save the file.
            using (FileStream fs = new FileStream("Saved.png",
                FileMode.Create, FileAccess.Write, FileShare.None))
            {
                encoder.Save(fs);
            }

            System.Media.SystemSounds.Beep.Play();
        }

        // Move the camera to the indicated position looking back at the origin.
        private void PositionCamera(float x, float y, float z, float yup)
        {
            hscroll.Value = 0;
            vscroll.Value = 0;
            PerspectiveCamera the_camera = viewCube.Camera as PerspectiveCamera;
            the_camera.Position = new Point3D(x, y, z);
            the_camera.LookDirection = new Vector3D(-x, -y, -z);
            the_camera.UpDirection = new Vector3D(0, yup, 0);

            Console.WriteLine(the_camera.Position.ToString());
            Console.WriteLine(the_camera.LookDirection.ToString());
            Console.WriteLine(the_camera.UpDirection.ToString());
            Console.WriteLine("**********");
        }

        // Move the camera to a specific position.
        private void btnView_Click(Object sender, RoutedEventArgs e)
        {
            MenuItem item = sender as MenuItem;
            string txt = item.Header.ToString().Replace("(", "").Replace(")", "");
            string[] values = txt.Split(',');
            float x = 3 * float.Parse(values[0]);
            float y = 3 * float.Parse(values[1]);
            float z = 3 * float.Parse(values[2]);
            float yup = y > 0 ? 1 : -1;
            PositionCamera(x, y, z, yup);
        }
    }

  <DockPanel Margin="0" >
        <Menu DockPanel.Dock="Top">
            <MenuItem Header="File" Name="mnuSave" Click="mnuSave_Click">Save</MenuItem>
            <MenuItem Header="View">
                <MenuItem Header="(1, 1, 1)" Name="mnuView111" Click="btnView_Click" />
                <MenuItem Header="(1, 1, -1)" Name="mnuView11_1" Click="btnView_Click" />
                <MenuItem Header="(-1, 1, -1)" Name="mnuView_11_1" Click="btnView_Click" />
                <MenuItem Header="(-1, 1, 1)" Name="mnuView_111" Click="btnView_Click" />

                <MenuItem Header="(1, -1, 1)" Name="mnuView1_11" Click="btnView_Click" />
                <MenuItem Header="(1, -1, -1)" Name="mnuView1_1_1" Click="btnView_Click" />
                <MenuItem Header="(-1, -1, -1)" Name="mnuView_1_1_1" Click="btnView_Click" />
                <MenuItem Header="(-1, -1, 1)" Name="mnuView_1_11" Click="btnView_Click" />
            </MenuItem>
        </Menu>
        <ScrollBar Name="hscroll" 
	      DockPanel.Dock="Bottom"
	      Orientation="Horizontal" 
	      Minimum="-180" Maximum="180" 
	      LargeChange="10" SmallChange="1" Value="0" />
        <ScrollBar Name="vscroll" 
	      DockPanel.Dock="Right"
	      Orientation="Vertical"
	      Minimum="-180" Maximum="180" 
	      LargeChange="10" SmallChange="1" Value="0" />

        <!--
           - The dockOuter control prevents the rendering
           - from including an implicit margin around dockCube
          -->
        <DockPanel Margin="0" Name="dockOuter" Background="White">
            <DockPanel Margin="0" Name="dockCube" Background="White">
                <Viewport3D Margin="0" Name="viewCube">
                    <ModelVisual3D>
                        <ModelVisual3D.Content>
                            <Model3DGroup>
                                <!-- Lights -->
                                <AmbientLight Color="Gray" />
                                <DirectionalLight Color="Gray" Direction="1,-2,-3" />
                                <DirectionalLight Color="Gray" Direction="-1,2,3" />

                                <!-- Top -->
                                <GeometryModel3D>
                                    <GeometryModel3D.Geometry>
                                        <MeshGeometry3D
                                            Positions = "-1,1,1 1,1,1 1,1,-1 -1,1,-1"
	                                        TriangleIndices = "0 1 2     2,3,0"
                                            TextureCoordinates="0,1 1,1 1,0 0,0"
                                        />
                                    </GeometryModel3D.Geometry>
                                    <GeometryModel3D.Material>
                                        <DiffuseMaterial>
                                            <DiffuseMaterial.Brush>
                                                <ImageBrush ImageSource="images\Top.png"/>
                                            </DiffuseMaterial.Brush>
                                        </DiffuseMaterial>
                                    </GeometryModel3D.Material>
                                </GeometryModel3D>

                                <!-- Front -->
                                <GeometryModel3D>
                                    <GeometryModel3D.Geometry>
                                        <MeshGeometry3D
                                            Positions = "-1,-1,1 1,-1,1 1,1,1 -1,1,1"
	                                        TriangleIndices = "0 1 2     2,3,0"
                                            TextureCoordinates="0,1 1,1 1,0 0,0"
                                        />
                                    </GeometryModel3D.Geometry>
                                    <GeometryModel3D.Material>
                                        <DiffuseMaterial>
                                            <DiffuseMaterial.Brush>
                                                <ImageBrush ImageSource="images\Front.png"/>
                                            </DiffuseMaterial.Brush>
                                        </DiffuseMaterial>
                                    </GeometryModel3D.Material>
                                </GeometryModel3D>

                                <!-- Right -->
                                <GeometryModel3D>
                                    <GeometryModel3D.Geometry>
                                        <MeshGeometry3D
                                            Positions = "1,-1,1 1,-1,-1 1,1,-1 1,1,1"
	                                        TriangleIndices = "0 1 2     2,3,0"
                                            TextureCoordinates="0,1 1,1 1,0 0,0"
                                        />
                                    </GeometryModel3D.Geometry>
                                    <GeometryModel3D.Material>
                                        <DiffuseMaterial>
                                            <DiffuseMaterial.Brush>
                                                <ImageBrush ImageSource="images\Right.png"/>
                                            </DiffuseMaterial.Brush>
                                        </DiffuseMaterial>
                                    </GeometryModel3D.Material>
                                </GeometryModel3D>

                                <!-- Left -->
                                <GeometryModel3D>
                                    <GeometryModel3D.Geometry>
                                        <MeshGeometry3D
                                            Positions = "-1,-1,-1 -1,-1,1 -1,1,1 -1,1,-1"
	                                        TriangleIndices = "0 1 2     2,3,0"
                                            TextureCoordinates="0,1 1,1 1,0 0,0"
                                        />
                                    </GeometryModel3D.Geometry>
                                    <GeometryModel3D.Material>
                                        <DiffuseMaterial>
                                            <DiffuseMaterial.Brush>
                                                <ImageBrush ImageSource="images\Left.png"/>
                                            </DiffuseMaterial.Brush>
                                        </DiffuseMaterial>
                                    </GeometryModel3D.Material>
                                </GeometryModel3D>

                                <!-- Back -->
                                <GeometryModel3D>
                                    <GeometryModel3D.Geometry>
                                        <MeshGeometry3D
                                            Positions = "1,-1,-1 -1,-1,-1 -1,1,-1 1,1,-1"
	                                        TriangleIndices = "0 1 2     2,3,0"
                                            TextureCoordinates="0,1 1,1 1,0 0,0"
                                        />
                                    </GeometryModel3D.Geometry>
                                    <GeometryModel3D.Material>
                                        <DiffuseMaterial>
                                            <DiffuseMaterial.Brush>
                                                <ImageBrush ImageSource="images\Back.png"/>
                                            </DiffuseMaterial.Brush>
                                        </DiffuseMaterial>
                                    </GeometryModel3D.Material>
                                </GeometryModel3D>

                                <!-- Bottom -->
                                <GeometryModel3D>
                                    <GeometryModel3D.Geometry>
                                        <MeshGeometry3D
                                            Positions = "-1,-1,-1 1,-1,-1 1,-1,1 -1,-1,1"
	                                        TriangleIndices = "0 1 2     2,3,0"
                                            TextureCoordinates="0,1 1,1 1,0 0,0"
                                        />
                                    </GeometryModel3D.Geometry>
                                    <GeometryModel3D.Material>
                                        <DiffuseMaterial>
                                            <DiffuseMaterial.Brush>
                                                <ImageBrush ImageSource="images\Bottom.png"/>
                                            </DiffuseMaterial.Brush>
                                        </DiffuseMaterial>
                                    </GeometryModel3D.Material>
                                </GeometryModel3D>
                            </Model3DGroup>
                        </ModelVisual3D.Content>
                    </ModelVisual3D>

                    <Viewport3D.Camera>
                        <PerspectiveCamera
                          Position = "1.75, 2.75, 2.75"
                          LookDirection = "-1.75, -2.75, -2.75"
                          UpDirection = "0, 1, 0"
                          FieldOfView = "60">
                            <PerspectiveCamera.Transform>
                                <Transform3DGroup>
                                    <RotateTransform3D>
                                        <RotateTransform3D.Rotation>
                                            <AxisAngleRotation3D
	                                          Axis="0 1 0" 
	                                          Angle="{Binding ElementName=hscroll, Path=Value}" />
                                        </RotateTransform3D.Rotation>
                                    </RotateTransform3D>
                                    <RotateTransform3D>
                                        <RotateTransform3D.Rotation>
                                            <AxisAngleRotation3D
	                                          Axis="1 0 0" 
	                                          Angle="{Binding ElementName=vscroll, Path=Value}" />
                                        </RotateTransform3D.Rotation>
                                    </RotateTransform3D>
                                </Transform3DGroup>
                            </PerspectiveCamera.Transform>
                        </PerspectiveCamera>
                    </Viewport3D.Camera>
                </Viewport3D>
            </DockPanel>
        </DockPanel>
    </DockPanel>


在3D开发过程中,我们必须首先清除三维坐标系,以便构建所需的3D模型,以及根据3D模型上的照片拍摄的光线(环境光线除外) 灯光)以获取不同的照明效果,并指定适当的 相机(Camera)的位置,以查看要查看的3D投影.

3D开发中的所有几何图形最终都由一系列三角形组成. 您还需要考虑将3D模型分解为三角形. 听到起来很麻烦,幸运的是,有一些辅助类可以帮助您处理这些三角形的分解,而您要做的是提供坐标系的关键点.

因为WPF 3D基于Direct 3D,并且WPF 2D直接用作图形渲染,并且默认使用开放全景抗锯齿(在某种情况下,您需要支持兼容的WDDM兼容图形). span>


In the 3D development process, we must first clear the three-dimensional coordinate system, so as to build the desired 3D Model, and the light according to the photo on the 3D model (except for ambient light) to get different lighting effects, and specify the appropriate Camera (Camera) position to see you want to see the 3D projection.

All the geometry in 3D development is ultimately composed of a series of triangles. You also need to consider breaking your 3D model into triangles. It is very cumbersome to hear, and fortunately there are some auxiliary classes to help you to deal with the decomposition of these triangles, and you are doing is to provide the key point of the coordinate system.

Because WPF 3D is based on Direct 3D, and WPF 2D as the direct use of graphics rendering, and the default open panorama anti-aliasing (there is a condition, you need to support compatible graphics WDDM-Compliant).

3D开发比2D开发更为复杂,需要考虑很多事情. 但是要获得更真实,更酷的效果,值得您学习. 祝您3D开发之旅愉快!

I wish you a trip to 3D development, all the way happy!

我希望这会引导您朝着正确的方向发展,并考虑将此问题标记为已回答.

I hope this guides you in a good direction, if possible, consider marking this question as answered.

最好的问候,

鲍勃


这篇关于WPF中WayFinder应用程序的实现的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆