/*--------------*/ /* Ja75.java */ /*--------------*/ import java.applet.Applet; import java.awt.*; //BorderLayout,GraphicsConfiguration,event import javax.media.j3d.*; //Java3d import com.sun.j3d.utils.applet.MainFrame; //MainFrame import com.sun.j3d.utils.universe.*; //SimpleUniverse import com.sun.j3d.utils.geometry.*; //Primitive import com.sun.j3d.utils.behaviors.mouse.*; //Mouse import com.sun.j3d.utils.image.TextureLoader; //TextureLoader@ import javax.vecmath.*; //Point3f,Color3f public class Ja75 extends Applet { private SimpleUniverse simpleU; private BoundingSphere bounds = new BoundingSphere(new Point3d(), 10.0); public void init() { //アプレットの中央にCanvas3Dを追加 setLayout(new BorderLayout()); Canvas3D canvas = new Canvas3D(SimpleUniverse.getPreferredConfiguration()); add(canvas, BorderLayout.CENTER); //シーングラフの生成 simpleU = new SimpleUniverse(canvas); simpleU.getViewingPlatform().setNominalViewingTransform(); //シーングラフの作成 simpleU.addBranchGraph(createSceneGraph()); } public BranchGroup createSceneGraph() { BranchGroup branchG0 = new BranchGroup(); //背景色の設定(設定が無い場合は黒) Background background = new Background(new Color3f(0.3f, 0.3f, 0.3f)); background.setApplicationBounds(bounds); branchG0.addChild(background); //マウス操作用のノード TransformGroup transG0 = new TransformGroup(); branchG0.addChild(transG0); //Appearanceを作成 Appearance ap = new Appearance(); ColoringAttributes ca = new ColoringAttributes(); ca.setColor(new Color3f( 0.0f, 0.0f, 1.0f)); //青 ap.setColoringAttributes(ca); //テクスチャ java.net.URL texFile = null; try{ texFile = new java.net.URL(getCodeBase().toString() + "diamond128.gif"); }catch(java.net.MalformedURLException ex){ System.out.println(ex.getMessage()); } //テクスチャ座標の自動生成 TexCoordGeneration texGen = new TexCoordGeneration(TexCoordGeneration.OBJECT_LINEAR, // new TexCoordGeneration(TexCoordGeneration.EYE_LINEAR, // new TexCoordGeneration(TexCoordGeneration.SPHERE_MAP, TexCoordGeneration.TEXTURE_COORDINATE_2, new Vector4f(2.0f, 0.0f, 0.0f, 0.0f), new Vector4f(0.0f, 2.0f, 0.0f, 0.0f)); ap.setTexCoordGeneration(texGen); TextureLoader loader = new TextureLoader(texFile, this); Texture texture = loader.getTexture(); ap.setTexture(texture); //円錐の生成 Cone cone = new Cone(0.5f, 1.0f, ap); transG0.addChild(cone); //マウスによる物体移動 transG0.setCapability(TransformGroup.ALLOW_TRANSFORM_READ); transG0.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE); MouseRotate mouseRot = new MouseRotate(transG0); mouseRot.setSchedulingBounds(bounds); transG0.addChild(mouseRot); branchG0.compile(); return branchG0; } public void destroy(){ simpleU.cleanup(); } public static void main(String[] args){ //Application MainFrame frame = new MainFrame(new Ja75(), 512, 512); } }