Exemplo n.º 1
0
        public void Init(ModelVisual3D model, Vector3D v1, Vector3D shotDirection)
        {
            this.model = model;

            shotDirection.Normalize();
            Vector3D v2 = v1 - shotDirection * length;
            Vector3D v3 = v1 + shotDirection * 1000;

            Material   material          = new DiffuseMaterial(Brushes.AliceBlue);
            SphereMesh MeshGeneratorBase = new Petzold.Media3D.SphereMesh();

            MeshGeneratorBase.Radius = 2;
            MeshGeometry3D sphere = MeshGeneratorBase.Geometry;

            //EndPoint
            //Vector3D v2 = new Vector3D(-30, -30, 0);
            EndPoint           = new GeometryModel3D(sphere, new DiffuseMaterial(Brushes.BurlyWood));
            EndPoint.Transform = new TranslateTransform3D(v2);

            cylinder          = new Cylinder();
            cylinder.Fold1    = 0.25;
            cylinder.Fold2    = 0.75;
            cylinder.Radius1  = 0.5;
            cylinder.Radius2  = 2;
            cylinder.Material = material;
            cylinder.Point1   = new Point3D(v1.X, v1.Y, v1.Z);
            cylinder.Point2   = new Point3D(v2.X, v2.Y, v2.Z);

            cylinder2          = new Cylinder();
            cylinder2.Fold1    = 0.25;
            cylinder2.Fold2    = 0.75;
            cylinder2.Radius1  = 0.1;
            cylinder2.Radius2  = 0.1;
            cylinder2.Material = new DiffuseMaterial(Brushes.Green);
            cylinder2.Point1   = new Point3D(v1.X, v1.Y, v1.Z);
            cylinder2.Point2   = new Point3D(v3.X, v3.Y, v3.Z);

            stickVisualModel         = new ModelVisual3D();
            stickVisualModel.Content = EndPoint;
            stickVisualModel.Children.Add(cylinder);

            stickVisualModel.Children.Add(cylinder2);

            model.Children.Add(stickVisualModel);

            cylinder.Material = new DiffuseMaterial(Brushes.BurlyWood);
        }
Exemplo n.º 2
0
        public Window1()
        {
            InitializeComponent();

            //group.Transform = new Transform3DGroup();
            model.Transform = new Transform3DGroup();

            Material          material          = new DiffuseMaterial(Brushes.AliceBlue);
            MeshGeneratorBase MeshGeneratorBase = new Petzold.Media3D.SphereMesh();
            MeshGeometry3D    sphere            = MeshGeneratorBase.Geometry;

            //StarPoint
            Vector3D             v1                    = new Vector3D(30, 30, 0);
            GeometryModel3D      StartPoint            = new GeometryModel3D(sphere, material);
            TranslateTransform3D translateTransform3D1 = new TranslateTransform3D(v1);
            Transform3DGroup     transform3DGroup1     = new Transform3DGroup();

            transform3DGroup1.Children.Add(new ScaleTransform3D(2, 2, 2));
            transform3DGroup1.Children.Add(translateTransform3D1);
            StartPoint.Transform = transform3DGroup1;

            //EndPoint
            Vector3D        v2       = new Vector3D(-30, -30, 0);
            GeometryModel3D EndPoint = new GeometryModel3D(sphere, new DiffuseMaterial(Brushes.BurlyWood));

            EndPoint.Transform = new TranslateTransform3D(v2);

            //ModelVisual3D modelVisual3D = new ModelVisual3D();
            //modelVisual3D.Content = StartPoint;
            //model.Children.Add(modelVisual3D);

            Model3DGroup model3DGroup = new Model3DGroup();

            model3DGroup.Children.Add(StartPoint);
            model3DGroup.Children.Add(EndPoint);
            model.Content = model3DGroup;
            //model.Content = StartPoint;
            //model.Content = EndPoint;

            Cylinder cylinder = new Cylinder();

            cylinder.Fold1    = 0.25;
            cylinder.Fold2    = 0.75;
            cylinder.Radius1  = 0.3;
            cylinder.Radius2  = 1.0;
            cylinder.Material = material;
            cylinder.Point1   = new Point3D(v1.X, v1.Y, v1.Z);
            cylinder.Point2   = new Point3D(v2.X, v2.Y, v2.Z);
            model.Children.Add(cylinder);

            cylinder.Material = new DiffuseMaterial(Brushes.BurlyWood);

            //ScreenSpaceLines3D ssl3D = new ScreenSpaceLines3D();
            //ssl3D.Color = Colors.White;
            //Point3DCollection gridLines = new Point3DCollection();

            //gridLines.Add(new Point3D(100, 0, 0));
            //gridLines.Add(new Point3D(-100, 0, 0));

            //int size = 100;
            //int interval = 10;
            //int len = 1000;

            //for (int i = -size; i <= size; i++)
            //{
            //    for (int j = -size; j <= size; j++)
            //    {
            //        // convert the loop iterators into the required grid cell size interval, relative to len
            //        double a = i * interval;
            //        double b = j * interval;

            //        // x line
            //        gridLines.Add(new Point3D(0, a, b));
            //        gridLines.Add(new Point3D(len, a, b));

            //        // y line
            //        gridLines.Add(new Point3D(a, 0, b));
            //        gridLines.Add(new Point3D(a, len, b));

            //        // z line
            //        gridLines.Add(new Point3D(a, b, 0));
            //        gridLines.Add(new Point3D(a, b, len));
            //    }
            //}
            //ssl3D.Points = gridLines;
            //ssl3D.Color = Colors.Red;
            //ssl3D.Thickness = 5;
            ////this.mainViewport.Children.Add(ssl3D);

            //viewport.Children.Add(ssl3D);
        }