2008年5月27日火曜日

【Java】 Java3Dで背景に画像(イメージ)を設定する方法

Java3Dで背景に画像を使う方法。

Background#setImageを使う。
このメソッドはImageComponent2Dを引数に取る。
ImageComponent2DはBufferedImageを読み込むことができる。
よって、画像をBufferedImageに変換する必要がある。

1. ImageからBufferedImageへ


BufferedImage buf = new BufferedImage(image.getWidth(null), image
.getHeight(null), BufferedImage.TYPE_3BYTE_BGR);
buf.createGraphics().drawImage(image, 0, 0, null);



2. Backgroundオブジェクトに画像書き込み許可を与えて、画像をセットする。


...
mSchedulingBounds = new BoundingSphere(new Point3d(0.0, 0.0, 0.0),
1000000.0);
...
Background mBackground = new Background();
mBackground.setApplicationBounds(mSchedulingBounds);
mBackground.setCapability(Background.ALLOW_IMAGE_WRITE);
mBackground.setImage(new ImageComponent2D(ImageComponent.FORMAT_RGB,
buf));
...
BranchGroup root = new BranchGroup();
...
root.addChild(mBackground);
...


ラベル:

0 件のコメント:

コメントを投稿

登録 コメントの投稿 [Atom]

この投稿へのリンク:

リンクを作成

<< ホーム