next up previous
Next: 6.7 Lightwave Up: 6.6 HelloUniverse Previous: 6.6.1 Interpolator

6.6.2 影響範囲(Bounds)

表示する対象の影響範囲を指定するためにBoundsクラスがあり, BoundingBox, BoundingSphereなどのサブクラスがある. Boundsオブジェクトは,Interpolatorオブジェクトに対して, setSchedulingBoundsで指定する.

/**
<applet align=middle
code="HelloUniverse.class" width=256 height=256>   
</applet>
 */

import java.applet.Applet;
import java.awt.BorderLayout;
import java.awt.event.*;
import java.awt.GraphicsConfiguration;
import com.sun.j3d.utils.applet.MainFrame;
import com.sun.j3d.utils.geometry.ColorCube;
import com.sun.j3d.utils.universe.*;
import javax.media.j3d.*;
import javax.vecmath.*;

public class HelloUniverse extends Applet {

  private SimpleUniverse u = null;
    
  public BranchGroup createSceneGraph() {
    BranchGroup objRoot = new BranchGroup();
    TransformGroup objTrans = new TransformGroup();

    objTrans.setCapability(TransformGroup.
                           ALLOW_TRANSFORM_WRITE);
    objRoot.addChild(objTrans);
    objTrans.addChild(new ColorCube(0.4));
    Transform3D yAxis = new Transform3D();
    Alpha rotationAlpha = new Alpha(-1, 4000);

    RotationInterpolator rotator =
      new RotationInterpolator(rotationAlpha,
                               objTrans, yAxis,
                               0.0f,
                               (float) Math.PI*2.0f);
    BoundingSphere bounds =
      new BoundingSphere(new Point3d(0.0,0.0,0.0),
                         100.0);
    rotator.setSchedulingBounds(bounds);
    objRoot.addChild(rotator);
    objRoot.compile();
    return objRoot;
  }
  public HelloUniverse() {
  }
  public void init() {
    setLayout(new BorderLayout());
    GraphicsConfiguration config =
      SimpleUniverse.getPreferredConfiguration();

    Canvas3D c = new Canvas3D(config);
    add("Center", c);
    BranchGroup scene = createSceneGraph();
    u = new SimpleUniverse(c);
    u.getViewingPlatform().setNominalViewingTransform();
    u.addBranchGraph(scene);
  }
  public void destroy() {
    u.removeAllLocales();
  }
  public static void main(String[] args) {
    new MainFrame(new HelloUniverse(), 256, 256);
  }
}

% javac HelloUniverse.java
% java HelloUniverse
という具合にすれば,図12のような 立方体が現れて,回転を始める.
図 12: HelloUniverse
\includegraphics[width=6.0cm]{/home/inaba/eps/lecture/fig/HelloUniverse.eps}
HelloUniverse.htmlは,下のようになっている.
<HTML>
<HEAD>
<TITLE>Hello, Universe!</TITLE>
</HEAD>
<BODY BGCOLOR="#000000">
<applet align=middle code="HelloUniverse.class"
          width=256 height=256>
<blockquote>
<hr>
If you were using a Java-capable browser,
you would see Hello Universe! instead of this paragraph.
<hr>
</blockquote>
</applet>
</BODY>
</HTML>


generated through LaTeX2HTML. M.Inaba 平成18年5月7日