protected void drawCurrentPolygon(Graphics2D g) { if (!(sourcePolygon instanceof TexturedPolygon3D)) { // not a textured polygon - return return; } buildSurface(); TexturedPolygon3D poly = (TexturedPolygon3D) destPolygon; Texture texture = poly.getTexture(); ScanRenderer scanRenderer = (ScanRenderer) scanRenderers.get(texture.getClass()); scanRenderer.setTexture(texture); Rectangle3D textureBounds = poly.getTextureBounds(); a.setToCrossProduct(textureBounds.getDirectionV(), textureBounds.getOrigin()); b.setToCrossProduct(textureBounds.getOrigin(), textureBounds.getDirectionU()); c.setToCrossProduct(textureBounds.getDirectionU(), textureBounds.getDirectionV()); // w is used to compute depth at each pixel w = SCALE * MIN_DISTANCE * Short.MAX_VALUE / (viewWindow.getDistance() * c.getDotProduct(textureBounds.getOrigin())); int y = scanConverter.getTopBoundary(); viewPos.y = viewWindow.convertFromScreenYToViewY(y); viewPos.z = -viewWindow.getDistance(); while (y <= scanConverter.getBottomBoundary()) { ScanConverter.Scan scan = scanConverter.getScan(y); if (scan.isValid()) { viewPos.x = viewWindow.convertFromScreenXToViewX(scan.left); int offset = (y - viewWindow.getTopOffset()) * viewWindow.getWidth() + (scan.left - viewWindow.getLeftOffset()); scanRenderer.render(offset, scan.left, scan.right); } y++; viewPos.y--; } }
public void parseLine(String line) throws NoSuchElementException { StringTokenizer tokenizer = new StringTokenizer(line); String command = tokenizer.nextToken(); if (command.equals("newmtl")) { // create a new material if needed String name = tokenizer.nextToken(); currentMaterial = (Material) materials.get(name); if (currentMaterial == null) { currentMaterial = new Material(); materials.put(name, currentMaterial); } } else if (command.equals("map_Kd")) { // give the current material a texture String name = tokenizer.nextToken(); File file = new File(path, name); if (!file.equals(currentMaterial.sourceFile)) { currentMaterial.sourceFile = file; currentMaterial.texture = (ShadedTexture) Texture.createTexture(file.getPath(), true); } } else { // unknown command - ignore it } }