アットウィキロゴ

JAVA45

import javax.media.j3d.*;
import com.sun.j3d.utils.universe.*;
import com.sun.j3d.utils.geometry.Box;
import javax.vecmath.*;
import java.awt.*;
import javax.swing.*;
public class ex45
{

/
public static void main(String[] args)
{
  ex45 test = new ex45();
}

public ex45()
{
  JFrame frame = new JFrame();
  frame.setSize(500,500);
  frame.setTitle("ex45");
  frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  JPanel cp = new JPanel();
  cp.setLayout(null);
  frame.add(cp);


  //============================================================================
  //次にJava3D関係の設定。
  //============================================================================

  GraphicsConfiguration g_config = SimpleUniverse.getPreferredConfiguration();
  Canvas3D canvas = new Canvas3D(g_config);
  canvas.setBounds(0,0,250,250);
  cp.add(canvas);


  //============================================================================
  //空のSimpleUniverseを生成。
  //============================================================================

  SimpleUniverse universe = new SimpleUniverse(canvas);
  frame.setVisible(true);


  //============================================================================
  //視点の設定
  //============================================================================
  ViewingPlatform camera = universe.getViewingPlatform();
  camera.setNominalViewingTransform();


  //============================================================================
  //ライトの設定
  //============================================================================

  Color3f light_color = new Color3f(1.7f,1.7f,1.7f);
  Vector3f light_direction = new Vector3f(0.2f,-0.2f,-0.6f);
  DirectionalLight light = new DirectionalLight(light_color,light_direction);
  BoundingSphere bounds = new BoundingSphere();
  light.setInfluencingBounds(bounds);
  BranchGroup group2 = new BranchGroup();
  group2.addChild(light);
  universe.addBranchGraph(group2);
  Appearance appearance = new Appearance();
  Material material = new Material();

  //DiffuseColorを設定します。引数は順に赤、緑、青です。今回はうすい紫色・・・。
  material.setDiffuseColor(0.3f,0.3f,0.6f);

  appearance.setMaterial(material);
  BranchGroup group1 = new BranchGroup();

  //y方向の寸法を、前回の半分にしてみます。
  Box box = new Box(0.5f,0.25f,0.5f,appearance);
  group1.addChild(box);
  universe.addBranchGraph(group1);

}

}
最終更新:2010年01月06日 16:17