class Light {
	public static final int AMBIENT = 0;
	public static final int DIRECTIONAL = 1;
	public static final int POINT = 2;

	private int lightType;
	private float x, y, z;           // the position of a point light or
									// the direction to a directional light
	private float ir, ig, ib;        // intensity of the light source

	public Light(int type, float xval, float yval , float zval, float r, float g, float b)
	{
		lightType = type;
		x = xval; y = yval; z = zval;
		ir = r;   ig = g;   ib = b;
		if (type == DIRECTIONAL) {
			float t = (float) (1 / Math.sqrt(x*x + y*y + z*z));
			x *= t;
			y *= t;
			z *= t;
		}
	}
	public void lightVertex( Point3D normal, Vertex3D vertex, float[] pointcolor, Surface s)
	{
		if (lightType == AMBIENT)
		{
			pointcolor[0] = s.r * s.ka * ir;
			pointcolor[1] = s.g * s.ka * ig;
			pointcolor[2] = s.b * s.ka * ib;
		}
		else if (lightType == DIRECTIONAL)
		{
			// Diffuse	
			float dot = normal.x() * 	-x + normal.y() * -y + normal.z() * -z;
			pointcolor[0] = s.r * s.kd * ir * dot;
			pointcolor[1] = s.g * s.kd * ig * dot;
			pointcolor[2] = s.b * s.kd * ib * dot;

		}
		else if (lightType == POINT)
		{
			// Diffuse	
		
			float nx = x - vertex.x();	
			float ny = y - vertex.y();	
			float nz = z - vertex.z();	
			float sx = (float)Math.sqrt(nx*nx +ny*ny + nz*nz);
			nx /= sx;
			ny /= sx;
			nz /= sx;
			float dot = normal.x() * nx + normal.y() * ny + normal.z() * nz;
			pointcolor[0] = s.r * s.kd * ir * dot;
			pointcolor[1] = s.g * s.kd * ig * dot;
			pointcolor[2] = s.b * s.kd * ib * dot;
		}
	}
}