/***************************************/ // // ColorCubeをY軸を中心に回転させる // /***************************************/ /*・・・・・・・・・・・・・・・・・・・・ プログラムに必要なパッケージの取り込み ・・・・・・・・・・・・・・・・・・・・*/ import java.applet.*; import java.awt.*; import javax.media.j3d.*; import javax.vecmath.*; import com.sun.j3d.utils.universe.*; import com.sun.j3d.utils.geometry.*; import com.sun.j3d.utils.applet.MainFrame; /*・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・ アプレットの作成 ・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・*/ public class AnimationColorCube_rotY extends Applet implements Runnable{ Transform3D transform3D = new Transform3D(); TransformGroup transformGroup = new TransformGroup(); Canvas3D canvas3D = new Canvas3D(SimpleUniverse.getPreferredConfiguration()); BorderLayout borderLayout = new BorderLayout( ); SimpleUniverse simpleUniverse = new SimpleUniverse( canvas3D ); BranchGroup objRoot = new BranchGroup( ); BoundingSphere boundingSphere = new BoundingSphere(); //DirectionalLight directionalLight = new DirectionalLight( ); //Appearance appearance = new Appearance( ); //Material material = new Material( ); //Sphere sphere = new Sphere( 0.1f, Sphere.GENERATE_NORMALS, appearance ); ColorCube colorCube = new ColorCube(0.2); Thread th; public AnimationColorCube_rotY( ){ transformGroup.setCapability(TransformGroup.ALLOW_TRANSFORM_READ); transformGroup.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE); this.setLayout( borderLayout ); this.add( canvas3D, BorderLayout.CENTER ); simpleUniverse.getViewingPlatform( ).setNominalViewingTransform( ); // directionalLight.setInfluencingBounds( boundingSphere ); // objRoot.addChild( directionalLight ); // appearance.setMaterial( material ); transform3D.rotY( 0.0); transformGroup.setTransform( transform3D ); // transformGroup.addChild( sphere ); transformGroup.addChild( colorCube ); objRoot.addChild( transformGroup ); simpleUniverse.addBranchGraph( objRoot ); th = new Thread(this); th.start(); } //end of public AnimationColorCube_rotY() /*・・・・・・・・・・・・・・・・・・・・・・・ 作成したクラスファイルの呼び出し ・・・・・・・・・・・・・・・・・・・・・・・*/ public static void main( String[ ] argV ){ AnimationColorCube_rotY AnimationColorCube_rotY = new AnimationColorCube_rotY( ); MainFrame mainFrame = new MainFrame( AnimationColorCube_rotY, 500, 500 ); } //end of main // この部分にアニメーションを書く public void run(){ int t; double r = 0.0; for(t=0; t<4000; t++){ // ○○回繰り返す r = r + 0.01; //回転角度の計算 try { transform3D.rotY( r ); transformGroup.setTransform( transform3D ); Thread.sleep(10); } catch(InterruptedException e) { } }//end of for(t=0; t<=100; t++) }//end of public void run() }