All pastes #816795 Raw Edit

Anonymous

public java v1 · immutable
·published 2007-12-15 00:08 UTC
rendered paste body
    private void drawModel(final Model model, final Graphics g) {        final Point mP = getLocation(model);        final int startX = mP.x;        final int startY = mP.y;        Arrays.sort(model.faces, this);        Face face;        final int[] colors = new int[model.faces.length];        final int colFactor = 255 / model.faces.length;        for(int i = 0; i < colors.length; i++)            colors[i] = colFactor * i;        int curFac = 0;        int curVert = 0;        for (int i = 0; i < model.faces.length; i++) {            face = model.faces[i];            if(Vertex.dotProduct(face.normal, plane_normal) < 0)                continue;            curFac++;            curVert += face.vertices.length;            g.translate(startX, startY);            if(clickPoint != null && face.intersects(clickPoint.x, clickPoint.y, 1, 1))                g.setColor(Color.RED);            else                g.setColor(new Color(colors[i]));            g.fillPolygon(face);            if(drawWireframe) {                g.setColor(Color.BLACK);                g.drawPolygon(face);            }            if(drawBounds) {                g.setColor(Color.RED);                Rectangle bounds = face.getBounds();                g.drawRect(startX + bounds.x, startY + bounds.y, bounds.width, bounds.height);            }            g.translate(-startX, -startY);        }        faces = curFac;        vertices = curVert;    }    private static Point getLocation(final Model model) {        final int x = (int) (model.x + (model.z / camera.z));        final int y = (int) (model.y + (model.z / camera.z));        return new Point(x, y);    }