public PolyhedronViewForm() { InitializeComponent(); Clicked = false; ng = false; polygon = new osPolyhedron(); camera = new osCamera(); }
//スクリーン座標に変換 public void Translate2D(osCamera c) { foreach (Vertex vtx in vertex) vtx.center2D = c.Translate(vtx.center3D); }
//マージソート private void mergeSort(osPolygon[] temp, osCamera c) { if (temp.Length > 1) { int m = temp.Length / 2; int n = temp.Length - m; osPolygon[] a1 = new osPolygon[m]; osPolygon[] a2 = new osPolygon[n]; for (int i = 0; i < m; i++) a1[i] = temp[i]; for (int i = 0; i < n; i++) a2[i] = temp[m + i]; mergeSort(a1, c); mergeSort(a2, c); merge(a1, a2, temp, c); } }
//マージ private void merge(osPolygon[] a1, osPolygon[] a2, osPolygon[] temp, osCamera c) { int i = 0, j = 0; while (i < a1.Length || j < a2.Length) { if (j >= a2.Length || (i < a1.Length && a1[i].center.Getdistance(c.Setposition) > a2[j].center.Getdistance(c.Setposition))) { temp[i + j] = a1[i]; i++; } else { temp[i + j] = a2[j]; j++; } } }
//面のソート public void sort(osCamera c) { ViewFace3D = Face3D; foreach (osPolygon pol in ViewFace3D) pol.SetCenter(); osPolygon[] temp; temp = ViewFace3D.ToArray(); mergeSort(temp, c); ViewFace3D = temp.ToList(); }
//2D座標として設定 public void SetFace2D(osCamera c) { foreach (osPolygon pol in Face3D) pol.Translate2D(c); foreach (Vertex dl in Dual) dl.center2D = c.Translate(dl.center3D); }