1:import java.applet.Applet;
   2:import java.awt.*;
   3:import com.sun.j3d.utils.applet.MainFrame;
   4:import com.sun.j3d.utils.universe.*;
   5:import com.sun.j3d.utils.geometry.*;
   6:import com.sun.j3d.utils.behaviors.mouse.*;
   7:import javax.media.j3d.*;
   8:import javax.vecmath.*;
   9:import javax.media.j3d.*;
  10:
  11:public class Simple4 extends Applet{
  12:        
  13:        public Simple4() {
  14:                setLayout(new BorderLayout());
  15:                GraphicsConfiguration config = SimpleUniverse.getPreferredConfiguration();
  16:                Canvas3D canvas3d = new Canvas3D(config);
  17:                add("Center", canvas3d);
  18:                BranchGroup scene = createSceneGraph();
  19:                SimpleUniverse sU = new SimpleUniverse(canvas3d);
  20:                sU.getViewingPlatform().setNominalViewingTransform();
  21:                sU.addBranchGraph(scene);
  22:        }       //end of Simple4 (constructor)
  23:        
  24:        public BranchGroup createSceneGraph(){
  25:                BranchGroup objRoot = new BranchGroup();
  26:                Transform3D scaleTransform = new Transform3D(   
  27:                                                        new Matrix3f(1.0f,0.0f,0.0f,0.0f,1.0f, 0.0f,0.0f,0.0f,1.0f), //rotation
  28:                                                        new Vector3d(), //tranlation
  29:                                                        0.5); //scaling
  30:                TransformGroup objScale = new TransformGroup(scaleTransform);
  31:                
  32:                TransformGroup objRotate = new TransformGroup();
  33:                objRotate.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
  34:                objRotate.setCapability(TransformGroup.ALLOW_TRANSFORM_READ);
  35:                
  36:                
  37:                objRoot.addChild(objScale);
  38:                objScale.addChild(objRotate);
  39:                objRotate.addChild(new AppearanceTestCube());
  40:                
  41:                MouseRotate mR = new MouseRotate();
  42:                mR.setTransformGroup(objRotate);
  43:                mR.setSchedulingBounds(new BoundingSphere());
  44:                objRoot.addChild(mR);
  45:                
  46:                MouseZoom mZ = new MouseZoom();
  47:                mZ.setTransformGroup(objRotate);
  48:                mZ.setSchedulingBounds(new BoundingSphere());
  49:                objRoot.addChild(mZ);
  50:                
  51:                
  52:                //Create ambient light
  53:                AmbientLight amb = new AmbientLight(new Color3f(1.0f,1.0f,1.0f));
  54:                amb.setInfluencingBounds(new BoundingSphere());
  55:                objScale.addChild(amb);
  56:                
  57:                
  58:                // Create the directional light
  59:                Color3f white = new Color3f(1.0f,  1.0f,  1.0f);
  60:                Vector3f dir = new Vector3f(-1.0f, -1.0f, -1.0f);
  61:                DirectionalLight dirLight = new DirectionalLight(white, dir);
  62:                dirLight.setInfluencingBounds(new BoundingSphere());
  63:                objScale.addChild(dirLight);
  64:                
  65:                objRoot.compile();
  66:                
  67:                return objRoot;
  68:        }       //end of createSceneGraph method of Simple4
  69:        
  70:        public static void main(String[] args){
  71:                Frame frame = new MainFrame(new Simple4(), 256, 256);
  72:        }       //end of main methof of Simple4
  73:        
  74:}       //end of Simple4 (class)
previous  start  toc  next