// D3Polys.java // 3Dim Multi Polygon Manipulate and Draw Calss // 3次元 複数の多角形 操作・描画 クラス // Copyright (C) 1996, 1997 Y.Nagatani // nagatani@eken.phys.nagoya-u.ac.jp import java.awt.Graphics; import java.awt.Color; import D3Vector; import D3Poly; public class D3Polys { public D3Poly [] poly; D3Polys (int polys) { poly = new D3Poly [polys]; for (int n = 0 ; n < poly.length ; n++) { double arg = 2.0 * Math.PI * n / poly.length * 0.7; poly[n] = new D3Poly (n/2+3); poly[n].translate (new D3Vector ( 1.0 * Math.cos(arg), 1.0 * Math.sin(arg), 0.0)); poly[n].setColor (Color.getHSBColor (1.0f * n/poly.length, 1.0f, 1.0f)); } } public D3Polys set (int nPoly, int points) { if (0 <= nPoly && nPoly < poly.length) { poly[nPoly] = new D3Poly (points); } else { System.out.println ("D3Polys: Polys Domain Error\n"); } return this; } public D3Polys set (int nPoly, int point, double x, double y, double z) { if (0 <= nPoly && nPoly < poly.length) { poly[nPoly].set (point,x,y,z); } else { System.out.println ("D3Polys: Polys Domain Error\n"); } return this; } public D3Polys paint (Graphics g, D3VecToD2 D3D2) { // depth sorat double depth [] = new double [poly.length]; int sequence[] = new int [poly.length]; for (int n = 0 ; n < poly.length ; n++) { depth[n] = poly[n].center().z; sequence[n] = n; } for (int n = poly.length-1 ; 0 < n ; n--) { for (int m = 0 ; m < n ; m++) { if (depth[sequence[m+1]] < depth[sequence[m ]]) { int seq = sequence[m+1]; sequence[m+1] = sequence[m]; sequence[m] = seq; } } } for (int n = 0 ; n < poly.length ; n++) { poly[sequence[n]].paint (g, D3D2); } return this; } public D3Polys paintByDepth (Graphics g, D3VecToD2 D3D2, double depthMin, double depthMax) { // depth sorat double depth[] = new double [poly.length]; int contents[] = new int [poly.length]; int sequence[] = new int [poly.length]; int polysReal = 0; for (int n = 0 ; n < poly.length ; n++) { double D = poly[n].center().z; if (depthMin < D && D < depthMax) { depth [polysReal] = D; contents[polysReal] = n; sequence[polysReal] = polysReal; polysReal++; } } for (int n = polysReal-1 ; 0 < n ; n--) { for (int m = 0 ; m < n ; m++) { if (depth[sequence[m+1]] < depth[sequence[m ]]) { int seq = sequence[m+1]; sequence[m+1] = sequence[m]; sequence[m] = seq; } } } for (int n = 0 ; n < polysReal ; n++) { poly[contents[sequence[n]]].paint (g, D3D2); } return this; } /* public D3Polys moveCircular (int n) { }*/ int NumMove = 0; public D3Polys move () { // poly[0].translate (new D3Vector (0.01,0.01,0)); for (int n = 0 ; n < poly.length ; n++) { // poly[n].rotZX (+2.0*Math.PI/360 * NumMove / 200); // poly[n].rotXY ( 2.0*Math.PI/360 * 5.248); // poly[n].rotYZ ( 2.0*Math.PI/360 * 1.511); poly[n].rotXY ( 2.0*Math.PI/360 * -30.248); poly[n].rotYZ ( 2.0*Math.PI/360 * -20.511); poly[n].rotXY ( 2.0*Math.PI/360 * 5.248); poly[n].rotYZ ( 2.0*Math.PI/360 * 22.511); poly[n].rotXY ( 2.0*Math.PI/360 * 30.248); // poly[n].rotZX (-2.0*Math.PI/360 * NumMove / 200); } for (int n = 0 ; n < poly.length ; n++) { poly[n].rotZXcent (2.0*Math.PI/360 * (n+1) * 2.3235); } NumMove ++; return this; } }