📄 ball.java
字号:
import com.sun.j3d.utils.geometry.*;
import com.sun.j3d.utils.universe.*;
import javax.media.j3d.*;
import javax.vecmath.*;
public class Ball {
public Ball(){
SimpleUniverse universe=new SimpleUniverse(); //创建宇宙
BranchGroup group=new BranchGroup(); //创建容纳物体的结构
Sphere sphere=new Sphere(0.5f); //创建一个球体并加入到物体组
group.addChild(sphere);
Color3f light1Color=new Color3f(1.8f,0.1f,0.1f); //创建一个从在点延伸100米的红色光源
BoundingSphere bounds=new BoundingSphere(new Point3d(0.0,0.0,0.0),100.0);
Vector3f light1Direction=new Vector3f(4.0f,-7.0f,-12.0f);
DirectionalLight light1=new DirectionalLight(light1Color,light1Direction);
light1.setInfluencingBounds(bounds);
group.addChild(light1);
universe.getViewingPlatform().setNominalViewingTransform(); // 注视球体
universe.addBranchGraph(group);
}
public static void main(String[] args){new Ball();}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -