A Ray Object
class Ray {
public static final float MAX_T = Float.MAX_VALUE;
Vector3D origin, direction;
float t;
Renderable object;
public Ray(Vector3D eye, Vector3D dir) {
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, but I prefer 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);
}
public String toString() {
return ("ray origin = "+origin+" direction = "+direction+" t = "+t);
}
}
|