Beispiel #1
0
        protected override Model3D CreateModel(params object[] vs)
        {
            MyLib.AssertTypes(vs, typeof(Point3D), typeof(Vector3D), typeof(Color), typeof(double), typeof(double), typeof(double), typeof(double));
            Position        = (Point3D)vs[0];
            Speed           = (Vector3D)vs[1];
            Color           = (Color)vs[2];
            RadiusStart     = (double)vs[3];
            RadiusEnd       = (double)vs[4];
            LifeTime        = (double)vs[5];
            SpeedRandomness = (double)vs[6];
            const int      n         = 10;
            List <Point3D> positions = new List <Point3D>();

            for (int i = 0; i < n; i++)
            {
                positions.Add(new Point3D(RadiusStart * Math.Cos(2 * Math.PI * i / n), RadiusStart * Math.Sin(2 * Math.PI * i / n), 0));
            }
            List <int> triangleIndices = new List <int>();

            for (int i = 2; i < n; i++)
            {
                triangleIndices.AddRange(new[] { 0, i - 1, i });
            }
            return(My3DGraphics.NewModel().AddTriangles(positions, triangleIndices).CreateModel(new SolidColorBrush(Color)));
        }
Beispiel #2
0
 protected override Model3D CreateModel(params object[] vs)
 {
     SubTransforms.Add(new MatrixTransform3D());
     MyLib.AssertTypes(vs, typeof(Point3D));
     Position = (Point3D)vs[0];
     My3DGraphics.Cuboid.AddFaces(new Point3D(0.1, 0.1, 0.1), out List <Point3D> vertices, out List <int> triangleIndices, out List <Vector3D> normals);
     return(My3DGraphics.NewModel().AddTriangles(vertices, triangleIndices, normals).CreateModel(new SolidColorBrush(Colors.White)));
 }
Beispiel #3
0
 Model3D CreateBodyModel()
 {
     //double r = 1.5;
     ///6 7
     ///4 5
     ///
     ///2 3
     ///0 1
     //var vertices = new List<Point3D>{, new Point3D(r, -r, -r), new Point3D(-r, r, -r), new Point3D(r, r, -r), new Point3D(-r, -r, r), new Point3D(r, -r, r), new Point3D(-r, r, r), new Point3D(r, r, r) };
     My3DGraphics.Cuboid.AddFaces(new Point3D(BodyRadius, BodyRadius, BodyRadius), out List <Point3D> vertices, out List <int> triangleIndices, out List <Vector3D> normals);
     return(My3DGraphics.NewModel().AddTriangles(vertices, triangleIndices, normals).CreateModel(new SolidColorBrush(Colors.PeachPuff)));
 }
                    Model3DGroup CreateModel(Description description, double scale, double angle, bool reversed)
                    {
                        var vs = description.Vertexes.Select(v => v.Multiply(scale));

                        if (reversed)
                        {
                            vs    = vs.Select(v => new Point3D(v.X, -v.Y, v.Z)).Reverse();
                            angle = -angle;
                        }
                        var front = My3DGraphics.NewModel().AddTriangles(vs, new[] { 3, 2, 0, 2, 1, 0 }).CreateModel(Brushes.Violet);
                        var back  = My3DGraphics.NewModel().AddTriangles(vs, new[] { 0, 1, 2, 0, 2, 3 }).CreateModel(Brushes.DarkViolet);

                        front.Transform = back.Transform = MyLib.Transform(front).Rotate(new Vector3D(1, 0, 0), angle).Value;
                        return(new Model3DGroup()
                        {
                            Children = { front, back }
                        });
                    }
