package scene.illumination;

import geometry.*;
import scene.basicTypes.*;
import scene.*;

// The DirectionalLight data type for a miniVRML scene.

public class DirectionalLight extends Light {
    float intensity, ambient;    // Light intensity (assumed white) and ambient component
    Vector3f direction;          // Direction TO light (normalised)

    public DirectionalLight(float ambient, float intens, Vector3f dir) {
        this.ambient = ambient;
        intensity = intens;
        direction = dir.negated().normalised();
    }
    /** The illumination at a given point from this light. */
    public LightFlux illumination(Point3f pt) {
        Colour myFluxColour = new Colour(intensity, intensity, intensity); 
        Ray ray = new Ray(pt.minus(direction.times(SURFACE_TOLERANCE)), direction);			// get the vector from the point TO the light
        if (sceneRoot.firstObjectHit(ray) != null) {		
           myFluxColour=null;					// if something is in the way, set the colour to NULL 
        }
        return new LightFlux(ambient, myFluxColour, direction);
    }

    public String toString() {
        return "Light: ambient " + ambient + ", intensity " + intensity + ", direction " + direction;
    }
}