package com.mathorama.wumpus; import java.awt.Color; import java.awt.Point; import java.awt.Polygon; import java.awt.Rectangle; public class Face implements Comparable { private Vertex[] v; private Color color; public Face(Vertex v0, Vertex v1, Vertex v2, Vertex v3, Vertex v4){ setColor(Color.WHITE); v = new Vertex[5]; v[0]=v0; v[1]=v1; v[2]=v2; v[3]=v3; v[4]=v4; } public Polygon polygon(Rectangle screen, double scale){ Polygon p = new Polygon(); for (int i=0; i<5; i++) p.addPoint(v[i].screenX(screen), v[i].screenY(screen)); return p; } public String toString(){ String s="["; for (Vertex n:v) s+=n.toString()+" "; return s+"]"; } @Override public int compareTo(Face o) { return (int)(100.0*this.distanceToViewpoint()-100*o.distanceToViewpoint()); } public double distanceToViewpoint(){ return center().distance(new Vertex(Vertex.CamX, Vertex.CamY, Vertex.CamZ)); } public Vertex center(){ double x,y,z; x=y=z=0; for(Vertex n:v){ x+=n.getX(); y+=n.getY(); z+=n.getZ(); } return new Vertex(x/5.0, y/5.0, z/5.0); } public Polygon getPolygon(Rectangle screen, double yAxis, double xAxis){ Polygon p = new Polygon(); for (int i=0; i<5; i++){ Point pt = v[i].screenXY(screen, yAxis, xAxis); p.addPoint(pt.x, pt.y); } return p; } public Polygon getOrthoPolygon(Rectangle screen, double yAxis, double xAxis){ Polygon p = new Polygon(); for (int i=0; i<5; i++){ Point pt = v[i].orthoXY(screen, yAxis, xAxis); p.addPoint(pt.x, pt.y); } return p; } public Color getColor() { return color; } public Color getCyan() { return new Color(0, 0, color.getBlue(), color.getTransparency()); } public Color getRed() { return new Color(color.getRed(),0, 0, color.getTransparency()); } public void setColor(Color color) { this.color = new Color(color.getRed(), color.getGreen(), color.getBlue(), 128); } }