/// <summary> /// Sort the spheres in z-order /// </summary> /// <param name="spheres"></param> private void SortSphere(List <Sphere3D> spheres) { for (int i = 0; i < spheres.Count; i++) { for (int j = i + 1; j < spheres.Count; j++) { if (spheres[i].Center.Z > spheres[j].Center.Z) { Sphere3D temp = spheres[i]; spheres[i] = spheres[j]; spheres[j] = temp; } } } }
private void MakeSpheres() { int sphereSize = 80; for (int i = 0; i < 2; i++) { for (int j = 0; j < 2; j++) { for (int k = 0; k < 2; k++) { Sphere3D sphere = new Sphere3D(new Point3D(-sphereSize + sphereSize * i, -sphereSize + sphereSize * j, -sphereSize + sphereSize * k), 20); sphere.Pen = new Pen(Color.FromArgb(rand.Next(255), rand.Next(255), rand.Next(255)), 2); sphere.Brush = new SolidBrush(Color.FromArgb(rand.Next(255), rand.Next(255), rand.Next(255))); spheres.Add(sphere); } } } }
/// <summary> /// Form Constructor - all initialization happens here - AFTER the InitializeComponent function. /// </summary> public Form1() { InitializeComponent(); // to push the output onto a specific monitor (parameter = 0 for primary, = 1 for secondary monitor, etc) ShowOnMonitor(0); timer1.Enabled = true; // create the demo objects // MakeHouse(lines); // cube.Scale(.5f); // cube.Translate(new Point3D(0, 50, 0)); // foreach (Line3D line in lines) //{ // //line.translate(new Point3D(0, 0, 0)); // line.Scale(scale); //} //variables for file reading var assembly = Assembly.GetExecutingAssembly(); var resourceName = "Graphics3D.BlockNRollSpecs.bnr"; using (Stream stream = assembly.GetManifestResourceStream(resourceName)) using (StreamReader reader = new StreamReader(stream)) { ReadFile(reader); Setup_Grid(gridnum); } // AxisLines(); // make a collection of spheres // MakeSpheres(); lightSrc = new Point3D(650, 1100, 650); sun = new Sphere3D(lightSrc, 200); sun.Brush = new SolidBrush(Color.Yellow); }