public Shape2D convertTo2D() { Point p1, p2; Shape2D shape = new Shape2D(); for (Line3D line : this.lines) { p1 = this.camera.project(line.getStart()); p2 = this.camera.project(line.getEnd()); shape.addLine(new Line2D(p1, p2)); } return shape; }
private void plotRaster(int i) { int fpz = fp8IntensityUp[i] >> (8 + zShift); int fpzBack = fpz >> 1; int x = xRaster[i]; int y = yRaster[i]; int z = zRaster[i]; if (tEndcapOpen) { if (notClipped) { g3d.plotPixelUnclipped(argbEndcap, xEndcap + x, yEndcap + y, zEndcap - z - 1); g3d.plotPixelUnclipped(argbEndcap, xEndcap - x, yEndcap - y, zEndcap + z - 1); } else { g3d.plotPixelClipped(argbEndcap, xEndcap + x, yEndcap + y, zEndcap - z - 1); g3d.plotPixelClipped(argbEndcap, xEndcap - x, yEndcap - y, zEndcap + z - 1); } } line3d.plotLineDelta( shadesA, isScreenedA, shadesB, isScreenedB, fpz, xA + x, yA + y, zA - z, dxB, dyB, dzB, notClipped); if (drawBackside) { line3d.plotLineDelta( shadesA[fpzBack], isScreenedA, shadesB[fpzBack], isScreenedB, xA - x, yA - y, zA + z, dxB, dyB, dzB, notClipped); } }
void renderCone( short colix, byte endcap, int diameter, float xA, float yA, float zA, float xTip, float yTip, float zTip) { if (diameter > (g3d.width + g3d.height) * MAX_FIX) return; dxBf = (xTip) - (xAf = xA); dyBf = (yTip) - (yAf = yA); dzBf = (zTip) - (zAf = zA); this.xA = (int) Math.floor(xAf); this.yA = (int) Math.floor(yAf); this.zA = (int) Math.floor(zAf); this.dxB = (int) Math.floor(dxBf); this.dyB = (int) Math.floor(dyBf); this.dzB = (int) Math.floor(dzBf); this.xTip = xTip; this.yTip = yTip; this.zTip = zTip; colixA = colix; shadesA = g3d.getShades(colix); isScreenedA = (colixA & Graphics3D.TRANSLUCENT_MASK) != 0; int intensityTip = Shade3D.calcIntensity(dxB, dyB, -dzB); g3d.plotPixelClipped(shadesA[intensityTip], isScreenedA, (int) xTip, (int) yTip, (int) zTip); this.diameter = diameter; if (diameter <= 1) { if (diameter == 1) line3d.plotLineDelta( colixA, isScreenedA, colixA, isScreenedA, this.xA, this.yA, this.zA, dxB, dyB, dzB, notClipped); return; } // float r2 = dxB*dxB + dyB*dyB + dzB*dzB; // System.out.println(r2); this.endcaps = endcap; calcArgbEndcap(false); generateBaseEllipsePrecisely(); if (endcaps == Graphics3D.ENDCAPS_FLAT) renderFlatEndcap(false); for (int i = rasterCount; --i >= 0; ) plotRasterCone(i); }
/** * Main program for tests * * @param args */ public static void main(String[] args) { Mesh3D box = Mesh3D.box(10, 20, 60); Line3D lineX = box.getLineX(); Line3D lineY = box.getLineY(); Line3D lineZ = box.getLineZ(); lineX.show(); lineY.show(); lineZ.show(); box.translateXYZ(100, 0.0, 0.0); box.show(); Line3D line = new Line3D(); List<Point3D> intersects = new ArrayList<Point3D>(); for (int p = 0; p < 100; p++) { double r = 600; double theta = Math.toRadians(90.0); // Math.toRadians(Math.random()*180.0); double phi = Math.toRadians(Math.random() * 360.0 - 180.0); line.set( 0.0, 0.0, 0.0, Math.sin(theta) * Math.cos(phi) * r, Math.sin(theta) * Math.sin(phi) * r, Math.cos(theta) * r); intersects.clear(); box.intersectionRay(line, intersects); System.out.println( "theta/phi = " + Math.toDegrees(theta) + " " + Math.toDegrees(phi) + " intersects = " + intersects.size()); } }
void render( short colixA, short colixB, byte endcaps, int diameter, int xA, int yA, int zA, int xB, int yB, int zB) { if (diameter > (g3d.width + g3d.height) * MAX_FIX) return; // XIE: begin: deal with long sticks to prevent huge raster arrays from being produced dxB = xB - xA; dyB = yB - yA; if (dxB * dxB + dyB * dyB > 4.0 * g3d.width * g3d.width) return; // XIE: end dzB = zB - zA; int r = diameter / 2 + 1; int codeMinA = line3d.clipCode(xA - r, yA - r, zA - r); int codeMaxA = line3d.clipCode(xA + r, yA + r, zA + r); int codeMinB = line3d.clipCode(xB - r, yB - r, zB - r); int codeMaxB = line3d.clipCode(xB + r, yB + r, zB + r); // all bits 0 --> no clipping notClipped = ((codeMinA | codeMaxA | codeMinB | codeMaxB) == 0); // any two bits same in all cases --> fully clipped if ((codeMinA & codeMaxB & codeMaxA & codeMinB) != 0) return; // fully clipped; zShift = g3d.getZShift((zA + zB) >> 1); if (diameter <= 1) { line3d.plotLineDelta( g3d.getColixArgb(colixA), Graphics3D.isColixTranslucent(colixA), g3d.getColixArgb(colixB), Graphics3D.isColixTranslucent(colixB), xA, yA, zA, dxB, dyB, dzB, notClipped); return; } drawBackside = (!notClipped || endcaps == Graphics3D.ENDCAPS_FLAT); this.diameter = diameter; this.xA = xA; this.yA = yA; this.zA = zA; this.endcaps = endcaps; shadesA = g3d.getShades(this.colixA = colixA); shadesB = g3d.getShades(this.colixB = colixB); isScreenedA = (colixA & Graphics3D.TRANSLUCENT_MASK) != 0; isScreenedB = (colixB & Graphics3D.TRANSLUCENT_MASK) != 0; calcArgbEndcap(true); generateBaseEllipse(); if (endcaps == Graphics3D.ENDCAPS_FLAT) renderFlatEndcap(true); for (int i = rasterCount; --i >= 0; ) plotRaster(i); if (endcaps == Graphics3D.ENDCAPS_SPHERICAL) renderSphericalEndcaps(); }
private void plotRasterCone(int i) { float x = txRaster[i]; float y = tyRaster[i]; float z = tzRaster[i]; float xUp = xAf + x, yUp = yAf + y, zUp = zAf - z; float xDn = xAf - x, yDn = yAf - y, zDn = zAf + z; if (tEndcapOpen) { g3d.plotPixelClipped(argbEndcap, isScreenedA, (int) xUp, (int) yUp, (int) zUp); g3d.plotPixelClipped(argbEndcap, isScreenedA, (int) xDn, (int) yDn, (int) zDn); } int fpz = fp8IntensityUp[i] >> (8 + zShift); line3d.plotLineDelta( shadesA, isScreenedA, shadesA, isScreenedA, fpz, (int) xUp, (int) yUp, (int) zUp, (int) Math.ceil(xTip - xUp), (int) Math.ceil(yTip - yUp), (int) Math.ceil(zTip - zUp), false); line3d.plotLineDelta( shadesA, isScreenedA, shadesA, isScreenedA, fpz, (int) xUp, (int) yUp + 1, (int) zUp, (int) Math.ceil(xTip - xUp), (int) Math.ceil(yTip - yUp) + 1, (int) Math.ceil(zTip - zUp), false); line3d.plotLineDelta( shadesA, isScreenedA, shadesA, isScreenedA, fpz, (int) xUp + 1, (int) yUp, (int) zUp, (int) Math.ceil(xTip - xUp) + 1, (int) Math.ceil(yTip - yUp), (int) Math.ceil(zTip - zUp), false); if (!(endcaps == Graphics3D.ENDCAPS_FLAT && dzB > 0)) { int argb = shadesA[0]; line3d.plotLineDelta( argb, isScreenedA, argb, isScreenedA, (int) xDn, (int) yDn, (int) zDn, (int) Math.ceil(xTip - xDn), (int) Math.ceil(yTip - yDn), (int) Math.ceil(zTip - zDn), false); } }
void renderBits( short colixA, short colixB, byte endcaps, int diameter, float xA, float yA, float zA, float xB, float yB, float zB) { if (diameter > (g3d.width + g3d.height) * MAX_FIX) // XIE return; // oops -- problem here if diameter < 0 is that we may have already clipped it! int r = diameter / 2 + 1; int codeMinA = line3d.clipCode((int) xA - r, (int) yA - r, (int) zA - r); int codeMaxA = line3d.clipCode((int) xA + r, (int) yA + r, (int) zA + r); int codeMinB = line3d.clipCode((int) xB - r, (int) yB - r, (int) zB - r); int codeMaxB = line3d.clipCode((int) xB + r, (int) yB + r, (int) zB + r); // all bits 0 --> no clipping notClipped = ((codeMinA | codeMaxA | codeMinB | codeMaxB) == 0); // any two bits same in all cases --> fully clipped if ((codeMinA & codeMaxB & codeMaxA & codeMinB) != 0) return; // fully clipped; dxBf = xB - xA; dyBf = yB - yA; dzBf = zB - zA; if (diameter == 0 || diameter == 1) { line3d.plotLineDelta( g3d.getColixArgb(colixA), Graphics3D.isColixTranslucent(colixA), g3d.getColixArgb(colixB), Graphics3D.isColixTranslucent(colixB), (int) xA, (int) yA, (int) zA, dxB, dyB, dzB, notClipped); return; } if (diameter > 0) { this.diameter = diameter; this.xAf = xA; this.yAf = yA; this.zAf = zA; } drawBackside = (!notClipped || endcaps == Graphics3D.ENDCAPS_FLAT); this.xA = (int) xAf; this.yA = (int) yAf; this.zA = (int) zAf; this.dxB = (int) dxBf; this.dyB = (int) dyBf; this.dzB = (int) dzBf; this.shadesA = g3d.getShades(this.colixA = colixA); this.shadesB = g3d.getShades(this.colixB = colixB); this.isScreenedA = (colixA & Graphics3D.TRANSLUCENT_MASK) != 0; this.isScreenedB = (colixB & Graphics3D.TRANSLUCENT_MASK) != 0; this.endcaps = endcaps; calcArgbEndcap(true); if (diameter > 0) generateBaseEllipsePrecisely(); if (endcaps == Graphics3D.ENDCAPS_FLAT) renderFlatEndcap(true); line3d.setLineBits(this.dxBf, this.dyBf); for (int i = rasterCount; --i >= 0; ) plotRasterBits(i); if (endcaps == Graphics3D.ENDCAPS_SPHERICAL) renderSphericalEndcaps(); this.xAf += dxBf; this.yAf += dyBf; this.zAf += dzBf; }