Пример #1
0
 private void AddLine(Point3D p0, Point3D p1, double radius, Brush brush, int divisions)
 {
     Cylinder line = new Cylinder();
     line.Divisions = divisions;
     line.IsClosed = true;
     line.DiffuseMaterial.Brush = brush;
     line.Radius = radius;
     line.From = p0;
     line.To = p1;
     Children.Add(line);
 }
Пример #2
0
        public Airplane()
        {
            Cylinder body = new Cylinder();
            body.DiffuseMaterial.Brush = brush;
            body.To = new Point3D(0, -1, 0);
            body.From = new Point3D(0, 0.4, 0);
            body.IsClosed = true;
            body.Radius = 0.1;
            Children.Add(body);

            Cone head = new Cone();
            head.DiffuseMaterial.Brush = Brushes.Red;
            head.Rotation1 = Math3D.RotationX(-90);
            head.Radius = 0.1;
            head.ScaleZ = 0.2;
            head.Position = new Point3D(0, 0.4, 0);
            Children.Add(head);

            Cylinder wings = new Cylinder();
            wings.DiffuseMaterial.Brush = Brushes.Yellow;
            wings.From = new Point3D(-1, 0, -0.01);
            wings.To = new Point3D(1, 0, -0.01);
            wings.ScaleX = 0.015;
            wings.ScaleY = 0.1;
            wings.IsClosed = true;
            Children.Add(wings);

            Cylinder tail = new Cylinder();
            tail.DiffuseMaterial.Brush = Brushes.Yellow;
            tail.From = new Point3D(-0.35, -0.9, 0.03);
            tail.To = new Point3D(0.35, -0.9, 0.03);
            tail.ScaleX = 0.015;
            tail.ScaleY = 0.1;
            tail.IsClosed = true;
            Children.Add(tail);

            Cylinder fin = new Cylinder();
            fin.DiffuseMaterial.Brush = Brushes.Green;
            fin.UpperRadius = 0.5;
            fin.IsClosed = true;
            fin.ScaleX = 0.015;
            fin.ScaleY = 0.1;
            fin.ScaleZ = 0.3;
            fin.Position = new Point3D(0, -0.9, 0);
            fin.Rotation2 = Math3D.RotationX(10);
            Children.Add(fin);
        }
Пример #3
0
        Object3D RandomPrimitive(double x, double y, double z, Brush brush1, Brush brush2)
        {
            Primitive3D obj = null;
            double angle1 = 180 * randy.NextDouble();
            double angle2 = 180 * (1 + randy.NextDouble());
            int index = count > 150 ? 2 : ++count % 10;
            switch (index)
            {
                case 0: //--- more cubes, please :-)
                case 1: obj = new Cube(); break;
                case 2: obj = new Balloon(z); break;
                case 3: obj = new Cone { IsClosed = true }; break;
                case 4: obj = new Cylinder { IsClosed = true }; break;
                case 5: obj = new Cylinder { StartDegrees = angle1, StopDegrees = angle2, IsClosed = true }; break;
                case 6: obj = new Disk(); break;
                case 7: obj = new Disk { StartDegrees = angle1, StopDegrees = angle2 }; break;
                case 8: obj = new Square(); break;
                case 9: obj = new Triangle(); break;
            }
            obj.ScaleZ = z;
            obj.Position = new Point3D(x, y, z);
            obj.DiffuseMaterial.Brush = GetRandomBrush();

            if (index > 5)
            {
                //--- flat objects need a BackMaterial and are rotated
                obj.BackMaterial = obj.Material;
                obj.Rotation1 = Math3D.RotationX(angle1);
                obj.Rotation2 = Math3D.RotationY(angle2);
            }
            else if (index < 2)//--- cubes
            {
                obj.DiffuseMaterial.Brush = brush1;
                obj.Position = new Point3D(x, y, z + 0.01);//--- avoid z fighting with the ground
            }
            else if (index == 2)//--- balloon
            {
                obj.ScaleZ = obj.ScaleX * 1.2;
            }
            else if (index == 4 || index == 5)//--- cylinder
            {
                obj.DiffuseMaterial.Brush = brush2;
                obj.Rotation1 = new Quaternion(Math3D.UnitZ, angle1);
            }
            return obj;
        }