import javax.media.j3d.*; // Canvas3D etc import java.applet.Applet; // Applet import java.awt.BorderLayout; // BorderLayout, Frame import java.awt.image.*; import java.util.*; import com.sun.j3d.utils.applet.MainFrame; // MainFrame import com.sun.j3d.utils.universe.*; import java.awt.Frame; import com.sun.j3d.utils.behaviors.mouse.*; import javax.vecmath.*; public class Prog5 extends Applet { public Prog5() { setLayout ( new BorderLayout() ); Canvas3D c = new Canvas3D ( null ); add ( "Center", c ); BranchGroup scene = createSceneGraph(); createLights ( scene ); SimpleUniverse u = new SimpleUniverse ( c ); u.getViewingPlatform().setNominalViewingTransform(); u.addBranchGraph ( scene ); } /* from SpinMouse.java */ private TransformGroup defaultMouseGroup() { TransformGroup mouseGroup = new TransformGroup(); mouseGroup.setCapability ( TransformGroup.ALLOW_TRANSFORM_READ ); mouseGroup.setCapability ( TransformGroup.ALLOW_TRANSFORM_WRITE ); BoundingSphere bounds = new BoundingSphere ( new Point3d ( 0.0, 0.0, 0.0 ), 100.0 ); MouseRotate behavior1 = new MouseRotate ( mouseGroup ); mouseGroup.addChild ( behavior1 ); behavior1.setSchedulingBounds ( bounds ); MouseZoom behavior2 = new MouseZoom ( mouseGroup ); mouseGroup.addChild ( behavior2 ); behavior2.setSchedulingBounds ( bounds ); MouseTranslate behavior3 = new MouseTranslate ( mouseGroup ); mouseGroup.addChild ( behavior3 ); behavior3.setSchedulingBounds ( bounds ); return mouseGroup; } /* from Lit.java, lighting off by default? No off if setAppearance(null) */ private void createLights ( BranchGroup graphRoot ) { BoundingSphere bounds = new BoundingSphere ( new Point3d ( 0.0, 0.0, 0.0 ), 100.0 ); Color3f ambientLightColor = new Color3f ( 0.2f, 0.2f, 0.2f ); AmbientLight ambientLight = new AmbientLight ( ambientLightColor ); ambientLight.setInfluencingBounds ( bounds ); graphRoot.addChild ( ambientLight ); Color3f lightColor = new Color3f ( 0.9f, 0.9f, 0.9f ); Vector3f direction = new Vector3f ( 1.0f, 1.0f, -1.0f ); DirectionalLight light1 = new DirectionalLight( lightColor, direction ); light1.setInfluencingBounds ( bounds ); graphRoot.addChild ( light1 ); } private BranchGroup createSceneGraph() { BranchGroup objRoot = new BranchGroup(); //Transform3D spin = new Transform3D(); //Transform3D tempspin = new Transform3D(); //spin.rotX ( Math.PI/4.0 ); //tempspin.rotY ( Math.PI/5.0 ); //spin.mul ( tempspin ); //TransformGroup objTrans = new TransformGroup ( spin ); TransformGroup objTrans = defaultMouseGroup(); objRoot.addChild ( objTrans ); TexTetra x = new TexTetra(this); objTrans.addChild ( x ); return objRoot; } /* private Texture createTexture() { int height = 64; int width = 64; int type = BufferedImage.TYPE_INT_RGB; BufferedImage bufferedImage = new BufferedImage( width, height, type ); WritableRaster writableRaster = bufferedImage.getRaster(); int red = 255<<24 + 255<<16 + 0<<8 + 0<<0; int green = 255<<24 + 0<<16 + 255<<8 + 0<<0; int blue = 255<<24 + 0<<16 + 0<<8 + 255<<0; int color = blue; for ( int i = 0; i < width; i++ ) for ( int j = 0; j < width; j++ ) { if ( color == blue ) color = red; else if ( color == red ) color = green; else if ( color == green ) color = blue; writableRaster.setSample ( i, j, 0, color ); //band 0 } int imageFormat = ImageComponent.FORMAT_RGB8; ImageComponent2D image = new ImageComponent2D ( imageFormat, bufferedImage ); int texFormat = Texture.RGB; int mode = Texture.BASE_LEVEL; Texture2D tex = new Texture2D ( mode, texFormat, width, height ); int level = 0; tex.setImage ( level, image ); return tex; } */ public static void main ( String[] args ) { Frame frame = new MainFrame ( new Prog5(), 256, 256 ); } }