アットウィキロゴ

JAVA 64 64 64

//******************************************************************************
//Java3D Light_test
//ライトを追加
//******************************************************************************


//==============================================================================
//インポート・ファイル
import javax.media.j3d.*;

import com.sun.j3d.utils.universe.*;
import com.sun.j3d.utils.geometry.*;
import javax.vecmath.*;

import java.awt.*;

import javax.swing.*;



//==============================================================================
//メイン・クラス
public class Light_test
{

//=============================================================================
//メイン・メソッド
public static void main(String[] args)
{
  Light_test test = new Light_test();
}


//=============================================================================
//コンストラクタ
public Light_test()
{

  //============================================================================
  //まずは、基礎フレームの設定。
  //============================================================================

  JFrame frame = new JFrame();
  frame.setSize(250,250);
  frame.setTitle("Light_test");
  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);


  //============================================================================
  //SimpleUniverseにSphereを追加
  //============================================================================

  BranchGroup group1 = new BranchGroup();
  Sphere sphere = new Sphere(0.5f);
  group1.addChild(sphere);
  universe.addBranchGraph(group1);


  //============================================================================
  //視点の設定
  //============================================================================
  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を作る
  BranchGroup group2 = new BranchGroup();

  //ライトをBranchGroupへ登録
  group2.addChild(light);

  //ライトのためのブランチ・グループを仮想空間へ登録
  universe.addBranchGraph(group2);

}

}
//ソースコードここまで。
//******************************************************************************
最終更新:2010年01月06日 15:16