//Vertex3D is a Point3D with another Point3D and some colors.
// (does not follow lm's class)

public class Vertex3D extends Point3D {
    public Point3D normal; //the local normal
    public int r, g, b; //PctInt
    public boolean lit;
    
  public Vertex3D() { 
    super(0f,0f,0f); lit = false; r=g=b=0;
    normal = new Point3D();};
  public Vertex3D(float x, float y, float z) {
    super(x,y,z); lit = false; r=g=b=0;
    normal = new Point3D();};
  
    public Vertex3D(Vertex3D V2) {
	super(V2);
	lit = V2.lit;
	r=V2.r; g=V2.g; b=V2.b;
	if (V2.normal != null)
	    normal = new Point3D(V2.normal.x,V2.normal.y,V2.normal.z);
	else 
	    normal = new Point3D();
	  
    }
    //an interpolating constructor
    public Vertex3D(Vertex3D v1, Vertex3D v2, float f) {
	x = v1.x + (v2.x - v1.x) * f;
	y = v1.y + (v2.y - v1.y) * f;
	z = v1.z + (v2.z - v1.z) * f;
	int fi = PctInt.from_float(f);
	r = v1.r + PctInt.mult((v2.r - v1.r),fi);
	g = v1.g + PctInt.mult((v2.g - v1.g),fi);
	b = v1.b + PctInt.mult((v2.b - v1.b),fi);
	lit = (v1.lit && v2.lit);
	normal = new Point3D(); //just so we have one
    }
    //add a polygon's normal to the current local normal
    //if we only add in unit normals, we can unitize this later
    // and we still get the right answer.
    public final void addPolyNormal(Point3D n) {
	normal.incr(n); //note: we are EXPECTING a normalized normal.
    }
    public final void Illuminate(int dr, int dg, int db) {
	if (!lit) {
	    r += dr; if (r > PctInt.ONE) r = PctInt.ONE;
	    g += dg; if (g > PctInt.ONE) g = PctInt.ONE;
	    b += db; if (b > PctInt.ONE) b = PctInt.ONE;
	}

    }
    public final void fix_illumination() { lit = true;}

    public final void ColorCopy(Vertex3D V) {
	r = V.r; g = V.g; b = V.b; lit = V.lit;
    }
}
		

