?? ambientlighttest.java
字號:
import java.applet.Applet;
import java.awt.BorderLayout;
import javax.media.j3d.*;
import javax.vecmath.*;
import com.sun.j3d.utils.applet.MainFrame;
import com.sun.j3d.utils.behaviors.mouse.*;
import com.sun.j3d.utils.geometry.*;
import com.sun.j3d.utils.universe.*;
public class AmbientLightTest extends Applet
{
public BranchGroup createBranchGroup()
{
BranchGroup branchGroupRoot=new BranchGroup();
BoundingSphere bounds=new BoundingSphere(new Point3d(0.0,0.0,0.0),100.0);
AmbientLight light=new AmbientLight(true,new Color3f(0.0f,1.0f,0.0f));
light.setInfluencingBounds(bounds);
branchGroupRoot.addChild(light);
TransformGroup transformGroup=new TransformGroup();
transformGroup.setCapability(TransformGroup.ALLOW_TRANSFORM_READ);
transformGroup.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
branchGroupRoot.addChild(transformGroup);
MouseRotate mouseRotate=new MouseRotate(transformGroup);
mouseRotate.setSchedulingBounds(bounds);
branchGroupRoot.addChild(mouseRotate);
MouseZoom mouseZoom=new MouseZoom(transformGroup);
mouseZoom.setSchedulingBounds(bounds);
branchGroupRoot.addChild(mouseZoom);
MouseTranslate mouseTranslate=new MouseTranslate(transformGroup);
mouseTranslate.setSchedulingBounds(bounds);
branchGroupRoot.addChild(mouseTranslate);
Appearance app=new Appearance();
Material material=new Material();
app.setMaterial(material);
Sphere sphere=new Sphere(0.5f,Sphere.GENERATE_NORMALS,app);
transformGroup.addChild(sphere);
branchGroupRoot.compile();
return branchGroupRoot;
}
public AmbientLightTest()
{
this.setLayout(new BorderLayout());
Canvas3D c=new Canvas3D(SimpleUniverse.getPreferredConfiguration());
this.add(c,"Center");
SimpleUniverse u=new SimpleUniverse(c);
u.getViewingPlatform().setNominalViewingTransform();
u.addBranchGraph(this.createBranchGroup());
}
public static void main(String[] args)
{
new MainFrame(new AmbientLightTest(),300,300);
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -