/** * Adds a series of polygons by rotating the points list (ps) steps times, and colouring them as * defined by the color array (stripes!). */ public void lathePolygons(float[][] ps, Color[] color, int steps) { float _ps[][] = new float[ps.length][3]; float stepAngle = (float) Math.PI * 2 / steps; // the angle of each step in radians int currColor = 0; float m[][]; for (int step = 0; step < steps; step++) { // translate each point to it next step round m = Tools3d.rotateAboutZ(stepAngle); for (int i = 0; i < ps.length; i++) { Tools3d.applyTo(m, ps[i], _ps[i]); } // build the polygons for (int point = 0; point < ps.length - 1; point++) { this.addPolygon( new float[][] {_ps[point], ps[point], ps[point + 1], _ps[point + 1]}, color[currColor]); } // copy the translated array to the starting array read for the next iteration for (int i = 0; i < ps.length; i++) { ps[i][0] = _ps[i][0]; ps[i][1] = _ps[i][1]; ps[i][2] = _ps[i][2]; } currColor++; if (currColor == color.length) { currColor = 0; } } }
/** * Uses the camera to map all points from model space, (x, y, z) to screen space (x_, y_, z_). * Remember that x_ represents the depth of the point and (y_, z_) maps to the screen (x, y) * co-ords of the point. * * @see CameraMan */ public void transform() { final float[] f = modelViewer.cameraMan.getFocus(); final float[][] m = modelViewer.cameraMan.getMatrix(); final float d = modelViewer.cameraMan.getDistance(); float[] a = new float[3]; visible = false; // set true if any points are visble to the camera for (int i = 0; i < npoints * 3; i += 3) { a[0] = ps[i] - f[0]; a[1] = ps[i + 1] - f[1]; a[2] = ps[i + 2] - f[2]; Tools3d.applyTo(m, a, a); visibles[i / 3] = Tools3d.projectYZ(a, a, d); ps_[i] = a[0]; if (visibles[i / 3]) { modelViewer.cameraMan.scaleToScreen(a); ps_[i + 1] = a[1]; ps_[i + 2] = a[2]; visible = true; } // depth bounding box if (i == 0) { x_min = x_max = ps_[i]; } else { if (ps_[i] < x_min) x_min = ps_[i]; if (ps_[i] > x_max) x_max = ps_[i]; } } }