package RayTracer;

import java.util.Enumeration;
import java.util.Vector;
import java.awt.Color;

public class Ray {
	public static final float MAX_T = Float.MAX_VALUE;
	Vector3D origin;
	Vector3D direction;
	public float illuminosityIntensity;
	float t;
	Renderable object;

	public Ray(Vector3D eye, Vector3D dir) {
		illuminosityIntensity = 1;
		origin = new Vector3D(eye);
		direction = Vector3D.normalize(dir);
	}

	public boolean trace(Vector objects) {
		Enumeration objList = objects.elements();
		t = MAX_T;
		object = null;
		while (objList.hasMoreElements()) {
			Renderable object = (Renderable) objList.nextElement();
			object.intersect(this);
		}
		return (object != null);
	}

	// The following method is not strictly needed, and most likely
	// adds unnecessary overhead, but I prefered the syntax
	//
	//            ray.Shade(...)
	// to
	//            ray.object.Shade(ray, ...)
	//
	public final Color Shade(Vector lights, Vector objects, Color bgnd) {
		return object.Shade(this, lights, objects, bgnd);
	}
	
	//Accessors...
	
	public Vector3D getRayOrigin () {
		return (new Vector3D(origin));
	}
	
	public Vector3D getRayDirection () {
		return (new Vector3D(direction));
	}
	
	public float getT () {
		return (t);
	}
	
	public void setT (float incomingT) {
		t = incomingT;
	}
	
	public void setObject (Renderable ob) {
		object = ob;
	}

	public String toString() {
		return ("ray origin = "+origin+"  direction = "+direction+"  t = "+t);
	}
}
