import com.sun.j3d.utils.geometry.*;
import com.sun.j3d.utils.universe.*;
import javax.media.j3d.*;
import javax.vecmath.*;

import java3d.*;


/**
 * An application that displays a cube in Java3D
 *
 * Note:  Under MS-Windows with Direct3D this application
 * must be run as follows:
 *
 *   java -Dj3d.rend=d3d LightingDriver
 *
 * because OpenGL is the default rendering technology (and some
 * MS-Windows installations do not support OpenGL)
 *
 * @author  Prof. David Bernstein, James Madison University
 * @version 1.0
 */
public class LightingDriver
{
    /**
     * The entry-point of the application
     *
     * @param args  The command line arguments
     */
    public static void main(String[] args)
    {
       AmbientLight             lightA;       
       ApplicationWindow3D      window;
       Appearance               appearance;       
       BranchGroup              scene;
       Color3f                  ambient, diffuse, emissive, specular;       
       DirectionalLight         lightD;       
       Material                 material;       
       SimpleUniverse           universe;
       Sphere                   sphere;
       
       
       window   = new ApplicationWindow3D();
       universe = window.getSimpleUniverse();
       scene = new BranchGroup();
       scene.addChild(new Background(0.0f, 0.0f, 0.0f));
       
       //[material
       // Create colors
       ambient  = new Color3f(0.329f, 0.223f, 0.027f);
       emissive = new Color3f(0.000f, 0.000f, 0.000f);       
       diffuse  = new Color3f(0.780f, 0.569f, 0.113f);
       specular = new Color3f(0.992f, 0.941f, 0.808f);
       
       // Create a Material
       material = new Material(ambient, emissive, diffuse, specular, 28.0f);
       
       // Create an Appearance
       appearance = new Appearance();
       appearance.setMaterial(material);
       //]material
       
       // Create a Sphere
       sphere = new Sphere(0.5f, Sphere.GENERATE_NORMALS, appearance);
       
       // Add the Sphere to the scene
       scene.addChild(sphere);

       //[lights
       // Construct the AmbientLight
       lightA = new AmbientLight();
       lightA.setInfluencingBounds(new BoundingSphere());

       // Add the AmbientLight to the scene
       scene.addChild(lightA);

       // Construct the DirectionalLight
       lightD = new DirectionalLight();
       lightD.setInfluencingBounds(new BoundingSphere());

       // Add the DirectionalLight to the scene
       scene.addChild(lightD);
       //]lights

       scene.compile();
       universe.addBranchGraph(scene);
    }
}
