public CubeModel(int divisions = 1) { Right = InitSquare(Math3D.UnitX, divisions); Left = InitSquare(-Math3D.UnitX, divisions); Rear = InitSquare(Math3D.UnitY, divisions); Front = InitSquare(-Math3D.UnitY, divisions); Top = InitSquare(Math3D.UnitZ, divisions); Bottom = InitSquare(-Math3D.UnitZ, divisions); }
private Square InitSquare(Vector3D v, int divisions) { Square square = new Square(divisions); square.LockUpdates(true); square.Position = (Point3D)v; if (v.Z == 0) { square.Rotation1 = Math3D.RotationX(90); square.Rotation2 = Math3D.RotationZ(90 * (v.X != 0 ? v.X : (v.Y + 1))); } else if (v.Z < 0) { square.Rotation1 = Math3D.RotationX(180); } square.LockUpdates(false); square.Transform.Freeze(); Children.Add(square); return square; }
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; }
void InitializeScene(Brush brush) { Square square = new Square(100); square.ScaleX = 60; square.ScaleY = 40; square.Transform.Freeze(); square.DiffuseMaterial.Brush = brush; square.BackMaterial = square.Material; scene.Models.Add(square); Brush brush1 = GetBrush("Facade"); Brush brush2 = GetBrush("Poster"); for (int i = 0; i < 170; i++) { double x = 58 * (2 * randy.NextDouble() - 1); double y = 38 * (2 * randy.NextDouble() - 1); double z = 3 * randy.NextDouble() + 1; Object3D obj = RandomPrimitive(x, y, z, brush1, brush2); scene.Models.Add(obj); } Tube tube = new Tube(12) { Radius = 0.1, IsPathClosed = true }; int n = 180; List<Point3D> path = new List<Point3D>(n); for (int i = 0; i < n; i++) { double t = MathUtils.PIx2 * i / n; path.Add(new Point3D(Math.Cos(t), Math.Sin(t), Math.Cos(6 * t) / 3)); } tube.Path = path; tube.DiffuseMaterial.Brush = Brushes.Green; tube.Position = new Point3D(-2, 2, 1); scene.Models.Add(tube); RunningMan man = new RunningMan(60, 40); scene.Models.Add(man); scene.TimerTicked += man.TimerTick; scene.TimerTicked += TimerTick; scene.ToggleHelperModels(); FocusManager.SetFocusedElement(this, scene); }