import com.sun.j3d.utils.geometry.*;
import com.sun.j3d.utils.universe.*;
import com.sun.j3d.utils.image.*;
import javax.media.j3d.*;
import javax.vecmath.*;
import java.awt.Container;

public class Bug {

  public Bug() {

    // Create the universe
    SimpleUniverse universe = new SimpleUniverse();

    // Create a structure to contain objects
    BranchGroup group = new BranchGroup();

    // Create a ball and an appearance
    Sphere sphere = new Sphere(0.5f);
    Appearance ap = new Appearance();
    
    // Globally used colors
	Color3f black = new Color3f(0.0f, 0.0f, 0.0f);
    Color3f red = new Color3f(0.7f, .15f, .15f);
    	
    // Set up the texture 
	TextureLoader loader = new TextureLoader("K:\\3d\\whitmarb.gif", new Container());
	Texture texture = loader.getTexture();
	texture.setBoundaryModeS(Texture.WRAP);
	texture.setBoundaryModeT(Texture.WRAP);
	texture.setBoundaryColor( new Color4f( 0.0f, 1.0f, 0.0f, 0.0f ) );
		
	TextureAttributes texAttr = new TextureAttributes();
 	texAttr.setTextureMode(TextureAttributes.MODULATE);
 	ap.setTextureAttributes(texAttr);
	ap.setTexture(texture);

	// Set up the material properties
	ap.setMaterial(new Material(red, black, red, black, 1.0f));

    sphere.setAppearance(ap);    
    group.addChild(sphere);

    // Create a white light that shines for 100m from the origin
    Color3f light1Color = new Color3f(1f, 1f, 1f);
    BoundingSphere bounds =
	    new BoundingSphere(new Point3d(0.0,0.0,0.0), 100.0);
    // more lights
    Vector3f light1Direction  = new Vector3f(4.0f, -7.0f, -12.0f);
    DirectionalLight light1
      = new DirectionalLight(light1Color, light1Direction);
    light1.setInfluencingBounds(bounds);
    group.addChild(light1);
    
    AmbientLight ambientLight = new AmbientLight(new Color3f(.5f, .5f, .5f));
    ambientLight.setInfluencingBounds(bounds);
    group.addChild(ambientLight);
    
    // blue background
    Color3f bgColor = new Color3f(0.05f, 0.05f, 0.5f);
    Background bgNode = new Background(bgColor) ;
    bgNode.setApplicationBounds(bounds) ;
    group.addChild(bgNode) ;
    
    // look towards the ball
    universe.getViewingPlatform().setNominalViewingTransform();

    // add the group of objects to the Universe
    universe.addBranchGraph(group);
}
  public static void main(String[] args) {
    new Bug();
  }
}
