?? myball.java
字號:
package com.java3d.examples;
import com.sun.j3d.utils.geometry.*;
import com.sun.j3d.utils.universe.*;
import javax.media.j3d.*;
import javax.vecmath.*;
public class myBall {
public myBall() {
// 創建宇宙
SimpleUniverse universe = new SimpleUniverse();
// 創建容納物體的結構
BranchGroup group = new BranchGroup();
// 創建一個球體并加入到物體組
Sphere sphere = new Sphere(0.5f,1,100);
group.addChild(sphere);
// 創建一個從原點延伸100米的紅色光源
Color3f light1Color = new Color3f(1.8f, 0.1f, 0.1f);
BoundingSphere bounds =
new BoundingSphere(new Point3d(0.0,0.0,0.0), 100);
BoundingSphere bounds2 =
new BoundingSphere(new Point3d(0.0,0.0,0.0), 1000);
Vector3f light1Direction = new Vector3f(5.0f, 5.0f, -12.0f);
//定義一組平行光,顏色和方向
DirectionalLight light1 = new DirectionalLight(light1Color, light1Direction);
light1.setInfluencingBounds(bounds);
//加入一環境光
AmbientLight ambientLight = new AmbientLight(new Color3f(1.0f, 1.0f, 1.0f));
ambientLight.setInfluencingBounds(bounds2);
//group.addChild(ambientLight);
group.addChild(light1);
// 注視球體
universe.getViewingPlatform().setNominalViewingTransform();
// 添加物體組到宇宙中
universe.addBranchGraph(group);
}
public static void main(String[] args) { new myBall(); }
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -