ball.java
来自「有关于java 3D的一些编程」· Java 代码 · 共 24 行
JAVA
24 行
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 + =
减小字号Ctrl + -
显示快捷键?