Beispiel #5
0
                protected override Model3D CreateModel(params object[] vs)
                {
                    MyLib.AssertTypes(vs, typeof(double), typeof(double), typeof(double), typeof(Color));
                    double r                    = (double)vs[0];
                    double coneAngle            = (double)vs[1];
                    double attackAngle          = (double)vs[2];
                    var    color                = (Color)vs[3];
                    double R                    = r / Math.Cos(coneAngle);
                    var    blade                = My3DGraphics.NewModel().AddTriangles(new[] { new Point3D(0, 0, 0), new Point3D(R, 0, 0), new Point3D(R, R / 7, 0), new Point3D(0, R / 30, 0) }, new[] { 0, 1, 2, 0, 2, 3, 3, 2, 0, 2, 1, 0 }).CreateModel(new SolidColorBrush(color));
                    var    bladeOriginTransform = blade.Transform;
                    double supportThickness     = R / 100;
                    var    support              = My3DGraphics.NewModel().AddTriangles(
                        new[] { new Point3D(0, 0, -supportThickness), new Point3D(R / 2, 0, -supportThickness), new Point3D(0, supportThickness, -supportThickness), new Point3D(R / 2, supportThickness, -supportThickness), new Point3D(0, 0, 0), new Point3D(R / 2, 0, 0), new Point3D(0, supportThickness, 0), new Point3D(R / 2, supportThickness, 0) },
                        ///6 7
                        ///4 5
                        ///
                        ///2 3
                        ///0 1
                        new[]
                    {
                        0, 2, 3, 0, 3, 1,
                        4, 5, 7, 4, 7, 6,
                        0, 1, 5, 0, 5, 4,
                        2, 6, 7, 2, 7, 3,
                        0, 4, 6, 0, 6, 2,
                        1, 3, 7, 1, 7, 5
                    }).CreateModel(new SolidColorBrush(Colors.Gray));
                    var supportOriginTransform = support.Transform;
                    var ans = new Model3DGroup();

                    ans.Children.Add(blade);
                    ans.Children.Add(support);
                    System.Diagnostics.Trace.WriteLine($"coneangle={coneAngle},{coneAngle / Math.PI * 180}");
                    setFoldingAction = new Action <double>(folding =>
                    {
                        double angle      = coneAngle + folding * (Math.PI / 2 - coneAngle);
                        blade.Transform   = MyLib.Transform(bladeOriginTransform).TranslatePrepend(new Vector3D(0.5 * R * Math.Cos(angle), 0, 0.5 * R * Math.Sin(angle))).RotatePrepend(new Vector3D(0, 1, 0), angle).TranslatePrepend(new Vector3D(-R / 2, 0, 0)).RotatePrepend(new Vector3D(1, 0, 0), attackAngle).Value;
                        support.Transform = MyLib.Transform(supportOriginTransform).Rotate(new Vector3D(0, 1, 0), -angle).Value;
                    });
                    setFoldingAction(0);
                    return(ans);
                }
Beispiel #6
0
                static Model3D TemporaryModel()
                {
                    const double   depth = 1, height = 1, lengthUp = 4, lengthDown = 2.5;
                    List <Point3D> positions = new List <Point3D> {
                        new Point3D(-lengthUp / 2, height / 2, 0), new Point3D(lengthUp / 2, height / 2, 0), new Point3D(lengthDown / 2, -height / 2, 0), new Point3D(-lengthDown / 2, -height / 2, 0)
                    };
                    List <int> indices = new List <int> {
                        0, 3, 2, 0, 2, 1
                    };
                    List <Point3D> trackPositions = positions.SelectConcat(v => v + new Vector3D(0, 0, depth / 2), v => v + new Vector3D(0, 0, -depth / 2)).ToList();
                    ///4----5
                    /// 7--6
                    ///
                    ///0----1
                    /// 3--2
                    List <int> trackIndices = indices.Concat(indices.Select(v => positions.Count + v).Reverse())
                                              .Concat(new[] { 0, 1, 5, 0, 5, 4 }.SelectAdd(v => v / 4 * 4 + (v + 1) % 4, v => v / 4 * 4 + (v + 2) % 4, v => v / 4 * 4 + (v + 3) % 4)).ToList();

                    return(My3DGraphics.NewModel().AddTriangles(trackPositions, trackIndices).CreateModel(new SolidColorBrush(Colors.SlateGray)));
                    //List<Point3D> tracksPositions = trackPositions.SelectConcat(v => v + new Vector3D(0, 0, gap / 2), v => v + new Vector3D(0, 0, -gap / 2)).ToList();
                    //List<int> tracksIndices = trackIndices.Concat(trackIndices.Select(v => trackPositions.Count + v)).ToList();
                }
Beispiel #7
0
        protected override Model3D CreateModel(params object[] vs)
        {
            MyLib.AssertTypes(vs, typeof(Vector3D), typeof(Size3D), typeof(Brush));
            var anchor = Anchor = (Vector3D)vs[0];
            var size   = (Size3D)vs[1];
            var brush  = (Brush)vs[2];

            My3DGraphics.Cuboid.AddFaces(new Point3D(size.X / 2, size.Y / 2, size.Z / 2), out List <Point3D> vertices, out List <int> triangleIndices, out List <Vector3D> normals, "xy-z");
            vertices = vertices.Select(p => p + new Vector3D(size.X, size.Y, size.Z) / 2 + anchor).ToList();
            System.Diagnostics.Trace.Assert(vertices.Count == 5 * 4 && triangleIndices.Count == 5 * 6 && normals.Count == 5 * 4);
            for (int k = 0; k <= 0; k++)
            {
                for (int i = k * 6, j = (k + 1) * 6 - 1; i < j; i++, j--)
                {
                    var t = triangleIndices[i]; triangleIndices[i] = triangleIndices[j]; triangleIndices[j] = t;
                }
                for (int i = k * 4; i < (k + 1) * 4; i++)
                {
                    normals[i] *= -1;
                }
            }
            return(My3DGraphics.NewModel().AddTriangles(vertices, triangleIndices, normals).CreateModel(brush));
        }