我希望能在程序运行过程中通过输入三维坐标添加个球~~不知道该如何实现我几乎所有的图形构造都是在XAML里完成的~~不知道应该怎么关联输入的坐标以及按钮的触发还有就是关于3DTOOLS里的screenspaceline功能~~我看例子程序里通过选一个选项就能显示实体或者框架但是不知道该怎么做还是代码部分求助啊

解决方案 »

  1.   

    问错地方了,这里人都不研究WPF
      

  2.   

    你可以上msdn中文论坛上问问:http://social.microsoft.com/Forums/zh-CN/wpfzhchs/threads另外在silverlight版也可以问问看。
      

  3.   

    后台写3D和摁下button时旋转,比较粗糙,如果是球需要循环用三角拼起来。    public partial class MainWindow : Window
        {
            Viewport3D viewport = new Viewport3D();
            Model3DGroup modelgroup = new Model3DGroup();
            GeometryModel3D geomodel = new GeometryModel3D();
            ModelVisual3D modelvisual = new ModelVisual3D();
            MeshGeometry3D mgeo = new MeshGeometry3D();
            MatrixTransform3D mt3d = new MatrixTransform3D();
            public MainWindow()
            {
                InitializeComponent();
                viewport.Camera = new PerspectiveCamera(new Point3D(0, 0, 3), new Vector3D(0, 0, -1), new Vector3D(1, 1, -1), 45);
                modelgroup.Children.Add(new DirectionalLight(Colors.White, new Vector3D(-1, -1, -1)));
                mgeo.Normals.Add(new Vector3D(0, 0, 1));
                mgeo.Normals.Add(new Vector3D(0, 0, 1));
                mgeo.Normals.Add(new Vector3D(0, 0, 1));
                mgeo.Normals.Add(new Vector3D(0, 0, 1));
                mgeo.Normals.Add(new Vector3D(0, 0, 1));
                mgeo.Normals.Add(new Vector3D(0, 0, 1));
                mgeo.Positions.Add(new Point3D(-0.5, -0.5, 0.5));
                mgeo.Positions.Add(new Point3D(0.5, -0.5, 0.5));
                mgeo.Positions.Add(new Point3D(0.5, 0.5, 0.5));
                mgeo.Positions.Add(new Point3D(0.5, 0.5, 0.5));
                mgeo.Positions.Add(new Point3D(-0.5, 0.5, 0.5));
                mgeo.Positions.Add(new Point3D(-0.5, -0.5, 0.5));
                mgeo.TextureCoordinates.Add(new Point(0, 0));
                mgeo.TextureCoordinates.Add(new Point(1, 0));
                mgeo.TextureCoordinates.Add(new Point(1, 1));
                mgeo.TextureCoordinates.Add(new Point(1, 1));
                mgeo.TextureCoordinates.Add(new Point(0, 1));
                mgeo.TextureCoordinates.Add(new Point(0, 0));
                mgeo.TriangleIndices.Add(0);
                mgeo.TriangleIndices.Add(1);
                mgeo.TriangleIndices.Add(2);
                mgeo.TriangleIndices.Add(3);
                mgeo.TriangleIndices.Add(4);
                mgeo.TriangleIndices.Add(5);
                geomodel.Geometry = mgeo; 
                geomodel.Material = new DiffuseMaterial(Brushes.Blue);
                geomodel.Transform = mt3d;
                modelgroup.Children.Add(geomodel);
                modelvisual.Content = modelgroup;
                viewport.Children.Add(modelvisual);
                grid1.Children.Add(viewport);
            }
            double i;
            private void button1_Click(object sender, RoutedEventArgs e)
            {
                i+=0.01;
                Matrix3D matrix = new Matrix3D();
                matrix.M11 = Math.Sin(i);
                matrix.M12 = Math.Cos(i);
                matrix.M13 = -Math.Sin(i);
                matrix.M21 = -Math.Cos(i);
                matrix.M22 = Math.Sin(i);
                matrix.M23 = Math.Cos(i);
                matrix.M31 = Math.Sin(i);
                matrix.M32 = -Math.Cos(i);
                matrix.M33 = Math.Cos(i);
                mt3d.Matrix = matrix;
            }
        }