import java.awt.Color;

public class Vertex3D extends Point3D {
  public float w;         // coordinate of vertex
  public float nx, ny, nz;        // vertex normal
  public boolean hasNormal;

  public Vertex3D()
    {
      nx = ny = nz = 0;
      hasNormal = false;
    }	

  public Vertex3D(float xval, float yval, float zval)
    {
      super(xval, yval, zval);
      w = 1;
      nx = ny = nz = 0;
      hasNormal = false;
    }	
  
  public void copy(Vertex3D v)
    {
      x = v.x;        y = v.y;        z = v.z;    w = v.w;
      nx = v.nx;      ny = v.ny;      nz = v.nz;
      hasNormal = v.hasNormal;
    }	

  public void setNormal(float xval, float yval, float zval) {
    float l = (float) (1 / Math.sqrt(xval*xval + yval*yval + zval*zval));
    xval *= l;
    yval *= l;
    zval *= l;
    nx = xval;
    ny = yval;
    nz = zval;
    hasNormal = true;
  }

  public void homogenize( )
    {
      if (w != 1) {
	w = 1 / w;
	x *= w;
	y *= w;
	z *= w;
	w = 1;
      }
    }
    
  public String toString()
    {
      return new String(" ["+x+", "+y+", "+z+", "+w+"]");
    }	
}	
